Skip to contentSkip to conversation

ltrace: Add test cases for command ltrace.

PATCH Superseded Wang Mingyu 1 participant 1 message Sep 18, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ltrace: Add test cases for command ltrace.

ltrace is a program that simply runs the specified command until it exits.
This test set is used to check the ountput syscall/time/count/help of command to trace and check if can be saved to file.

---
 tests/Functional.ltrace/fuego_test.sh           | 17 +++++++++++++++++
 tests/Functional.ltrace/ltrace_test.sh          |  4 ++++
 tests/Functional.ltrace/spec.json               |  6 ++++++
 tests/Functional.ltrace/tests/ltrace_count.sh   | 16 ++++++++++++++++
 tests/Functional.ltrace/tests/ltrace_help.sh    | 13 +++++++++++++
 tests/Functional.ltrace/tests/ltrace_output.sh  | 16 ++++++++++++++++
 tests/Functional.ltrace/tests/ltrace_syscall.sh | 16 ++++++++++++++++
 tests/Functional.ltrace/tests/ltrace_time.sh    | 16 ++++++++++++++++
 8 files changed, 104 insertions(+)
 create mode 100644 tests/Functional.ltrace/fuego_test.sh
 create mode 100755 tests/Functional.ltrace/ltrace_test.sh
 create mode 100644 tests/Functional.ltrace/spec.json
 create mode 100644 tests/Functional.ltrace/tests/ltrace_count.sh
 create mode 100644 tests/Functional.ltrace/tests/ltrace_help.sh
 create mode 100644 tests/Functional.ltrace/tests/ltrace_output.sh
 create mode 100644 tests/Functional.ltrace/tests/ltrace_syscall.sh
 create mode 100644 tests/Functional.ltrace/tests/ltrace_time.sh
tests/Functional.ltrace/fuego_test.sh new file +17 -0
new file mode 100644
index 0000000..ecfc4e7
@@ -0,0 +1,17 @@
+function test_pre_check {
+    assert_has_program ltrace
+}
+
+function test_deploy {
+    put $TEST_HOME/ltrace_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    ./ltrace_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.ltrace/ltrace_test.sh new file +4 -0
new file mode 100755
index 0000000..dd5ce37
@@ -0,0 +1,4 @@
+#!/bin/sh
+for i in tests/*.sh; do
+    sh $i
+done
tests/Functional.ltrace/spec.json new file +6 -0
new file mode 100644
index 0000000..fce7a19
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.ltrace",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.ltrace/tests/ltrace_count.sh new file +16 -0
new file mode 100644
index 0000000..f0caabf
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run comannd ltrace to count time and calls.
+#  option: -c
+
+test="count"
+
+rm log_for_foego || true
+ltrace -c dd if=/dev/urandom of=/dev/null count=1000 > log_for_foego 2>&1
+if grep "usecs/call" log_for_foego
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm log_for_foego
tests/Functional.ltrace/tests/ltrace_help.sh new file +13 -0
new file mode 100644
index 0000000..ea45a7e
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+#  In target, run comannd ltrace to display help message.
+#  option: -h/--help
+
+test="help"
+
+if ltrace -h | grep [uU]sage
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
tests/Functional.ltrace/tests/ltrace_output.sh new file +16 -0
new file mode 100644
index 0000000..7343272
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  Write the trace output to the file filename rather than to stderr.
+#  option: -o/--output
+
+test="output"
+
+rm log_for_foego || true
+ltrace -o log_for_foego ls
+if grep "+++ exited (status 0) +++" log_for_foego
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm log_for_foego
tests/Functional.ltrace/tests/ltrace_syscall.sh new file +16 -0
new file mode 100644
index 0000000..d079470
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run comannd ltrace to display system calls.
+#  option: -S
+
+test="syscall"
+
+rm log_for_foego || true
+ltrace -S ls > log_for_foego 2>&1
+if grep "getdents" log_for_foego
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm log_for_foego
tests/Functional.ltrace/tests/ltrace_time.sh new file +16 -0
new file mode 100644
index 0000000..565a2a6
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#  In target, run comannd ltrace to show the time spent inside each call.
+#  option: -T
+
+test="time"
+
+rm log_for_foego || true
+ltrace -T ls > log_for_foego 2>&1
+if grep "<[0-9].[0-9]\{6\}>" log_for_foego
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+rm log_for_foego
Signature · 1 line
2.17.1