[Ltrace-devel] [PATCH 11/11] Add a simple libdl test
Joe Damato
ice799 at gmail.com
Mon Nov 8 23:47:44 UTC 2010
---
.gitignore | 1 +
testsuite/ltrace.minor/libdl-simple-lib.c | 4 ++
testsuite/ltrace.minor/libdl-simple.c | 24 +++++++++++++
testsuite/ltrace.minor/libdl-simple.exp | 52 +++++++++++++++++++++++++++++
4 files changed, 81 insertions(+), 0 deletions(-)
create mode 100644 testsuite/ltrace.minor/libdl-simple-lib.c
create mode 100644 testsuite/ltrace.minor/libdl-simple.c
create mode 100644 testsuite/ltrace.minor/libdl-simple.exp
diff --git a/.gitignore b/.gitignore
index 14278c3..099141f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@ testsuite/ltrace.main/system_calls
testsuite/ltrace.minor/attach-process
testsuite/ltrace.minor/count-record
testsuite/ltrace.minor/demangle
+testsuite/ltrace.minor/libdl-simple
testsuite/ltrace.minor/print-instruction-pointer
testsuite/ltrace.minor/time-record-T
testsuite/ltrace.minor/time-record-tt
diff --git a/testsuite/ltrace.minor/libdl-simple-lib.c b/testsuite/ltrace.minor/libdl-simple-lib.c
new file mode 100644
index 0000000..6340d9d
--- /dev/null
+++ b/testsuite/ltrace.minor/libdl-simple-lib.c
@@ -0,0 +1,4 @@
+int test_libdl(int x)
+{
+ return x * 1337;
+}
diff --git a/testsuite/ltrace.minor/libdl-simple.c b/testsuite/ltrace.minor/libdl-simple.c
new file mode 100644
index 0000000..0bef5cf
--- /dev/null
+++ b/testsuite/ltrace.minor/libdl-simple.c
@@ -0,0 +1,24 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+int main(int argc, char **argv) {
+ void *handle;
+ int (*test)(int);
+ char *error;
+
+ handle = dlopen ("liblibdl-simple.so", RTLD_LAZY);
+ if (!handle) {
+ fputs (dlerror(), stderr);
+ exit(1);
+ }
+
+ test = dlsym(handle, "test_libdl");
+ if ((error = dlerror()) != NULL) {
+ fputs(error, stderr);
+ exit(1);
+ }
+
+ printf("%d\n", test(5));
+ dlclose(handle);
+}
diff --git a/testsuite/ltrace.minor/libdl-simple.exp b/testsuite/ltrace.minor/libdl-simple.exp
new file mode 100644
index 0000000..dac7a09
--- /dev/null
+++ b/testsuite/ltrace.minor/libdl-simple.exp
@@ -0,0 +1,52 @@
+set testfile "libdl-simple"
+set srcfile ${testfile}.c
+set binfile ${testfile}
+set libfile "libdl-simple-lib"
+set libsrc $srcdir/$subdir/$libfile.c
+set lib_sl $objdir/$subdir/lib$testfile.so
+
+verbose "compiling source file now....."
+# Build the shared libraries this test case needs.
+if { [ltrace_compile_shlib $libsrc $lib_sl [debug]] != ""
+ || [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug shlib=/usr/lib/libdl.so} ] != "" } {
+ send_user "Testcase compile failed, so all tests in this file will automatically fail.\n"
+}
+
+# set options for ltrace.
+ltrace_options "-x" "test_libdl"
+
+# Run PUT for ltrace.
+set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
+verbose "ltrace runtest output: $exec_output\n"
+
+# Check the output of this program.
+if [regexp {ELF from incompatible architecture} $exec_output] {
+ fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!"
+ return
+} elseif [ regexp {Couldn't get .hash data} $exec_output ] {
+ fail "Couldn't get .hash data!"
+ return
+}
+
+# Verify the time for calling sleep.
+set fd [ open $objdir/$subdir/$binfile.ltrace r]
+set FOUND 0
+while { [gets $fd line] >= 0 } {
+ # match the line with sleep and extract the spent time in sleep and sleep argument.
+ if [ regexp {(test_libdl)\(} $line match tester ] then {
+ verbose "test_libdl = $tester"
+
+ if { $tester == "test_libdl" } then {
+ pass "Successfully traced libdl loaded function."
+ } else {
+ fail "Failed to trace libdl loaded function."
+ }
+ set FOUND 1
+ break
+ }
+}
+close $fd
+
+if {$FOUND != 1} then {
+ fail "Fail to trace libdl loaded function!"
+}
--
1.7.0.4
More information about the Ltrace-devel
mailing list