Add tests cases for expected output
authorSofian Brabez <sbz@FreeBSD.org>
Thu, 16 Apr 2020 23:25:20 +0000 (01:25 +0200)
committerSofian Brabez <sbz@FreeBSD.org>
Fri, 17 Apr 2020 00:33:53 +0000 (02:33 +0200)
Use [kyua](https://github.com/jmmv/kyua) FreeBSD test suite framework to
add elfdbg test cases to cover with symbols and without symbols.

The FreeBSD test suite framework require a Kyuafile and to declare the
AFT test case. Everything is documented in kyua(1), atf(7) and tests(7)
man pages.

Makefile
tests/Kyuafile [new file with mode: 0644]
tests/elfdbg_test.sh [new file with mode: 0755]
tests/test_helper.sh [new file with mode: 0644]

index 6a93b2875dcee99a35fa93596698721a5dd7b391..1d4c2c68a1c6c49ee7540ab7f8753d099812a7e2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,4 +9,7 @@ SRCS=   elfdbg.c
 
 LDADD= -lelf
 
+test:
+       @(cd tests && kyua test && kyua report)
+
 .include <bsd.prog.mk>
diff --git a/tests/Kyuafile b/tests/Kyuafile
new file mode 100644 (file)
index 0000000..c456599
--- /dev/null
@@ -0,0 +1,5 @@
+syntax(2)
+
+test_suite('elfdbg')
+
+atf_test_program{name='elfdbg_test.sh'}
diff --git a/tests/elfdbg_test.sh b/tests/elfdbg_test.sh
new file mode 100755 (executable)
index 0000000..5fd3a7a
--- /dev/null
@@ -0,0 +1,59 @@
+#! /usr/bin/env atf-sh
+
+. $(atf_get_srcdir)/test_helper.sh
+
+atf_test_case stripped
+
+stripped_head()
+{
+    atf_set "descr" "ELF binary test without debug symbols"
+
+}
+
+stripped_body()
+{
+    generate_bin_nodbg
+
+    out=$(elfdbg bin)
+    expected="NO DEBUG"
+    if [ "$out" == "$expected" ]; then
+        atf_pass
+    else
+        atf_fail "Wrong output w/o debug symbols"
+    fi
+}
+
+stripped_cleanup()
+{
+    rm -rf bin bin.c
+}
+
+atf_test_case not_stripped
+
+not_stripped_head()
+{
+    atf_set "descr" "ELF binary test with debug symbols"
+}
+not_stripped_body()
+{
+    generate_bin_dbg
+
+    out=$(elfdbg bin)
+    expected="HAS DEBUG"
+    if [ "$out" == "$expected" ]; then
+        atf_pass
+    else
+        atf_fail "Wrong output w/ debug symbols"
+    fi
+}
+
+not_stripped_cleanup()
+{
+    rm -rf bin bin.c
+}
+
+atf_init_test_cases()
+{
+    atf_add_test_case stripped
+    atf_add_test_case not_stripped
+}
diff --git a/tests/test_helper.sh b/tests/test_helper.sh
new file mode 100644 (file)
index 0000000..9eab858
--- /dev/null
@@ -0,0 +1,23 @@
+generate_bin_nodbg()
+{
+       cat > bin.c << EOF
+int
+main(void) {
+    return (0);
+}
+EOF
+       /usr/bin/cc -o bin bin.c
+    /usr/bin/strip bin
+}
+
+generate_bin_dbg()
+{
+       cat > bin.c << EOF
+int
+main(void) {
+    return (0);
+}
+EOF
+       /usr/bin/cc -g -o bin bin.c
+}
+