[ltrace-commits] 04/06: Test suite for the DWARF functionality
Petr Machata
pmachata-guest at moszumanska.debian.org
Tue Sep 2 13:26:54 UTC 2014
This is an automated email from the git hooks/post-receive script.
pmachata-guest pushed a commit to branch pmachata/dima-rebase
in repository ltrace.
commit b9500ecd60554a180fb06b9aabb7ddca874f5ebf
Author: Petr Machata <pmachata at redhat.com>
Date: Tue Sep 2 15:21:59 2014 +0200
Test suite for the DWARF functionality
This was written by Dima Kogan <dima at secretsauce.net>.
---
testsuite/ltrace.main/Makefile.am | 7 +-
testsuite/ltrace.main/dwarf.c | 56 +++++++++++++
testsuite/ltrace.main/dwarf.conf | 5 ++
testsuite/ltrace.main/dwarf.exp | 139 ++++++++++++++++++++++++++++++++
testsuite/ltrace.main/dwarflib.c | 80 ++++++++++++++++++
testsuite/ltrace.main/dwarflib.h | 56 +++++++++++++
testsuite/ltrace.main/dwarflib_cxx.cc11 | 21 +++++
testsuite/ltrace.main/dwarflib_cxx.hh | 10 +++
8 files changed, 372 insertions(+), 2 deletions(-)
diff --git a/testsuite/ltrace.main/Makefile.am b/testsuite/ltrace.main/Makefile.am
index 12bbb9b..23ab8ab 100644
--- a/testsuite/ltrace.main/Makefile.am
+++ b/testsuite/ltrace.main/Makefile.am
@@ -20,9 +20,12 @@ EXTRA_DIST = branch_func.c branch_func.exp filters.exp hello-vfork.c \
main-threaded.c main-threaded.exp main-vfork.c main-vfork.exp \
parameters.c parameters.conf parameters.exp parameters-lib.c \
parameters2.exp parameters3.exp signals.c signals.exp \
- system_calls.c system_calls.exp system_call_params.exp
+ system_calls.c system_calls.exp system_call_params.exp \
+ dwarf.conf dwarf.exp dwarf.c dwarflib.c dwarflib.h \
+ dwarflib_cxx.cc11 dwarflib_cxx.hh
+
CLEANFILES = *.o *.so *.log *.sum *.ltrace setval.tmp \
- main main-internal parameters signals system_calls
+ main main-internal parameters signals system_calls dwarf
MAINTAINERCLEANFILES = Makefile.in
diff --git a/testsuite/ltrace.main/dwarf.c b/testsuite/ltrace.main/dwarf.c
new file mode 100644
index 0000000..82a5ddb
--- /dev/null
+++ b/testsuite/ltrace.main/dwarf.c
@@ -0,0 +1,56 @@
+#include "dwarflib.h"
+#include "dwarflib_cxx.hh"
+#include <unistd.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <time.h>
+
+void main(void)
+{
+ struct list l = { .x = 5, .next = NULL };
+ linkedlisttest( &l );
+
+ struct tree d = {.x = 4};
+ struct tree c = {.x = 3, .right = &d};
+ struct tree b = {.x = 2};
+ struct tree a = {.x = 1, .left = &b, .right = &c};
+ treetest( &a );
+
+ struct loop_a la = {.x = 5};
+ struct loop_b lb = {.x = 6};
+ la.b = &lb;
+ lb.a = &la;
+ looptest(&la);
+
+ enum E ea = A, eb = B;
+ enumtest( ea, eb );
+
+#ifndef UNIONTEST_DISABLE
+ union U u1 = {.a = 5};
+ union U u2 = {.a = 6};
+ uniontest( u1, u2 );
+#endif
+
+ struct witharray s = {.x = {1.0,2.0,1.0,2.0,1.0}};
+ arraytest( &s );
+
+#ifndef COMPLEXTEST_DISABLE
+ float complex x = 3 + 4*I;
+ complextest(&x);
+#endif
+
+ enum_cxx_test();
+
+ stringtest("test");
+ stringtest(NULL);
+
+ FILEtest( stdout, stderr );
+
+ voidfunc();
+
+ // tests aliased symbols. On my amd64 Debian/sid box this generates a
+ // reference to nanosleep, while the debug symbols have __nanosleep and
+ // __GI___nanosleep
+ usleep(33);
+ nanosleep(&(struct timespec){.tv_nsec = 44}, NULL);
+}
diff --git a/testsuite/ltrace.main/dwarf.conf b/testsuite/ltrace.main/dwarf.conf
new file mode 100644
index 0000000..8019032
--- /dev/null
+++ b/testsuite/ltrace.main/dwarf.conf
@@ -0,0 +1,5 @@
+# necessary because following the DWARF definition of FILE eventually gets to a
+# void argument, and ltrace does an assert(0) when trying to print it. The
+# details of FILE are unimportant anyway, so printing just its address is fine,
+# which is what this config does
+typedef _IO_FILE = void;
diff --git a/testsuite/ltrace.main/dwarf.exp b/testsuite/ltrace.main/dwarf.exp
new file mode 100644
index 0000000..1cf014b
--- /dev/null
+++ b/testsuite/ltrace.main/dwarf.exp
@@ -0,0 +1,139 @@
+# This file was written by Dima Kogan <dima at secretsauce.net>
+#
+# Copyright (C) 2014 Dima Kogan
+#
+# Same license as ltrace itself: GPL version 2 or later
+
+proc run_dwarf_test {ref_output ltrace_opts} {
+
+ global srcdir subdir objdir
+
+ set srcfile dwarf.c
+ set binfile dwarf
+ set libsrc "$srcdir/$subdir/dwarflib.c $srcdir/$subdir/dwarflib_cxx.cc11"
+ set lib_so_basename libdwarftest.so
+ set lib_so $objdir/$subdir/$lib_so_basename
+
+ if [get_compiler_info $binfile] {
+ return -1
+ }
+
+ verbose "compiling source file now....."
+ if { [ltrace_compile_shlib $libsrc $lib_so debug ] != ""
+ || [ltrace_compile $srcdir/$subdir/$srcfile $objdir/$subdir/$binfile executable [list debug shlib=$lib_so] ] != ""} {
+ send_user "Build failed!\n"
+ } else {
+ ltrace_options "-F" "ltrace.main/dwarf.conf" {*}$ltrace_opts
+ set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
+
+ # Check the output of this program.
+ verbose "ltrace runtest output: $exec_output\n"
+ 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
+ }
+
+ foreach pattern_line [ split $ref_output "\n"] {
+ ltrace_verify_output ${objdir}/${subdir}/${binfile}.ltrace $pattern_line 1
+ }
+ }
+}
+
+
+
+
+
+set ltrace_opts_l {"-A5" "-l" "libdwarftest.so"}
+set ref_output_l [subst -nocommands -novariables {
+dwarf->linkedlisttest({ 5, nil }) * = <void>
+dwarf->treetest({ 1, { 2, nil, nil }, { 3, nil, { 4, nil, nil } } } <unfinished ...>
+libdwarftest.so->treetest({ 2, nil, nil }) * = nil
+libdwarftest.so->treetest({ 3, nil, { 4, nil, nil } } <unfinished ...>
+libdwarftest.so->treetest({ 4, nil, nil }) * = nil
+<... treetest resumed> ) * = { 5, nil, nil }
+<... treetest resumed> ) * = { 2, { 3, nil, nil }, { 4, nil, { 5, nil, nil } } }
+dwarf->looptest({ { recurse^, 6 }, 5 }) * = <void>
+dwarf->enumtest(A, B) * = 0
+dwarf->arraytest(.* 1.000000, 2.000000, 1.000000, 2.000000, 1.000000 [^\\\.]* * = 1.000000
+dwarf->enum_cxx_test( <unfinished ...>
+libdwarftest.so->_Z3f127Colors2(GREEN2) * = RED1
+libdwarftest.so->_Z3f347Colors4(BLUE4) * = RED3
+libdwarftest.so->_Z3f557Colors5(RED5) * = RED5
+<... enum_cxx_test resumed> ) * = <void>
+dwarf->stringtest('t') * = 4
+dwarf->stringtest(nil) * = -1
+dwarf->FILEtest(0x[0-9a-z]*, 0x[0-9a-z]*) * = <void>
+dwarf->voidfunc() * = <void>
+} ]
+run_dwarf_test $ref_output_l $ltrace_opts_l
+
+set ltrace_opts_demangling {"-C" "-l" "libdwarftest.so"}
+set ref_output_demangling [subst -nocommands -novariables {
+libdwarftest.so->f12(Colors2)(GREEN2) * = RED1
+libdwarftest.so->f34(Colors4)(BLUE4) * = RED3
+libdwarftest.so->f55(Colors5)(RED5) * = RED5
+} ]
+run_dwarf_test $ref_output_demangling $ltrace_opts_demangling
+
+set ltrace_opts_x {"-A5" "-L" "-x" "@libdwarftest.so"}
+set ref_output_x [subst -nocommands -novariables {
+linkedlisttest at libdwarftest.so({ 5, nil }) * = <void>
+treetest at libdwarftest.so({ 1, { 2, nil, nil }, { 3, nil, { 4, nil, nil } } } <unfinished ...>
+treetest at libdwarftest.so({ 2, nil, nil }) * = nil
+treetest at libdwarftest.so({ 3, nil, { 4, nil, nil } } <unfinished ...>
+treetest at libdwarftest.so({ 4, nil, nil }) * = nil
+<... treetest resumed> ) * = { 5, nil, nil }
+<... treetest resumed> ) * = { 2, { 3, nil, nil }, { 4, nil, { 5, nil, nil } } }
+looptest at libdwarftest.so({ { recurse^, 6 }, 5 }) * = <void>
+enumtest at libdwarftest.so(A, B) * = 0
+arraytest at libdwarftest.so(.* 1.000000, 2.000000, 1.000000, 2.000000, 1.000000 [^\\\.*]* * = 1.000000
+enum_cxx_test at libdwarftest.so( <unfinished ...>
+_Z3f127Colors2 at libdwarftest.so(GREEN2) * = RED1
+_Z3f347Colors4 at libdwarftest.so(BLUE4) * = RED3
+_Z3f557Colors5 at libdwarftest.so(RED5) * = RED5
+<... enum_cxx_test resumed> ) * = <void>
+stringtest at libdwarftest.so('t') * = 4
+stringtest at libdwarftest.so(nil) * = -1
+FILEtest at libdwarftest.so(0x[0-9a-z]*, 0x[0-9a-z]*) * = <void>
+voidfunc at libdwarftest.so() * = <void>
+} ]
+run_dwarf_test $ref_output_x $ltrace_opts_x
+
+set ltrace_opts_e {"-A5" "-e" "@libdwarftest.so"}
+set ref_output_e [subst -nocommands -novariables {
+libdwarftest.so->treetest({ 2, nil, nil }) * = nil
+libdwarftest.so->treetest({ 3, nil, { 4, nil, nil } } <unfinished ...>
+libdwarftest.so->treetest({ 4, nil, nil }) * = nil
+<... treetest resumed> ) * = { 5, nil, nil }
+libdwarftest.so->_Z3f127Colors2(GREEN2) * = RED1
+libdwarftest.so->_Z3f347Colors4(BLUE4) * = RED3
+libdwarftest.so->_Z3f557Colors5(RED5) * = RED5
+} ]
+run_dwarf_test $ref_output_e $ltrace_opts_e
+
+set ltrace_opts_e {"-l" "libc.so*"}
+set ref_output_e [subst -nocommands -novariables {
+libdwarftest.so->ftell(0x[0-9a-z]*) * = -1
+libdwarftest.so->strlen('t') * = 4
+dwarf->usleep(33) * = 0
+dwarf->nanosleep({ 0, 44 }, nil) * = 0
+} ]
+run_dwarf_test $ref_output_e $ltrace_opts_e
+
+set ltrace_opts_e {"-L" "-x" "@libc.so*"}
+set ref_output_e [subst -nocommands -novariables {
+ftell at libc.so.6(0x[0-9a-z]*
+strlen at libc.so.6('t') * = 4
+usleep at libc.so.6(33 <unfinished ...>
+nanosleep at libc.so.6({ 0, 33000 }, nil) * = 0
+<... usleep resumed> ) * = 0
+nanosleep at libc.so.6({ 0, 44 }, nil) * = 0
+} ]
+run_dwarf_test $ref_output_e $ltrace_opts_e
+
+
+# why does ftell(...) show a hex argument? Means we know what ftell is, but not what FILE is
+
diff --git a/testsuite/ltrace.main/dwarflib.c b/testsuite/ltrace.main/dwarflib.c
new file mode 100644
index 0000000..2402400
--- /dev/null
+++ b/testsuite/ltrace.main/dwarflib.c
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "dwarflib.h"
+
+void printtree( const struct tree* tree, int indent )
+{
+ if( tree == NULL )
+ {
+ printf("%*sNULL\n", indent*4, "");
+ }
+ else
+ {
+ printf("%*s%d\n", indent*4, "", tree->x);
+ printtree( tree->left, indent+1 );
+ printtree( tree->right, indent+1 );
+ }
+}
+
+
+void linkedlisttest( struct list* l )
+{
+}
+
+struct tree treetest(struct tree* t)
+{
+ if(t->left != NULL) treetest(t->left);
+ if(t->right != NULL) treetest(t->right);
+ t->x++;
+
+ return *t;
+}
+
+void looptest( loop_a_t* a )
+{
+ a->x++;
+ a->b->x++;
+ ftell(stdin);
+}
+
+int enumtest( enum E a, E_t b )
+{
+ return a == b;
+}
+
+#ifndef UNIONTEST_DISABLE
+int uniontest( union U u1, union U u2 )
+{
+ u1.a = u2.b;
+ return u1.a;
+}
+#endif
+
+double arraytest( struct witharray* s )
+{
+ return s->x[0];
+}
+
+#ifndef COMPLEXTEST_DISABLE
+double complex complextest(const float complex* x)
+{
+ double complex y = (double complex)(*x);
+ y *= 2;
+ return y;
+}
+#endif
+
+int stringtest(char* str)
+{
+ if(str == NULL) return -1;
+ return strlen(str);
+}
+
+void FILEtest( FILE* a, const FILE* b )
+{
+}
+
+void voidfunc(void)
+{
+}
diff --git a/testsuite/ltrace.main/dwarflib.h b/testsuite/ltrace.main/dwarflib.h
new file mode 100644
index 0000000..adba76b
--- /dev/null
+++ b/testsuite/ltrace.main/dwarflib.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include <stdio.h>
+#include <complex.h>
+
+// ltrace doesn't know about these yet, so turn off the tests
+#define UNIONTEST_DISABLE
+#define COMPLEXTEST_DISABLE
+
+struct list
+{
+ int x;
+ struct list* next;
+};
+void linkedlisttest( struct list* l );
+
+struct tree
+{
+ int x;
+ struct tree* left;
+ struct tree* right;
+};
+struct tree treetest(struct tree* t);
+
+struct loop_a;
+struct loop_b;
+typedef struct loop_a { struct loop_b* b; int x;} loop_a_t;
+ struct loop_b { loop_a_t* a; int x;};
+void looptest( loop_a_t* a );
+
+enum E { A,B,C };
+typedef enum E E_t;
+int enumtest( enum E a, E_t b );
+
+#ifndef UNIONTEST_DISABLE
+union U { int a, b; };
+int uniontest( union U u1, union U u2 );
+#endif
+
+struct witharray
+{
+ double x[5];
+};
+double arraytest( struct witharray* s );
+
+#ifndef COMPLEXTEST_DISABLE
+double complex complextest(const float complex* x);
+#endif
+
+int stringtest(char* str);
+
+void FILEtest( FILE* a, const FILE* b );
+
+void voidfunc(void);
+
+void printtree( const struct tree* tree, int indent );
diff --git a/testsuite/ltrace.main/dwarflib_cxx.cc11 b/testsuite/ltrace.main/dwarflib_cxx.cc11
new file mode 100644
index 0000000..12d2901
--- /dev/null
+++ b/testsuite/ltrace.main/dwarflib_cxx.cc11
@@ -0,0 +1,21 @@
+#include <cstdint>
+#include "dwarflib_cxx.hh"
+
+enum class Colors1 : std::int8_t { RED1 = 1, GREEN1 = 2, BLUE1 = 3 };
+enum class Colors2 : std::uint8_t { RED2 = 1, GREEN2 = 2, BLUE2 = 200 };
+enum class Colors3 : char { RED3 = 1, GREEN3 = 2, BLUE3 = 3 };
+enum class Colors4 { RED4, GREEN4, BLUE4 };
+enum Colors5 { RED5, GREEN5, BLUE5 };
+
+
+Colors1 f12(Colors2 x) { return Colors1::RED1; }
+Colors3 f34(Colors4 x) { return Colors3::RED3; }
+Colors5 f55(Colors5 x) { return RED5; }
+
+
+extern "C" void enum_cxx_test(void)
+{
+ f12( Colors2::GREEN2 );
+ f34( Colors4::BLUE4 );
+ f55( RED5 );
+}
diff --git a/testsuite/ltrace.main/dwarflib_cxx.hh b/testsuite/ltrace.main/dwarflib_cxx.hh
new file mode 100644
index 0000000..b2e0815
--- /dev/null
+++ b/testsuite/ltrace.main/dwarflib_cxx.hh
@@ -0,0 +1,10 @@
+#ifndef DWARFLIB_CXX_HH
+#define DWARFLIB_CXX_HH
+
+#ifdef __cplusplus
+extern "C"
+#endif
+
+void enum_cxx_test(void);
+
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/ltrace.git
More information about the ltrace-commits
mailing list