Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
DISCONTINUED:openSUSE:11.1:Update
ltrace
ltrace.trunk-r35.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ltrace.trunk-r35.patch of Package ltrace
------------------------------------------------------------------------ r35 | pgilliam-guest | 2006-03-13 23:12:01 +0000 (Mon, 13 Mar 2006) | 3 lines Changed paths: M /ltrace/trunk/ChangeLog M /ltrace/trunk/Makefile.in M /ltrace/trunk/configure.ac A /ltrace/trunk/testsuite A /ltrace/trunk/testsuite/Makefile.in A /ltrace/trunk/testsuite/README A /ltrace/trunk/testsuite/config A /ltrace/trunk/testsuite/config/unix.exp A /ltrace/trunk/testsuite/lib A /ltrace/trunk/testsuite/lib/compiler.c A /ltrace/trunk/testsuite/lib/compiler.cc A /ltrace/trunk/testsuite/lib/ltrace.exp A /ltrace/trunk/testsuite/ltrace.main A /ltrace/trunk/testsuite/ltrace.main/Makefile.in A /ltrace/trunk/testsuite/ltrace.main/main-internal-1.c A /ltrace/trunk/testsuite/ltrace.main/main-internal.c A /ltrace/trunk/testsuite/ltrace.main/main-internal.exp A /ltrace/trunk/testsuite/ltrace.main/main-lib.c A /ltrace/trunk/testsuite/ltrace.main/main.c A /ltrace/trunk/testsuite/ltrace.main/main.exp A /ltrace/trunk/testsuite/ltrace.main/signals.c A /ltrace/trunk/testsuite/ltrace.main/signals.exp A /ltrace/trunk/testsuite/ltrace.main/system_calls.c A /ltrace/trunk/testsuite/ltrace.main/system_calls.exp A /ltrace/trunk/testsuite/ltrace.minor A /ltrace/trunk/testsuite/ltrace.minor/Makefile.in A /ltrace/trunk/testsuite/ltrace.minor/attach-process.c A /ltrace/trunk/testsuite/ltrace.minor/attach-process.exp A /ltrace/trunk/testsuite/ltrace.minor/count-record.c A /ltrace/trunk/testsuite/ltrace.minor/count-record.exp A /ltrace/trunk/testsuite/ltrace.minor/demangle-lib.cpp A /ltrace/trunk/testsuite/ltrace.minor/demangle.cpp A /ltrace/trunk/testsuite/ltrace.minor/demangle.exp A /ltrace/trunk/testsuite/ltrace.minor/demangle.h A /ltrace/trunk/testsuite/ltrace.minor/print-instruction-pointer.c A /ltrace/trunk/testsuite/ltrace.minor/print-instruction-pointer.exp A /ltrace/trunk/testsuite/ltrace.minor/time-record-T.exp A /ltrace/trunk/testsuite/ltrace.minor/time-record-tt.exp A /ltrace/trunk/testsuite/ltrace.minor/time-record-ttt.exp A /ltrace/trunk/testsuite/ltrace.minor/time-record.c A /ltrace/trunk/testsuite/ltrace.minor/trace-clone.c A /ltrace/trunk/testsuite/ltrace.minor/trace-clone.exp A /ltrace/trunk/testsuite/ltrace.minor/trace-fork.c A /ltrace/trunk/testsuite/ltrace.minor/trace-fork.exp A /ltrace/trunk/testsuite/ltrace.torture A /ltrace/trunk/testsuite/ltrace.torture/Makefile.in A /ltrace/trunk/testsuite/ltrace.torture/signals.c A /ltrace/trunk/testsuite/ltrace.torture/signals.exp A /ltrace/trunk/testsuite/run-my-tests.sh A /ltrace/trunk/testsuite/so_test1 A /ltrace/trunk/testsuite/so_test2 Add a dejagnu-based testsuite. ------------------------------------------------------------------------ --- ChangeLog | 53 +++ Makefile.in | 10 configure.ac | 5 testsuite/Makefile.in | 72 ++++ testsuite/README | 244 ++++++++++++++++ testsuite/config/unix.exp | 1 testsuite/lib/compiler.c | 58 +++ testsuite/lib/compiler.cc | 45 +++ testsuite/lib/ltrace.exp | 277 +++++++++++++++++++ testsuite/ltrace.main/Makefile.in | 34 ++ testsuite/ltrace.main/main-internal-1.c | 8 testsuite/ltrace.main/main-internal.c | 19 + testsuite/ltrace.main/main-internal.exp | 33 ++ testsuite/ltrace.main/main-lib.c | 7 testsuite/ltrace.main/main.c | 21 + testsuite/ltrace.main/main.exp | 39 ++ testsuite/ltrace.main/signals.c | 48 +++ testsuite/ltrace.main/signals.exp | 39 ++ testsuite/ltrace.main/system_calls.c | 68 ++++ testsuite/ltrace.main/system_calls.exp | 67 ++++ testsuite/ltrace.minor/Makefile.in | 37 ++ testsuite/ltrace.minor/attach-process.c | 16 + testsuite/ltrace.minor/attach-process.exp | 38 ++ testsuite/ltrace.minor/count-record.c | 51 +++ testsuite/ltrace.minor/count-record.exp | 77 +++++ testsuite/ltrace.minor/demangle-lib.cpp | 97 ++++++ testsuite/ltrace.minor/demangle.cpp | 121 ++++++++ testsuite/ltrace.minor/demangle.exp | 63 ++++ testsuite/ltrace.minor/demangle.h | 36 ++ testsuite/ltrace.minor/print-instruction-pointer.c | 11 testsuite/ltrace.minor/print-instruction-pointer.exp | 42 ++ testsuite/ltrace.minor/time-record-T.exp | 84 +++++ testsuite/ltrace.minor/time-record-tt.exp | 107 +++++++ testsuite/ltrace.minor/time-record-ttt.exp | 112 +++++++ testsuite/ltrace.minor/time-record.c | 23 + testsuite/ltrace.minor/trace-clone.c | 31 ++ testsuite/ltrace.minor/trace-clone.exp | 44 +++ testsuite/ltrace.minor/trace-fork.c | 33 ++ testsuite/ltrace.minor/trace-fork.exp | 40 ++ testsuite/ltrace.torture/Makefile.in | 34 ++ testsuite/ltrace.torture/signals.c | 44 +++ testsuite/ltrace.torture/signals.exp | 37 ++ testsuite/run-my-tests.sh | 43 ++ 43 files changed, 2367 insertions(+), 2 deletions(-) Index: Makefile.in =================================================================== --- Makefile.in.orig +++ Makefile.in @@ -40,7 +40,11 @@ ltrace: sysdeps/sysdep.o $(OBJ) sysdeps/sysdep.o: dummy $(MAKE) -C sysdeps/$(OS) -clean: +clean-deja: + $(RM) testrun.log testrun.sum + cd testsuite; make clean + +clean: clean-deja $(MAKE) -C sysdeps/$(OS) clean rm -f ltrace $(OBJ) rm -f *~ *.bak a.out core KK @@ -48,6 +52,7 @@ clean: distclean: clean rm -f autogen.sh config.cache config.status config.log config.h Makefile configure.scan rm -rf autom4te.cache + cd testsuite; make distclean realclean: distclean rm configure config.h.in @@ -75,6 +80,9 @@ install: ltrace $(INSTALL_FILE) COPYING README TODO BUGS ChangeLog $(DESTDIR)$(docdir) $(INSTALL_FILE) ltrace.1 $(DESTDIR)$(mandir)/man1 +check: + cd testsuite; $(MAKE) check + dummy: .PHONY: all clean distclean dist install dummy Index: configure.ac =================================================================== --- configure.ac.orig +++ configure.ac @@ -84,4 +84,7 @@ dnl are built without LFS. It is import dnl of libelf and ltrace matches. AC_SYS_LARGEFILE fi -AC_OUTPUT(Makefile) +AC_OUTPUT(Makefile testsuite/Makefile \ + testsuite/ltrace.main/Makefile testsuite/ltrace.minor/Makefile \ + testsuite/ltrace.torture/Makefile ) + Index: ChangeLog =================================================================== --- ChangeLog.orig +++ ChangeLog @@ -1,3 +1,56 @@ +2006-03=13 Paul Gilliam <pgilliam@us.ibm.com> + + * Makefile.in: Add targets to support testsuite, including 'check'. + * confiure.ac: Add testsuite Makefile's to AC_OUTPUT. + * testsuite: Add dejagnu base testsuite. + * testsuite/config/: Add + * testsuite/config/unix.exp: Add + * testsuite/lib/: Add + * testsuite/lib/compiler.c: Add + * testsuite/lib/compiler.cc: Add + * testsuite/lib/ltrace.exp: Add + * testsuite/ltrace.main/: Add + * testsuite/ltrace.main/main.c: Add + * testsuite/ltrace.main/main.exp: Add + * testsuite/ltrace.main/main-internal-1.c: Add + * testsuite/ltrace.main/main-internal.c: Add + * testsuite/ltrace.main/main-internal.exp: Add + * testsuite/ltrace.main/main-lib.c: Add + * testsuite/ltrace.main/Makefile.in: Add + * testsuite/ltrace.main/signals.c: Add + * testsuite/ltrace.main/signals.exp: Add + * testsuite/ltrace.main/system_calls.c: Add + * testsuite/ltrace.main/system_calls.exp: Add + * testsuite/ltrace.minor/: Add + * testsuite/ltrace.minor/attach-process.c: Add + * testsuite/ltrace.minor/attach-process.exp: Add + * testsuite/ltrace.minor/count-record.c: Add + * testsuite/ltrace.minor/count-record.exp: Add + * testsuite/ltrace.minor/demangle.cpp: Add + * testsuite/ltrace.minor/demangle.exp: Add + * testsuite/ltrace.minor/demangle.h: Add + * testsuite/ltrace.minor/demangle-lib.cpp: Add + * testsuite/ltrace.minor/Makefile.in: Add + * testsuite/ltrace.minor/print-instruction-pointer.c: Add + * testsuite/ltrace.minor/print-instruction-pointer.exp: Add + * testsuite/ltrace.minor/time-record.c: Add + * testsuite/ltrace.minor/time-record-T.exp: Add + * testsuite/ltrace.minor/time-record-tt.exp: Add + * testsuite/ltrace.minor/time-record-ttt.exp: Add + * testsuite/ltrace.minor/trace-clone.c: Add + * testsuite/ltrace.minor/trace-clone.exp: Add + * testsuite/ltrace.minor/trace-fork.c: Add + * testsuite/ltrace.minor/trace-fork.exp: Add + * testsuite/ltrace.torture/: Add + * testsuite/ltrace.torture/Makefile.in: Add + * testsuite/ltrace.torture/signals.c: Add + * testsuite/ltrace.torture/signals.exp: Add + * testsuite/Makefile.in: Add + * testsuite/README: Add + * testsuite/run-my-tests.sh: Add + * testsuite/so_test1/: Add + * testsuite/so_test2/: Add + 2006-03-13 Paul Gilliam <pgilliam@us.ibm.com> * options.h: New structure for opt_x list elements, now with 'found'. Index: testsuite/run-my-tests.sh =================================================================== --- /dev/null +++ testsuite/run-my-tests.sh @@ -0,0 +1,43 @@ +#! /bin/sh +bitmode="" + +# This shell script is used to run the ltrace test suite. It is possible to +# run it via 'make check' using RUNTESTFLAGS. This script just makes it easy. + +function usage +{ + echo usage: `basename $0` '-m32|-m64 [<tool> | ""] [<test.exp>]' +} + +# The first argument is not optional: it must either be -m32 or -m64. If the +# second argument is used, it specifies the file name of the ltrace to be +# tested. The third argument specifies a particular test case to run. If +# the third argument is omitted, then all test cases are run. If you wish to +# use the third argument, but not the second, specify the second as "". + +# there is a secret argument: if the name of this script is 'test', then +# the --verbose argument is added to RUNTESTFLAGS. + +if [ x"$1" == x -o x"$1" != x-m32 -a x"$1" != x-m64 ]; then + usage + exit 1 +fi + +flags='' + +if [ `basename $0` == test ]; then + flags="--verbose " +fi + +if [ x"$2" != x ]; then + flags="${flags}--tool_exec=$2 " +fi + +flags="${flags}CFLAGS_FOR_TARGET=$1" + +if [ x"$3" != x ]; then + flags="$flags $3" +fi + +set -o xtrace +make check RUNTESTFLAGS="$flags" Index: testsuite/Makefile.in =================================================================== --- /dev/null +++ testsuite/Makefile.in @@ -0,0 +1,72 @@ +# Copyright (C) 1992 - 2001 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +AUTOMAKE_OPTIONS = dejagnu +EXPECT = expect +RUNTEST = runtest +CC = @CC@ + +srcdir = . +RUNTESTDEFAULTFLAGS = --srcdir $(srcdir) + +CLEANFILES = *.log *.sum site.bak setval.tmp site.exp + +SUBDIRS = ltrace.main ltrace.minor ltrace.torture + +#all: all-recursive + +.SUFFIXES: + +check-DEJAGNU: site.exp + EXPECT=$(EXPECT); export EXPECT; + @$(RUNTEST) $(RUNTESTDEFAULTFLAGS) $(RUNTESTFLAGS); + +site.exp: + @echo 'Making a new site.exp file...' + @echo '## these variables are automatically generated by make ##' >site.tmp + @echo '# Do not edit here. If you wish to override these values' >>site.tmp + @echo '# edit the last section' >>site.tmp + @echo 'set srcdir $(srcdir)' >>site.tmp + @echo "set objdir `pwd`" >>site.tmp + @echo '## All variables above are generated by configure. Do Not Edit ##' >>site.tmp + @test ! -f site.exp || \ + sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp + @-rm -f site.bak + @test ! -f site.exp || mv site.exp site.bak + @mv site.tmp site.exp + +check: check-DEJAGNU + +clean: + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making clean in $$subdir"; \ + (cd $$subdir && $(MAKE) clean ) done; + + -rm -f $(CLEANFILES) + +distclean: + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making clean in $$subdir"; \ + (cd $$subdir && $(MAKE) distclean ) done; + -rm -f Makefile + -rm -f $(CLEANFILES) + +.PHONY: $(RECURSIVE_TARGETS) check clean distclean realclean + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: Index: testsuite/config/unix.exp =================================================================== --- /dev/null +++ testsuite/config/unix.exp @@ -0,0 +1 @@ +load_lib ltrace.exp Index: testsuite/lib/ltrace.exp =================================================================== --- /dev/null +++ testsuite/lib/ltrace.exp @@ -0,0 +1,277 @@ +# This file was written by Yao Qi. (qiyao@cn.ibm.com) + +# Generic ltrace test subroutines that should work for any target. If these +# need to be modified for any target, it can be done with a variable +# or by passing arguments. + + +global LTRACE +if [info exists TOOL_EXECUTABLE] { + set LTRACE $TOOL_EXECUTABLE +} else { + set LTRACE $objdir/../ltrace +} + +global LTRACE_OPTIONS +set LTRACE_OPTIONS ""; + +# ltrace_compile SOURCE DEST TYPE OPTIONS +# +# Compile PUT(program under test) by native compiler. ltrace_compile runs +# the right compiler, and TCL captures the output, and I evaluate the output. +# +# SOURCE is the name of program under test, with full directory. +# DEST is the name of output of compilation, with full directory. +# TYPE is an enum-like variable to affect the format or result of compiler +# output. Values: +# executable if output is an executable. +# object if output is an object. +# OPTIONS is option to compiler in this compilation. +proc ltrace_compile {source dest type options} { + global LTRACE_TESTCASE_OPTIONS; + + # Add platform-specific options if a shared library was specified using + # "shlib=librarypath" in OPTIONS. + set new_options "" + set shlib_found 0 + + foreach opt $options { + if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] { + if [test_compiler_info "xlc*"] { + # IBM xlc compiler doesn't accept shared library named other + # than .so: use "-Wl," to bypass this + lappend source "-Wl,$shlib_name" + } else { + lappend source $shlib_name + } + + if {$shlib_found == 0} { + set shlib_found 1 + + if { ([test_compiler_info "gcc-*"]&& ([istarget "powerpc*-*-aix*"]|| [istarget "rs6000*-*-aix*"] ))} { + lappend options "additional_flags=-L${objdir}/${subdir}" + } elseif { [istarget "mips-sgi-irix*"] } { + lappend options "additional_flags=-rpath ${objdir}/${subdir}" + } + } + + } else { + lappend new_options $opt + } + } + #end of for loop + set options $new_options + # dump some information for debug purpose. + verbose "options are $options" + verbose "source is $source $dest $type $options" + + set result [target_compile $source $dest $type $options]; + verbose "result is $result" + regsub "\[\r\n\]*$" "$result" "" result; + regsub "^\[\r\n\]*" "$result" "" result; + if { $result != "" && [lsearch $options quiet] == -1} { + clone_output "compile failed for ltrace test, $result" + } + return $result; +} + +proc get_compiler_info {binfile args} { + # For compiler.c and compiler.cc + global srcdir + + # I am going to play with the log to keep noise out. + global outdir + global tool + + # These come from compiler.c or compiler.cc + global compiler_info + + # Legacy global data symbols. + #global gcc_compiled + + # Choose which file to preprocess. + set ifile "${srcdir}/lib/compiler.c" + if { [llength $args] > 0 && [lindex $args 0] == "c++" } { + set ifile "${srcdir}/lib/compiler.cc" + } + + # Run $ifile through the right preprocessor. + # Toggle ltrace.log to keep the compiler output out of the log. + #log_file + set cppout [ ltrace_compile "${ifile}" "" preprocess [list "$args" quiet] ] + #log_file -a "$outdir/$tool.log" + + # Eval the output. + set unknown 0 + foreach cppline [ split "$cppout" "\n" ] { + if { [ regexp "^#" "$cppline" ] } { + # line marker + } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } { + # blank line + } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } { + # eval this line + verbose "get_compiler_info: $cppline" 2 + eval "$cppline" + } else { + # unknown line + verbose "get_compiler_info: $cppline" + set unknown 1 + } + } + + # Reset to unknown compiler if any diagnostics happened. + if { $unknown } { + set compiler_info "unknown" + } + return 0 +} + +proc test_compiler_info { {compiler ""} } { + global compiler_info + verbose "compiler_info=$compiler_info" + # if no arg, return the compiler_info string + + if [string match "" $compiler] { + if [info exists compiler_info] { + return $compiler_info + } else { + perror "No compiler info found." + } + } + + return [string match $compiler $compiler_info] +} + +proc ltrace_compile_shlib {sources dest options} { + set obj_options $options + verbose "+++++++ [test_compiler_info]" + switch -glob [test_compiler_info] { + "xlc-*" { + lappend obj_options "additional_flags=-qpic" + } + "gcc-*" { + if { !([istarget "powerpc*-*-aix*"] + || [istarget "rs6000*-*-aix*"]) } { + lappend obj_options "additional_flags=-fpic" + } + } + "xlc++-*" { + lappend obj_options "additional_flags=-qpic" + } + + default { + fail "Bad compiler!" + } + } + + set outdir [file dirname $dest] + set objects "" + foreach source $sources { + set sourcebase [file tail $source] + if {[ltrace_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} { + return -1 + } + lappend objects ${outdir}/${sourcebase}.o + } + + set link_options $options + if { [test_compiler_info "xlc-*"] || [test_compiler_info "xlc++-*"]} { + lappend link_options "additional_flags=-qmkshrobj" + } else { + lappend link_options "additional_flags=-shared" + } + if {[ltrace_compile "${objects}" "${dest}" executable $link_options] != ""} { + return -1 + } +} + +# +# ltrace_options OPTIONS_LIST +# Pass ltrace commandline options. +# +proc ltrace_options { args } { + + global LTRACE_OPTIONS + set LTRACE_OPTIONS $args +} + +# +# ltrace_runtest LD_LIBRARY_PATH BIN FILE +# Trace the execution of BIN and return result. +# +# BIN is program-under-test. +# LD_LIBRARY_PATH is the env for program-under-test to run. +# FILE is to save the output from ltrace with default name $BIN.ltrace. +# Retrun output from ltrace. +# +proc ltrace_runtest { args } { + + global LTRACE + global LTRACE_OPTIONS + + verbose "LTRACE = $LTRACE" + + set LD_LIBRARY_PATH_ [lindex $args 0] + set BIN [lindex $args 1] + + # specify the output file, the default one is $BIN.ltrace + if [llength $args]==3 then { + set file [lindex $args 2] + } else { + set file $BIN.ltrace + } + # append this option to LTRACE_OPTIONS. + lappend LTRACE_OPTIONS "-o" + lappend LTRACE_OPTIONS "$file" + verbose "LTRACE_OPTIONS = $LTRACE_OPTIONS" + #ltrace the PUT. + catch "exec sh -c {export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_; $LTRACE $LTRACE_OPTIONS $BIN;exit}" output + + # return output from ltrace. + return $output +} + +# +# ltrace_saveoutput OUTPUT FILE +# Save OUTPUT from ltrace to file FILE. +# OUTPUT is output from ltrace or return value of ltrace_runtest. +# FILE is file save output. +# +proc ltrace_saveoutput { args } { + + set output [lindex $args 0] + set file [lindex $args 1] + + set fd [open $file w] + puts $fd $output + close $fd +} + + +# +# ltrace_verify_output FILE_TO_SEARCH PATTERN MAX_LINE +# Verify the ltrace output by comparing the number of PATTERN in +# FILE_TO_SEARCH with INSTANCE_NO. Do not specify INSTANCE_NO if +# instance number is ignored in this test. +# Reutrn: +# 0 = number of PATTERN in FILE_TO_SEARCH inqual to INSTANCE_NO. +# 1 = number of PATTERN in FILE_TO_SEARCH qual to INSTANCE_NO. +# +proc ltrace_verify_output { file_to_search pattern {instance_no 0}} { + + # compute the number of PATTERN in FILE_TO_SEARCH by grep and wc. + catch "exec sh -c {grep $pattern $file_to_search | wc -l ;exit}" output + verbose "output = $output" + + if { $instance_no == 0 } then { + if { $output == 0 } then { + fail "Fail to find $pattern in $file_to_search" + } else { + pass "$pattern in $file_to_search" + } + } elseif { $output >= $instance_no } then { + pass "$pattern in $file_to_search for $output times" + } else { + fail "$pattern in $file_to_search for $output times ,should be $instance_no" + } +} Index: testsuite/lib/compiler.c =================================================================== --- /dev/null +++ testsuite/lib/compiler.c @@ -0,0 +1,58 @@ +/* This test file is part of GDB, the GNU debugger. + + Copyright 1995, 1997, 1999, 2003, 2004 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + */ + +/* Sometimes the behavior of a test depends upon the compiler used to + compile the test program. A test script can call get_compiler_info + to figure out the compiler version and test_compiler_info to test it. + + get_compiler_info runs the preprocessor on this file and then eval's + the result. This sets various symbols for use by test_compiler_info. + + TODO: make compiler_info a local variable for get_compiler_info and + test_compiler_info. + + TODO: all clients should use test_compiler_info and should not + use gcc_compiled, hp_cc_compiler, or hp_aCC_compiler. + + */ + +/* Note the semicolon at the end of this line. Older versions of + hp c++ have a bug in string preprocessing: if the last token on a + line is a string, then the preprocessor concatenates the next line + onto the current line and eats the newline! That messes up TCL of + course. That happens with HP aC++ A.03.13, but it no longer happens + with HP aC++ A.03.45. */ + +set compiler_info "unknown" ; + +#if defined (__GNUC__) +#if defined (__GNUC_PATCHLEVEL__) +/* Only GCC versions >= 3.0 define the __GNUC_PATCHLEVEL__ macro. */ +set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__} -] +#else +set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ "unknown"} -] +#endif +#endif + +#if defined (__xlc__) +/* IBM'x xlc compiler. NOTE: __xlc__ expands to a double quoted string of four + numbers seperated by '.'s: currently "7.0.0.0" */ +set need_a_set [regsub -all {\.} [join {xlc __xlc__} -] - compiler_info] +#endif Index: testsuite/lib/compiler.cc =================================================================== --- /dev/null +++ testsuite/lib/compiler.cc @@ -0,0 +1,45 @@ +/* This test file is part of GDB, the GNU debugger. + + Copyright 1995, 1999, 2003, 2004 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + */ + +/* This file is exactly like compiler.c. I could just use compiler.c if + I could be sure that every C++ compiler accepted extensions of ".c". */ + +/* Note the semicolon at the end of this line. Older versions of + hp c++ have a bug in string preprocessing: if the last token on a + line is a string, then the preprocessor concatenates the next line + onto the current line and eats the newline! That messes up TCL of + course. That happens with HP aC++ A.03.13, but it no longer happens + with HP aC++ A.03.45. */ + +set compiler_info "unknown" ; + +#if defined (__GNUC__) +#if defined (__GNUC_PATCHLEVEL__) +/* Only GCC versions >= 3.0 define the __GNUC_PATCHLEVEL__ macro. */ +set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__} -] +#else +set compiler_info [join {gcc __GNUC__ __GNUC_MINOR__ "unknown"} -] +#endif +#endif + +#if defined (__xlC__) +/* xlC++ version like 800 */ +set compiler_info [join {xlc++ __IBMCPP__} -] +#endif Index: testsuite/README =================================================================== --- /dev/null +++ testsuite/README @@ -0,0 +1,244 @@ + README for ltrace testsuite + 18, October, 2005 by Yao Qi <qiyao@cn.ibm.com> + +This is the README file for ltrace testsuite. + +Quick Overview +============== + + This testsuite is based on the dejagnu framework, which is again +dependent on Expect and Tcl. So all these three package (tcl, expect +and dejagnu) should be installed on your system before running these +tests. + + After unpacking file ltrace-0.3.36.tar.gz: + + tar -zxvfm ltrace-0.3.36.tar.gz + + you'll find a directory named ltrace-0.3.36, which contains: + + debian etc testsuite sysdeps + +you can first build this package, then run the testsuite in the +following steps: + + 1 cd ltrace-0.3.36 + + 2 Confiugre ltrace for 32-bit mode or 64-bit mode. + ./configure + OR CC='gcc -m64' ./configure + + 3 Build ltace + make + + 4 Run all the test in default mode. + make check + + The default is to test the ltrace just built, using the default +compiler options. You can control this by adding a symbol to 'make check': + + To test the shipped ltrace tool (as opposed to the just built by "make") + + --tool_exec=/usr/bin/ltrace + + To change compiler switches for the target test cases + + CFLAGS_FOR_TARGET=-m64 + + To change the target compiler (instead of shipped gcc) + + CC_FOR_TARGET=/opt/gcc-4.0/bin/gcc + + + You can run all the tests in different mode respectively as follows, + + (1) ./run-my-tests.sh -m32 + OR make check + + (test ltrace in build tree and compile test cases in 32-bit mode) + + (2) ./run-my-tests.sh -m64 + OR make check RUNTESTFLAGS="CFLAGS_FOR_TARGET=-m64" + + (test ltrace in build tree and compile test cases in 64-bit mode) + + (3) ./run-my-tests.sh -m32 /usr/bin/ltrace + OR make check RUNTESTFLAGS="--tool_exec=/usr/bin/ltrace" + + (test shipped ltrace and compile test cases in 32-bit mode) + + (4) ./run-my-tests.sh -m64 /usr/bin/ltrace + OR make check RUNTESTFLAGS="--tool_exec=/usr/bin/ltrace CFLAGS_FOR_TARGET=-m64" + + (run shipped ltrace and compile test cases in 64-bit mode) + + (5) cd testsuite; make test + + (run ltrace in build tree and compile test cases same as ltrace itself) + + + (6) make check RUNTESTFLAGS="--tool_exec=/usr/bin/ltrace CFLAGS_FOR_TARGET=-m64 CC_FOR_TARGET=/opt/gcc-4.0/bin/gcc" + + (run shipped ltrace and compile test cases in 64 bit mode by /opt/gcc-4.0/bin/gcc) +Ltrace Testsuite +================ + + This testsuite for ltrace is a DejaGNU based testsuite that can +either be used to test your newly built ltrace, or for regression +testing a ltrace with local modifications. + + Running the testsuite requires the prior installation of DejaGNU. +The directory ftp://sources.redhat.com/pub/dejagnu/ will contain a +recent snapshot. Once DejaGNU is installed or built and add the +location of runtest into $PATH, you can run the tests in one of the +four ways it mentioned in Quick Overview. The DejaGNU framework could +be built in following steps: + + 1 Uppack these three packages. + tar zxvf dejagnu-1.4.4.tar.gz + tar zxvf tcl8.4.9-src.tar.gz + tar zxvf expect-5.43.0.tar.gz + + 2 Build them and install. + cd dejagnu-1.4.4 + ./configure + make + make install + cd .. + + cd tcl8.4.9/unix + ./configure + make + make install + cd .. + + cd expect-5.43 + ./configure + make + make install + cd .. + + See the DejaGNU documentation and dejagnu-1.4.4/README for further +details. + + +Componets in ltrace testsuite +============================= + + This testsuite include all the source code you need for ltrace +test in a single directory, which is "ltrace-0.3.36/testsuite". +This directory includes the following files and sub-directories: + +`config/unix.exp` + configuration file for dejagnu-based test. + +`lib/ltrace.exp` + some basic functions used in all the test cases. + +`ltrace.main/` + some basic tests for major fetures of ltrace. + + (1) ltrace.main/main.exp does tests on tracing a function +implemented in a shared library. + + (2) ltrace.main/main-internal.exp does tests on tracing a function +implemented in main executable. + + (3) ltrace.main/signals.exp do test on tracing user-defined signals +sent by program to itself. + + (4) ltrace.main/system_calls.exp do test on tracing all the system +calls in program. + +`ltrace.minor/` + some tests for minor fetures of ltrace. + + (1) ltrace.minor/attach-process.exp do test on attching a process. + + (2) ltrace.minor/count-record.exp do test on counting time and +calls. + + (3) ltrace.minor/demangle.exp do test on demangling the C++ symbols. + + (4) ltrace.minor/time-record-T.exp do test on showing the time spent +inside each call. + + (5) ltrace.minor/time-record-tt.exp + (6) ltrace.minor/time-record-ttt.exp do test on printing absolute +timestamps in different format. + + (7) ltrace.minor/trace-clone.exp do test on following clone to child +process. + + (8) ltrace.minor/trace-fork.exp do test on following fork to child +process. + +`ltrace.torture/` + some tests in extreme condations. + + (1) ltrace.torture/signals.exp do test on tracing flooded signals +send to program itself. + +Trouble shootings +================= + + (1) Running ltrace with -u option requires the superuser privilege. +You must make sure you are root or have already got root's password. + + (2) Check the *.ltrace files in each ltrace.* directories if there are +some FAILs in the output. They are informative. + + (3) Add --verbose option in RUNTESTFLAGS when 'make check' if you want +to see more details of these tests. + +Test case extension +=================== + + Current testsuite is quite basic. The framework of testsuite is +extendable and scalealbe, so you can add new testcases into it easily. +I will describe how to do that in different ways. + + (1) Add new test case in an existed testcase directory. + + It is simple. Just add a foo.exp script and a relevant foo.c if +necessary. The dejagnu framework can run that script automatically when +you run "make check". The executable and object file would be generate +in the test, please add them in 'clean' entry in Makefile.in to ensure +that they could be cleaned up automatically when run 'make clean'. + + (2) Add new test case in a new testcase directory. + + It is a little complicated. Fisrt create a new directory in +testsuite/ with the same pattern as others, for example ltrace.bar, +and then create a Makefile.in, an Expect script foo.exp, and relative +foo.c if necessary. Then modify the configure.ac in ltrace-0.3.36/, +and add "testsuite/ltrace.bar/Makefile" into macro AC_OUTPUT, +testsuite/ltrace.bar/Makefile will be generated when you configure +this package. + + Adding Makefile.in in the new directroy is just to remove +intermediate files and log files automatically later, such as foo.ltrace, +object files and executables. For example, if you want to remove A.ltrace, +B.ltrace, A and B at the time of cleanup, you can write Makefile.in +like this: + + clean: + -rm -f A B + -rm -f *.o + -rm -f *.ltrace + distclean: clean + -rm -f Makefile + + At last add the new directory 'ltrace.bar' into the macro SUBDIRS +in testsuite/Makefile.in. + + Rerun the autoconf and ./configure in ./ltrace-0.3.36, the Makefile +will be updated. + + + +^L +(this is for editing this file with GNU emacs) +Local Variables: +mode: text +End: Index: testsuite/ltrace.main/main-internal.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/main-internal.c @@ -0,0 +1,19 @@ + /* Ltrace Test : main-internal.c. + Objectives : Verify that ltrace can trace call from main + executable within it. + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ +#include<stdio.h> + +extern void display ( char* ); + +#define DISPLAY_LOOP 12 + +int +main () +{ + int i; + printf ("should not show up if '-X display' is used.\n"); + for (i=0; i< DISPLAY_LOOP; i++) + display ("Function call within executable."); +} + Index: testsuite/ltrace.main/main.exp =================================================================== --- /dev/null +++ testsuite/ltrace.main/main.exp @@ -0,0 +1,39 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "main" +set srcfile ${testfile}.c +set binfile ${testfile} +set libfile "main-lib" +set libsrc $srcdir/$subdir/$libfile.c +set lib_sl $srcdir/$subdir/lib$testfile.so + + +if [get_compiler_info $binfile] { + return -1 +} + +verbose "compiling source file now....." +if { [ltrace_compile_shlib $libsrc $lib_sl debug ] != "" + || [ltrace_compile $srcdir/$subdir/$srcfile $srcdir/$subdir/$binfile executable [list debug shlib=$lib_sl] ] != ""} { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-l" "$srcdir/$subdir/libmain.so" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Verify the output by checking numbers of print in main.ltrace. +set pattern "print" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 10 Index: testsuite/ltrace.main/signals.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/signals.c @@ -0,0 +1,48 @@ +/* Ltrace Test : signals.c. + Objectives : Verify that ltrace can trace user defined signal. + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include<stdio.h> +#include<signal.h> +#include <sys/types.h> + +#define LOOP 7 + +void +handler(int signum,siginfo_t *info,void *act) +{ + /* Trace printf in signal handler. */ + printf("sival_int = %d\n",info->si_value.sival_int); +} + +int +main () +{ + struct sigaction act; + union sigval mysigval; + int i; + int sig; + pid_t pid; + + mysigval.sival_int=0; + + /* Use an user-defined signal 1. */ + sig = SIGUSR1; + pid=getpid(); + + sigemptyset(&act.sa_mask); + act.sa_sigaction=handler; + act.sa_flags=SA_SIGINFO; + + if(sigaction(sig,&act,NULL) < 0) + { + printf("install sigal error\n"); + } + + for(i=0; i<LOOP; i++) + { + sleep(1); + sigqueue(pid,sig,mysigval); + } + return 0; +} Index: testsuite/ltrace.main/Makefile.in =================================================================== --- /dev/null +++ testsuite/ltrace.main/Makefile.in @@ -0,0 +1,34 @@ +# Copyright (C) 1992 - 2001 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +CLEANFILES = *.log *.sum site.bak setval.tmp site.exp + +.SUFFIXES: +clean: + -rm -f main main-internal system_calls signals + -rm -f *.o *.so + -rm -f *.ltrace + -rm -f $(CLEANFILES) +distclean: clean + -rm -f Makefile + + +.PHONY: $(RECURSIVE_TARGETS) check clean distclean realclean + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: Index: testsuite/ltrace.main/system_calls.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/system_calls.c @@ -0,0 +1,68 @@ +/* Ltrace Test : system_calls.c. + Objectives : Verify that Ltrace can trace all the system calls in + execution. + + You can add new system calls in it and add its verification in + system_calls correspondingly. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include <stdio.h> +#include <unistd.h> +#include <sys/syscall.h> +#include <sys/stat.h> +#include <errno.h> + +void exit (int); + +#define BUF_SIZE 100 + +int +main () +{ + FILE* fp; + char s[]="system_calls"; + char buffer[BUF_SIZE]; + struct stat state; + + /* SYS_open. */ + fp = fopen ("system_calls.tmp", "w"); + if (fp == NULL) + { + printf("Can not create system_calls.tmp\n"); + exit (0); + } + /* SYS_write. */ + fwrite(s, sizeof(s), 1, fp); + /* SYS_lseek. */ + fseek (fp, 0, SEEK_CUR); + /* SYS_read. */ + fread(buffer, sizeof(s), 1, fp); + /* SYS_close. */ + fclose(fp); + + /* SYS_getcwd. */ + getcwd (buffer, BUF_SIZE); + /* SYS_chdir. */ + chdir ("."); + /* SYS_symlink. */ + symlink ("system_calls.tmp", "system_calls.link"); + /* SYS_unlink. */ + remove("system_calls.link"); + /* SYS_rename. */ + rename ("system_calls.tmp", "system_calls.tmp1"); + /* SYS_stat. */ + stat ("system_calls.tmp", &state); + /* SYS_access. */ + access ("system_calls.tmp", R_OK); + remove("system_calls.tmp1"); + + /* SYS_mkdir. */ + mkdir ("system_call_mkdir", 0777); + /* SYS_rmdir. */ + rmdir ("system_call_mkdir"); + + return 0; +} + + Index: testsuite/ltrace.main/main.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/main.c @@ -0,0 +1,21 @@ +/* Ltrace Test : main.c. + Objectives : Verify that ltrace can trace call a library function + from main executable. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +extern void print ( char* ); + +#define PRINT_LOOP 10 + +int +main () +{ + int i; + + for (i=0; i<PRINT_LOOP; i++) + print ("Library function call!"); + + return 0; +} + Index: testsuite/ltrace.main/main-internal.exp =================================================================== --- /dev/null +++ testsuite/ltrace.main/main-internal.exp @@ -0,0 +1,33 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "main-internal" +set srcfile ${testfile}.c +set binfile ${testfile} + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c ${srcdir}/${subdir}/${testfile}-1.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-x" "display" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 do static plt2addr} $exec_output ] { + fail "Couldn't do static plt2addr!" + return +} elseif [regexp {Couldn't get .hash data from} $exec_output ] { + fail "Couldn't get .hash data!" + return +} + +set pattern "display" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 12 Index: testsuite/ltrace.main/main-lib.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/main-lib.c @@ -0,0 +1,7 @@ +#include<stdio.h> + +void +print(char* s) +{ + printf("%s\n",s); +} Index: testsuite/ltrace.main/signals.exp =================================================================== --- /dev/null +++ testsuite/ltrace.main/signals.exp @@ -0,0 +1,39 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "signals" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail\n." +} + +# set options for ltrace. +ltrace_options "-L" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Extract LOOP from source file. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + regexp {define LOOP.*([0-9]+)} $line match count +} +close $fd + +# Verify the output of ltrace by checking the number of SIGUSR1 in signal.ltrace +set pattern "SIGUSR1" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern $count Index: testsuite/ltrace.main/main-internal-1.c =================================================================== --- /dev/null +++ testsuite/ltrace.main/main-internal-1.c @@ -0,0 +1,8 @@ +#include<stdio.h> + +void +display ( char* s ) +{ + printf("%s\n",s); +} + Index: testsuite/ltrace.main/system_calls.exp =================================================================== --- /dev/null +++ testsuite/ltrace.main/system_calls.exp @@ -0,0 +1,67 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "system_calls" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-S" + +#Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + + +set pattern "SYS_munmap" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 2 +set pattern "SYS_write" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_unlink" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + +set pattern "SYS_brk" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_open" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_fstat" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_mmap" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_close" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + +set pattern "SYS_getcwd" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_chdir" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_symlink" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_unlink" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_stat" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_access" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_rename" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_mkdir" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 +set pattern "SYS_rmdir" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 Index: testsuite/ltrace.minor/Makefile.in =================================================================== --- /dev/null +++ testsuite/ltrace.minor/Makefile.in @@ -0,0 +1,37 @@ +# Copyright (C) 1992 - 2001 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +CLEANFILES = *.log *.sum site.bak setval.tmp site.exp + +.SUFFIXES: +clean: + -rm -f demangle trace-fork trace-clone + -rm -f time-record-tt time-record-ttt time-record-T + -rm -f attach-process count-record + -rm -f print-instruction-pointer + -rm -f *.o *.so + -rm -f *.ltrace + -rm -f $(CLEANFILES) +distclean: clean + -rm -f Makefile + + +.PHONY: $(RECURSIVE_TARGETS) check clean distclean realclean + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: Index: testsuite/ltrace.minor/print-instruction-pointer.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/print-instruction-pointer.exp @@ -0,0 +1,42 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "print-instruction-pointer" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ltrace_compile "${srcdir}/${subdir}/${srcfile}" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-i" +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Get the addrss by objdump and sed. +catch "exec sh -c {objdump -d $srcdir/$subdir/$binfile | sed -n '/^\[0-9a-fA-F\]\[0-9a-fA-F\]* <main>/,/^\[0-9a-fA-F\]\[0-9a-fA-F\]* </p'| grep -A 1 'call\\|bl' }" output +#verbose "output=$output" +catch "exec sh -c {echo \"$output\" | sed -n '2p'| awk -F' ' '{print \$1}'|awk -F: '{print \$1}'}" addr1 +catch "exec sh -c {echo \"$output\" | sed -n '5p'| awk -F' ' '{print \$1}'|awk -F: '{print \$1}'}" addr2 + +verbose "addr1 = $addr1" +verbose "addr2 = $addr2" +# Verify the output by checking numbers of print in main.ltrace. +set pattern "$addr1.*printf" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + +set pattern "$addr2.*printf" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 Index: testsuite/ltrace.minor/count-record.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/count-record.c @@ -0,0 +1,51 @@ +/* Ltrace Test : count-record.c. + Objectives : Verify that Ltrace can count all the system calls in + execution and report a summary on exit. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include <stdio.h> +#include <unistd.h> +#include <sys/syscall.h> +#include <sys/stat.h> +#include <errno.h> + +void exit (int); + +#define BUF_SIZE 100 + +/* Do as many operations as possible to record these calls. */ +int +main () +{ + FILE* fp; + char s[]="system_calls"; + char buffer[BUF_SIZE]; + struct stat state; + + fp = fopen ("system_calls.tmp", "w"); + if (fp == NULL) + { + printf("Can not create system_calls.tmp\n"); + exit (0); + } + + fwrite(s, sizeof(s), 1, fp); + fseek (fp, 0, SEEK_CUR); + fread(buffer, sizeof(s), 1, fp); + fclose(fp); + + getcwd (buffer, BUF_SIZE); + chdir ("."); + symlink ("system_calls.tmp", "system_calls.link"); + remove("system_calls.link"); + rename ("system_calls.tmp", "system_calls.tmp1"); + stat ("system_calls.tmp", &state); + access ("system_calls.tmp", R_OK); + remove("system_calls.tmp1"); + + mkdir ("system_call_mkdir", 0777); + rmdir ("system_call_mkdir"); + + return 0; +} Index: testsuite/ltrace.minor/trace-clone.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/trace-clone.exp @@ -0,0 +1,44 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "trace-clone" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} +global LTRACE + +#Run PUT for ltarce. +spawn $LTRACE -f $srcdir/$subdir/$binfile +set timeout 4 +expect timeout { + fail "Time out! Maybe caused by ltrace segment fault or improper timeout value here!" + return +} + +catch "exec $LTRACE -f $srcdir/$subdir/$binfile" exec_output +# Save the output +ltrace_saveoutput "${exec_output}" ${srcdir}/${subdir}/${testfile}.ltrace + +#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 {Operation not permitted} $exec_output ] { + fail "Operation not permitted, see testrun.log for details!" + return +} elseif [ regexp {killed by SIGKILL} $exec_output ] { + fail "killed by SIGKILL!" + return +} + + + +set pattern "clone" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + Index: testsuite/ltrace.minor/trace-fork.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/trace-fork.exp @@ -0,0 +1,40 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "trace-fork" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} +global LTRACE +set exec_output "" + +#Run PUT for ltarce. +spawn $LTRACE -f $srcdir/$subdir/$binfile +set timeout 4 +expect timeout { + fail "Time out! Maybe caused by ltrace segment fault or improper timeout value here!" + return +} + +catch "exec $LTRACE -f $srcdir/$subdir/$binfile" exec_output + +#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 +} + +ltrace_saveoutput "${exec_output}" ${srcdir}/${subdir}/${testfile}.ltrace + +set pattern "fork" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + Index: testsuite/ltrace.minor/time-record-tt.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/time-record-tt.exp @@ -0,0 +1,107 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "time-record" +set srcfile ${testfile}.c +set binfile ${testfile}-tt + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# Set options for ltrace. +ltrace_options "-tt" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Verify the time for calling sleep. +set fd [ open $srcdir/$subdir/$binfile.ltrace r] +set FOUND 0 +while { [gets $fd line] >= 0 } { + # match the line with sleep and extract the strat time and sleep argument. + if [ regexp {[0-9]+:([0-9]+):([0-9]+)\.[0-9]+ sleep\(([0-9]+)} $line match start_min start_sec sleep_sec] then { + # Remove extra zero. + regexp {0([1-9])} $start_min match start_min + regexp {0([1-9])} $start_sec match start_sec + + verbose "start_sec = $start_sec, sleep_sec = $sleep_sec" + # get a new line for the end time of sleep + gets $fd line + regexp {[0-9]+:([0-9]+):([0-9]+)} $line match end_min end_sec + verbose "end_sec = $end_sec" + + # Remove extra zero. + regexp {0([1-9])} $end_min match end_min + regexp {0([1-9])} $end_sec match end_sec + + if { (($end_min - $start_min)*60 + $end_sec - $start_sec)== $sleep_sec } then { + pass "Correct Timestamp." + } else { + fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!" + } + set FOUND 1 + break + } +} +close $fd + +if {$FOUND != 1} then { + fail "Fail to find call sleep!" +} + +# Get the time of sleep and nanosleep in C source file. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { + break + } +} +close $fd + +# Verify the time for calling nanosleep. +set FOUND 0 +set fd [ open $srcdir/$subdir/$binfile.ltrace r] +while { [gets $fd line] >= 0 } { + # match the line with sleep and extract the strat time and sleep argument. + if [ regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then { + # Remove extra zeros. + regexp {0([1-9])} $start_sec match start_sec + regexp {0*([1-9][0-9]*)} $start_usec match start_usec + + verbose "start_sec = $start_sec, start_usec = $start_usec, sleep_usec = $nanosleep_usec" + # get a new line for the end time of sleep + gets $fd line + regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec + + # Remove extra zeros. + regexp {0([1-9])} $end_sec match end_sec + regexp {0*([1-9][0-9]*)} $end_usec match end_usec + + verbose "end_sec = $end_sec, end_usec = $end_usec" + if { (($end_sec - $start_sec)*1000 + $end_usec - $start_usec) >= $nanosleep_usec} then { + pass "Correct Timestamp." + } else { + fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!" + } + set FOUND 1 + break + } +} + +if { $FOUND != 1} then { + fail "Fail to find nanosleep" +} +close $fd + Index: testsuite/ltrace.minor/time-record.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/time-record.c @@ -0,0 +1,23 @@ +/* Ltrace Test : time-record.c. + Objectives : Verify that Ltrace can record timestamp and spent + time inside each call. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ +#include <stdio.h> +#include <time.h> + +#define SLEEP_COUNT 2 +#define NANOSLEEP_COUNT 50 + +int +main () +{ + struct timespec request, remain; + request.tv_sec = 0; + request.tv_nsec = NANOSLEEP_COUNT * 1000000; + + sleep (SLEEP_COUNT); + nanosleep (&request, NULL); + + return 0; +} Index: testsuite/ltrace.minor/demangle.cpp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/demangle.cpp @@ -0,0 +1,121 @@ +/* Ltrace Test : demangle.cpp + Objectives : Verify that ltrace can demangle C++ symbols. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include<stddef.h> +#include"demangle.h" + +/* Number of arguments */ +extern int Fi_i(int); +extern int Fi_s (short); +extern int Fii_i(int , int); +extern int Fiii_i(int, int, int); +extern int Fie_i(int bar, ...); + +/* Return types */ +extern void Fv_v(void); +extern char Fv_c(void); +extern signed char Fv_Sc(void); +extern unsigned char Fv_Uc(void); +extern short Fv_s(void); +extern unsigned short Fv_Us(void); +extern int Fv_i(void); +extern const int Fv_Ci(void); +extern unsigned int Fv_Ui(void); +extern volatile int Fv_Vi(void); +extern long Fv_l(void); +extern unsigned long Fv_Ul(void); +extern float Fv_f(void) ; +extern double Fv_g(void); +extern long double Fv_Lg(void); + + +/* Pointers */ +extern void * Fv_Pv(void); +extern void ** Fv_PPv(void); + +/* References */ +extern int& Fv_Ri(void); + +/* Argument types */ +extern int FPi_i(int *a); +extern int FA10_i_i(int a[10]) ; +extern int Fc_i(char bar); +extern int Ff_i(float bar); +extern int Fg_i(double bar); + +/* Function pointers */ +typedef int (*x)(int); +typedef int (*y)(short); + +extern int Fx_i(x); +extern int Fxx_i(x fnptr, x fnptr2); +extern int Fxxx_i(x fnptr, x fnptr2, x fnptr3); +extern int Fxxi_i(x fnptr, x fnptr2, x fnptr3, int i); +extern int Fxix_i(x fnptr, int i, x fnptr3); +extern int Fxyxy_i(x fnptr, y fnptr2, x fnptr3, y fnptr4); + + +extern void Fmyclass_v(myclass m); +extern void Fmxmx_v(myclass arg1, x arg2, myclass arg3, x arg4); + +int main () +{ + int i; + + i = Fi_i (0); + i = Fii_i (0,0); + i = Fiii_i (0,0,0); + i = Fie_i (0); + + Fv_v (); + Fv_c (); + Fv_Sc (); + Fv_Uc (); + Fv_s (); + Fv_Us (); + Fv_i (); + Fv_Ci (); + Fv_Ui (); + Fv_Vi (); + Fv_l (); + Fv_Ul (); + Fv_f (); + Fv_g (); + Fv_Lg (); + + Fv_Pv (); + Fv_PPv (); + + Fv_Ri (); + + FPi_i (&i); + FA10_i_i (&i); + Fc_i ('a'); + Ff_i (1.1f); + Fg_i (1.1); + + Fx_i (Fi_i); + Fxx_i (Fi_i, Fi_i); + Fxxx_i (Fi_i, Fi_i, Fi_i); + Fxxi_i (Fi_i, Fi_i, Fi_i, 0); + Fxyxy_i (Fi_i, Fi_s, Fi_i, Fi_s); + + myclass a,c; + myclass* b; + + a.Fi_i (0); + a.Fis_i (0); + a++; + c = a + 2; + + nested n; + n.Fi_i (0); + + b = (myclass*) new myclass(0); + delete (b); + Fmyclass_v (a); + + return 0; +} Index: testsuite/ltrace.minor/count-record.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/count-record.exp @@ -0,0 +1,77 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "count-record" +set srcfile ${testfile}.c +set binfile ${testfile} + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-c" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + + +ltrace_saveoutput $exec_output $srcdir/$subdir/$binfile.ltrace + +# +# This is a sample output and Verify the forth and fifth column. +# +# 13.31 0.001051 1051 1 rmdir +# 12.81 0.001012 1012 1 fopen +# 10.32 0.000815 407 2 remove +# 9.56 0.000755 755 1 mkdir +# 7.86 0.000621 621 1 fseek +# 6.86 0.000542 542 1 fwrite +# 6.60 0.000521 521 1 fclose +# 6.03 0.000476 476 1 rename +# 5.61 0.000443 443 1 symlink +# 5.05 0.000399 399 1 chdir +# 4.80 0.000379 379 1 access +# 4.00 0.000316 316 1 __xstat +# 3.81 0.000301 301 1 getcwd +# 3.39 0.000268 268 1 fread +# + +set pattern "\'1 rmdir\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 fopen\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'2 remove\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 mkdir\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 fseek\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 fwrite\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 fclose\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 rename\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 symlink\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 chdir\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 access\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 getcwd\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern +set pattern "\'1 fread\'" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern + Index: testsuite/ltrace.minor/demangle-lib.cpp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/demangle-lib.cpp @@ -0,0 +1,97 @@ +#include<stddef.h> +#include<iostream> + +#include"demangle.h" + +/* Number of arguments */ +int Fi_i(int bar) { return 0; } +int Fi_s(short bar) {return 0; } +int Fii_i(int bar, int goo) { return 0; } +int Fiii_i(int bar, int goo, int hoo) { return 0; } +int Fie_i(int bar, ...) { return 0; } + +/* Return types */ +void Fv_v(void) { ; } +char Fv_c(void) { return 0; } +signed char Fv_Sc(void) { return 0; } +unsigned char Fv_Uc(void) { return 0; } +short Fv_s(void) { return 0; } +unsigned short Fv_Us(void) { return 0; } +int Fv_i(void) { return 0; } +const int Fv_Ci(void) { return 0; } +unsigned int Fv_Ui(void) { return 0; } +volatile int Fv_Vi(void) { return 0; } +long Fv_l(void) { return 0; } +unsigned long Fv_Ul(void) { return 0; } +float Fv_f(void) { return 0; } +double Fv_g(void) { return 0; } +long double Fv_Lg(void) { return 0; } + +/* Pointers */ +void *Fv_Pv(void) { return 0; } +void **Fv_PPv(void) { return 0; } + +/* References */ +int& Fv_Ri(void) { static int x; return x; } + +/* Argument types */ +int FPi_i(int *a) { return 0; } +int FA10_i_i(int a[10]) { return 0; } +int Fc_i(char bar) { return 0; } +int Ff_i(float bar) { return 0; } +int Fg_i(double bar) { return 0; } + +/* Function pointers */ +typedef int (*x)(int); +typedef int (*y)(short); + +int Fx_i(x fnptr) { return 0; } +int Fxx_i(x fnptr, x fnptr2) { return 0; } +int Fxxx_i(x fnptr, x fnptr2, + x fnptr3) { return 0; } +int Fxxi_i(x fnptr, x fnptr2, + x fnptr3, int i) { return 0; } +int Fxix_i(x fnptr, int i, + x fnptr3) { return 0; } +int Fxyxy_i(x fnptr, y fnptr2, + x fnptr3, y fnptr4) { return 0; } + +/* Class methods */ +class myclass; +myclass::myclass(void) { myint = 0; } +myclass::myclass(int x) { myint = x; } +myclass::~myclass() { ; } + +int myclass::Fi_i(int bar) { return myint; } +int myclass::Fis_i(int bar) { return bar; } + +void* myclass::operator new(size_t size) +{ + void* p = malloc(size);return p; +} +void myclass::operator delete(void *p) {free(p);} + +myclass myclass::operator++() { return myclass(++myint); } +myclass myclass::operator++(int) { return myclass(myint++); } + +/* Binary */ +myclass myclass::operator+(int x) { return myclass(myint + x); } + +/* Assignment */ +myclass& myclass::operator=(const myclass& from) +{ + myint = from.myint; + return *this; +} + +/* test clashes */ +class nested; + +nested::nested(void) { ; } +nested::~nested() { ; } +int nested::Fi_i(int bar) { return bar; } + +void Fmyclass_v(myclass m) { ; } +void Fmxmx_v(myclass arg1, x arg2, + myclass arg3, x arg4) { ; } + Index: testsuite/ltrace.minor/attach-process.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/attach-process.c @@ -0,0 +1,16 @@ +/* Ltrace Test : attach-process.c. + Objectives : Verify that ltrace can attach to a running process + by its PID. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include<unistd.h> +#include <sys/types.h> + +int +main () +{ + sleep (5); + sleep (1); + return 0; +} Index: testsuite/ltrace.minor/demangle.h =================================================================== --- /dev/null +++ testsuite/ltrace.minor/demangle.h @@ -0,0 +1,36 @@ + +class myclass { + int myint; + public: + myclass(int x); + myclass(void); + ~myclass(); + static int Fis_i(int bar); + int Fi_i(int bar); + /* Overloaded operators */ + void* operator new(size_t); + void operator delete(void *); + /* Unary operation. */ + myclass operator++();// Preincrement + myclass operator++(int);// Postincrement + + /* Binary operation. */ + myclass operator+(int); + + /* Assignment */ + myclass& operator=(const myclass& from); + /* Nested classes */ + class nested { + public: + nested(); + ~nested(); + int Fi_i(int bar); + }; +}; + +class nested { + public: + nested(); + ~nested(); + int Fi_i(int bar); +}; Index: testsuite/ltrace.minor/time-record-T.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/time-record-T.exp @@ -0,0 +1,84 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "time-record" +set srcfile ${testfile}.c +set binfile ${testfile}-T + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-T" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Get the time of nanosleep in C source file. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { + break + } +} +close $fd + + +# Verify the time for calling sleep. +set fd [ open $srcdir/$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 {sleep\(([0-9]+).*<([0-9]+\.[0-9]+)>} $line match sleep_sec sec ] then { + verbose "sleep_sec = $sleep_sec, sec = $sec" + + if { $sec >= $sleep_sec } then { + pass "Correct Time spent inside call." + } else { + fail "Spent $sec inside call, but PUT call sleep($sleep_sec)!" + } + set FOUND 1 + break + } +} +close $fd + +if {$FOUND != 1} then { + fail "Fail to find call sleep!" +} + +# Verify the time for calling nanosleep. +set FOUND 0 +set fd [ open $srcdir/$subdir/$binfile.ltrace r] +while { [gets $fd line] >= 0 } { + # match the line with nanosleep and extract spent time and nanosleep argument. + if [ regexp {nanosleep.*<([0-9]+\.[0-9]+)>} $line match usec] then { + verbose "nanosleep_usec = $nanosleep_usec, usec = $usec" + + if { $usec * 1000 >= $nanosleep_usec} then { + pass "Correct Time spent inside call." + } else { + fail "Spent $usec inside call, but PUT call nanosleep($nanosleep_usec)!" + } + set FOUND 1 + break + } +} + +if { $FOUND != 1} then { + fail "Fail to find nanosleep" +} +close $fd + Index: testsuite/ltrace.minor/demangle.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/demangle.exp @@ -0,0 +1,63 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "demangle" +set srcfile ${testfile}.cpp +set binfile ${testfile} +set libfile "demangle-lib" +set libsrc $srcdir/$subdir/$libfile.cpp +set lib_sl $srcdir/$subdir/lib$testfile.so + +verbose "compiling source file now....." +if [get_compiler_info $binfile "c++"] { + return -1 +} + +verbose "compiling source file now....." +if { [ltrace_compile_shlib $libsrc $lib_sl [list debug c++]] != "" + || [ltrace_compile $srcdir/$subdir/$srcfile $srcdir/$subdir/$binfile executable [list debug shlib=$lib_sl c++] ] != ""} { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# set options for ltrace. +ltrace_options "-C" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# read function declarations from demangle.cpp and verify them in demangle.ltrace. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + if [regexp {extern (double|float|void|char|int|short|long|void \*|void \*\*) ([^ ])\(} $line match type fun] { + ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $fun + } +} +close $fd + +#read member fucntions of classs from demangle-lib.cpp and verify them in demagle.ltrace. +set fd [ open $srcdir/$subdir/$testfile-lib.cpp r] +while { [gets $fd line] >= 0 } { + if [ regexp {((myclass|nested)::[^\(]*)\(} $line match fun] { + # For Debug purpose. + verbose "fun = $fun" + # Extract new/delete for remove extra SPACE in $fun, for example, + # $fun = "myclass::operator delete" will confuse ltrace_verify_output if it + # was an argument to it. + if [regexp {(new|delete)} $fun match sub_fun] { + ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $sub_fun + } else { + # Verify class member functions without SPACE. + ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $fun + } + } +} +close $fd Index: testsuite/ltrace.minor/print-instruction-pointer.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/print-instruction-pointer.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +int main () +{ + int i=0; + printf("%d\n",i); + i=1; + printf("%d\n",i); + + return 0; +} Index: testsuite/ltrace.minor/attach-process.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/attach-process.exp @@ -0,0 +1,38 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "attach-process" +set srcfile ${testfile}.c +set binfile ${testfile} + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# Run the program and get PID of it. +catch "exec $srcdir/$subdir/$binfile &" output + +# get PID from ps output. +regexp {([0-9]+)} $output match PID +verbose "PID = $PID" + +# Run PUT for ltarce. +global LTRACE +catch "exec $LTRACE -S -p $PID -o ${srcdir}/${subdir}/${testfile}.ltrace" exec_output + +# 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 +} + +# Verify the output in attach-process.ltrace by checking the number +# of sleep. +set pattern "sleep" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern 1 + Index: testsuite/ltrace.minor/trace-clone.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/trace-clone.c @@ -0,0 +1,31 @@ +/* Ltrace Test : trace-clone.c. + Objectives : Verify that ltrace can trace to child process after + clone called. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include <stdio.h> +#include <sys/types.h> +#include <stdlib.h> +#include <sched.h> + +int child () +{ + return 0; +} + +typedef int (* myfunc)(); + +int main () +{ + pid_t pid; + static char stack[1024]; + + if ((pid = clone((myfunc)&child, stack,CLONE_FS, NULL )) < 0) + { + perror("clone called failed"); + exit (1); + } + + return 0; +} Index: testsuite/ltrace.minor/time-record-ttt.exp =================================================================== --- /dev/null +++ testsuite/ltrace.minor/time-record-ttt.exp @@ -0,0 +1,112 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "time-record" +set srcfile ${testfile}.c +set binfile ${testfile}-ttt + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +} + +# Set options for ltrace. +ltrace_options "-ttt" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Verify the time for calling sleep. +set fd [ open $srcdir/$subdir/$binfile.ltrace r] +set FOUND 0 +while { [gets $fd line] >= 0 } { + # match the line with sleep and extract the strat time and sleep argument. + if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* sleep\(([0-9]+)} $line match start_sec start_usec sleep_sec] then { + + # Remove extra zeros. + regexp {0*([1-9][0-9]*)} $start_sec match start_sec + regexp {0*([1-9][0-9]*)} $start_usec match start_usec + + verbose "start_sec = $start_sec, start_usec = $start_usec,sleep_sec = $sleep_sec" + # get a new line for the end time of sleep + gets $fd line + regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec + verbose "end_sec = $end_sec, end_usec=$end_usec" + + # Remove extra zeros. + regexp {0*([1-9][0-9]*)} $end_sec match end_sec + regexp {0*([1-9][0-9]*)} $end_usec match end_usec + + if { $end_sec - $start_sec >= $sleep_sec } then { + pass "Correct Timestamp." + } else { + fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!" + } + set FOUND 1 + break + } +} + +close $fd + +if {$FOUND != 1} then { + fail "Fail to find call sleep!" +} + + +# Get the time of nanosleep in C source file. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { + break + } +} +close $fd + +# Verify the time for calling nanosleep. +set FOUND 0 +set fd [ open $srcdir/$subdir/$binfile.ltrace r] +while { [gets $fd line] >= 0 } { + # match the line with sleep and extract the strat time and sleep argument. + if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then { + + # Remove extra zeros. + regexp {0*([1-9][0-9]*)} $start_sec match start_sec + regexp {0*([1-9][0-9]*)} $start_usec match start_usec + + verbose "start_sec = $start_sec, start_usec = $start_usec, nanosleep_usec = $nanosleep_usec" + # get a new line for the end time of sleep + gets $fd line + regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec + + # Remove extra zeros. + regexp {0*([1-9][0-9]*)} $end_sec match end_sec + regexp {0*([1-9][0-9]*)} $end_usec match end_usec + + verbose "end_sec = $end_sec, end_usec = $end_usec" + if { ($end_sec - $start_sec)*1000 + $end_usec - $start_usec >= $nanosleep_usec} then { + pass "Correct Timestamp." + } else { + fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!" + } + set FOUND 1 + break + } +} + +if { $FOUND != 1} then { + fail "Fail to find nanosleep" +} +close $fd + Index: testsuite/ltrace.minor/trace-fork.c =================================================================== --- /dev/null +++ testsuite/ltrace.minor/trace-fork.c @@ -0,0 +1,33 @@ +/* Ltrace Test : trace-fork.c + Objectives : Verify that ltrace can trace to child process after + fork called. + + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include <stdio.h> +#include <sys/types.h> + +void +child () +{ + printf("Fork Child\n"); + sleep(1); +} + +int +main () +{ + pid_t pid; + pid = fork (); + + if (pid == -1) + printf("fork failed!\n"); + else if (pid == 0) + child(); + else + { + printf("My child pid is %d\n",pid); + wait(); + } + return 0; +} Index: testsuite/ltrace.torture/signals.c =================================================================== --- /dev/null +++ testsuite/ltrace.torture/signals.c @@ -0,0 +1,44 @@ +/* Ltrace Test : signals.c. + Objectives : Verify that ltrace can trace user defined signal. + This file was written by Yao Qi <qiyao@cn.ibm.com>. */ + +#include<stdio.h> +#include<signal.h> +#include <sys/types.h> + +#define LOOP 20 + +void +handler(int signum,siginfo_t *info,void *act) +{ +} + +int +main () +{ + struct sigaction act; + union sigval mysigval; + int i; + int sig; + pid_t pid; + + mysigval.sival_int=0; + sig = 10; + pid=getpid(); + + sigemptyset(&act.sa_mask); + act.sa_sigaction=handler; + act.sa_flags=SA_SIGINFO; + + if(sigaction(sig,&act,NULL) < 0) + { + printf("install sigal error\n"); + } + + for(i=0; i< LOOP; i++) + { + usleep(100); + sigqueue(pid,sig,mysigval); + } + return 0; +} Index: testsuite/ltrace.torture/Makefile.in =================================================================== --- /dev/null +++ testsuite/ltrace.torture/Makefile.in @@ -0,0 +1,34 @@ +# Copyright (C) 1992 - 2001 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 1, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +CLEANFILES = *.log *.sum site.bak setval.tmp site.exp + +.SUFFIXES: +clean: + -rm -f signals + -rm -f *.o *.so + -rm -f *.ltrace + -rm -f $(CLEANFILES) +distclean: clean + -rm -f Makefile + + +.PHONY: $(RECURSIVE_TARGETS) check clean distclean realclean + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: Index: testsuite/ltrace.torture/signals.exp =================================================================== --- /dev/null +++ testsuite/ltrace.torture/signals.exp @@ -0,0 +1,37 @@ +# This file was written by Yao Qi <qiyao@cn.ibm.com>. + +set testfile "signals" +set srcfile ${testfile}.c +set binfile ${testfile} + + +verbose "compiling source file now....." +# Build the shared libraries this test case needs. +if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${subdir}/${binfile}" executable {debug} ] != "" } { + send_user "Testcase compile failed, so all tests in this file will automatically fail\n." +} + +# Set options for ltrace. +ltrace_options "-L" + +# Run PUT for ltarce. +set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$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 +} + +# Extract LOOP from source file. +set fd [ open $srcdir/$subdir/$srcfile r] +while { [gets $fd line] >= 0 } { + regexp {define LOOP.*([0-9]+)} $line match count +} +set pattern "SIGUSR1" +ltrace_verify_output ${srcdir}/${subdir}/${testfile}.ltrace $pattern $count +
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor