diff options
author | fche <fche> | 2006-08-12 05:13:09 +0000 |
---|---|---|
committer | fche <fche> | 2006-08-12 05:13:09 +0000 |
commit | 814bc89d4635f101b2c0077598f31aad95ed15b7 (patch) | |
tree | 407a49dbaf446af4751f5068607a7fb8dad0611d | |
parent | 6b6d04673a1ef175821afc7d4fabdb496698e8e3 (diff) | |
download | systemtap-steved-814bc89d4635f101b2c0077598f31aad95ed15b7.tar.gz systemtap-steved-814bc89d4635f101b2c0077598f31aad95ed15b7.tar.xz systemtap-steved-814bc89d4635f101b2c0077598f31aad95ed15b7.zip |
2006-08-12 Frank Ch. Eigler <fche@elastic.org>
* configure.ac, Makefile.am: Descend into testsuite/
directory. Remove local test logic.
* configure, Makefile.in: Regenerated.
* runtest.sh: Not yet removed.
* HACKING: Update for new testsuite layout.
2006-08-12 Frank Ch. Eigler <fche@elastic.org>
* all: Reorganized old pass-1..4 tests one dejagnu bucket.
Moved over old pass-5 tests, except for disabled syscalls tests.
* Makefile (installcheck): New target for running pass-1..5
tests against installed systemtap.
195 files changed, 6587 insertions, 125 deletions
@@ -1,3 +1,11 @@ +2006-08-12 Frank Ch. Eigler <fche@elastic.org> + + * configure.ac, Makefile.am: Descend into testsuite/ + directory. Remove local test logic. + * configure, Makefile.in: Regenerated. + * runtest.sh: Not yet removed. + * HACKING: Update for new testsuite layout. + 2006-08-10 David Smith <dsmith@redhat.com> * elaborate.cxx (duplicate_function_remover): Added class. @@ -11,6 +19,7 @@ the original probe (BZ# 2421). 2006-08-08 Li Guanglei <guanglei@cn.ibm.com> + * stapprobes.5.in: document process.*, tcp.*, udp.* 2006-08-09 Thang Nguyen <thang.p.nguyen@intel.com> @@ -40,17 +40,18 @@ the <systemtap@sources.redhat.com> mailing list. As far as practicable, changes should be accompanied by test cases to prevent future regressions. Tests should be run on at least - x86, and ideally also on some 64-bit platform. + x86, and ideally also on some 64-bit platform. The test suite is + located under /src/testsuite and is based on dejagnu. "make check" + runs unprivileged tests only against an uninstalled build tree. + "make installcheck" runs all tests against an installed tree. Tests that don't require probe execution should go into new or - modified files under /src/testsuite/, a simple automake-flavoured - bucket. Subdirectories exist for testing only up to pass 1 - (parseok/parseko), pass 2 (semok/semko), pass 3 (transok,transko), - and pass 4 (buildok/buildko). The "ko" tests are for expected - (deliberate) errors. - - Tests that execute probes (pass 5) go under /tests/testsuite/, a - dejagnu-based bucket that will require root access to run. + modified files under the *{ok,ko} directories, which are scanned + by corresponding systemtap.pass1-4/*.exp files. The "ko" tests are + for expected (deliberate) errors. + + Tests that execute probes (pass 5) should include their own .exp/.stp + files under any other appropriate systemtap.* testsuite subdirectory. - translator diff --git a/Makefile.am b/Makefile.am index 9ab51d1e..b02f8a9e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,21 +82,6 @@ install-data-local: (cd $(srcdir)/tapset; find . -name '*.stp' -print \ | while read f; do $(INSTALL_DATA) -D $$f $(DESTDIR)$(pkgdatadir)/tapset/$$f; done) -p=$(srcdir)/testsuite/parse -s=$(srcdir)/testsuite/sem -t=$(srcdir)/testsuite/trans -b=$(srcdir)/testsuite/build -TESTS = $(wildcard $(p)ok/*.stp) $(wildcard $(p)ko/*.stp) \ - $(wildcard $(s)ok/*.stp) $(wildcard $(s)ko/*.stp) \ - $(wildcard $(t)ok/*.stp) $(wildcard $(t)ko/*.stp) \ - $(wildcard $(b)ok/*.stp) $(wildcard $(b)ko/*.stp) -XFAIL_TESTS = $(wildcard $(p)ko/*.stp) \ - $(wildcard $(s)ko/*.stp) \ - $(wildcard $(t)ko/*.stp) \ - $(wildcard $(b)ko/*.stp) - -TESTS_ENVIRONMENT = $(srcdir)/runtest.sh - TEST_COV_DIR = coverage gcov: @@ -113,7 +98,6 @@ lcov: clean-local: rm -f *.gcov *.gcno *.gcda ${PACKAGE_TARNAME}-*.tar.gz - rm -rf testresults rm -rf ${PACKAGE_TARNAME}-${PACKAGE_VERSION} rm -rf $(TEST_COV_DIR) rm -rf stap.info @@ -123,6 +107,8 @@ uninstall-local: rm -rf $(DESTDIR)$(libexecdir)/$(PACKAGE) -rm -rf $(DESTDIR)$(localstatedir)/cache/$(PACKAGE) +SUBDIRS = testsuite if BUILD_LKET_B2A - SUBDIRS = runtime/lket/b2a + SUBDIRS += runtime/lket/b2a endif + diff --git a/Makefile.in b/Makefile.in index 83e13c5e..11a7bbc0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -46,6 +46,7 @@ bin_PROGRAMS = stap$(EXEEXT) @BUILD_ELFUTILS_FALSE@stap_DEPENDENCIES = pkglibexec_PROGRAMS = stpd$(EXEEXT) noinst_PROGRAMS = loc2c-test$(EXEEXT) +@BUILD_LKET_B2A_TRUE@am__append_4 = runtime/lket/b2a subdir = . DIST_COMMON = README $(am__configure_deps) $(dist_man_MANS) \ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ @@ -112,7 +113,7 @@ NROFF = nroff MANS = $(dist_man_MANS) ETAGS = etags CTAGS = ctags -DIST_SUBDIRS = runtime/lket/b2a +DIST_SUBDIRS = testsuite runtime/lket/b2a DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -247,23 +248,8 @@ EXTRA_DIST = buildrun.h elaborate.h loc2c.h session.h \ parse.h staptree.h tapsets.h translate.h \ testsuite runtest.sh systemtap.spec runtime tapset -p = $(srcdir)/testsuite/parse -s = $(srcdir)/testsuite/sem -t = $(srcdir)/testsuite/trans -b = $(srcdir)/testsuite/build -TESTS = $(wildcard $(p)ok/*.stp) $(wildcard $(p)ko/*.stp) \ - $(wildcard $(s)ok/*.stp) $(wildcard $(s)ko/*.stp) \ - $(wildcard $(t)ok/*.stp) $(wildcard $(t)ko/*.stp) \ - $(wildcard $(b)ok/*.stp) $(wildcard $(b)ko/*.stp) - -XFAIL_TESTS = $(wildcard $(p)ko/*.stp) \ - $(wildcard $(s)ko/*.stp) \ - $(wildcard $(t)ko/*.stp) \ - $(wildcard $(b)ko/*.stp) - -TESTS_ENVIRONMENT = $(srcdir)/runtest.sh TEST_COV_DIR = coverage -@BUILD_LKET_B2A_TRUE@SUBDIRS = runtime/lket/b2a +SUBDIRS = testsuite $(am__append_4) all: $(BUILT_SOURCES) config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive @@ -849,79 +835,6 @@ GTAGS: distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -check-TESTS: $(TESTS) - @failed=0; all=0; xfail=0; xpass=0; skip=0; \ - srcdir=$(srcdir); export srcdir; \ - list='$(TESTS)'; \ - if test -n "$$list"; then \ - for tst in $$list; do \ - if test -f ./$$tst; then dir=./; \ - elif test -f $$tst; then dir=; \ - else dir="$(srcdir)/"; fi; \ - if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *" $$tst "*) \ - xpass=`expr $$xpass + 1`; \ - failed=`expr $$failed + 1`; \ - echo "XPASS: $$tst"; \ - ;; \ - *) \ - echo "PASS: $$tst"; \ - ;; \ - esac; \ - elif test $$? -ne 77; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *" $$tst "*) \ - xfail=`expr $$xfail + 1`; \ - echo "XFAIL: $$tst"; \ - ;; \ - *) \ - failed=`expr $$failed + 1`; \ - echo "FAIL: $$tst"; \ - ;; \ - esac; \ - else \ - skip=`expr $$skip + 1`; \ - echo "SKIP: $$tst"; \ - fi; \ - done; \ - if test "$$failed" -eq 0; then \ - if test "$$xfail" -eq 0; then \ - banner="All $$all tests passed"; \ - else \ - banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ - fi; \ - else \ - if test "$$xpass" -eq 0; then \ - banner="$$failed of $$all tests failed"; \ - else \ - banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ - fi; \ - fi; \ - dashes="$$banner"; \ - skipped=""; \ - if test "$$skip" -ne 0; then \ - skipped="($$skip tests were not run)"; \ - test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$skipped"; \ - fi; \ - report=""; \ - if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ - report="Please report to $(PACKAGE_BUGREPORT)"; \ - test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$report"; \ - fi; \ - dashes=`echo "$$dashes" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - test -z "$$skipped" || echo "$$skipped"; \ - test -z "$$report" || echo "$$report"; \ - echo "$$dashes"; \ - test "$$failed" -eq 0; \ - else :; fi - distdir: $(DISTFILES) $(am__remove_distdir) mkdir $(distdir) @@ -1068,7 +981,6 @@ distcleancheck: distclean $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) check-recursive all-am: Makefile $(PROGRAMS) $(SCRIPTS) $(MANS) config.h @@ -1166,11 +1078,11 @@ uninstall-info: uninstall-info-recursive uninstall-man: uninstall-man1 uninstall-man5 .PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am am--refresh check \ - check-TESTS check-am clean clean-binPROGRAMS clean-generic \ - clean-local clean-noinstPROGRAMS clean-pkglibexecPROGRAMS \ - clean-recursive ctags ctags-recursive dist dist-all dist-bzip2 \ - dist-gzip dist-hook dist-shar dist-tarZ dist-zip distcheck \ - distclean distclean-compile distclean-generic distclean-hdr \ + check-am clean clean-binPROGRAMS clean-generic clean-local \ + clean-noinstPROGRAMS clean-pkglibexecPROGRAMS clean-recursive \ + ctags ctags-recursive dist dist-all dist-bzip2 dist-gzip \ + dist-hook dist-shar dist-tarZ dist-zip distcheck distclean \ + distclean-compile distclean-generic distclean-hdr \ distclean-recursive distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-binPROGRAMS install-data \ @@ -1229,7 +1141,6 @@ lcov: clean-local: rm -f *.gcov *.gcno *.gcda ${PACKAGE_TARNAME}-*.tar.gz - rm -rf testresults rm -rf ${PACKAGE_TARNAME}-${PACKAGE_VERSION} rm -rf $(TEST_COV_DIR) rm -rf stap.info @@ -5222,7 +5222,7 @@ DATE="$date" ac_config_headers="$ac_config_headers config.h:config.in" - ac_config_files="$ac_config_files Makefile systemtap.spec stp_check stap.1 stapprobes.5 stapfuncs.5 stapex.5 lket.5 runtime/lket/b2a/Makefile" + ac_config_files="$ac_config_files Makefile systemtap.spec stp_check stap.1 stapprobes.5 stapfuncs.5 stapex.5 lket.5 runtime/lket/b2a/Makefile testsuite/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -5817,6 +5817,7 @@ do "stapex.5" ) CONFIG_FILES="$CONFIG_FILES stapex.5" ;; "lket.5" ) CONFIG_FILES="$CONFIG_FILES lket.5" ;; "runtime/lket/b2a/Makefile" ) CONFIG_FILES="$CONFIG_FILES runtime/lket/b2a/Makefile" ;; + "testsuite/Makefile" ) CONFIG_FILES="$CONFIG_FILES testsuite/Makefile" ;; "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 diff --git a/configure.ac b/configure.ac index ac48e0ec..e2ce76a9 100644 --- a/configure.ac +++ b/configure.ac @@ -59,7 +59,7 @@ AC_DEFINE_UNQUOTED(DATE, "$date", [Configuration/build date]) AC_SUBST(DATE, "$date") AC_CONFIG_HEADERS([config.h:config.in]) -AC_CONFIG_FILES(Makefile systemtap.spec stp_check stap.1 stapprobes.5 stapfuncs.5 stapex.5 lket.5 runtime/lket/b2a/Makefile) +AC_CONFIG_FILES(Makefile systemtap.spec stp_check stap.1 stapprobes.5 stapfuncs.5 stapex.5 lket.5 runtime/lket/b2a/Makefile testsuite/Makefile) AC_OUTPUT if test $build_elfutils = yes; then diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog new file mode 100644 index 00000000..29896f99 --- /dev/null +++ b/testsuite/ChangeLog @@ -0,0 +1,6 @@ +2006-08-12 Frank Ch. Eigler <fche@elastic.org> + + * all: Reorganized old pass-1..4 tests one dejagnu bucket. + Moved over old pass-5 tests, except for disabled syscalls tests. + * Makefile (installcheck): New target for running pass-1..5 + tests against installed systemtap. diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am new file mode 100644 index 00000000..c2bd2d9c --- /dev/null +++ b/testsuite/Makefile.am @@ -0,0 +1,18 @@ +# Makefile.am --- automake input file for systemtap +## process this file with automake to produce Makefile.in + +AUTOMAKE_OPTIONS = dejagnu + + +# The stap symlink is to enable "#! stap" test scripts. +all-local: + @ln -sf ../stap . + +clean-local: + @rm -f ./stap site.exp + +check-local: + +installcheck-local: clean site.exp + echo "set prefix $(DESTDIR)$(prefix)" >> site.exp + $(MAKE) AM_RUNTESTFLAGS="--tool_opts install" check diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in new file mode 100644 index 00000000..640938a4 --- /dev/null +++ b/testsuite/Makefile.in @@ -0,0 +1,342 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Makefile.am --- automake input file for systemtap +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +subdir = testsuite +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ChangeLog +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +DEJATOOL = $(PACKAGE) +RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir +EXPECT = expect +RUNTEST = runtest +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BUILD_ELFUTILS_FALSE = @BUILD_ELFUTILS_FALSE@ +BUILD_ELFUTILS_TRUE = @BUILD_ELFUTILS_TRUE@ +BUILD_LKET_B2A_FALSE = @BUILD_LKET_B2A_FALSE@ +BUILD_LKET_B2A_TRUE = @BUILD_LKET_B2A_TRUE@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ +MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +U = @U@ +VERSION = @VERSION@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +stap_LIBS = @stap_LIBS@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +AUTOMAKE_OPTIONS = dejagnu +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu testsuite/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu testsuite/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +uninstall-info-am: +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + + +check-DEJAGNU: site.exp + srcdir=`$(am__cd) $(srcdir) && pwd`; export srcdir; \ + EXPECT=$(EXPECT); export EXPECT; \ + runtest=$(RUNTEST); \ + if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \ + l='$(DEJATOOL)'; for tool in $$l; do \ + $$runtest $(AM_RUNTESTFLAGS) $(RUNTESTDEFAULTFLAGS) $(RUNTESTFLAGS); \ + done; \ + else echo "WARNING: could not find \`runtest'" 1>&2; :;\ + fi +site.exp: Makefile + @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 + +distclean-DEJAGNU: + -rm -f site.exp site.bak + -l='$(DEJATOOL)'; for tool in $$l; do \ + rm -f $$tool.sum $$tool.log; \ + done + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) check-DEJAGNU check-local +check: check-am +all-am: Makefile all-local +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-local mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-DEJAGNU distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: installcheck-local + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am + +.PHONY: all all-am all-local check check-DEJAGNU check-am check-local \ + clean clean-generic clean-local distclean distclean-DEJAGNU \ + distclean-generic distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installcheck-local \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \ + uninstall-am uninstall-info-am + + +# The stap symlink is to enable "#! stap" test scripts. +all-local: + @ln -sf ../stap . + +clean-local: + @rm -f ./stap site.exp + +check-local: + +installcheck-local: clean site.exp + echo "set prefix $(DESTDIR)$(prefix)" >> site.exp + $(MAKE) AM_RUNTESTFLAGS="--tool_opts install" check +# 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: diff --git a/testsuite/lib/stap_run.exp b/testsuite/lib/stap_run.exp new file mode 100644 index 00000000..d230e8e5 --- /dev/null +++ b/testsuite/lib/stap_run.exp @@ -0,0 +1,72 @@ +# stap_run.exp +# +# Will Cohen +# 8/12/2005 + + +# stap_run TEST_NAME LOAD_GEN_FUNCTION OUTPUT_CHECK_STRING +# TEST_NAME is path to the current test +# LOAD_GEN_FUNCTION (optional) to produce something to measure +# returns 0 if successful +# returns 1 if there was a problem +# OUTPUT_CHECK_STRING (optional) examines the output of experiment +# returns 0 if successful +# returns 1 if there was a problem +# Additional arguments are passed to stap as-is. +proc stap_run { TEST_NAME {LOAD_GEN_FUNCTION ""} {OUTPUT_CHECK_STRING ""} args } { + if {![installtest_p]} { untested $TEST_NAME; return } + + set cmd [concat {stap -v} $args] + if [file readable $TEST_NAME] { + lappend cmd $TEST_NAME + } + eval spawn $cmd + expect { + -re {^Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms.\r\n} + {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"; exp_continue} + -re {^Pass 5: starting run.\r\n} {exp_continue} + -timeout 30 -re "^systemtap starting probe\r\n" { + pass "$TEST_NAME startup" + if {$LOAD_GEN_FUNCTION != ""} then { + #run the interesting test here + if {[eval $LOAD_GEN_FUNCTION] == 0} then { + pass "$TEST_NAME load generation" + } else { + fail "$TEST_NAME load generation" + } + } + + send "\003" + + #check the output to see if it is sane + set output "^systemtap ending probe\r\n$OUTPUT_CHECK_STRING" + + expect { + -re $output { + pass "$TEST_NAME shutdown and output" + expect { + -re {^Pass\ ([5]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms.\r\n} + {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)" + verbose -log "metric:\t$TEST_NAME $pass1$pass2$pass3$pass4$pass5"} + } + } + timeout { fail "$TEST_NAME shutdown (timeout)" } + eof { fail "$TEST_NAME shutdown (eof)" } + } + } + -re "semantic error:" { fail "$TEST_NAME compilation" } + timeout { fail "$TEST_NAME startup (timeout)"; send "\003" } + eof { fail "$TEST_NAME startup (eof)" } + } + catch close + wait +} + +proc no_load {} { +# nothing in here +# load to use when nothing is needed + return 0 +} + +# tests better all be true +set all_pass_string "(systemtap test success\r\n)+" diff --git a/testsuite/lib/stap_run2.exp b/testsuite/lib/stap_run2.exp new file mode 100644 index 00000000..a182a2c5 --- /dev/null +++ b/testsuite/lib/stap_run2.exp @@ -0,0 +1,51 @@ +# stap_run2.exp +# +# Simple script for testing multiple lines of exact output. + + +# stap_run2 TEST_NAME +# TEST_NAME is path to the current test +# Additional arguments are passed to stap as-is. +# +# global result_string must be set to the expected output + +set timeout 20 + +proc stap_run2 { TEST_NAME args } { + if {![installtest_p]} { untested $TEST_NAME; return } + + # fix up expected string + regsub -all \n $::result_string \r\n output + + # spawn test + set cmd [concat {stap -v} $args] + if [file readable $TEST_NAME] { + lappend cmd $TEST_NAME + } + eval spawn $cmd + + expect { + -re {^Pass\ ([1234]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms.\r\n} + {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)"; exp_continue} + -re {^Pass 5: starting run.\r\n} {exp_continue} + -ex $output { + pass "$TEST_NAME passed" + expect { + -re {^Pass\ ([5]):[^\r]*\ in\ ([0-9]+)usr/([0-9]+)sys/([0-9]+)real\ ms.\r\n} + {set pass$expect_out(1,string) "\t$expect_out(2,string)\t$expect_out(3,string)\t$expect_out(4,string)" + verbose -log "metric:\t$TEST_NAME $pass1$pass2$pass3$pass4$pass5"} + } + } + timeout { + fail "$TEST_NAME timed out" } + eof { + fail "$TEST_NAME unexpected EOF" } + -re "semantic error:" { fail "$TEST_NAME compilation" } + -re "ERROR:" { + send "\003" + fail "$TEST_NAME runtime error" + } + } + catch close + wait +} diff --git a/testsuite/lib/stap_run_binary.exp b/testsuite/lib/stap_run_binary.exp new file mode 100644 index 00000000..6d5de4b8 --- /dev/null +++ b/testsuite/lib/stap_run_binary.exp @@ -0,0 +1,23 @@ +# stap_run_binary.exp +# +# Simple script for testing binary output +# stap_run_binary TEST_NAME +# TEST_NAME is path to the current test +# global result_string must be set to the expected output + +proc stap_run_binary { TEST_NAME} { + if {![installtest_p]} { untested $TEST_NAME; return } + + set hex_args {-ve 8/1 "%02x " "\n"} + set res [exec stap $TEST_NAME | hexdump $hex_args] + + if {[string compare $res $::result_string] == 0} { + pass "$TEST_NAME passed" + } else { + fail "$TEST_NAME failed" + puts "EXPECTED:\n-----------------------\n<$::result_string>" + puts "-----------------------\n" + puts "GOT:\n-----------------------\n<$res>" + puts "-----------------------\n" + } +} diff --git a/testsuite/lib/systemtap.exp b/testsuite/lib/systemtap.exp new file mode 100644 index 00000000..6bb578b4 --- /dev/null +++ b/testsuite/lib/systemtap.exp @@ -0,0 +1,61 @@ +load_lib site.exp + +proc installtest_p {} { + global TOOL_OPTIONS + if {[info exists TOOL_OPTIONS] && ($TOOL_OPTIONS == "install")} { + return 1 + } else { return 0 } +} + +proc print_systemtap_version {} { + set version [exec /bin/uname -r] + set location "/boot/vmlinux-$version" + if {! [file exists $location]} { + # try the debuginfo location + set location "/usr/lib/debug/lib/modules/$version/vmlinux" + if {! [file exists $location]} { set location "" } + } + + print "kernel location: $location" + print "kernel version: $version" + + set location [exec /usr/bin/which stap] + regexp {version [^)]*} [exec stap -V 2>@ stdout] version + + print "systemtap location: $location" + print "systemtap version: $version" +} + + +proc setup_systemtap_environment {} { + global srcdir prefix env + + # need an absolute SRCDIR for the top-level src/ tree + if {[string index $srcdir 0] != "/"} then { + set env(SRCDIR) [exec pwd]/$srcdir/.. + } else { + set env(SRCDIR) $srcdir/.. + } + + if [installtest_p] { + set env(LD_LIBRARY_PATH) $prefix/lib/systemtap + set env(SYSTEMTAP_TAPSET) $prefix/share/systemtap/tapset + set env(SYSTEMTAP_RUNTIME) $prefix/share/systemtap/runtime + set env(PATH) $prefix/bin:$env(PATH) + } else { + set env(LD_LIBRARY_PATH) ../lib-elfutils:../lib-elfutils/systemtap + set env(SYSTEMTAP_TAPSET) $env(SRCDIR)/tapset + set env(SYSTEMTAP_RUNTIME) $env(SRCDIR)/runtime + set env(PATH) ..:$env(PATH) + } +} + + +setup_systemtap_environment +print_systemtap_version + + +proc systemtap_init {args} {} +proc systemtap_version {} {} +proc systemtap_exit {} {} + diff --git a/testsuite/systemtap.base/add.exp b/testsuite/systemtap.base/add.exp new file mode 100644 index 00000000..e0522ae2 --- /dev/null +++ b/testsuite/systemtap.base/add.exp @@ -0,0 +1,7 @@ +# Simple function to test that systemtap addition works + +load_lib "stap_run.exp" + +set test "add" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/add.stp b/testsuite/systemtap.base/add.stp new file mode 100644 index 00000000..3fa7be38 --- /dev/null +++ b/testsuite/systemtap.base/add.stp @@ -0,0 +1,26 @@ +/* + * add.stp + * + * Check the systemtap "addition" works + */ + +global x3 +global x1 +global x2 + +probe begin +{ + log("systemtap starting probe") + x1 = 42; x2 = 53; +} + +probe end +{ + log("systemtap ending probe") + x3 = x1 + x2; + if (x3 != 95 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.base/bench.exp b/testsuite/systemtap.base/bench.exp new file mode 100644 index 00000000..bc3b28bb --- /dev/null +++ b/testsuite/systemtap.base/bench.exp @@ -0,0 +1,14 @@ +set test "bench" + +if {![installtest_p]} {untested $test; return} + +spawn stap -tu $srcdir/$subdir/bench.stp +set ok 0 +expect { + -timeout 180 + -re {probe[^\r]*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +wait +if {$ok > 10} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.base/bench.stp b/testsuite/systemtap.base/bench.stp new file mode 100644 index 00000000..0568bc97 --- /dev/null +++ b/testsuite/systemtap.base/bench.stp @@ -0,0 +1,31 @@ + +// This bucket aims to trigger all basic generated C code constructs. +// It should be run with "-tu". + +probe repeat = begin,begin,begin,begin,begin,begin,begin,begin, + begin,begin,begin,begin,begin,begin,begin,begin, + begin,begin,begin,begin,begin,begin,begin,begin, + begin,begin,begin,begin,begin,begin,begin,begin, + begin,begin,begin,begin,begin,begin,begin,begin + {} + +probe test.null = repeat {} probe test.null {} // null probe +probe test.intassmt = repeat {i = 0} probe test.intassmt {} +probe test.gintassmt = repeat {gn = 0} probe test.gintassmt {} global gn +probe test.intincr = repeat {i++} probe test.intincr {} +probe test.gintincr = repeat {gn++} probe test.gintincr {} + +probe test.strassmt = repeat {s=""} probe test.strassmt {} +probe test.gstrassmt = repeat {gs=""} probe test.gstrassmt {} global gs + +probe test.forloop = repeat {for(i=0;i<10;i++) ;} probe test.forloop {} +probe test.ifgint = repeat {if (gn>0) ;} probe test.ifgint {} +probe test.next = repeat {next} probe test.next {} + +probe test.stataccum = repeat {gS <<< 1} probe test.stataccum {} global gS +probe test.statcount = repeat {@count(gS)} probe test.statcount {} + +probe test.nnarrassmt = repeat {gnn[1] = 1} probe test.nnarrassmt {} global gnn +probe test.ssarrassmt = repeat {gss["foo"] = "bar"} probe test.ssarrassmt {} global gss + +probe begin { exit () } diff --git a/testsuite/systemtap.base/div0.exp b/testsuite/systemtap.base/div0.exp new file mode 100644 index 00000000..169ded56 --- /dev/null +++ b/testsuite/systemtap.base/div0.exp @@ -0,0 +1,10 @@ +# Simple function to test that systemtap divide by 0 doesn't kill the machine +# FIXME correct the output check + +load_lib "stap_run.exp" + +set test "div0" + +set output_string "(.*)division by 0 near(.*)" + +stap_run $srcdir/$subdir/$test.stp no_load $output_string diff --git a/testsuite/systemtap.base/div0.stp b/testsuite/systemtap.base/div0.stp new file mode 100644 index 00000000..65710f09 --- /dev/null +++ b/testsuite/systemtap.base/div0.stp @@ -0,0 +1,27 @@ +/* + * div.stp0 + * + * Check the systemtap divide by 0 does not kill the machine + * FIXME this test needs to be refined + */ + +global x3 +global x1 +global x2 + +probe begin +{ + log("systemtap starting probe") + x1 = 56088; x2 = 0; +} + +probe end +{ + log("systemtap ending probe") + x3 = x1 / x2; + if (x3 != 456 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.base/equal.exp b/testsuite/systemtap.base/equal.exp new file mode 100644 index 00000000..eda645d2 --- /dev/null +++ b/testsuite/systemtap.base/equal.exp @@ -0,0 +1,10 @@ +# Simple function to test that equal operation works + +load_lib "stap_run.exp" + +set test "equal" + +# better have a count other than zero to show that probe fired +set output_string "count = \[1-9\]\[0-9\]*\r\ncount2 = \[1-9\]\[0-9\]*\r\nsystemtap test success\r\n" + +stap_run $srcdir/$subdir/$test.stp no_load $output_string diff --git a/testsuite/systemtap.base/equal.stp b/testsuite/systemtap.base/equal.stp new file mode 100644 index 00000000..83ca0115 --- /dev/null +++ b/testsuite/systemtap.base/equal.stp @@ -0,0 +1,28 @@ +/* + * equal.stp + * + * Simple function to test that equal operation works + */ + +global count +global count2 + +probe begin { log("systemtap starting probe") } + +probe kernel.function("schedule") { ++count; ++count2; } + +probe end +{ + log("systemtap ending probe") + log("count = " . sprint(count)); + log("count2 = " . sprint(count)); + if ( count == count2) { + if ( (count-1) == count2 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + } else { + log("systemtap test failure"); + } +} diff --git a/testsuite/systemtap.base/finloop2.exp b/testsuite/systemtap.base/finloop2.exp new file mode 100644 index 00000000..1b253cba --- /dev/null +++ b/testsuite/systemtap.base/finloop2.exp @@ -0,0 +1,11 @@ +# Simple function to test that systemtap can generate a kernel module that +# instruments a function, install it, and get some output. + +load_lib "stap_run.exp" + +set test "finloop2" + +# better have a count other than zero to show that probe fired +set output_string "count = \[1-9\]\[0-9\]*\r\nloop_count = \[1-9\]\[0-9\]*\r\nsystemtap test success\r\n" + +stap_run $srcdir/$subdir/$test.stp no_load $output_string diff --git a/testsuite/systemtap.base/finloop2.stp b/testsuite/systemtap.base/finloop2.stp new file mode 100644 index 00000000..8f12fd8a --- /dev/null +++ b/testsuite/systemtap.base/finloop2.stp @@ -0,0 +1,34 @@ +/* + * kfunct.stp + * + * Check the systemtap avoids infinite loops + * install it, and get some output. + */ + +global count +global loop_count + +probe begin +{ + log("systemtap starting probe") +} + +probe kernel.function("schedule") +{ + ++count; + for(a = 1; a <=10; ++a) { + ++loop_count; + } +} + +probe end +{ + log("systemtap ending probe") + log("count = " . sprint(count)); + log("loop_count = " . sprint(loop_count)); + if ( count * 10 == loop_count) { + log("systemtap test success"); + } else { + log("systemtap test failure"); + } +} diff --git a/testsuite/systemtap.base/if.exp b/testsuite/systemtap.base/if.exp new file mode 100644 index 00000000..5fbcbf2c --- /dev/null +++ b/testsuite/systemtap.base/if.exp @@ -0,0 +1,8 @@ +# Simple function to test that systemtap can generate a kernel module that +# instruments a function, install it, and get some output. + +load_lib "stap_run.exp" + +set test "if" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/if.stp b/testsuite/systemtap.base/if.stp new file mode 100644 index 00000000..bcbafd51 --- /dev/null +++ b/testsuite/systemtap.base/if.stp @@ -0,0 +1,22 @@ +/* + * if.stp + * + * Check the systemtap if statement works + */ + +probe begin { log("systemtap starting probe") } + +probe end +{ + log("systemtap ending probe") + if (1) { + log("systemtap test success"); + } else { + log("systemtap test failure"); + } + if (0) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.base/inc.exp b/testsuite/systemtap.base/inc.exp new file mode 100644 index 00000000..977ad4be --- /dev/null +++ b/testsuite/systemtap.base/inc.exp @@ -0,0 +1,7 @@ +# Simple function to test that systemtap ++ works + +load_lib "stap_run.exp" + +set test "inc" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/inc.stp b/testsuite/systemtap.base/inc.stp new file mode 100644 index 00000000..f37b2cee --- /dev/null +++ b/testsuite/systemtap.base/inc.stp @@ -0,0 +1,24 @@ +/* + * inc.stp + * + * Check the systemtap ++ works + */ + +global x1 + +probe begin +{ + log("systemtap starting probe"); + x1 = 41; +} + +probe end +{ + log("systemtap ending probe"); + ++x1; + if (x1 != 42 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.base/kfunct.exp b/testsuite/systemtap.base/kfunct.exp new file mode 100644 index 00000000..e0a0f709 --- /dev/null +++ b/testsuite/systemtap.base/kfunct.exp @@ -0,0 +1,11 @@ +# Simple function to test that systemtap can generate a kernel module that +# instruments a function, install it, and get some output. + +load_lib "stap_run.exp" + +set test "kfunct" + +# better have a count other than zero to show that probe fired +set output_string "count = \[1-9\]\[0-9\]*\r\n" + +stap_run $srcdir/$subdir/$test.stp no_load $output_string diff --git a/testsuite/systemtap.base/kfunct.stp b/testsuite/systemtap.base/kfunct.stp new file mode 100644 index 00000000..15be51bd --- /dev/null +++ b/testsuite/systemtap.base/kfunct.stp @@ -0,0 +1,24 @@ +/* + * kfunct.stp + * + * Very simple function to test that systemtap can generate a kernel module, + * install it, and get some output. + */ + +global count + +probe begin +{ + log("systemtap starting probe") +} + +probe kernel.function("schedule") +{ + ++count; +} + +probe end +{ + log("systemtap ending probe") + log("count = " . sprint(count)); +} diff --git a/testsuite/systemtap.base/kmodule.exp b/testsuite/systemtap.base/kmodule.exp new file mode 100644 index 00000000..05f464f8 --- /dev/null +++ b/testsuite/systemtap.base/kmodule.exp @@ -0,0 +1,22 @@ +# Simple function to test that systemtap can generate instument a module +# function, install it, and get some output. + +load_lib "stap_run.exp" + +set test "kmodule" + +proc kmodule_load {} { + # force the filesystem to be synced + if {[lindex [local_exec "sync" "" "" 100] 0] == 0} { + return 0 + } else { + return 1 + } +} + +# better have a count other than zero to show that probe fired +set output_string "count = \[0-9\]\[0-9\]*\r\n" + +#make sure have ext3 module loaded before trying this + +stap_run $srcdir/$subdir/$test.stp kmodule_load $output_string diff --git a/testsuite/systemtap.base/kmodule.stp b/testsuite/systemtap.base/kmodule.stp new file mode 100644 index 00000000..e8f0287f --- /dev/null +++ b/testsuite/systemtap.base/kmodule.stp @@ -0,0 +1,24 @@ +/* + * kmodule.stp + * + * Simple function to test that systemtap can generate instument a module + * function, install it, and get some output. + */ + +global count + +probe begin +{ + log("systemtap starting probe") +} + +probe module("ext3").function("ext3_sync_file") +{ + ++count; +} + +probe end +{ + log("systemtap ending probe") + log("count = " . sprint(count)); +} diff --git a/testsuite/systemtap.base/logical_and.exp b/testsuite/systemtap.base/logical_and.exp new file mode 100644 index 00000000..5dc86760 --- /dev/null +++ b/testsuite/systemtap.base/logical_and.exp @@ -0,0 +1,7 @@ +# Simple function to test that systemtap logial and works + +load_lib "stap_run.exp" + +set test "logical_and" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/logical_and.stp b/testsuite/systemtap.base/logical_and.stp new file mode 100644 index 00000000..5017190b --- /dev/null +++ b/testsuite/systemtap.base/logical_and.stp @@ -0,0 +1,41 @@ +/* + * logical_and.stp + * + * Check the systemtap "logical and" works + */ + +global x1_0 +global x2_1 +global x3_0 +global x4_1 + +probe begin +{ + log("systemtap starting probe") + x1_0 = 0; x2_1 = 1; x3_0 = 0; x4_1 = 1; +} + +probe end +{ + log("systemtap ending probe") + if (x1_0 && x3_0 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + if (x2_1 && x3_0 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + if (x1_0 && x4_1 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + if (x2_1 && x4_1 ) { + log("systemtap test success"); + } else { + log("systemtap test failure"); + } +} diff --git a/testsuite/systemtap.base/not.exp b/testsuite/systemtap.base/not.exp new file mode 100644 index 00000000..9898c2e2 --- /dev/null +++ b/testsuite/systemtap.base/not.exp @@ -0,0 +1,7 @@ +# Simple function to test that systemtap binary not works + +load_lib "stap_run.exp" + +set test "not" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/not.stp b/testsuite/systemtap.base/not.stp new file mode 100644 index 00000000..3e1bbd50 --- /dev/null +++ b/testsuite/systemtap.base/not.stp @@ -0,0 +1,24 @@ +/* + * neg.stp + * + * Check the systemtap negation works + */ + +global x2, x1 + +probe begin +{ + log("systemtap starting probe") + x1 = 0xaaaaaaaaaaaaaaaa +} + +probe end +{ + log("systemtap ending probe") + x2 = ~x1; + if ( x2 != 0x5555555555555555 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.base/probefunc.exp b/testsuite/systemtap.base/probefunc.exp new file mode 100644 index 00000000..10190fc9 --- /dev/null +++ b/testsuite/systemtap.base/probefunc.exp @@ -0,0 +1,58 @@ +# Test cases for probefunc() function + +load_lib "stap_run.exp" + +proc grep {fd re } { + while {[gets $fd s] >= 0} { + if [regexp $re $s] { + return $s + } + } +} + +proc sleep_one_sec {} { + after 1000; + return 0; +} + +set systemtap_script { + global funcname + probe %s { + funcname = probefunc() + } + probe begin { + log("systemtap starting probe") + } + probe end { + log("systemtap ending probe") + printf("%%s\n", funcname) + } +} + +# open /proc/kallsyms to get address for scheduler_tick symbol +set symf "/proc/kallsyms" +set symfd [open $symf r] +set re "\\mscheduler_tick\\M" +set rs [grep $symfd $re] +set flds [split $rs " "] +set addr [lindex $flds 0] +close $symfd + +set prefix "probefunc:" + +# test probefunc() with kernel.statement() +set output_string "\\mscheduler_tick\\M" +set probepoint "kernel.statement(0x$addr)" +set script [format $systemtap_script $probepoint] +stap_run $prefix$probepoint sleep_one_sec $output_string -e $script + +# test probefunc() with kernel.function() +set probepoint "kernel.function(\"scheduler_tick\")" +set script [format $systemtap_script $probepoint] +stap_run $prefix$probepoint sleep_one_sec $output_string -e $script + +# test probefunc() with kernel.inline() +set output_string "\\mcontext_switch\\M" +set probepoint "kernel.inline(\"context_switch\")" +set script [format $systemtap_script $probepoint] +stap_run $prefix$probepoint sleep_one_sec $output_string -e $script diff --git a/testsuite/systemtap.base/simple.exp b/testsuite/systemtap.base/simple.exp new file mode 100644 index 00000000..b22114f9 --- /dev/null +++ b/testsuite/systemtap.base/simple.exp @@ -0,0 +1,11 @@ +# Very simple function to test that systemtap can generate a kernel module, +# install it, and get some output. + +load_lib "stap_run.exp" + +set test "simple" + +#check to see whether get the marker indicating the probe is loaded and running +#should check to see whether exited for some reason +#should be error is something else is printed. +stap_run $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.base/simple.stp b/testsuite/systemtap.base/simple.stp new file mode 100644 index 00000000..28a81cff --- /dev/null +++ b/testsuite/systemtap.base/simple.stp @@ -0,0 +1,16 @@ +/* + * simple.stp + * + * Very simple function to test that systemtap can generate a kernel module, + * install it, and get some output. + */ + +probe begin +{ + log("systemtap starting probe") +} + +probe end +{ + log("systemtap ending probe") +} diff --git a/testsuite/systemtap.base/timeofday.exp b/testsuite/systemtap.base/timeofday.exp new file mode 100644 index 00000000..0597b153 --- /dev/null +++ b/testsuite/systemtap.base/timeofday.exp @@ -0,0 +1,30 @@ +# timeofday.exp +# +# This test is meant to make sure that our time functions can still be called +# from contexts where do_gettimeofday is unsafe (e.g. when xtime_lock is held). +# See bug #2525 for more details. + +load_lib "stap_run.exp" + +proc sleep_one_sec {} { + after 1000; + return 0; +} + +set systemtap_script { + global timeofday + probe kernel.function("do_timer") { + timeofday = gettimeofday_us() + } + probe begin { + log("systemtap starting probe") + } + probe end { + log("systemtap ending probe") + printf("%d\n", timeofday) + } +} + +set output_string "\\d+\\r\\n" + +stap_run "timeofday test" sleep_one_sec $output_string -e $systemtap_script diff --git a/testsuite/systemtap.base/timers.exp b/testsuite/systemtap.base/timers.exp new file mode 100644 index 00000000..40870f61 --- /dev/null +++ b/testsuite/systemtap.base/timers.exp @@ -0,0 +1,18 @@ +# Test the functionality of the various timer.* probes. + +load_lib "stap_run.exp" + +set test "timers" + +# A simple load that give the timers a chance to run +proc sleep_ten_secs {} { + after 10000; + return 0; +} + +#check to see whether get the marker indicating the probe is loaded and running +#should check to see whether exited for some reason +#should be error is something else is printed. +set output_string "(\\w+ = \\d+\r\n){7}${all_pass_string}(WARNING.*skipped.*)?" + +stap_run $srcdir/$subdir/$test.stp sleep_ten_secs $output_string diff --git a/testsuite/systemtap.base/timers.stp b/testsuite/systemtap.base/timers.stp new file mode 100644 index 00000000..9f370e74 --- /dev/null +++ b/testsuite/systemtap.base/timers.stp @@ -0,0 +1,73 @@ +/* + * timers.stp + * + * Test the functionality of the various timer.* probes. + */ + +global p +global j1, j2, jmax +global ms1, ms500, msmax + +probe begin +{ + log("systemtap starting probe") +} + +probe timer.profile { ++p } + +probe timer.jiffies(1) { ++j1 } +probe timer.jiffies(2) { ++j2 } +probe timer.jiffies(1000000) { ++jmax } + +/* as long as HZ>2, ms(1) and ms(500) + * will produce different counts */ +probe timer.ms(1) { ++ms1 } +probe timer.ms(500) { ++ms500 } +probe timer.ms(1000000) { ++msmax } + +probe end +{ + log("systemtap ending probe") + log("p = " . sprint(p)) + log("j1 = " . sprint(j1)) + log("j2 = " . sprint(j2)) + log("jmax = " . sprint(jmax)) + log("ms1 = " . sprint(ms1)) + log("ms500 = " . sprint(ms500)) + log("msmax = " . sprint(msmax)) + + /* profile counter should be non-zero, and at + * least as many as the jiffies(1) counter */ + if ((p > 0) && (p >= j1)) { + log("systemtap test success") + } else { + log("unexpected profile count") + log("systemtap test failure"); + } + + /* jiffies(1) should count more than jiffies(2), + * and both should be non-zero. */ + if ((j2 > 0) && (j2 < j1)) { + log("systemtap test success") + } else { + log("unexpected jiffies count") + log("systemtap test failure"); + } + + /* ms(1) should count more than ms(500), + * and both should be non-zero. */ + if ((ms500 > 0) && (ms500 < ms1)) { + log("systemtap test success") + } else { + log("unexpected ms count") + log("systemtap test failure"); + } + + /* both 'infinite' intervals should register zero counts */ + if ((jmax == 0) && (msmax == 0)) { + log("systemtap test success") + } else { + log("unexpected count on 'infinite' interval") + log("systemtap test failure"); + } +} diff --git a/testsuite/systemtap.base/tri.exp b/testsuite/systemtap.base/tri.exp new file mode 100644 index 00000000..5f418e5b --- /dev/null +++ b/testsuite/systemtap.base/tri.exp @@ -0,0 +1,7 @@ +# Simple function to test that systemtap ?: operation works + +load_lib "stap_run.exp" + +set test "tri" + +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string diff --git a/testsuite/systemtap.base/tri.stp b/testsuite/systemtap.base/tri.stp new file mode 100644 index 00000000..80aed1e7 --- /dev/null +++ b/testsuite/systemtap.base/tri.stp @@ -0,0 +1,36 @@ +/* + * tri.stp + * + * Check the systemtap ?: operator works + */ + +global x1, x2, x3, x4, x5, x6 + +probe begin +{ + log("systemtap starting probe"); + x1 = 0; x2 = 1; x3=30; +} + +probe end +{ + log("systemtap ending probe") + x4 = x1 ? 9: 10; + x5 = x2 ? 99: 100; + x6 = x3 ? 999: 1000; + if (x4 != 10 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + if (x5 != 99 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } + if (x6 != 999 ) { + log("systemtap test failure"); + } else { + log("systemtap test success"); + } +} diff --git a/testsuite/systemtap.maps/absentstats.exp b/testsuite/systemtap.maps/absentstats.exp new file mode 100644 index 00000000..99de9b0f --- /dev/null +++ b/testsuite/systemtap.maps/absentstats.exp @@ -0,0 +1,21 @@ +# PR 2142+2610 + +set test "absentstats" + +if {![installtest_p]} { untested $test; return } + +set ok 0 +set ko 0 + +spawn stap -DMAXERRORS=20 $srcdir/$subdir/$test.stp +# spawn echo hello children 0 +expect { + -re {^ERROR: empty aggregate[^\r]*\r} { incr ko ; exp_continue } + -re {^WARNING: Number of errors} { incr ko ; exp_continue } + -re {^0\r} { incr ok ; exp_continue } + -re {\n} { exp_continue } + eof { } +} +wait + +if {$ok == 2 && $ko == 13} then { pass $test } else { fail "$test ($ok $ko)" } diff --git a/testsuite/systemtap.maps/absentstats.stp b/testsuite/systemtap.maps/absentstats.stp new file mode 100644 index 00000000..641af5d3 --- /dev/null +++ b/testsuite/systemtap.maps/absentstats.stp @@ -0,0 +1,21 @@ +# stap -DMAXERRORS=40 + +global sc +probe begin { log(sprint(@count(sc))) } +probe begin { print(@sum(sc)) } +probe begin { print(@max(sc)) } +probe begin { print(@min(sc)) } +probe begin { print(@avg(sc)) } +probe begin { print(@hist_log(sc)) } +probe begin { x=@hist_log(sc)[5]; print(x) } + +global ry +probe begin { log(sprint(@count(ry[4]))) } +probe begin { print(@sum(ry[4])) } +probe begin { print(@max(ry[4])) } +probe begin { print(@min(ry[4])) } +probe begin { print(@avg(ry[4])) } +probe begin { print(@hist_log(ry[4])) } +probe begin { x=@hist_log(ry[4])[5]; print(x) } + +probe begin { exit() } diff --git a/testsuite/systemtap.maps/foreach_fail.exp b/testsuite/systemtap.maps/foreach_fail.exp new file mode 100644 index 00000000..6d5439b7 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_fail.exp @@ -0,0 +1,17 @@ +# Simple function to test maps of ints containing ints + +# modifying maps while in a foreach should produce a compilation error. + +set test foreach_fail +if {![installtest_p]} { untested $test; return } + +spawn stap $srcdir/$subdir/$test.stp +expect { + timeout { + fail "$test timed out" } + eof { + fail "$test unexpected EOF" } + -re "semantic error:" { pass "$test correctly failed to compile" } +} +close +wait diff --git a/testsuite/systemtap.maps/foreach_fail.stp b/testsuite/systemtap.maps/foreach_fail.stp new file mode 100755 index 00000000..a371c0c8 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_fail.stp @@ -0,0 +1,19 @@ +# modifying maps while in a foreach should produce a compilation error. + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[i] = i*i + + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + foreach (i in foo) + foo[i]++ + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + exit() +} diff --git a/testsuite/systemtap.maps/foreach_foreach.exp b/testsuite/systemtap.maps/foreach_foreach.exp new file mode 100644 index 00000000..a84937e3 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_foreach.exp @@ -0,0 +1,114 @@ +# Simple test of nested foreaches + +load_lib "stap_run2.exp" + +set test "foreach_foreach" + +set ::result_string {foo[1] = 1 +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[5] = 25 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 +foo[10] = 100 + +bar[1] = 1 +bar[2] = 8 +bar[3] = 27 +bar[4] = 64 +bar[5] = 125 +bar[6] = 216 +bar[7] = 343 +bar[8] = 512 +bar[9] = 729 +bar[10] = 1000 + +foo[1] = 1 +bar[1] = 1 +foo[2] = 4 +bar[2] = 8 +foo[3] = 9 +bar[3] = 27 +foo[4] = 16 +bar[4] = 64 +foo[5] = 25 +bar[5] = 125 +foo[6] = 36 +bar[6] = 216 +foo[7] = 49 +bar[7] = 343 +foo[8] = 64 +bar[8] = 512 +foo[9] = 81 +bar[9] = 729 +foo[10] = 100 +bar[10] = 1000 + +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[1] = 1 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[2] = 4 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[3] = 9 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[4] = 16 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[5] = 25 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[6] = 36 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[7] = 49 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[8] = 64 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[9] = 81 +bar[20] = 8000 +bar[21] = 9261 +bar[22] = 10648 +bar[23] = 12167 +bar[24] = 13824 +foo[10] = 100 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/foreach_foreach.stp b/testsuite/systemtap.maps/foreach_foreach.stp new file mode 100755 index 00000000..09a230f5 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_foreach.stp @@ -0,0 +1,40 @@ +# nested foreach + +global foo, bar + +probe begin { + for (i=0;i<11;i++) + foo[i] = i*i + + for (i=0;i<11;i++) + bar[i] = i*i*i + + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + printf("\n") + + foreach (i in bar) + printf("bar[%d] = %d\n", i, bar[i]) + + printf("\n") + + foreach (i in foo) { + printf("foo[%d] = %d\n", i, foo[i]) + printf("bar[%d] = %d\n", i, bar[i]) + } + + printf("\n") + + delete bar + for (i=20;i<25;i++) + bar[i] = i*i*i + + foreach (i in foo) { + foreach (j in bar) + printf("bar[%d] = %d\n", j, bar[j]) + printf("foo[%d] = %d\n", i, foo[i]) + } + + exit() +} diff --git a/testsuite/systemtap.maps/ii.exp b/testsuite/systemtap.maps/ii.exp new file mode 100644 index 00000000..915e9c30 --- /dev/null +++ b/testsuite/systemtap.maps/ii.exp @@ -0,0 +1,65 @@ +# Simple function to test maps of ints containing ints + +load_lib "stap_run2.exp" + +set test "ii" +set ::result_string {foo[1] = 1 +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[5] = 25 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 +foo[10] = 100 + +foo[1] = 1 +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 +foo[10] = 100 + +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 + +foo[2] = 4 +foo[3] = 900 +foo[4] = -16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = -81 + +foo[2] = 4 +foo[3] = 900 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = -81 + + +foo[1] = 1 +foo[2] = 5 +foo[3] = 14 +foo[4] = 30 +foo[5] = 55 +foo[6] = 91 +foo[7] = 140 +foo[8] = 204 +foo[9] = 285 +foo[10] = 385 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/ii.stp b/testsuite/systemtap.maps/ii.stp new file mode 100755 index 00000000..a83ae8ce --- /dev/null +++ b/testsuite/systemtap.maps/ii.stp @@ -0,0 +1,58 @@ +#test of int maps containing ints + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[i] = i*i + + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # delete out of the middle + foo[5] = 0 + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # delete first entry + foo[1] = 0 + # and last entry + foo[10] = 0 + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # change a couple + foo[9] = -81 + foo[4] = -foo[4] + foo[3] *= 100 + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # delete one + foo[4] = 0 + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # delete all + for (i=0;i<11;i++) + foo[i] = 0 + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + # load it again + for (i=0;i<11;i++) + foo[i] = i*i + for (i=0;i<11;i++) + foo[i] += foo[i-1] + printf("\n") + foreach (i in foo) + printf("foo[%d] = %d\n", i, foo[i]) + + exit() +} + diff --git a/testsuite/systemtap.maps/iiiiii.exp b/testsuite/systemtap.maps/iiiiii.exp new file mode 100644 index 00000000..69fdfd3d --- /dev/null +++ b/testsuite/systemtap.maps/iiiiii.exp @@ -0,0 +1,72 @@ +# Simple test of maps with 5 ints as keys, returning ints + +load_lib "stap_run2.exp" + +set test "iiiiii" +set ::result_string {foo[0,0,0,0,1] = 1 +foo[0,0,0,1,0] = 1 +foo[0,0,0,1,1] = 2 +foo[0,0,1,0,0] = 1 +foo[0,0,1,0,1] = 2 +foo[0,0,1,1,0] = 2 +foo[0,0,1,1,1] = 3 +foo[0,1,0,0,0] = 1 +foo[0,1,0,0,1] = 2 +foo[0,1,0,1,0] = 2 +foo[0,1,0,1,1] = 3 +foo[0,1,1,0,0] = 2 +foo[0,1,1,0,1] = 3 +foo[0,1,1,1,0] = 3 +foo[0,1,1,1,1] = 4 +foo[1,0,0,0,0] = 1 +foo[1,0,0,0,1] = 2 +foo[1,0,0,1,0] = 2 +foo[1,0,0,1,1] = 3 +foo[1,0,1,0,0] = 2 +foo[1,0,1,0,1] = 3 +foo[1,0,1,1,0] = 3 +foo[1,0,1,1,1] = 4 +foo[1,1,0,0,0] = 2 +foo[1,1,0,0,1] = 3 +foo[1,1,0,1,0] = 3 +foo[1,1,0,1,1] = 4 +foo[1,1,1,0,0] = 3 +foo[1,1,1,0,1] = 4 +foo[1,1,1,1,0] = 4 +foo[1,1,1,1,1] = 5 + +foo[0,0,0,0,1] = 1 +foo[0,0,0,1,0] = 1 +foo[0,0,0,1,1] = 2 +foo[0,0,1,0,0] = 1 +foo[0,0,1,0,1] = 2 +foo[0,0,1,1,0] = 2 +foo[0,1,0,0,0] = 1 +foo[0,1,0,0,1] = 2 +foo[0,1,0,1,0] = 2 +foo[0,1,0,1,1] = 3 +foo[0,1,1,0,0] = 2 +foo[0,1,1,0,1] = 3 +foo[0,1,1,1,0] = 3 +foo[0,1,1,1,1] = 4 +foo[1,0,0,0,0] = 1 +foo[1,0,0,0,1] = 2 +foo[1,0,0,1,0] = 2 +foo[1,0,0,1,1] = 3 +foo[1,0,1,0,0] = 2 +foo[1,0,1,0,1] = 3 +foo[1,0,1,1,0] = 3 +foo[1,0,1,1,1] = 4 +foo[1,1,0,0,0] = 2 +foo[1,1,0,0,1] = 3 +foo[1,1,0,1,0] = 3 +foo[1,1,0,1,1] = 4 +foo[1,1,1,0,0] = 3 +foo[1,1,1,0,1] = 4 +foo[1,1,1,1,0] = 4 +foo[1,1,1,1,1] = 5 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/iiiiii.stp b/testsuite/systemtap.maps/iiiiii.stp new file mode 100755 index 00000000..369c2fec --- /dev/null +++ b/testsuite/systemtap.maps/iiiiii.stp @@ -0,0 +1,23 @@ +#simple test of maps with 5 ints as keys, returning ints + +global foo + +probe begin { + for (i=0;i<2;i++) + for (j=0;j<2;j++) + for (k=0;k<2;k++) + for (m=0;m<2;m++) + for (n=0;n<2;n++) + foo[i,j,k,m,n] = i+j+k+m+n + + foreach ([a,b,c,d,e] in foo) + printf("foo[%d,%d,%d,%d,%d] = %d\n", a,b,c,d,e, foo[a,b,c,d,e]) + + foo[0,0,1,1,1] = 0 + printf("\n") + foreach ([a,b,c,d,e] in foo) + printf("foo[%d,%d,%d,%d,%d] = %d\n", a,b,c,d,e, foo[a,b,c,d,e]) + + exit() +} + diff --git a/testsuite/systemtap.maps/is.exp b/testsuite/systemtap.maps/is.exp new file mode 100644 index 00000000..b94ad860 --- /dev/null +++ b/testsuite/systemtap.maps/is.exp @@ -0,0 +1,71 @@ +# Simple function to test maps of ints containing strings + +load_lib "stap_run2.exp" + +set test "is" +set ::result_string {foo[0] = The Result is 0 +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[5] = The Result is 25 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 +foo[10] = The Result is 100 + +foo[0] = The Result is 0 +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 +foo[10] = The Result is 100 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 4<------ +foo[4] = The Result is 16(CHANGED) +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = New result is -81 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 4<------ +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = New result is -81 + + +foo[0] = # 0 +foo[1] = # 1 +foo[2] = # 4 +foo[3] = # 9 +foo[4] = # 16 +foo[5] = # 25 +foo[6] = # 36 +foo[7] = # 49 +foo[8] = # 64 +foo[9] = # 81 +foo[10] = # 100 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/is.stp b/testsuite/systemtap.maps/is.stp new file mode 100755 index 00000000..993f375e --- /dev/null +++ b/testsuite/systemtap.maps/is.stp @@ -0,0 +1,59 @@ +#test of int maps containing strings + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[i] = "The Result is ".sprint(i*i) + + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # delete out of the middle + foo[5] = "" + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # delete first entry + foo[0] = "" + # and last entry + foo[10] = "" + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # change a couple + foo[9] = "New result is -81" + foo[4] = foo[4]."(CHANGED)" + foo[3] = foo[2]."<------" + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # delete one + foo[4] = "" + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # delete all + delete foo + + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + # load it again + for (i=0;i<11;i++) + foo[i] = sprint(i*i) + for (i=0;i<11;i++) + foo[i] = "# ".sprint(i*i) + + printf("\n") + foreach (i in foo) + printf("foo[%d] = %s\n", i, foo[i]) + + exit() +} + diff --git a/testsuite/systemtap.maps/ix.exp b/testsuite/systemtap.maps/ix.exp new file mode 100644 index 00000000..4f587db6 --- /dev/null +++ b/testsuite/systemtap.maps/ix.exp @@ -0,0 +1,51 @@ +# Simple function to test maps of ints containing stats + +load_lib "stap_run2.exp" + +set test "ix" + +set ::result_string {foo[0]: count:3 sum:98 avg:32 min:-2 max:100 +foo[1]: count:3 sum:99 avg:33 min:-2 max:100 +foo[2]: count:3 sum:100 avg:33 min:-2 max:100 +foo[3]: count:3 sum:101 avg:33 min:-2 max:100 +foo[4]: count:3 sum:102 avg:34 min:-2 max:100 +foo[5]: count:3 sum:103 avg:34 min:-2 max:100 +foo[6]: count:3 sum:104 avg:34 min:-2 max:100 +foo[7]: count:3 sum:105 avg:35 min:-2 max:100 +foo[8]: count:3 sum:106 avg:35 min:-2 max:100 +foo[9]: count:3 sum:107 avg:35 min:-2 max:100 +foo[10]: count:3 sum:108 avg:36 min:-2 max:100 + +Now reverse order... +foo[10]: count:3 sum:108 avg:36 min:-2 max:100 +foo[9]: count:3 sum:107 avg:35 min:-2 max:100 +foo[8]: count:3 sum:106 avg:35 min:-2 max:100 +foo[7]: count:3 sum:105 avg:35 min:-2 max:100 +foo[6]: count:3 sum:104 avg:34 min:-2 max:100 +foo[5]: count:3 sum:103 avg:34 min:-2 max:100 +foo[4]: count:3 sum:102 avg:34 min:-2 max:100 +foo[3]: count:3 sum:101 avg:33 min:-2 max:100 +foo[2]: count:3 sum:100 avg:33 min:-2 max:100 +foo[1]: count:3 sum:99 avg:33 min:-2 max:100 +foo[0]: count:3 sum:98 avg:32 min:-2 max:100 + +Now adding 10 to each... +foo[0]: count:4 sum:108 avg:27 min:-2 max:100 +foo[1]: count:4 sum:109 avg:27 min:-2 max:100 +foo[2]: count:4 sum:110 avg:27 min:-2 max:100 +foo[3]: count:4 sum:111 avg:27 min:-2 max:100 +foo[4]: count:4 sum:112 avg:28 min:-2 max:100 +foo[5]: count:4 sum:113 avg:28 min:-2 max:100 +foo[6]: count:4 sum:114 avg:28 min:-2 max:100 +foo[7]: count:4 sum:115 avg:28 min:-2 max:100 +foo[8]: count:4 sum:116 avg:29 min:-2 max:100 +foo[9]: count:4 sum:117 avg:29 min:-2 max:100 +foo[10]: count:4 sum:118 avg:29 min:-2 max:100 + +Run a quick foreach without sorting... +complete sum of foo:1243 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/ix.stp b/testsuite/systemtap.maps/ix.stp new file mode 100755 index 00000000..328fa066 --- /dev/null +++ b/testsuite/systemtap.maps/ix.stp @@ -0,0 +1,37 @@ +#test of int maps containing stats + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[i] <<< 100 + for (i=0;i<11;i++) + foo[i] <<< i + for (i=0;i<11;i++) + foo[i] <<< -2 + + foreach (i+ in foo) + printf("foo[%d]: count:%d sum:%d avg:%d min:%d max:%d\n", + i, @count(foo[i]), @sum(foo[i]), @avg(foo[i]), + @min(foo[i]), @max(foo[i])) + printf("\nNow reverse order...\n") + foreach (i- in foo) + printf("foo[%d]: count:%d sum:%d avg:%d min:%d max:%d\n", + i, @count(foo[i]), @sum(foo[i]), @avg(foo[i]), + @min(foo[i]), @max(foo[i])) + + printf ("\nNow adding 10 to each...\n") + for (i=0;i<11;i++) + foo[i] <<< 10 + foreach (i+ in foo) + printf("foo[%d]: count:%d sum:%d avg:%d min:%d max:%d\n", + i, @count(foo[i]), @sum(foo[i]), @avg(foo[i]), + @min(foo[i]), @max(foo[i])) + + printf ("\nRun a quick foreach without sorting...\n"); + foreach (i in foo) + allsum += @sum(foo[i]) + printf ("complete sum of foo:%d\n", allsum) + exit() +} + diff --git a/testsuite/systemtap.maps/ix_clear.exp b/testsuite/systemtap.maps/ix_clear.exp new file mode 100644 index 00000000..96bba1ba --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear.exp @@ -0,0 +1,24 @@ +# function to test error handling when reading nonexistent pmap elements + +set test "ix_clear" +if {![installtest_p]} { untested $test; return } + +set pass_result {foo\[1\] = 1 1*ERROR: empty aggregate*} + + +# spawn test +spawn stap $srcdir/$subdir/$test.stp +expect { + $pass_result { + pass "$test passed" + } + -timeout 30 { + send "\003" + fail "$test timed out" + } + eof { + fail "$test unexpected EOF" } + -re "semantic error:" { fail "$test compilation" } +} +close +wait diff --git a/testsuite/systemtap.maps/ix_clear.stp b/testsuite/systemtap.maps/ix_clear.stp new file mode 100755 index 00000000..a36e5400 --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear.stp @@ -0,0 +1,12 @@ +#test of int maps containing stats + +global foo + +probe begin { + foo[1] <<< 1 + printf("foo[1] = %d %d\n", @count(foo[1]), @sum(foo[1])) + delete foo[1] + printf("foo[1] = %d %d\n", @count(foo[1]), @sum(foo[1])) + exit() +} + diff --git a/testsuite/systemtap.maps/ix_clear2.exp b/testsuite/systemtap.maps/ix_clear2.exp new file mode 100644 index 00000000..702ecc4f --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear2.exp @@ -0,0 +1,25 @@ +# function to test error handling when reading nonexistent pmap elements + +set test "ix_clear2" +if {![installtest_p]} { untested $test; return } + + +set pass_result {foo\[1\] = 1 1*ERROR: empty aggregate*} + + +# spawn test +spawn stap $srcdir/$subdir/$test.stp +expect { + $pass_result { + pass "$test passed" + } + -timeout 30 { + send "\003" + fail "$test timed out" + } + eof { + fail "$test unexpected EOF" } + -re "semantic error:" { fail "$test compilation" } +} +close +wait diff --git a/testsuite/systemtap.maps/ix_clear2.stp b/testsuite/systemtap.maps/ix_clear2.stp new file mode 100755 index 00000000..cedec482 --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear2.stp @@ -0,0 +1,12 @@ +# test clearing pmaps + +global foo + +probe begin { + foo[1] <<< 1 + printf("foo[1] = %d %d\n", @count(foo[1]), @sum(foo[1])) + delete foo + printf("foo[1] = %d %d\n", @count(foo[1]), @sum(foo[1])) + exit() +} + diff --git a/testsuite/systemtap.maps/ix_clear3.exp b/testsuite/systemtap.maps/ix_clear3.exp new file mode 100644 index 00000000..5ccde188 --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear3.exp @@ -0,0 +1,23 @@ +# function to test error handling when reading nonexistent pmap elements + +set test "ix_clear3" +if {![installtest_p]} { untested $test; return } + +set pass_result {*ERROR: empty aggregate*} + +# spawn test +spawn stap $srcdir/$subdir/$test.stp +expect { + $pass_result { + pass "$test passed" + } + -timeout 30 { + send "\003" + fail "$test timed out" + } + eof { + fail "$test unexpected EOF" } + -re "semantic error:" { fail "$test compilation" } +} +close +wait diff --git a/testsuite/systemtap.maps/ix_clear3.stp b/testsuite/systemtap.maps/ix_clear3.stp new file mode 100755 index 00000000..f53318fe --- /dev/null +++ b/testsuite/systemtap.maps/ix_clear3.stp @@ -0,0 +1,10 @@ +# test uninitialized pmap element + +global foo + +probe begin { + foo[1] <<< 1 + printf("foo[2] = %d %d\n", @count(foo[2]), @sum(foo[2])) + exit() +} + diff --git a/testsuite/systemtap.maps/ix_hist.exp b/testsuite/systemtap.maps/ix_hist.exp new file mode 100644 index 00000000..afa5ddf7 --- /dev/null +++ b/testsuite/systemtap.maps/ix_hist.exp @@ -0,0 +1,68 @@ +# Simple function to test istograms + +load_lib "stap_run2.exp" + +set test "ix_hist" + +set ::result_string {value |-------------------------------------------------- count + 0 | 1 + 1 | 1 + 2 |@ 2 + 4 |@@ 4 + 8 |@@@@ 8 + 16 |@@@@@@@@ 16 + 32 |@@@@@@@@@@@@@@@@ 32 + 64 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 64 + 128 | 0 + 256 | 0 + +value |-------------------------------------------------- count + 0 | 1 + 1 | 0 + 2 | 1 + 4 | 2 + 8 |@ 4 + 16 |@@ 8 + 32 |@@@@@ 16 + 64 |@@@@@@@@@@ 32 + 128 |@@@@@@@@@@@@@@@@@@@@@ 64 + 256 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 128 + 512 | 0 + 1024 | 0 + +value |-------------------------------------------------- count + 0 | 1 + 1 | 0 + 2 | 1 + 4 | 1 + 8 | 3 + 16 |@ 5 + 32 |@@ 11 + 64 |@@@@@ 21 + 128 |@@@@@@@@@@ 43 + 256 |@@@@@@@@@@@@@@@@@@@@@ 85 + 512 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 171 + 1024 |@@@@@@@@@@ 42 + 2048 | 0 + 4096 | 0 + +value |-------------------------------------------------- count + 0 | 1 + 1 | 0 + 2 | 0 + 4 | 1 + 8 | 2 + 16 | 4 + 32 |@ 8 + 64 |@@ 16 + 128 |@@@@@ 32 + 256 |@@@@@@@@@@ 64 + 512 |@@@@@@@@@@@@@@@@@@@@@ 128 + 1024 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 256 + 2048 | 0 + 4096 | 0 +} + +stap_run2 $srcdir/$subdir/$test.stp -DMAXACTION=10000 + + diff --git a/testsuite/systemtap.maps/ix_hist.stp b/testsuite/systemtap.maps/ix_hist.stp new file mode 100755 index 00000000..2d0a3b17 --- /dev/null +++ b/testsuite/systemtap.maps/ix_hist.stp @@ -0,0 +1,15 @@ +# test of int maps containing stats + +global foo + +probe begin { + for (i=0;i<5;i++) + for (j=0;j<i*128;j++) + foo[i] <<< i*j + + foreach (i+ in foo) + print(@hist_log(foo[i])) + + exit() +} + diff --git a/testsuite/systemtap.maps/pmap_agg_overflow.exp b/testsuite/systemtap.maps/pmap_agg_overflow.exp new file mode 100644 index 00000000..f559f00a --- /dev/null +++ b/testsuite/systemtap.maps/pmap_agg_overflow.exp @@ -0,0 +1,27 @@ +# function to test error handling of pmap aggregation + +set test "pmap_agg_overflow" +if {![installtest_p]} { untested $test; return } + +set pass_result "^(ERROR: aggregation overflow.*\r\n){2}WARNING: Number of errors: 2, skipped probes: 0\r\n$" +set skip_result "^WARNING: This test only applies to smp systems...\r\n$" + +# spawn test +spawn stap -DMAXERRORS=1 -g $srcdir/$subdir/$test.stp +expect { + -re $pass_result { + pass "$test passed" + } + -re $skip_result { + unsupported "$test requires smp" + } + -timeout 30 { + send "\003" + fail "$test timed out" + } + eof { + fail "$test unexpected EOF" } + -re "semantic error:" { fail "$test compilation" } +} +close +wait diff --git a/testsuite/systemtap.maps/pmap_agg_overflow.stp b/testsuite/systemtap.maps/pmap_agg_overflow.stp new file mode 100755 index 00000000..81268550 --- /dev/null +++ b/testsuite/systemtap.maps/pmap_agg_overflow.stp @@ -0,0 +1,38 @@ +# try to induce overflow of pmap aggregation +# (this will only work on smp machines) + +global stat, count, max_count + +probe begin { + if (num_online_cpus() < 2) { + warn("This test only applies to smp systems...") + exit() + } + max_count = num_online_cpus() * max_map_entries() +} + +probe timer.profile { + i = ++count + if (i >= max_count) exit() + stat[i] <<< i +} + +probe end { + # pmap aggregation should overflow here + foreach (i in stat) + printf("@count(stat[%d]) = %d\n", i, @count(stat[i])) +} + +probe end { + # sorted pmap aggregation should overflow here + foreach (i+ in stat) + printf("@count(stat[%d]) = %d\n", i, @count(stat[i])) +} + +function max_map_entries:long() %{ + THIS->__retvalue = MAXMAPENTRIES; +%} + +function num_online_cpus:long() %{ + THIS->__retvalue = num_online_cpus(); +%} diff --git a/testsuite/systemtap.maps/si.exp b/testsuite/systemtap.maps/si.exp new file mode 100644 index 00000000..53bc1271 --- /dev/null +++ b/testsuite/systemtap.maps/si.exp @@ -0,0 +1,65 @@ +# Simple function to test maps of strings containing ints + +load_lib "stap_run2.exp" + +set test "si" +set ::result_string {foo[1] = 1 +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[5] = 25 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 +foo[10] = 100 + +foo[1] = 1 +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 +foo[10] = 100 + +foo[2] = 4 +foo[3] = 9 +foo[4] = 16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = 81 + +foo[2] = 4 +foo[3] = 900 +foo[4] = -16 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = -81 + +foo[2] = 4 +foo[3] = 900 +foo[6] = 36 +foo[7] = 49 +foo[8] = 64 +foo[9] = -81 + + +foo[1] = 1 +foo[2] = 5 +foo[3] = 14 +foo[4] = 30 +foo[5] = 55 +foo[6] = 91 +foo[7] = 140 +foo[8] = 204 +foo[9] = 285 +foo[10] = 385 +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/si.stp b/testsuite/systemtap.maps/si.stp new file mode 100755 index 00000000..3267b283 --- /dev/null +++ b/testsuite/systemtap.maps/si.stp @@ -0,0 +1,62 @@ +#test of string maps containing ints + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[sprint(i)] = i*i + + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + # delete out of the middle + foo["5"] = 0 + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + # delete first entry + foo["1"] = 0 + # and last entry + foo["10"] = 0 + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + + # change a couple + foo["9"] = -81 + foo["4"] = -foo["4"] + foo["3"] *= 100 + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + + # delete one + foo["4"] = 0 + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + + # delete all + delete foo + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + + # load it again + for (i=0;i<11;i++) + foo[sprint(i)] = i*i + for (i=0;i<11;i++) + foo[sprint(i)] += foo[sprint(i-1)] + printf("\n") + foreach (str in foo) + printf("foo[%s] = %d\n", str, foo[str]) + + + exit() +} + diff --git a/testsuite/systemtap.maps/ss.exp b/testsuite/systemtap.maps/ss.exp new file mode 100644 index 00000000..f3a32118 --- /dev/null +++ b/testsuite/systemtap.maps/ss.exp @@ -0,0 +1,69 @@ +# Simple function to test maps of strings containing strings + +load_lib "stap_run2.exp" + +set test "ss" +set ::result_string {foo[0] = The Result is 0 +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[5] = The Result is 25 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 +foo[10] = The Result is 100 + +foo[0] = The Result is 0 +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 +foo[10] = The Result is 100 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 9 +foo[4] = The Result is 16 +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = The Result is 81 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 4<------ +foo[4] = The Result is 16(CHANGED) +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = New result is -81 + +foo[1] = The Result is 1 +foo[2] = The Result is 4 +foo[3] = The Result is 4<------ +foo[6] = The Result is 36 +foo[7] = The Result is 49 +foo[8] = The Result is 64 +foo[9] = New result is -81 + + +foo[0] = # 0 +foo[1] = # 1 +foo[2] = # 4 +foo[3] = # 9 +foo[4] = # 16 +foo[5] = # 25 +foo[6] = # 36 +foo[7] = # 49 +foo[8] = # 64 +foo[9] = # 81 +foo[10] = # 100 +} + +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.maps/ss.stp b/testsuite/systemtap.maps/ss.stp new file mode 100755 index 00000000..d649c25c --- /dev/null +++ b/testsuite/systemtap.maps/ss.stp @@ -0,0 +1,62 @@ +#test of string maps containing strings + +global foo + +probe begin { + for (i=0;i<11;i++) + foo[sprint(i)] = "The Result is ".sprint(i*i) + + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + # delete out of the middle + foo["5"] = "" + printf("\n") + + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + # delete first entry + foo["0"] = "" + # and last entry + foo["10"] = "" + printf("\n") + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + + # change a couple + foo["9"] = "New result is -81" + foo["4"] = foo["4"]."(CHANGED)" + foo["3"] = foo["2"]."<------" + printf("\n") + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + + # delete one + foo["4"] = "" + printf("\n") + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + + # delete all + delete foo + printf("\n") + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + # load it again + for (i=0;i<11;i++) + foo[sprint(i)] = sprint(i*i) + for (i=0;i<11;i++) + foo[sprint(i)] = "# ".sprint(i*i) + + printf("\n") + foreach (str in foo) + printf("foo[%s] = %s\n", str, foo[str]) + + exit() +} + diff --git a/testsuite/systemtap.pass1-4/buildko.exp b/testsuite/systemtap.pass1-4/buildko.exp new file mode 100644 index 00000000..1a208fa6 --- /dev/null +++ b/testsuite/systemtap.pass1-4/buildko.exp @@ -0,0 +1,8 @@ +set self buildko +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + setup_xfail *-*-* + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/buildok.exp b/testsuite/systemtap.pass1-4/buildok.exp new file mode 100644 index 00000000..35c0e6c6 --- /dev/null +++ b/testsuite/systemtap.pass1-4/buildok.exp @@ -0,0 +1,14 @@ +set self buildok +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + # some tests are known to fail. + switch $test { + buildok/sched_test.stp {setup_kfail 1155 *-*-*} + buildok/seven.stp {setup_kfail 9999 *-*-*} + buildok/process_test.stp {setup_kfail 9999 *-*-*} + buildok/syscall.stp {setup_kfail 9999 *-*-*} + } + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/parseko.exp b/testsuite/systemtap.pass1-4/parseko.exp new file mode 100644 index 00000000..c69c3e27 --- /dev/null +++ b/testsuite/systemtap.pass1-4/parseko.exp @@ -0,0 +1,8 @@ +set self parseko +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + setup_xfail *-*-* + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/parseok.exp b/testsuite/systemtap.pass1-4/parseok.exp new file mode 100644 index 00000000..56d287b9 --- /dev/null +++ b/testsuite/systemtap.pass1-4/parseok.exp @@ -0,0 +1,7 @@ +set self parseok +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/semko.exp b/testsuite/systemtap.pass1-4/semko.exp new file mode 100644 index 00000000..020d48b4 --- /dev/null +++ b/testsuite/systemtap.pass1-4/semko.exp @@ -0,0 +1,8 @@ +set self semko +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + setup_xfail *-*-* + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/semok.exp b/testsuite/systemtap.pass1-4/semok.exp new file mode 100644 index 00000000..f02c8643 --- /dev/null +++ b/testsuite/systemtap.pass1-4/semok.exp @@ -0,0 +1,7 @@ +set self semok +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/transko.exp b/testsuite/systemtap.pass1-4/transko.exp new file mode 100644 index 00000000..8aa5bec8 --- /dev/null +++ b/testsuite/systemtap.pass1-4/transko.exp @@ -0,0 +1,8 @@ +set self transko +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + setup_xfail *-*-* + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.pass1-4/transok.exp b/testsuite/systemtap.pass1-4/transok.exp new file mode 100644 index 00000000..1594e485 --- /dev/null +++ b/testsuite/systemtap.pass1-4/transok.exp @@ -0,0 +1,7 @@ +set self transok +foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { + set test $self/[file tail $file] + verbose -log "Running $file" + set rc [catch {exec $file >>& systemtap.log} err] + if {$rc == 0} { pass $test } else { fail "$test rc $rc" } +} diff --git a/testsuite/systemtap.printf/basic1.exp b/testsuite/systemtap.printf/basic1.exp new file mode 100644 index 00000000..c354a6dc --- /dev/null +++ b/testsuite/systemtap.printf/basic1.exp @@ -0,0 +1,4 @@ +load_lib "stap_run2.exp" +set test "basic1" +set ::result_string {HelloWorld} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/basic1.stp b/testsuite/systemtap.printf/basic1.stp new file mode 100644 index 00000000..3d2e35c6 --- /dev/null +++ b/testsuite/systemtap.printf/basic1.stp @@ -0,0 +1,6 @@ +probe begin +{ + printf("Hello"); + printf("World"); + exit() +} diff --git a/testsuite/systemtap.printf/basic2.exp b/testsuite/systemtap.printf/basic2.exp new file mode 100644 index 00000000..385cc5c5 --- /dev/null +++ b/testsuite/systemtap.printf/basic2.exp @@ -0,0 +1,4 @@ +load_lib "stap_run2.exp" +set test "basic2" +set ::result_string {HelloWorld} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/basic2.stp b/testsuite/systemtap.printf/basic2.stp new file mode 100644 index 00000000..8c5891b4 --- /dev/null +++ b/testsuite/systemtap.printf/basic2.stp @@ -0,0 +1,6 @@ +probe begin +{ + printf("Hello"); + print("World"); + exit() +} diff --git a/testsuite/systemtap.printf/basic3.exp b/testsuite/systemtap.printf/basic3.exp new file mode 100644 index 00000000..2eb74431 --- /dev/null +++ b/testsuite/systemtap.printf/basic3.exp @@ -0,0 +1,6 @@ +load_lib "stap_run2.exp" +set test "basic3" +set ::result_string {Hello +World +} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/basic3.stp b/testsuite/systemtap.printf/basic3.stp new file mode 100644 index 00000000..23f826d6 --- /dev/null +++ b/testsuite/systemtap.printf/basic3.stp @@ -0,0 +1,6 @@ +probe begin +{ + printf("Hello\n"); + print("World\n"); + exit() +} diff --git a/testsuite/systemtap.printf/basic4.exp b/testsuite/systemtap.printf/basic4.exp new file mode 100644 index 00000000..3b89a24d --- /dev/null +++ b/testsuite/systemtap.printf/basic4.exp @@ -0,0 +1,4 @@ +load_lib "stap_run2.exp" +set test "basic4" +set ::result_string {HelloWorldHelloWorld} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/basic4.stp b/testsuite/systemtap.printf/basic4.stp new file mode 100644 index 00000000..06caeebf --- /dev/null +++ b/testsuite/systemtap.printf/basic4.stp @@ -0,0 +1,12 @@ +probe begin +{ + printf("Hello"); + printf("World"); + exit() +} +probe end +{ + printf("Hello"); + printf("World"); + exit() +} diff --git a/testsuite/systemtap.printf/basic5.exp b/testsuite/systemtap.printf/basic5.exp new file mode 100644 index 00000000..9fe0ad16 --- /dev/null +++ b/testsuite/systemtap.printf/basic5.exp @@ -0,0 +1,4 @@ +load_lib "stap_run2.exp" +set test "basic5" +set ::result_string {HelloWorldHelloWorld} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/basic5.stp b/testsuite/systemtap.printf/basic5.stp new file mode 100644 index 00000000..8ddb089d --- /dev/null +++ b/testsuite/systemtap.printf/basic5.stp @@ -0,0 +1,22 @@ +# This test is really a transport test. +# Waiting one second makes sure the two probes +# send the data in different packets, at least +# with procfs. + +probe begin +{ + printf("Hello"); + printf("World"); +} + +probe timer.ms(1000) +{ + exit() +} + +probe end +{ + printf("Hello"); + printf("World"); + exit() +} diff --git a/testsuite/systemtap.printf/bin.stp b/testsuite/systemtap.printf/bin.stp new file mode 100644 index 00000000..ac86059d --- /dev/null +++ b/testsuite/systemtap.printf/bin.stp @@ -0,0 +1,18 @@ +# test of 16-bit binary prints +# need to use big_endian2() to get consistent results across +# different-endian architectures. + +probe begin +{ + set_endian(2) + printf("%2b", 0x12) + printf("%2b", 0x34) + printf("%2b%2b", 0xabcd, 0x5678) + a = 0x12345678 + b = 0xabcd + c = 0x8888 + d = 0xcdef + printf("%2b%2b%2b%2b", a, b, c, d) + printf("a=%2b b=%2b c=%2b d=%2b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin1.exp b/testsuite/systemtap.printf/bin1.exp new file mode 100644 index 00000000..e25a6e9c --- /dev/null +++ b/testsuite/systemtap.printf/bin1.exp @@ -0,0 +1,4 @@ +load_lib "stap_run_binary.exp" +set test "bin1" +set ::result_string {42 } +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/bin1.stp b/testsuite/systemtap.printf/bin1.stp new file mode 100644 index 00000000..2177d8b3 --- /dev/null +++ b/testsuite/systemtap.printf/bin1.stp @@ -0,0 +1,5 @@ +probe begin +{ + printf("%1b", 0x42) + exit() +} diff --git a/testsuite/systemtap.printf/bin2.exp b/testsuite/systemtap.printf/bin2.exp new file mode 100644 index 00000000..bab11e39 --- /dev/null +++ b/testsuite/systemtap.printf/bin2.exp @@ -0,0 +1,7 @@ +load_lib "stap_run_binary.exp" +set test "bin2" +set ::result_string {12 34 56 78 12 34 56 78 +61 3d 12 20 62 3d 34 20 +63 3d 56 20 64 3d 78 } + +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/bin2.stp b/testsuite/systemtap.printf/bin2.stp new file mode 100644 index 00000000..b7d221b5 --- /dev/null +++ b/testsuite/systemtap.printf/bin2.stp @@ -0,0 +1,13 @@ +probe begin +{ + printf("%1b", 0x12) + printf("%1b", 0x34) + printf("%1b%1b", 0x56, 0x78) + a = 0x12 + b = 0x34 + c = 0x56 + d = 0x78 + printf("%1b%1b%1b%1b", a, b, c, d) + printf("a=%1b b=%1b c=%1b d=%1b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin3.exp b/testsuite/systemtap.printf/bin3.exp new file mode 100644 index 00000000..e3ffaed5 --- /dev/null +++ b/testsuite/systemtap.printf/bin3.exp @@ -0,0 +1,11 @@ +load_lib "stap_run_binary.exp" +set ::result_string {00 12 00 34 ab cd 56 78 +56 78 ab cd 88 88 cd ef +61 3d 56 78 20 62 3d ab +cd 20 63 3d 88 88 20 64 +3d cd ef } + +set test "bin3" +stap_run_binary $srcdir/$subdir/$test.stp +set test "bin3a" +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/bin3.stp b/testsuite/systemtap.printf/bin3.stp new file mode 100644 index 00000000..ac86059d --- /dev/null +++ b/testsuite/systemtap.printf/bin3.stp @@ -0,0 +1,18 @@ +# test of 16-bit binary prints +# need to use big_endian2() to get consistent results across +# different-endian architectures. + +probe begin +{ + set_endian(2) + printf("%2b", 0x12) + printf("%2b", 0x34) + printf("%2b%2b", 0xabcd, 0x5678) + a = 0x12345678 + b = 0xabcd + c = 0x8888 + d = 0xcdef + printf("%2b%2b%2b%2b", a, b, c, d) + printf("a=%2b b=%2b c=%2b d=%2b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin3a.stp b/testsuite/systemtap.printf/bin3a.stp new file mode 100644 index 00000000..c0a30448 --- /dev/null +++ b/testsuite/systemtap.printf/bin3a.stp @@ -0,0 +1,17 @@ +# test of 16-bit binary prints +# need to use big_endian2() to get consistent results across +# different-endian architectures. + +probe begin +{ + printf("%2b", big_endian2(0x12)) + printf("%2b", big_endian2(0x34)) + printf("%2b%2b", big_endian2(0xabcd), big_endian2(0x5678)) + a = big_endian2(0x12345678) + b = big_endian2(0xabcd) + c = big_endian2(0x8888) + d = big_endian2(0xcdef) + printf("%2b%2b%2b%2b", a, b, c, d) + printf("a=%2b b=%2b c=%2b d=%2b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin4.exp b/testsuite/systemtap.printf/bin4.exp new file mode 100644 index 00000000..5da24366 --- /dev/null +++ b/testsuite/systemtap.printf/bin4.exp @@ -0,0 +1,14 @@ +load_lib "stap_run_binary.exp" +set ::result_string {00 00 00 12 00 00 00 34 +ab cd ef 00 00 00 56 78 +12 34 56 78 11 11 22 22 +88 88 99 99 cd ef 00 00 +61 3d 12 34 56 78 20 62 +3d 11 11 22 22 20 63 3d +88 88 99 99 20 64 3d cd +ef 00 00 } + +set test "bin4" +stap_run_binary $srcdir/$subdir/$test.stp +set test "bin4a" +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/bin4.stp b/testsuite/systemtap.printf/bin4.stp new file mode 100644 index 00000000..638a38e6 --- /dev/null +++ b/testsuite/systemtap.printf/bin4.stp @@ -0,0 +1,17 @@ +# test of 32-bit binary prints +# Also tests big_endian4() + +probe begin +{ + set_endian(2) + printf("%4b", 0x12) + printf("%4b", 0x34) + printf("%4b%4b", 0xabcdef00, 0x5678) + a = 0x12345678 + b = 0x11112222 + c = 0x88889999 + d = 0xcdef0000 + printf("%4b%4b%4b%4b", a, b, c, d) + printf("a=%4b b=%4b c=%4b d=%4b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin4a.stp b/testsuite/systemtap.printf/bin4a.stp new file mode 100644 index 00000000..40bbec7f --- /dev/null +++ b/testsuite/systemtap.printf/bin4a.stp @@ -0,0 +1,16 @@ +# test of 32-bit binary prints +# Also tests big_endian4() + +probe begin +{ + printf("%4b", big_endian4(0x12)) + printf("%4b", big_endian4(0x34)) + printf("%4b%4b", big_endian4(0xabcdef00), big_endian4(0x5678)) + a = big_endian4(0x12345678) + b = big_endian4(0x11112222) + c = big_endian4(0x88889999) + d = big_endian4(0xcdef0000) + printf("%4b%4b%4b%4b", a, b, c, d) + printf("a=%4b b=%4b c=%4b d=%4b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin5.exp b/testsuite/systemtap.printf/bin5.exp new file mode 100644 index 00000000..11564bd5 --- /dev/null +++ b/testsuite/systemtap.printf/bin5.exp @@ -0,0 +1,20 @@ +load_lib "stap_run_binary.exp" +set ::result_string {00 00 00 00 00 00 00 12 +00 00 00 00 00 00 00 34 +ab cd 00 00 11 11 22 22 +56 78 56 78 56 78 56 78 +00 12 34 56 78 ab cd ef +11 11 22 22 33 33 44 44 +88 88 99 99 aa aa bb bb +cd ef 00 00 11 11 22 22 +61 3d 00 12 34 56 78 ab +cd ef 20 62 3d 11 11 22 +22 33 33 44 44 20 63 3d +88 88 99 99 aa aa bb bb +20 64 3d cd ef 00 00 11 +11 22 22 } + +set test "bin5" +stap_run_binary $srcdir/$subdir/$test.stp +set test "bin5a" +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/bin5.stp b/testsuite/systemtap.printf/bin5.stp new file mode 100644 index 00000000..3a88de60 --- /dev/null +++ b/testsuite/systemtap.printf/bin5.stp @@ -0,0 +1,18 @@ +# test of 64-bit binary prints +# need to use big_endian8() to get consistent results across +# different-endian architectures. + +probe begin +{ + set_endian(2) + printf("%8b", 0x12) + printf("%8b", 0x34) + printf("%8b%8b", 0xabcd000011112222, 0x5678567856785678) + a = 0x0012345678abcdef + b = 0x1111222233334444 + c = 0x88889999aaaabbbb + d = 0xcdef000011112222 + printf("%8b%8b%8b%8b", a, b, c, d) + printf("a=%8b b=%8b c=%8b d=%8b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/bin5a.stp b/testsuite/systemtap.printf/bin5a.stp new file mode 100644 index 00000000..ebee2e01 --- /dev/null +++ b/testsuite/systemtap.printf/bin5a.stp @@ -0,0 +1,17 @@ +# test of 64-bit binary prints +# need to use big_endian8() to get consistent results across +# different-endian architectures. + +probe begin +{ + printf("%8b", big_endian8(0x12)) + printf("%8b", big_endian8(0x34)) + printf("%8b%8b", big_endian8(0xabcd000011112222), big_endian8(0x5678567856785678)) + a = big_endian8(0x0012345678abcdef) + b = big_endian8(0x1111222233334444) + c = big_endian8(0x88889999aaaabbbb) + d = big_endian8(0xcdef000011112222) + printf("%8b%8b%8b%8b", a, b, c, d) + printf("a=%8b b=%8b c=%8b d=%8b",a,b,c,d) + exit() +} diff --git a/testsuite/systemtap.printf/int1.exp b/testsuite/systemtap.printf/int1.exp new file mode 100644 index 00000000..56fb8e62 --- /dev/null +++ b/testsuite/systemtap.printf/int1.exp @@ -0,0 +1,25 @@ +load_lib "stap_run2.exp" +set test "int1" +set ::result_string {1,10,9000000000000,-1,-1024 + 1,10,9000000000000,-1,-1024 + 1, 10, 9000000000000, -1, -1024 +0000000000000001,0000000000000010,0009000000000000,-000000000000001,-000000000001024 + +1,10,9000000000000,18446744073709551615,18446744073709550592 + 1,10,9000000000000,18446744073709551615,18446744073709550592 + 1, 10, 9000000000000,18446744073709551615,18446744073709550592 +0000000000000001,0000000000000010,0009000000000000,18446744073709551615,18446744073709550592 + +1,a,82f79cd9000,ffffffffffffffff,fffffffffffffc00 + 1, a,82f79cd9000,ffffffffffffffff,fffffffffffffc00 + 1, a, 82f79cd9000,ffffffffffffffff,fffffffffffffc00 +0000000000000001,000000000000000a,0000082f79cd9000,ffffffffffffffff,fffffffffffffc00 + 1, A, 82F79CD9000,FFFFFFFFFFFFFFFF,FFFFFFFFFFFFFC00 +0000000000000001,000000000000000A,0000082F79CD9000,FFFFFFFFFFFFFFFF,FFFFFFFFFFFFFC00 + +1,12,202757163310000,1777777777777777777777,1777777777777777776000 + 1,12,202757163310000,1777777777777777777777,1777777777777777776000 + 1, 12, 202757163310000,1777777777777777777777,1777777777777777776000 +0000000000000001,0000000000000012,0202757163310000,1777777777777777777777,1777777777777777776000 +} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/int1.stp b/testsuite/systemtap.printf/int1.stp new file mode 100644 index 00000000..0acd4304 --- /dev/null +++ b/testsuite/systemtap.printf/int1.stp @@ -0,0 +1,42 @@ +probe begin +{ + i = 1 + j = 10 + k = 9000000000000 + m = -1 + n = -1024 + + # signed decimal + printf("%d,%d,%d,%d,%d\n",i,j,k,m,n) + printf("%2d,%2d,%2d,%2d,%2d\n",i,j,k,m,n) + printf("%16d,%16d,%16d,%16d,%16d\n",i,j,k,m,n) + printf("%016d,%016d,%016d,%016d,%016d\n",i,j,k,m,n) + + printf("\n") + + # unsigned decimal + printf("%u,%u,%u,%u,%u\n",i,j,k,m,n) + printf("%2u,%2u,%2u,%2u,%2u\n",i,j,k,m,n) + printf("%16u,%16u,%16u,%16u,%16u\n",i,j,k,m,n) + printf("%016u,%016u,%016u,%016u,%016u\n",i,j,k,m,n) + + printf("\n") + + # hex + printf("%x,%x,%x,%x,%x\n",i,j,k,m,n) + printf("%2x,%2x,%2x,%2x,%2x\n",i,j,k,m,n) + printf("%16x,%16x,%16x,%16x,%16x\n",i,j,k,m,n) + printf("%016x,%016x,%016x,%016x,%016x\n",i,j,k,m,n) + printf("%16X,%16X,%16X,%16X,%16X\n",i,j,k,m,n) + printf("%016X,%016X,%016X,%016X,%016X\n",i,j,k,m,n) + + printf("\n") + + # octal + printf("%o,%o,%o,%o,%o\n",i,j,k,m,n) + printf("%2o,%2o,%2o,%2o,%2o\n",i,j,k,m,n) + printf("%16o,%16o,%16o,%16o,%16o\n",i,j,k,m,n) + printf("%016o,%016o,%016o,%016o,%016o\n",i,j,k,m,n) + + exit() +} diff --git a/testsuite/systemtap.printf/oct.exp b/testsuite/systemtap.printf/oct.exp new file mode 100644 index 00000000..c676ff0e --- /dev/null +++ b/testsuite/systemtap.printf/oct.exp @@ -0,0 +1,7 @@ +load_lib "stap_run_binary.exp" +set test "oct" +set ::result_string {10 01 02 03 04 05 06 07 +08 09 0a 0b 0c 0d 0e 0f +10 11 12 13 14 15 16 17 +18 19 1a 1b 1c 1d 1e 1f} +stap_run_binary $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/oct.stp b/testsuite/systemtap.printf/oct.stp new file mode 100644 index 00000000..255ccfe5 --- /dev/null +++ b/testsuite/systemtap.printf/oct.stp @@ -0,0 +1,8 @@ +probe begin +{ + printf("\020\01\02\03\04\05\06\07") + printf("\010\011\012\013\014\015\016\017") + printf("\020\021\022\023\024\025\026\027") + printf("\030\031\032\033\034\035\036\037") + exit() +} diff --git a/testsuite/systemtap.printf/ptr.exp b/testsuite/systemtap.printf/ptr.exp new file mode 100644 index 00000000..0ad0083e --- /dev/null +++ b/testsuite/systemtap.printf/ptr.exp @@ -0,0 +1,67 @@ +load_lib "stap_run2.exp" +set test "ptr" + +if {$::tcl_platform(wordSize) == 8} { + set ::result_string "0x0000000000000000 +0x0000000000000001 +0x0000000012345678 +0x12345678abcdef00 +0x0000000012345678 + + 0x0000000000000000X + 0x0000000000000001X + 0x0000000012345678X + 0x12345678abcdef00X + 0x0000000012345678X + +0x000000000000000000X +0x000000000000000001X +0x000000000012345678X +0x0012345678abcdef00X +0x000000000012345678X + +0x000000 +0x000001 +0x12345678 +0x12345678abcdef00 +0x12345678 + +0x000000X +0x000001X +0x12345678X +0x12345678abcdef00X +0x12345678X +" +} else { + set ::result_string "0x00000000 +0x00000001 +0x12345678 +0xabcdef00 +0x12345678 + + 0x00000000X + 0x00000001X + 0x12345678X + 0xabcdef00X + 0x12345678X + +0x000000000000000000X +0x000000000000000001X +0x000000000012345678X +0x0000000000abcdef00X +0x000000000012345678X + +0x000000 +0x000001 +0x12345678 +0xabcdef00 +0x12345678 + +0x000000X +0x000001X +0x12345678X +0xabcdef00X +0x12345678X +" +} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/ptr.stp b/testsuite/systemtap.printf/ptr.stp new file mode 100644 index 00000000..397ff922 --- /dev/null +++ b/testsuite/systemtap.printf/ptr.stp @@ -0,0 +1,42 @@ +probe begin +{ + printf("%p\n",0) + printf("%p\n",1) + printf("%p\n",0x12345678) + printf("%p\n",0x12345678abcdef00) + printf("%p\n",0x0000000012345678) + + printf("\n") + + printf("%20pX\n",0) + printf("%20pX\n",1) + printf("%20pX\n",0x12345678) + printf("%20pX\n",0x12345678abcdef00) + printf("%20pX\n",0x0000000012345678) + + printf("\n") + + printf("%-20pX\n",0) + printf("%-20pX\n",1) + printf("%-20pX\n",0x12345678) + printf("%-20pX\n",0x12345678abcdef00) + printf("%-20pX\n",0x0000000012345678) + + printf("\n") + + printf("%8p\n",0) + printf("%8p\n",1) + printf("%8p\n",0x12345678) + printf("%8p\n",0x12345678abcdef00) + printf("%8p\n",0x0000000012345678) + + printf("\n") + + printf("%-8pX\n",0) + printf("%-8pX\n",1) + printf("%-8pX\n",0x12345678) + printf("%-8pX\n",0x12345678abcdef00) + printf("%-8pX\n",0x0000000012345678) + + exit() +} diff --git a/testsuite/systemtap.printf/string1.exp b/testsuite/systemtap.printf/string1.exp new file mode 100644 index 00000000..7b47336b --- /dev/null +++ b/testsuite/systemtap.printf/string1.exp @@ -0,0 +1,7 @@ +load_lib "stap_run2.exp" +set test "string1" +set ::result_string {The string is <Foobar!> +Foobar!XYZZY +XYZZYFoobar!XYZZYFoobar! +} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/string1.stp b/testsuite/systemtap.printf/string1.stp new file mode 100644 index 00000000..69671620 --- /dev/null +++ b/testsuite/systemtap.printf/string1.stp @@ -0,0 +1,9 @@ +probe begin +{ + s = "Foobar!" + printf("The string is <%s>\n", s); + t = "XYZZY" + printf("%s%s\n",s,t); + printf("%s%s%s%s\n",t,s,t,s); + exit() +} diff --git a/testsuite/systemtap.printf/string2.exp b/testsuite/systemtap.printf/string2.exp new file mode 100644 index 00000000..a64bfa38 --- /dev/null +++ b/testsuite/systemtap.printf/string2.exp @@ -0,0 +1,119 @@ +set test "string2" +set ::result_string {s is <12345678901234567890123456789012345678901234567890> +t is <1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890> + 0: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 1: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 2: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 3: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 4: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 5: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 6: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 7: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 8: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 + 9: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +10: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +11: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +12: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +13: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +14: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +15: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +16: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +17: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +18: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +19: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +20: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +21: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +22: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +23: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +24: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +25: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +26: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +27: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +28: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +29: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +30: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +31: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +32: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +33: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +34: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +35: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +36: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +37: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +38: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +39: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +40: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +41: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +42: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +43: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +44: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +45: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +46: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +47: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +48: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +49: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +50: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +51: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +52: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +53: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +54: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +55: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +56: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +57: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +58: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +59: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +60: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +61: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +62: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +63: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +64: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +65: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +66: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +67: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +68: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +69: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +70: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +71: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +72: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +73: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +74: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +75: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +76: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +77: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +78: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +79: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +80: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +81: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +82: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +83: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +84: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +85: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +86: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +87: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +88: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +89: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +90: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +91: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +92: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +93: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +94: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +95: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +96: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +97: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +98: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +99: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890} + +set TEST_NAME "$srcdir/$subdir/$test.stp" + +if {![installtest_p]} { untested $TEST_NAME; return } + +set res [exec stap $TEST_NAME] + +if {[string compare $res $::result_string] == 0} { + pass "$TEST_NAME passed" +} else { + fail "$TEST_NAME failed" + puts "EXPECTED:\n-----------------------\n<$::result_string>" + puts "-----------------------\n" + puts "GOT:\n-----------------------\n<$res>" + puts "-----------------------\n" +} diff --git a/testsuite/systemtap.printf/string2.stp b/testsuite/systemtap.printf/string2.stp new file mode 100644 index 00000000..4d8e354b --- /dev/null +++ b/testsuite/systemtap.printf/string2.stp @@ -0,0 +1,12 @@ +probe begin +{ + # 50 chars + s = "12345678901234567890123456789012345678901234567890" + # 100 chars + t = s.s + printf("s is <%s>\n", s); + printf("t is <%s>\n", t); + for (i = 0; i < 100; i++) + printf("%2d: %s\n", i, t); + exit() +} diff --git a/testsuite/systemtap.printf/text_str.exp b/testsuite/systemtap.printf/text_str.exp new file mode 100644 index 00000000..2871b2ea --- /dev/null +++ b/testsuite/systemtap.printf/text_str.exp @@ -0,0 +1,58 @@ +load_lib "stap_run2.exp" +set test "text_str" +set ::result_string {a=1234567890 +b=12345678901234567890 +c=123456789012345678901234567890 +----- Using text_str ----- +a=1234567890 +b=12345678901234567890 +c=123456789012345678901234567890 +----- Using text_strn ----- +a=1234567890 +b=12345678901234567890 +c=123456789012345678901234567890 +----- Using text_strn len = 10 ----- +a=1234567890 +b=1234567890 +c=1234567890 +----- Using text_strn quoted ----- +a="1234567890" +b="12345678901234567890" +c="123456789012345678901234567890" +----- Using text_strn len=10, quoted ----- +a="12345"... +b="12345"... +c="12345"... +----- Using text_strn len=12, quoted ----- +a="1234567890" +b="1234567"... +c="1234567"... +----- Using text_str ----- +a=\n\nXYZZY\31 +b=?\31\a\n\n\r\n +c=\n\nXYZZY\31?\31\a\n\n\r\n +----- Using text_strn ----- +a=\n\nXYZZY\31 +b=?\31\a\n\n\r\n +c=\n\nXYZZY\31?\31\a\n\n\r\n +----- Using text_strn len = 10 ----- +a=\n\nXYZZY +b=?\31\a\n\n +c=\n\nXYZZY +----- Using text_strn len = 12 ----- +a=\n\nXYZZY\31 +b=?\31\a\n\n\r +c=\n\nXYZZY\31 +----- Using text_strn quoted ----- +a="\n\nXYZZY\31" +b="?\31\a\n\n\r\n" +c="\n\nXYZZY\31?\31\a\n\n\r\n" +----- Using text_strn len=10, quoted ----- +a="\n\nX"... +b="?\31\"... +c="\n\nX"... +----- Using text_strn len=14, quoted ----- +a="\n\nXYZZY\31" +b="?\31\a\n\"... +c="\n\nXYZZY"...} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.printf/text_str.stp b/testsuite/systemtap.printf/text_str.stp new file mode 100644 index 00000000..05acc431 --- /dev/null +++ b/testsuite/systemtap.printf/text_str.stp @@ -0,0 +1,79 @@ +probe begin { + a = "1234567890" + b = a.a + c = a.b + printf("a=%s\n", a) + printf("b=%s\n", b) + printf("c=%s\n", c) + + printf("----- Using text_str -----\n"); + printf("a=%s\n", text_str(a)) + printf("b=%s\n", text_str(b)) + printf("c=%s\n", text_str(c)) + + printf("----- Using text_strn -----\n"); + printf("a=%s\n", text_strn(a,0,0)) + printf("b=%s\n", text_strn(b,0,0)) + printf("c=%s\n", text_strn(c,0,0)) + + printf("----- Using text_strn len = 10 -----\n"); + printf("a=%s\n", text_strn(a,10,0)) + printf("b=%s\n", text_strn(b,10,0)) + printf("c=%s\n", text_strn(c,10,0)) + + printf("----- Using text_strn quoted -----\n"); + printf("a=%s\n", text_strn(a,0,1)) + printf("b=%s\n", text_strn(b,0,1)) + printf("c=%s\n", text_strn(c,0,1)) + + printf("----- Using text_strn len=10, quoted -----\n"); + printf("a=%s\n", text_strn(a,10,1)) + printf("b=%s\n", text_strn(b,10,1)) + printf("c=%s\n", text_strn(c,10,1)) + + printf("----- Using text_strn len=12, quoted -----\n"); + printf("a=%s\n", text_strn(a,12,1)) + printf("b=%s\n", text_strn(b,12,1)) + printf("c=%s\n", text_strn(c,12,1)) + + a = "\n\nXYZZY\031" + b = "\077\031\a\n\n\r\n" + c = a.b + + printf("----- Using text_str -----\n"); + printf("a=%s\n", text_str(a)) + printf("b=%s\n", text_str(b)) + printf("c=%s\n", text_str(c)) + + printf("----- Using text_strn -----\n"); + printf("a=%s\n", text_strn(a,0,0)) + printf("b=%s\n", text_strn(b,0,0)) + printf("c=%s\n", text_strn(c,0,0)) + + printf("----- Using text_strn len = 10 -----\n"); + printf("a=%s\n", text_strn(a,10,0)) + printf("b=%s\n", text_strn(b,10,0)) + printf("c=%s\n", text_strn(c,10,0)) + + printf("----- Using text_strn len = 12 -----\n"); + printf("a=%s\n", text_strn(a,12,0)) + printf("b=%s\n", text_strn(b,12,0)) + printf("c=%s\n", text_strn(c,12 ,0)) + + printf("----- Using text_strn quoted -----\n"); + printf("a=%s\n", text_strn(a,0,1)) + printf("b=%s\n", text_strn(b,0,1)) + printf("c=%s\n", text_strn(c,0,1)) + + printf("----- Using text_strn len=10, quoted -----\n"); + printf("a=%s\n", text_strn(a,10,1)) + printf("b=%s\n", text_strn(b,10,1)) + printf("c=%s\n", text_strn(c,10,1)) + + printf("----- Using text_strn len=14, quoted -----\n"); + printf("a=%s\n", text_strn(a,14,1)) + printf("b=%s\n", text_strn(b,14,1)) + printf("c=%s\n", text_strn(c,14,1)) + + exit() +} diff --git a/testsuite/systemtap.samples/args.exp b/testsuite/systemtap.samples/args.exp new file mode 100644 index 00000000..14f19f17 --- /dev/null +++ b/testsuite/systemtap.samples/args.exp @@ -0,0 +1,72 @@ +set test "args" +if {![installtest_p]} { untested $test; return } + +set stappath [exec which stap] +set stpdpath [exec dirname $stappath]/../libexec/systemtap/stpd + +if [file exists $stpdpath] { + pass "$test search for stpd ($stpdpath)" +} else { + fail "$test search for stpd" + return +} + +set modname "args_[pid]" +spawn stap -k -p4 -m $modname $srcdir/$subdir/args.stp +set tmpdir NO_SUCH_FILE +expect { + -timeout 30 + -re {Keeping temporary directory "([/a-zA-Z0-9_]*)"} { pass "$test compile"; + set tmpdir $expect_out(1,string) } + timeout { fail "$test compile (timeout)" } + eof { } +} +catch {close}; wait +if [file exists $tmpdir] { + pass "$test search for tmpdir ($tmpdir)" +} else { + fail "$test search for tmpdir" + return +} + +set modpath "$tmpdir/$modname.ko" +if [file exists $modpath] { + pass "$test search for probe module ($modpath)" +} else { + fail "$test search for probe module" + return +} + +spawn sudo $stpdpath -r -d [pid] $modpath foo=hello bar=999 +set ok 0 +expect { + -timeout 30 + -re {foo=hello bar=999} { incr ok } + timeout { } + eof { } +} +catch {close}; wait +if {$ok == 1} { + pass "$test run 1" +} else { + fail "$test run 1" +} + +spawn sudo $stpdpath -r -d [pid] $modpath foo=goodbye bar=0 +set ok 0 +expect { + -timeout 30 + -re {foo=goodbye bar=0} { incr ok } + timeout { } + eof { } +} +catch {close}; wait +if {$ok == 1} { + pass "$test run 2" +} else { + fail "$test run 2" +} + + + +exec /bin/rm -rf $tmpdir diff --git a/testsuite/systemtap.samples/args.stp b/testsuite/systemtap.samples/args.stp new file mode 100644 index 00000000..85e731ac --- /dev/null +++ b/testsuite/systemtap.samples/args.stp @@ -0,0 +1,9 @@ +#! stap + +global foo, bar + +probe begin { + log ("foo=" . foo . " bar=" . sprint (bar+0 /* cast bar to integer */)) + exit () +} + diff --git a/testsuite/systemtap.samples/arith.exp b/testsuite/systemtap.samples/arith.exp new file mode 100644 index 00000000..cd00ab71 --- /dev/null +++ b/testsuite/systemtap.samples/arith.exp @@ -0,0 +1,14 @@ +set test "arith" +if {![installtest_p]} { untested $test; return } + +spawn stap -DMAXNESTING=5 $srcdir/$subdir/arith.stp +set ok 0 +expect { + -timeout 30 + -re {passes: [0-9]* failures: 0} { incr ok } + timeout { fail "$test (timeout)" } + eof { } +} +close +wait +if {$ok == 1} { pass "$test" } { fail "$test" } diff --git a/testsuite/systemtap.samples/arith.stp b/testsuite/systemtap.samples/arith.stp new file mode 100644 index 00000000..80f0c040 --- /dev/null +++ b/testsuite/systemtap.samples/arith.stp @@ -0,0 +1,79 @@ +global testno, passes, failures + +function test (v,n1,n2) { + if (n1 == n2) { + passes ++ + result = "pass" + } else { + failures ++ + result = "fail" + } + log ("test " . (sprint (++testno)) . " [" . v . "]\t" . result) +} + +function stest (v,n1,n2) { + if (n1 == n2) { + passes ++ + result = "pass" + } else { + failures ++ + result = "fail" + } + log ("test " . (sprint (++testno)) . " [" . v . "]\t" . result) +} + + +probe begin { + test ("+", 0, 0+0) + test ("+", 33339999, 33330000+9999) + test ("-", -1, 2-3) + test ("==", 1, -1==-1) + test ("!=", 1, -1!=1) + test ("== s", 1, "foobar"=="foobar") + test ("<= s", 1, "fooban"<="foobar") + test ("> s", 1, "xxx">"aaa") + test ("<", 1, -1<0) + test ("<", 1, 85723838<8273823892) + test ("*", 100300400500, 1003004005 * 100) + test ("*", -1*-500, 500) + test ("/", 1003004005/1000, 1003004) + test ("%", 1003004005%1000, 5) + test ("/", -1/-1, 1) + test ("%", -1%-1, 0) + test ("/", 0/-100, 0) + test ("%", 0%-100, 0) + test ("/", (-2147483647-1)/-1, 2147483648) + test ("%", (-2147483647-1)%-1, 0) + # but (-9223372036854775807-1)/-1 may overflow + test ("%", (-9223372036854775807-1)%-1, 0) + test ("&", 0x555&0xaaa, 0) + test ("|", 0x555|0xaaa, 0xfff) + test ("^", 0x55f^0xaaf, 0xff0) + test ("&&", 0x555&&0xaaa, 1) + test ("||", 0x555||0xaaa, 1) + test ("<<", 0<<5, 0) + test ("<<", 1<<8, 0x100) + test ("<<", 120<<-2, 120) + test ("<<", 120<<0, 120) + test ("<<", -4096<<-3, -4096) + test (">>", -4096>>3, -512) + test (">>", -4096>>-3, -4096) + test (">>", 120>>-2, 120) + test (">>", 120>>0, 120) + i=1; test ("--i", --i, 0) + i=1; test ("++i", ++i, 2) + i=1; test ("i--", i--, 1) + i=1; test ("i++", i++, 1) + i=1; test ("+=", i+=4, 5) test ("after +=", i, 5) + i=5; test ("/=", i/=2, 2) test ("after /=", i, 2) + a="1" b="2"; stest (".=", a .= b, "12") stest ("after .=", a, "12") +} + + +probe timer.jiffies(1) { # some time after all the begin probes + exit () +} + +probe end { + log ("passes: " . sprint(passes) . " failures: " . sprint(failures)) +} diff --git a/testsuite/systemtap.samples/arith_limits.exp b/testsuite/systemtap.samples/arith_limits.exp new file mode 100644 index 00000000..d60308c6 --- /dev/null +++ b/testsuite/systemtap.samples/arith_limits.exp @@ -0,0 +1,13 @@ +set test "arith" +if {![installtest_p]} { untested $test; return } + +spawn stap -DMAXNESTING=5 $srcdir/$subdir/arith_limits.stp +set ok 0 +expect { + -timeout 30 + -re {passes: [0-9]* failures: 0} { incr ok } + timeout { fail "$test (timeout)" } + eof { } +} +wait +if {$ok == 1} { pass "$test" } { fail "$test" } diff --git a/testsuite/systemtap.samples/arith_limits.stp b/testsuite/systemtap.samples/arith_limits.stp new file mode 100644 index 00000000..f38a5a68 --- /dev/null +++ b/testsuite/systemtap.samples/arith_limits.stp @@ -0,0 +1,81 @@ +global testno, passes, failures + +function test (v,n1,n2) { + if (n1 == n2) { + passes ++ + result = "pass" + } else { + failures ++ + result = "fail" + } + log ("test " . (sprint (testno++)) . " [" . v . "]\t\t" . result) +} + +# Exactly the same as test() except it will magically work for strings. +# Wouldn't it be nice if we didn't have to do this? + +function teststr (v,n1,n2) { + if (n1 == n2) { + passes ++ + result = "pass" + } else { + failures ++ + result = "fail" + } + log ("test " . (sprint (testno++)) . " [" . v . "]\t\t" . result) +} + + + +probe begin { + # max/minimum signed 32-bit values. + # these could cause problems for 32-bit cpus when overflows + # occur into 64-but values + lmax = 0x7fffffff + lmin = -0x80000000 + + # max/minimum signed 64-bit values + llmax = 0x7fffffffffffffff + llmin = -0x7fffffffffffffff-1 + + # 32-bit limit tests + teststr ("string lmax", sprint(lmax), "2147483647") + teststr ("hex lmax", sprintf("0x%x", lmax), "0x7fffffff") + teststr ("string lmin", sprint(lmin), "-2147483648") + teststr ("hex lmin", sprintf("0x%x", lmin), "0xffffffff80000000") + test ("lmax/-1", lmax/-1, -2147483647); + test ("lmin/-1", lmin/-1, 2147483648); + test ("lmax +1", lmax+1, 2147483648); + test ("lmin -1", lmin-1, -2147483649); + + # 64-bit limits + teststr ("string llmax", sprint(llmax), "9223372036854775807") + teststr ("hex llmax", sprintf("0x%x", llmax), "0x7fffffffffffffff") + teststr ("string llmin", sprint(llmin), "-9223372036854775808") + teststr ("hex llmin", sprintf("0x%x", llmin), "0x8000000000000000") + test ("llmax/-1", llmax/-1, -llmax) + test ("llmax*-1", llmax*-1, -llmax) + + # the next three overflow and produce predictable, although + # wrong results + test ("llmin/-1", llmin/-1, llmin) + test ("llmin*-1", llmin*-1, llmin) + test ("llmax +1", llmax+1, llmin) + test ("llmin -1", llmin-1, llmax) + + # modulo tests + test ("llmax%1", llmax%1, 0) + test ("llmin%1", llmin%1, 0) + test ("0%1 ", 0%1, 0) + test ("0%lmax", 0%lmax, 0) + test ("1%lmax", 1%lmax, 1) + test ("0%lmin", 0%lmin, 0) + test ("1%lmin", 1%lmin, 1) + + exit() +} + +probe end { + print ("passes: " . sprint(passes)) + print (" failures: " . sprint(failures). "\n") +} diff --git a/testsuite/systemtap.samples/control_limits.exp b/testsuite/systemtap.samples/control_limits.exp new file mode 100644 index 00000000..d0ad7d2d --- /dev/null +++ b/testsuite/systemtap.samples/control_limits.exp @@ -0,0 +1,42 @@ +set test "control_limits MAXNESTING" +if {![installtest_p]} { untested $test; return } + +spawn stap -u -DMAXNESTING=5 $srcdir/$subdir/control_limits.stp +set ok 0 +expect { + -timeout 60 -re {ERROR.*MAXNESTING} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +if {$ok == 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "control_limits MAXACTION" +spawn stap -u -DMAXACTION=500 $srcdir/$subdir/control_limits.stp +set ok 0 +expect { + -timeout 60 -re {ERROR.*MAXACTION} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +if {$ok == 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "control_limits MAXSTRINGLEN small" +spawn stap -u -DMAXSTRINGLEN=50 $srcdir/$subdir/control_limits.stp +set ok 0 +expect { + -timeout 60 -re {ERROR.*MAXSTRINGLEN reduced} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +if {$ok == 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "control_limits MAXSTRINGLEN large" +spawn stap -u -DMAXSTRINGLEN=500 $srcdir/$subdir/control_limits.stp +set ok 0 +expect { + -timeout 60 -re {ERROR.*MAXSTRINGLEN enlarged} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +if {$ok == 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + diff --git a/testsuite/systemtap.samples/control_limits.stp b/testsuite/systemtap.samples/control_limits.stp new file mode 100644 index 00000000..89b0bae4 --- /dev/null +++ b/testsuite/systemtap.samples/control_limits.stp @@ -0,0 +1,24 @@ + +# for MAXNESTING testing +function recurse (n) { + if (n > 0) recurse (n-1) +} +probe begin { + recurse (7) +} + +# for MAXACTION testing +probe begin { + for (i=0; i<498; i++) {} +} + +# for MAXSTRINGLEN testing +probe begin { + s = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678" # last 8 will be \0'd + if (strlen(s) < 127) error ("MAXSTRINGLEN reduced") + if (strlen(s) > 127) error ("MAXSTRINGLEN enlarged") +} + + +probe begin { exit () } + diff --git a/testsuite/systemtap.samples/ioblocktest.exp b/testsuite/systemtap.samples/ioblocktest.exp new file mode 100644 index 00000000..43c44f5e --- /dev/null +++ b/testsuite/systemtap.samples/ioblocktest.exp @@ -0,0 +1,12 @@ +# Test the functionality of the various ioblock probes. + +load_lib "stap_run.exp" +set test "ioblocktest" + +proc sleep_ten_secs {} { + after 10000; + return 0; +} + +set output_string "\\mioblock*" +stap_run $srcdir/$subdir/$test.stp sleep_ten_secs $output_string diff --git a/testsuite/systemtap.samples/ioblocktest.stp b/testsuite/systemtap.samples/ioblocktest.stp new file mode 100644 index 00000000..1386903c --- /dev/null +++ b/testsuite/systemtap.samples/ioblocktest.stp @@ -0,0 +1,14 @@ +#! stap +global teststr +probe begin { log("systemtap starting probe") } + +probe ioblock.request { + teststr = sprintf("ioblock: %s\t%d\t%s\t%d\n", devname, sector, bio_rw_str(rw), rw) +} +probe ioblock.end { + teststr = sprintf("ioblock: %s\t%d\t%s\t%d\n", devname, sector, bio_rw_str(rw), rw) +} +probe end { + log("systemtap ending probe") + printf("%s\n", teststr) +} diff --git a/testsuite/systemtap.samples/iotask.stp b/testsuite/systemtap.samples/iotask.stp new file mode 100644 index 00000000..13d273a3 --- /dev/null +++ b/testsuite/systemtap.samples/iotask.stp @@ -0,0 +1,45 @@ +# iotask.stp +# A reimplementation of user script: iotask.stp given at OLS 2005 +# in the current language. +# +# Will Cohen +# 9/22/2005 + +global names, opens +global reads, read_bytes +global writes, write_bytes + +probe kernel.function("sys_open") { + ++names[execname()]; ++opens[execname()]; +} + +probe kernel.function("sys_read") { + ++names[execname()]; ++reads[execname()]; + read_bytes[execname()] += $count; +} + +probe kernel.function("sys_write") { + ++names[execname()]; ++writes[execname()]; + write_bytes[execname()] += $count; +} + +probe begin { log( "starting probe" ); } + +probe end { + foreach( name in names){ + log ("process: " . name); + if (opens[name]) + log( "opens n=" . sprint(opens[name])); + if ( reads[name]){ + count = reads[name]; total=read_bytes[name]; + log("reads n, sum, avg=". sprint(count) + . "," . sprint(total) . "," . sprint(total/count)); + } + if (writes[name]){ + count = writes[name]; total=write_bytes[name]; + log("writes n, sum, avg=". sprint(count) + . "," . sprint(total) . "," . sprint(total/count)); + } + log(""); + } +} diff --git a/testsuite/systemtap.samples/iotask2.stp b/testsuite/systemtap.samples/iotask2.stp new file mode 100644 index 00000000..1f3248e3 --- /dev/null +++ b/testsuite/systemtap.samples/iotask2.stp @@ -0,0 +1,42 @@ +global names, opens, reads, writes + +probe begin { log("starting probe") } + +probe timer.ms(10000) { + log("stopping probe after 10 seconds") + exit() +} + +probe kernel.function("sys_open") { + e=execname(); names[e]=1 + opens[e] ++ # simple integer array +} + +probe kernel.function("sys_read") { + e=execname(); names[e]=1 + reads[e] <<< $count # statistics array +} + +probe kernel.function("sys_write") { + e=execname(); names[e]=1 + writes[e] <<< $count # statistics array +} + + +probe end { + foreach (name+ in names) { # sort by name + printf("process: %s\n", name) + if (opens[name]) + printf("opens n=%d\n", opens[name]) + if (@count(reads[name])) + printf("reads n=%d, sum=%d, avg=%d\n", + @count(reads[name]), # extracting stat results + @sum(reads[name]), + @avg(reads[name])) + if (@count(writes[name])) + printf("writes n=%d, sum=%d, avg=%d\n", + @count(writes[name]), # extracting stat results + @sum(writes[name]), + @avg(writes[name])) + } +} diff --git a/testsuite/systemtap.samples/kmalloc-stacks.stp b/testsuite/systemtap.samples/kmalloc-stacks.stp new file mode 100644 index 00000000..25a23f2d --- /dev/null +++ b/testsuite/systemtap.samples/kmalloc-stacks.stp @@ -0,0 +1,35 @@ +global kmalloc_stack + +function reset_maxaction () %{ + if (CONTEXT && CONTEXT->actioncount) + CONTEXT->actioncount=0; +%} + +function write_output() +{ + foreach (stack in kmalloc_stack) { + log("<hashkey>"); + print_stack(stack); + log("</hashkey>"); + print("<hashval>"); + print(sprint(kmalloc_stack[stack])); + log("</hashval>"); + reset_maxaction(); + } +} + +probe timer.jiffies(5000) +{ + write_output(); + delete kmalloc_stack; +} + +probe kernel.function("__kmalloc") +{ + kmalloc_stack[backtrace()]++; +} + +probe end +{ + write_output(); +} diff --git a/testsuite/systemtap.samples/kmalloc-top b/testsuite/systemtap.samples/kmalloc-top new file mode 100755 index 00000000..42a6d152 --- /dev/null +++ b/testsuite/systemtap.samples/kmalloc-top @@ -0,0 +1,97 @@ +#!/usr/bin/perl +# +# This script accumulates the execution paths of all calls to kmalloc +# in the kernel. On Ctrl-C, it sorts, filters and displays them on +# stdout. +# +# The -e (exclude) option can be used to specify a comma-separated list +# - any stack with contents matching any of the items in the list will +# be excluded from the output. +# +# The -m (min) option can be used to specify the minimum number of +# occurrences a stack needs to be included in the output. +# +# Usage: ./kmalloc-top [-m min] [-i exclude list] +# Ctrl-c + +use Getopt::Std; + +my $kmalloc_stacks; +my $total_kmallocs; +my $sorted_stacks; +my $min_count = 1; +my $exclude; + +$SIG{INT} = \&sigint_handler; + +getopts('e:m:'); + +if ($opt_e) { + $exclude = join('|', split(/,/, $opt_e)); + print "Will exclude stacks containing: $exclude\n"; +} + +if ($opt_m) { + $min_count = $opt_n; +} +print "Will print stacks with counts >= $min_count.\n"; +print STDERR "Press Ctrl-C to stop.\n"; + +open STREAM, "stap -g kmalloc-stacks.stp |" or die "Couldn't get output stream $!"; + +while (<STREAM>) { + if (/<hashval>(.*?)<\/hashval>/) { + update_hash($key, $1); + $key = ""; + } elsif ($_ !~ (/<hashkey>|<\/hashkey>/)) { + $key .= $_; + } +} + +$num_keys_before_filtering = scalar keys %kmalloc_stacks; +filter_stacks(); +$num_keys_after_filtering = scalar keys %kmalloc_stacks; +sort_stacks(); +summarize(); +exit(); + +sub update_hash +{ + my($key, $val) = @_; + $kmalloc_stacks{$key} += $val; + $total_kmallocs += $val; +} + +sub filter_stacks +{ + while (($stack, $count) = each %kmalloc_stacks) { + if ($count < $min_count) { + delete $kmalloc_stacks{$stack}; + } elsif ($exclude && $stack =~ /$exclude/) { + delete $kmalloc_stacks{$stack}; + } + } +} + +sub sort_stacks +{ + @sorted_stacks = sort { $kmalloc_stacks{$b} <=> $kmalloc_stacks{$a} } keys %kmalloc_stacks; +} + +sub summarize { + print "\n"; + foreach $stack(@sorted_stacks) { + print "This path seen $kmalloc_stacks{$stack} times:\n$stack\n"; + } + + print "Total kmallocs (before filtering): $total_kmallocs\n"; + print "Num stacks before filtering: $num_keys_before_filtering\n"; + print "Num stacks after filtering: $num_keys_after_filtering\n"; + + close(STREAM); +} + +sub sigint_handler +{ + system("pkill kmalloc-stacks"); +} diff --git a/testsuite/systemtap.samples/pfaults.exp b/testsuite/systemtap.samples/pfaults.exp new file mode 100644 index 00000000..b230cc6a --- /dev/null +++ b/testsuite/systemtap.samples/pfaults.exp @@ -0,0 +1,17 @@ +set test "pfaults" +if {![installtest_p]} { untested $test; return } + +spawn stap -g $srcdir/$subdir/pfaults.stp +set pid $spawn_id +set ok 0 +expect { + -timeout 30 + -re "Page fault tracking, start time" { incr ok; exp_continue } + -timeout 30 + -re "Page fault tracking, end time" { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging pfaults.stp correctly +wait +if {$ok == 2} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/pfaults.stp b/testsuite/systemtap.samples/pfaults.stp new file mode 100644 index 00000000..753409ba --- /dev/null +++ b/testsuite/systemtap.samples/pfaults.stp @@ -0,0 +1,64 @@ +#! stap + +global pidnames, faults, fault_types + +probe kernel.function(%( kernel_v > "2.6.9" %? "__handle_mm_fault" + %: "handle_mm_fault" %)) { + + # Maintain a pid-to-execname mapping. This logic should get transplanted + # into a tapset script that is automatically included upon reference to + # its exported global variable. + pidnames[pid()] = execname() + + faults [pid(), $write_access ? 1 : 0] ++ +} + +# (needed only until bug 1132 supports $retvalue) +function get_retvalue:long () %{ THIS->__retvalue = fetch_register(0); %} + +probe kernel.function(%( kernel_v > "2.6.9" %? "__handle_mm_fault" + %: "handle_mm_fault" %)).return { + fault_types [pid(), get_retvalue()] ++ +} + + +# Some constants, to come from a future "VM tapset" + +global VM_FAULT_OOM, VM_FAULT_SIGBUS, VM_FAULT_MINOR, VM_FAULT_MAJOR +probe begin { + VM_FAULT_OOM=-1 + VM_FAULT_SIGBUS=0 + VM_FAULT_MINOR=1 + VM_FAULT_MAJOR=2 +} + + +# Shut down the probing session after a while +probe timer.ms(1000) { report() } +probe timer.ms(10000) { exit() } + +function _(n) { return sprint(n) } # let's abbreviate + +function report () { + print ("time=" . _(gettimeofday_s()) . "\n") + foreach ([pid] in pidnames) { + if (faults[pid,0]+faults[pid,1] == 0) continue + print (pidnames[pid] . "[" . _(pid) . "]" . + " reads=" . _(faults[pid,0]) . + " writes=" . _(faults[pid,1]) . + " oom=" . _(fault_types[pid,VM_FAULT_OOM]) . + " sigbus=" . _(fault_types[pid,VM_FAULT_SIGBUS]) . + " minor=" . _(fault_types[pid,VM_FAULT_MINOR]) . + " major=" . _(fault_types[pid,VM_FAULT_MAJOR]) . + "\n") + } + delete faults + delete fault_types +} + +probe begin { + print ("Page fault tracking, start time=" . _(gettimeofday_s()) . "\n") +} +probe end { + print ("Page fault tracking, end time=" . _(gettimeofday_s()) . "\n") +} diff --git a/testsuite/systemtap.samples/poll_map.exp b/testsuite/systemtap.samples/poll_map.exp new file mode 100644 index 00000000..6e26380a --- /dev/null +++ b/testsuite/systemtap.samples/poll_map.exp @@ -0,0 +1,14 @@ +set test "poll_map" +if {![installtest_p]} { untested $test; return } + +spawn stap -g $srcdir/$subdir/poll_map.stp +set ok 0 +expect { + -timeout 90 + -ex "SUCCESS" { incr ok } + timeout { fail "$test (timeout)" } + eof { } +} +close +wait +if {$ok == 1} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/poll_map.stp b/testsuite/systemtap.samples/poll_map.stp new file mode 100755 index 00000000..ba494ddb --- /dev/null +++ b/testsuite/systemtap.samples/poll_map.stp @@ -0,0 +1,33 @@ +#! stap + +# test that polling loops do not exit when conflicts happen +# see PR 1379 + +global called, num_polls + +probe kernel.function( "sys_*" ) { + called[execname(),name]++ +} + +probe timer.ms(1000) +{ + print("\n\n") + num_to_do = 10 + foreach ([n,f] in called-) { + printf("%s called %s\t%d times\n", n, f, called[n,f]) + num_to_do-- + if (num_to_do <= 0) + break + } + delete called + num_polls++ + if (num_polls > 30) + exit() +} + +probe end { + if (num_polls <= 30) + print ("FAIL\n") + else + print ("SUCCESS\n") +} diff --git a/testsuite/systemtap.samples/primes.exp b/testsuite/systemtap.samples/primes.exp new file mode 100644 index 00000000..5381494d --- /dev/null +++ b/testsuite/systemtap.samples/primes.exp @@ -0,0 +1,21 @@ +set test "primes" +if {![installtest_p]} { untested $test; return } + +spawn stap $srcdir/$subdir/primes.stp +set ok 0 +expect { + -timeout 30 + -ex {odds[0] = 1} { incr ok; exp_continue } + -ex {odds[1] = 3} { incr ok; exp_continue } + -ex {odds[3] = 7} { incr ok; exp_continue } + -ex {odds[4] = 9} { incr ok; exp_continue } + -ex {evens[2] = 6} { incr ok; exp_continue } + -ex {evens[1] = 4} { incr ok; exp_continue } + -ex {evens[0] = 2} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging primes.stp correctly +wait + +if {$ok == 7} { pass "$test" } { fail "$test" } diff --git a/testsuite/systemtap.samples/primes.stp b/testsuite/systemtap.samples/primes.stp new file mode 100644 index 00000000..7e7aeb37 --- /dev/null +++ b/testsuite/systemtap.samples/primes.stp @@ -0,0 +1,21 @@ +#! stap +global odds, evens +probe begin { + # "no" and "ne" are local integers + for (i=1; i<10; i++) { + if (i % 2) odds [no++] = i + else evens [ne++] = i + } + delete odds[2] + delete evens[3] + exit () +} + +probe end { + foreach (x+ in odds) { + log("odds[" . sprint(x) . "] = " . sprint(odds[x])) + } + foreach (x in evens-) { + log("evens[" . sprint(x) . "] = " . sprint(evens[x])) + } +} diff --git a/testsuite/systemtap.samples/profile.exp b/testsuite/systemtap.samples/profile.exp new file mode 100644 index 00000000..39b4587f --- /dev/null +++ b/testsuite/systemtap.samples/profile.exp @@ -0,0 +1,14 @@ +set test "profile" +if {![installtest_p]} { untested $test; return } + +spawn stap $srcdir/$subdir/profile.stp +set ok 0 +expect { + -timeout 30 -re {kernel.function[^\r]*ttime=[0-9]*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging primes.stp correctly +wait + +if {$ok > 0} { pass "$test ($ok)" } { fail "$test" } diff --git a/testsuite/systemtap.samples/profile.stp b/testsuite/systemtap.samples/profile.stp new file mode 100644 index 00000000..1a93153d --- /dev/null +++ b/testsuite/systemtap.samples/profile.stp @@ -0,0 +1,38 @@ +#! stap + +global command, syscall_count, syscall_times, this_syscall_time, this_syscall + +function accumulate () { + pid = pid() + if (! ([pid] in command)) command[pid] = execname() + syscall=pp() # just the substring ideally + syscall_count[pid,syscall] ++ + this_syscall[pid] = syscall + this_syscall_time[pid] = gettimeofday_us() +} +function decumulate () { + pid = pid() + syscall = this_syscall[pid] + syscall_times[pid,syscall] += + gettimeofday_us() - this_syscall_time[pid] + # free up memory + this_syscall[pid] = "" + this_syscall_time[pid] = 0 +} +probe kernel.function("sys_*") { + accumulate () +} +probe kernel.function("sys_*").return { + decumulate () +} +probe timer.ms(5000) { + exit () +} +probe end { + foreach ([pid,syscall] in syscall_count-) { + log (command[pid] . "(" . sprint(pid) . ") " . syscall . + " count=" . sprint(syscall_count[pid,syscall]) . + " ttime=" . sprint(syscall_times[pid,syscall])) + if (count++ > 30) next + } +} diff --git a/testsuite/systemtap.samples/queue_demo.exp b/testsuite/systemtap.samples/queue_demo.exp new file mode 100644 index 00000000..71feddd6 --- /dev/null +++ b/testsuite/systemtap.samples/queue_demo.exp @@ -0,0 +1,13 @@ +set test "queue_demo" +if {![installtest_p]} { untested $test; return } + +spawn stap $srcdir/$subdir/queue_demo.stp +set ok 0 +expect { + -timeout 30 + -re {block-[^\r]*} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} + +if {$ok > 4 && $ok < 10} { pass "$test" } { fail "$test" } diff --git a/testsuite/systemtap.samples/queue_demo.stp b/testsuite/systemtap.samples/queue_demo.stp new file mode 100644 index 00000000..61a3b6d1 --- /dev/null +++ b/testsuite/systemtap.samples/queue_demo.stp @@ -0,0 +1,32 @@ + +probe begin { + qsq_start ("block-read") + qsq_start ("block-write") +} + +probe timer.ms(3500), end { + qsq_print ("block-read") + qsq_start ("block-read") + qsq_print ("block-write") + qsq_start ("block-write") +} + +probe timer.ms(10000) { exit () } + + +# synthesize queue work/service using three randomized "threads" for each queue. + +global tc +function qs_doit (thread, name) { + n = tc[thread] = (tc[thread]+1) % 3 # per-thread state counter + if (n==1) qs_wait (name) + else if (n==2) qs_run (name) + else if (n==0) qs_done (name) +} + +probe timer.ms(100).randomize(100) { qs_doit (0, "block-read") } +probe timer.ms(100).randomize(100) { qs_doit (1, "block-read") } +probe timer.ms(100).randomize(100) { qs_doit (2, "block-read") } +probe timer.ms(100).randomize(100) { qs_doit (3, "block-write") } +probe timer.ms(100).randomize(100) { qs_doit (4, "block-write") } +probe timer.ms(100).randomize(100) { qs_doit (5, "block-write") } diff --git a/testsuite/systemtap.samples/scf.stp b/testsuite/systemtap.samples/scf.stp new file mode 100644 index 00000000..1108fdea --- /dev/null +++ b/testsuite/systemtap.samples/scf.stp @@ -0,0 +1,25 @@ +# scf.stp +# A reimplementation of user script:smp_call_function example given at OLS 2005 +# in the current language. +# +# Will Cohen +# 9/22/2005 + +global traces + +probe kernel.function("smp_call_function") +{ + traces[pid(), pexecname(), backtrace()] += 1; +} + +probe begin { print( "starting probe\n" ); } + +probe end { + print("end of data collection\n"); + foreach( [pid, name, stack] in traces){ + print( "traces[" . sprint(pid) . "," . name . ",\n" ); + print_stack(stack) + print( "] = " . sprint(traces[pid, name, stack]) ); + print( "\n" ); + } +} diff --git a/testsuite/systemtap.samples/scf2.stp b/testsuite/systemtap.samples/scf2.stp new file mode 100644 index 00000000..5ad46350 --- /dev/null +++ b/testsuite/systemtap.samples/scf2.stp @@ -0,0 +1,13 @@ +global traces + +probe kernel.function("smp_call_function") { + traces[pid(), pexecname(), backtrace()] ++ +} +probe timer.ms(1000) { exit () } +probe end { + foreach ([pid+, name, stack] in traces) { # sort by pid + printf ("traces[%d,%s,\n", pid, name) + print_stack (stack) + printf ("] = %d\n", traces[pid, name, stack]); + } +} diff --git a/testsuite/systemtap.samples/symbols.exp b/testsuite/systemtap.samples/symbols.exp new file mode 100644 index 00000000..52e90e93 --- /dev/null +++ b/testsuite/systemtap.samples/symbols.exp @@ -0,0 +1,14 @@ +set test "symbols" +if {![installtest_p]} { untested $test; return } + +spawn stap -g $srcdir/$subdir/symbols.stp +set ok 0 +expect { + -timeout 30 + -re { 0x[a-f0-9]+[^\r]*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging symbols.stp correctly +wait +if {$ok == 11} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/symbols.stp b/testsuite/systemtap.samples/symbols.stp new file mode 100644 index 00000000..040c3444 --- /dev/null +++ b/testsuite/systemtap.samples/symbols.stp @@ -0,0 +1,11 @@ +#! stap + +probe begin { + # a spectrum of figures for 32-bit x86 + print_stack ("0x0 0x80000000 0xc0000000 0xe0000000 0xf0000000 0xffffffff") + # for x86_64 + print_stack ("0xffffffff00000000 0xffffffff80000000 0xffffffff80120000") + print_stack ("0xffffffff88000000 0xffffffffffffffff") + # ... for a total of 11 lines, which symbols.exp counts + exit () +} diff --git a/testsuite/systemtap.samples/syscalls.stp b/testsuite/systemtap.samples/syscalls.stp new file mode 100644 index 00000000..670b239d --- /dev/null +++ b/testsuite/systemtap.samples/syscalls.stp @@ -0,0 +1,7 @@ +#! stap + +global count +probe kernel.function("sys_*") { + print (sprint(pid()) . " " . pp() . "\n") + if (++count > 100) exit() +} diff --git a/testsuite/systemtap.samples/syscalls1.exp b/testsuite/systemtap.samples/syscalls1.exp new file mode 100644 index 00000000..edfddf6f --- /dev/null +++ b/testsuite/systemtap.samples/syscalls1.exp @@ -0,0 +1,14 @@ +set test "syscalls-count" +if {![installtest_p]} { untested $test; return } + +spawn stap -p2 $srcdir/$subdir/syscalls.stp +set ok 0 +expect { + -timeout 30 + -re {kernel.function[^\r]*sys_[^\r]*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging psyscalls.stp correctly +wait +if {$ok > 200 && $ok < 350} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/syscalls2.exp b/testsuite/systemtap.samples/syscalls2.exp new file mode 100644 index 00000000..c817f23f --- /dev/null +++ b/testsuite/systemtap.samples/syscalls2.exp @@ -0,0 +1,14 @@ +set test "syscalls-run" +if {![installtest_p]} { untested $test; return } +spawn stap $srcdir/$subdir/syscalls.stp +set ok 0 +expect { + -timeout 60 -re {[0-9]* kernel.function[^\r]*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging psyscalls.stp correctly +wait +# 150 is conservative - it's larger than 100 to allow a bit of slop +# between the exit() call and the actual shutdown +if {$ok >= 100 && $ok < 150} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/sysopen.exp b/testsuite/systemtap.samples/sysopen.exp new file mode 100644 index 00000000..7f98ff3f --- /dev/null +++ b/testsuite/systemtap.samples/sysopen.exp @@ -0,0 +1,12 @@ +set test "sysopen" +if {![installtest_p]} { untested $test; return } +spawn stap $srcdir/$subdir/sysopen.stp +set ok 0 +expect { + -timeout 60 -re {.* opened .*\r} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +#FIXME does not handle case of hanging sysopen.stp correctly +wait +if {$ok > 1} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/sysopen.stp b/testsuite/systemtap.samples/sysopen.stp new file mode 100644 index 00000000..58a27b71 --- /dev/null +++ b/testsuite/systemtap.samples/sysopen.stp @@ -0,0 +1,9 @@ +#! stap + +# pulling out some params has been a problem; see PR 1295 +probe kernel.function("sys_open") { + log (execname() . " opened " . user_string($filename)) +} +probe timer.ms(10000) { + exit () +} diff --git a/testsuite/systemtap.samples/tcp_connections.stp b/testsuite/systemtap.samples/tcp_connections.stp new file mode 100644 index 00000000..a4449b60 --- /dev/null +++ b/testsuite/systemtap.samples/tcp_connections.stp @@ -0,0 +1,49 @@ +#! stap + +%{ +#include <linux/version.h> +#include <net/sock.h> +#include <net/tcp.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) +#define LPORT (inet->inet.num) +#define DADDR (&inet->inet.daddr) +#else +#define LPORT (inet->num) +#define DADDR (&inet->daddr) +#endif +%} + +function get_local_port:long(sock) +%{ + unsigned long ptr = (unsigned long) THIS->sock; + + struct inet_sock *inet = (struct inet_sock *) ptr; + THIS->__retvalue = (long long) LPORT; +%} + +function get_ip_source:string(sock) +%{ + unsigned long ptr = (unsigned long) THIS->sock; + struct inet_sock *inet = (struct inet_sock *) ptr; + unsigned char addr[4]; + memcpy(addr, DADDR, sizeof(addr)); + sprintf(THIS->__retvalue, "%d.%d.%d.%d", + addr[0], addr[1], addr[2], addr[3]); + +%} + + +probe begin { + log ("UID\tCMD\t\tPID\t\tPORT\tIP_SOURCE") +} + +probe kernel.function("tcp_accept").return { + sock = $return + if (sock != 0) + log(sprint(uid())."\t". + execname()."\t\t". + sprint(pid())."\t\t ". + sprint(get_local_port(sock))."\t". + get_ip_source(sock)) +} diff --git a/testsuite/systemtap.samples/tcp_connections_wa.stp b/testsuite/systemtap.samples/tcp_connections_wa.stp new file mode 100644 index 00000000..4c5e2399 --- /dev/null +++ b/testsuite/systemtap.samples/tcp_connections_wa.stp @@ -0,0 +1,55 @@ +%{ +#include <linux/version.h> +#include <net/sock.h> +#include <net/tcp.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) +#define LPORT (inet->inet.num) +#define DADDR (&inet->inet.daddr) +#else +#define LPORT (inet->num) +#define DADDR (&inet->daddr) +#endif +%} + + +function get_eax:long () %{ + if (CONTEXT && CONTEXT->regs) + THIS->__retvalue = CONTEXT->regs->eax; + else + THIS->__retvalue = 0; +%} + +function get_local_port:long(sock) +%{ + unsigned long ptr = (unsigned long) THIS->sock; + + struct inet_sock *inet = (struct inet_sock *) ptr; + THIS->__retvalue = (long long) LPORT; +%} + +function get_ip_source:string(sock) +%{ + unsigned long ptr = (unsigned long) THIS->sock; + struct inet_sock *inet = (struct inet_sock *) ptr; + unsigned char addr[4]; + memcpy(addr, DADDR, sizeof(addr)); + sprintf(THIS->__retvalue, "%d.%d.%d.%d", + addr[0], addr[1], addr[2], addr[3]); + +%} + +probe begin { + log ("UID\tCMD\t\tPID\t\tPORT\tIP_SOURCE") +} +probe kernel.function("tcp_accept").return { + sock = get_eax() + if (sock != 0) + log(sprint(uid())."\t". + execname()."\t\t". + sprint(pid())."\t\t ". + sprint(get_local_port(sock))."\t". + get_ip_source(sock)) +} + + diff --git a/testsuite/systemtap.samples/tcptest.exp b/testsuite/systemtap.samples/tcptest.exp new file mode 100644 index 00000000..d34cc5f4 --- /dev/null +++ b/testsuite/systemtap.samples/tcptest.exp @@ -0,0 +1,12 @@ +# Test the functionality of the tcp probes + +load_lib "stap_run.exp" +set test "tcptest" + +proc sleep_ten_secs {} { + after 10000; + return 0; +} + +set output_string "\\mTCP totalbytes: \\d+\\M" +stap_run $srcdir/$subdir/$test.stp sleep_ten_secs $output_string diff --git a/testsuite/systemtap.samples/tcptest.stp b/testsuite/systemtap.samples/tcptest.stp new file mode 100644 index 00000000..2c88e2c7 --- /dev/null +++ b/testsuite/systemtap.samples/tcptest.stp @@ -0,0 +1,73 @@ +#! stap +global uids, pidnames, send_bytes, recv_bytes, pid_ports, pid_src_ips, pid_rtos +global pid_state, pid_mss, pid_ssthresh, pid_cwnd, totalbytes + +probe begin { log("systemtap starting probe") } + +probe end { + log("systemtap ending probe") + printf("TCP totalbytes: %d\n", totalbytes) +} + +function print_report() +{ + lines = 0; + log ("UID\tPID\tSIZE\tNAME\t\t\tPORT\tSOURCE\t\tRTO\tRCVMSS\tSSTHRES\tCWND\tSTATE") + for (lines = 0; lines <= 21; lines ++) { + if (!lines) { + foreach (_pid_ in pidnames) { + printf("%d\t%d\t%d\t%s\t\t\t%d\t%s\t%d\t%d\t%d\t%d\t%d\n", + uids[_pid_],_pid_,send_bytes[_pid_] + recv_bytes[_pid_], + pidnames[_pid_],pid_ports[_pid_], + pid_src_ips[_pid_],pid_rtos[_pid_], pid_mss[_pid_], + pid_ssthresh[_pid_],pid_cwnd[_pid_],pid_state[_pid_]); + lines++ + } + } else { + print("\n") + } + } +} + +probe tcp.sendmsg { + pid_ports[pid()] = inet_get_local_port(sock) + pid_src_ips[pid()] = inet_get_ip_source(sock) + pid_rtos[pid()] = tcp_get_info_rto(sock) +} + +probe tcp.recvmsg { + pid_cwnd[pid()] = tcp_get_info_snd_cwnd(sock) + pid_mss[pid()] = tcp_ts_get_info_rcv_mss(sock) + pid_ssthresh[pid()] = tcp_ts_get_info_snd_ssthresh(sock) + pid_state[pid()] = tcp_ts_get_info_state(sock) +} + +probe tcp.sendmsg.return { + if (size > 0) { + send_bytes[pid()] += size + totalbytes += size + pidnames[pid()] = execname() + uids[pid()] = uid() + } +} + +probe tcp.recvmsg.return { + if (size > 0) { + recv_bytes[pid()] += size + totalbytes += size + pidnames[pid()] = execname() + uids[pid()] = uid() + } +} + +probe tcp.disconnect { + delete pidnames[pid()] +} + +probe timer.ms(2000) { + print_report() + foreach (_pid_ in pidnames) { + send_bytes[_pid_] = 0 + recv_bytes[_pid_] = 0 + } +} diff --git a/testsuite/systemtap.samples/topsys.stp b/testsuite/systemtap.samples/topsys.stp new file mode 100644 index 00000000..e6e6bb2a --- /dev/null +++ b/testsuite/systemtap.samples/topsys.stp @@ -0,0 +1,69 @@ +#! stap -g +# +# This script continuously lists the top 20 systemcalls in the interval +# of 2000 jiffies. +# + +global syscalls_count, syscalls + +function syscall_name:string () %{ + char *str, buff[80]; + char *tok; + str = buff; + strlcpy(str, CONTEXT->probe_point, sizeof(buff)); + tok = strsep(&str, "\""); + tok = strsep(&str, "@"); + sprintf(str, "%-25s", tok); + strlcpy(THIS->__retvalue, str, MAXSTRINGLEN); +%} + +function reset_maxaction () %{ + if (CONTEXT && CONTEXT->actioncount) + CONTEXT->actioncount=0; +%} + +function accumulate () { + syscall=syscall_name() + syscalls_count[syscall]++ + # I use this array to refer to syscalls_count array in + # the reset_syscalls_count. Initalize with a non-zero. + syscalls[syscall]=1 +} + + +function print_top () { + lcnt=0 + reset_maxaction () + foreach ([syscall] in syscalls_count-) { + sys_cnt = syscalls_count[syscall] + log (syscall . "\t\t\t\t" . sprint(sys_cnt)) + if (lcnt++ == 20) + break; + } + syscalls_count[lsyscall]=0 +} + +function reset_syscalls_count () { + # For some reason, I have to do this to get pass the elaboration + # phase on RHEL4 (seg fault). Under FC4, it works fine with out + # the 'dummy_init' + syscalls["dummy_init"]=0 + foreach ([sys] in syscalls) + syscalls_count[sys]=0 +} + +function print_systop () { + log ("SYSCALL \t\t\t\tCOUNT") + print_top() + reset_syscalls_count () +} + +probe kernel.function("sys_*") { + accumulate () +} + +probe timer.jiffies(2000) { + print_systop () + log("--------------------------------------------------------------") +} + diff --git a/testsuite/systemtap.samples/transport-counts b/testsuite/systemtap.samples/transport-counts new file mode 100755 index 00000000..87335cb9 --- /dev/null +++ b/testsuite/systemtap.samples/transport-counts @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +# tracks gaps (missing records) and repeats in the transport-testing +# output. If there aren't any missing records or repeats, it prints +# "test passed", otherwise "test failed" +# +# Usage: transport-counts <output file> + +$prev = 0; +$total_missing = 0; +$repeats = 0; + +open TRACEFILE, $ARGV[0] + or die "Couldn't open trace file $ARGV[0]"; + +while (<TRACEFILE>) { + chomp; + if (/\[(\d*)/) { + if ($prev + 1 != $1) { + $start_missing = $prev + 1; + $end_missing = $1 - 1; + if ($start_missing > $end_missing) { + $repeats++; + } else { + $total_missing += $end_missing - $start_missing; + } + } + $prev = $1; + } +} +print "total missing: $total_missing\n"; +print "repeats: $repeats\n"; +print "last event logged: $prev\n"; +if ($total_missing == 0 && $repeats == 0) { + print "test passed\n"; +} else { + print "test failed\n"; +} diff --git a/testsuite/systemtap.samples/transport.exp b/testsuite/systemtap.samples/transport.exp new file mode 100644 index 00000000..b7d6d77b --- /dev/null +++ b/testsuite/systemtap.samples/transport.exp @@ -0,0 +1,73 @@ +set test "transport normal - procfs" +if {![installtest_p]} { untested $test; return } + +spawn stap -o probe.out -DMAXACTION=1000000 $srcdir/$subdir/transport1.stp +set ok 0 +expect { + -timeout 60 + timeout { fail "$test (timeout)" } + eof { spawn $srcdir/$subdir/transport-counts probe.out + expect { + -ex {test passed} { incr ok; exp_continue } + eof { spawn rm probe.out } + } + } +} +close +wait + +if {$ok >= 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "transport normal - relayfs" +spawn stap -b -o probe.out -DMAXACTION=1000000 $srcdir/$subdir/transport1.stp +set ok 0 +expect { + -timeout 60 + timeout { fail "$test (timeout)" } + eof { spawn $srcdir/$subdir/transport-counts probe.out + expect { + -ex {test passed} { incr ok; exp_continue } + eof { spawn rm probe.out } + } + } +} +close +wait + +if {$ok >= 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "transport fill staging buffer - procfs" +spawn stap -o probe.out -DMAXACTION=1000000 $srcdir/$subdir/transport2.stp +set ok 0 +expect { + -timeout 60 + timeout { fail "$test (timeout)" } + eof { spawn $srcdir/$subdir/transport-counts probe.out + expect { + -ex {test passed} { incr ok; exp_continue } + eof { spawn rm probe.out } + } + } +} +close +wait + +if {$ok >= 1} { pass "$test ($ok)" } { fail "$test ($ok)" } + +set test "transport fill staging buffer - relayfs" +spawn stap -b -o probe.out -DMAXACTION=1000000 $srcdir/$subdir/transport2.stp +set ok 0 +expect { + -timeout 60 + timeout { fail "$test (timeout)" } + eof { spawn $srcdir/$subdir/transport-counts probe.out + expect { + -ex {test passed} { incr ok; exp_continue } + eof { spawn rm probe.out } + } + } +} +close +wait + +if {$ok >= 1} { pass "$test ($ok)" } { fail "$test ($ok)" } diff --git a/testsuite/systemtap.samples/transport1.stp b/testsuite/systemtap.samples/transport1.stp new file mode 100644 index 00000000..5e9cfcd0 --- /dev/null +++ b/testsuite/systemtap.samples/transport1.stp @@ -0,0 +1,32 @@ +# This script tests normal logging - it logs a fair amount of data +# in each probe hit, but not enough to fill up the staging buffers. + +global maxcount +global count +global n + +function write_output() +{ + for (i = 0; i < n; i++) + log("[".sprint(count++)."] testing 123, testing, testing. testing 123, testing, testing") +} + +probe timer.jiffies(5) +{ + write_output(); + if (count >= maxcount) + exit() +} + +probe begin +{ + count = 1 + n = 50 + maxcount = 1000 +} + +probe end +{ + log("total records written: ".sprint(count - 1)) + log("records per iteration: ".sprint(n)) +} diff --git a/testsuite/systemtap.samples/transport2.stp b/testsuite/systemtap.samples/transport2.stp new file mode 100644 index 00000000..1de90768 --- /dev/null +++ b/testsuite/systemtap.samples/transport2.stp @@ -0,0 +1,33 @@ +# This script tests normal logging - it logs a larger amount of data +# in each probe hit, enough to fill up the staging buffers, so it +# should detect anomalies in flushing the staging buffers. + +global maxcount +global count +global n + +function write_output() +{ + for (i = 0; i < n; i++) + log("[".sprint(count++)."] testing 123, testing, testing. testing 123, testing, testing") +} + +probe timer.jiffies(5) +{ + write_output(); + if (count >= maxcount) + exit() +} + +probe begin +{ + count = 1 + n = 500 + maxcount = 10000 +} + +probe end +{ + log("total records written: ".sprint(count - 1)) + log("records per iteration: ".sprint(n)) +} diff --git a/testsuite/systemtap.stress/all_kernel_functions.exp b/testsuite/systemtap.stress/all_kernel_functions.exp new file mode 100644 index 00000000..f81b6430 --- /dev/null +++ b/testsuite/systemtap.stress/all_kernel_functions.exp @@ -0,0 +1,59 @@ +load_lib "stap_run.exp" + +proc genload {} { + # if 'genload' from the ltp exists, use it to create a real load + set genload {/usr/local/ltp/testcases/bin/genload} + if [file executable $genload] { + exec $genload -c 10 -i 10 -m 10 -t 10 + # ^^^^^ run for 10 seconds + # ^^^^^ 10 procs spinning on malloc + # ^^^^^ 10 procs spinning on sync + # ^^^^^ 10 procs spinning on sqrt + } else { + # sleep for a bit + after 10000 + } + return 0 +} + +proc probe_ok {probepoint} { + set cmd {exec stap -p2 -e} + lappend cmd "probe $probepoint {}" + return ![catch $cmd] +} + +set systemtap_script { + global stat + probe %s { + stat[probefunc()] <<< 1 + } + probe begin { + log("systemtap starting probe") + } + probe end { + log("systemtap ending probe") + foreach (func in stat) + printf("%%d %%s\n", @count(stat[func]), func) + } +} + +set letters [split {abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ} {}] + +set output_string "(\\d+ \\w+\\r\\n)*(WARNING.*skipped.*)?" + +# Because this test is known to expose system crashes, it is not enabled +# by default. Change the line below to 'if 1' to enable it. +if 0 { + foreach start $letters { + set probepoint "kernel.function(\"$start*\")" + set prefix "all_kernel_functions:" + if [probe_ok $probepoint] { + set script [format $systemtap_script $probepoint] + stap_run $prefix$probepoint genload $output_string -e $script + } else { + unsupported "$prefix no match for $probepoint" + } + } +} else { + untested "all_kernel_functions is disabled" +} diff --git a/testsuite/systemtap.stress/current.exp b/testsuite/systemtap.stress/current.exp new file mode 100644 index 00000000..8f4ebff2 --- /dev/null +++ b/testsuite/systemtap.stress/current.exp @@ -0,0 +1,26 @@ +# Simple function to test that systemtap can generate instument a module +# function, install it, and get some output. + +load_lib "stap_run.exp" + +set test "current" + +proc current_load {} { + # if 'genload' from the ltp exists, use it to create a real load + set genload {/usr/local/ltp/testcases/bin/genload} + if [file executable $genload] { + exec $genload -c 10 -i 10 -m 10 -t 10 + # ^^^^^ run for 10 seconds + # ^^^^^ 10 procs spinning on malloc + # ^^^^^ 10 procs spinning on sync + # ^^^^^ 10 procs spinning on sqrt + } else { + # sleep for a bit + after 10000 + } + return 0 +} + +set output_string "(\\w+ = \\d+\r\n){5}${all_pass_string}(WARNING.*skipped.*)?" + +stap_run $srcdir/$subdir/$test.stp current_load $output_string -g diff --git a/testsuite/systemtap.stress/current.stp b/testsuite/systemtap.stress/current.stp new file mode 100644 index 00000000..40673581 --- /dev/null +++ b/testsuite/systemtap.stress/current.stp @@ -0,0 +1,97 @@ +/* + * current.stp (requires Guru mode) + * + * Test the validity of the current pointer in various contexts. + */ + +global length + +function commlen:long () %{ + THIS->__retvalue = strlen(current->comm); +%} + +function pcommlen:long () %{ + THIS->__retvalue = strlen(current->parent->comm); +%} + +probe begin { log("systemtap starting probe") } + +probe + timer.profile, + %( arch != "x86_64" %? + # __switch_to.return is broken on x86_64 - see PR2068 + %( arch != "ia64" %? + # __switch_to is macro definition in ia64, + # and ia64_switch_to is defined in assemble language + kernel.function("__switch_to"), + kernel.function("__switch_to").return, + %) + %) + + /* XXX + * It would be nice if we could just do this: + * kernel.statement("__switch_to@*:*") + * to probe every line in the function + */ + + /* add other kernels/archs here as desired... */ + %( arch == "x86_64" %? + %( kernel_vr == "2.6.9-22.ELsmp" %? + /* the lines before, at, and after the update of pcurrent */ + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:508"), + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:509"), + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:510"), + %) + %( kernel_vr == "2.6.9-24.ELsmp" %? + /* the lines before, at, and after the update of pcurrent */ + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:501"), + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:502"), + kernel.statement("__switch_to@arch/x86_64/kernel/process.c:503"), + %) + %) + + kernel.function("*@kernel/sched.c"), + kernel.function("*@kernel/sched.c").return, + module("*").function("*interrupt*"), + module("*").function("*interrupt*").return +{ + length <<< commlen() + length <<< pcommlen() +} + +function get_TASK_COMM_LEN:long() %{ + /* TASK_COMM_LEN was introduced in 2.6.11, before which + * the length of the comm string was hard-coded to 16 */ +#ifdef TASK_COMM_LEN + THIS->__retvalue = TASK_COMM_LEN; +#else + THIS->__retvalue = 16; +#endif +%} + +probe end { + log("systemtap ending probe") + printf("count = %d\n", @count(length)) + printf("sum = %d\n", @sum(length)) + printf("min = %d\n", @min(length)) + printf("max = %d\n", @max(length)) + printf("avg = %d\n", @avg(length)) + + /* + * Check that the min & max lengths look reasonable. If any string was + * either empty or too big, then the current pointer probably wasn't + * valid, even though it dereferenced without crashing. + */ + if (@min(length) > 0) { + log("systemtap test success") + } else { + log("unexpected minimum length") + log("systemtap test failure") + } + if (@max(length) < get_TASK_COMM_LEN()) { + log("systemtap test success") + } else { + log("unexpected maximum length") + log("systemtap test failure") + } +} diff --git a/testsuite/systemtap.syscall/ChangeLog b/testsuite/systemtap.syscall/ChangeLog new file mode 100644 index 00000000..9f0bf54e --- /dev/null +++ b/testsuite/systemtap.syscall/ChangeLog @@ -0,0 +1,34 @@ +2006-07-21 Martin Hunt <hunt@redhat.com> + + * signal.c: Fix expected pattern. + +2006-06-26 Martin Hunt <hunt@redhat.com> + * stat.c: Add utime() test + +2006-06-15 Martin Hunt <hunt@redhat.com> + * chmod.c: Results for some archs have + 4294967295 instead of -1. Fix expected results + for now. + +2006-06-15 Martin Hunt <hunt@redhat.com> + * chmod.c: New test. + +2006-06-14 Martin Hunt <hunt@redhat.com> + * test.tcl: Escape "|". + * uid.c: Add setfsuid and setfsgid tests. + * uid16.c: Ditto. + * mmap.c, openclose.c, readwrite.c, stat.c: Fix + expected results for sys_open calls. + +2006-06-14 Martin Hunt <hunt@redhat.com> + * setgetgid.c: Renamed to uid.c. Added more syscalls. + * uid16.c: Add some more calls. + +2006-06-13 Martin Hunt <hunt@redhat.com> + * test.exp: Modify to recognize unsupported tests. + * test.tcl: Ditto. + * uid16.c: ifdef out for all but i386. + +2006-06-13 Martin Hunt <hunt@redhat.com> + * sys.stp: Add indentation for nested syscalls. + * uid16.c: New. diff --git a/testsuite/systemtap.syscall/README b/testsuite/systemtap.syscall/README new file mode 100644 index 00000000..41e6d895 --- /dev/null +++ b/testsuite/systemtap.syscall/README @@ -0,0 +1,52 @@ +How these tests work: + +Dejagnu finds all *.c files, compiles them and runs them in a temporary +directory while running the systemtap script sys.stp. To avoid +recompiling sys.stp over and over, the test.exp is smart enough to +compile sys.stp once and save the module. + + +You can run all the tests here with +> runtest test.exp + +You can run single tests with +> gcc -o testname testname.c +>./test.tcl testname + +OR, if you want to run multiple tests and don't want all the delays +with recompiling sys.stp each time, + +> stap -kp4 sys.stp +Keeping temporary directory "/tmp/stapPThTaQ" +> ./test.tcl testname /tmp/stapPThTaQ/*.ko +> ./test.tcl testname2 /tmp/stapPThTaQ/*.ko +... +> rm -rf /tmp/stapPThTaQ + +Finally, if you need to know why a test is failing, use +"test-debug.tcl" exactly as above. After running the test, it will open a +window with the results and expected results. + + + +HOW TO WRITE TESTS + +1. write a test case C file using some system calls. + +2. After each system call, put a comment on the next line starting with "//" +The comment should have the expected output. Where an arbitrary number +is expected, put "NNNN" (for decimal) or "XXXX" (for hex). Or you can +just write regular expressions. The "NNNN" and "XXXX" are just shorthand to +aid readability and are converted to regular expressions in test.tcl. + +3. Somewhere is your test program puts a comment line like this: +/* COVERAGE: syscall1 syscall2 ... */ +where you list the systemcalls that are tested. Then you can run +coverage.tcl and get a coverage report. + +You probably want to write your test case without the comments first. Make +sure it compiles and works as expected. Then try it with +"stap sys.stp -c ./testname" or test-debug.tcl to see the output. + +IMPORTANT: Note that the test scripts create a temporary directory for each +test program. Each program will run in an empty directory. diff --git a/testsuite/systemtap.syscall/access.c b/testsuite/systemtap.syscall/access.c new file mode 100644 index 00000000..065206b7 --- /dev/null +++ b/testsuite/systemtap.syscall/access.c @@ -0,0 +1,34 @@ +/* COVERAGE: access */ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd1; + + fd1 = creat("foobar1",S_IREAD|S_IWRITE); + + access("foobar1", F_OK); + // access ("foobar1", F_OK) = 0 + + access("foobar1", R_OK); + // access ("foobar1", R_OK) = 0 + + access("foobar1", W_OK); + // access ("foobar1", W_OK) = 0 + + access("foobar1", X_OK); + // access ("foobar1", X_OK) = -NNNN (EACCES) + + access("foobar1", R_OK|W_OK); + // access ("foobar1", W_OK |R_OK) = 0 + + access("foobar1", R_OK|W_OK|X_OK); + // access ("foobar1", X_OK |W_OK |R_OK) = -NNNN (EACCES) + + return 0; +} diff --git a/testsuite/systemtap.syscall/acct.c b/testsuite/systemtap.syscall/acct.c new file mode 100644 index 00000000..ec392793 --- /dev/null +++ b/testsuite/systemtap.syscall/acct.c @@ -0,0 +1,10 @@ +/* COVERAGE: acct */ +#include <unistd.h> + +int main() +{ + acct("foobar"); + // acct ("foobar") = -NNNN (EPERM) + + return 0; +} diff --git a/testsuite/systemtap.syscall/alarm.c b/testsuite/systemtap.syscall/alarm.c new file mode 100755 index 00000000..bae92253 --- /dev/null +++ b/testsuite/systemtap.syscall/alarm.c @@ -0,0 +1,44 @@ +/* COVERAGE: alarm nanosleep pause */ +#include <sys/types.h> +#include <unistd.h> +#include <time.h> +#include <string.h> +#include <signal.h> + +static void +sigrt_act_handler(int signo, siginfo_t *info, void *context) +{ +} + +int main() +{ + struct timespec rem, t = {0,789}; + struct sigaction sigrt_act; + memset(&sigrt_act, 0, sizeof(sigrt_act)); + sigrt_act.sa_handler = (void *)sigrt_act_handler; + sigaction(SIGALRM, &sigrt_act, NULL); + + alarm(1); + // alarm (1) = 0 + + pause(); + // pause () = + + alarm(0); + // alarm (0) = 0 + + sleep(1); + // nanosleep (\[1.000000000\], XXXX) = 0 + + usleep(1234); + // nanosleep (\[0.001234000\], 0x[0]+) = 0 + + nanosleep(&t, &rem); + // nanosleep (\[0.000000789\], XXXX) = 0 + + nanosleep(&t, NULL); + // nanosleep (\[0.000000789\], 0x[0]+) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/chmod.c b/testsuite/systemtap.syscall/chmod.c new file mode 100644 index 00000000..fd7473f4 --- /dev/null +++ b/testsuite/systemtap.syscall/chmod.c @@ -0,0 +1,81 @@ +/* COVERAGE: chmod fchmod chown fchown lchown */ +/* COVERAGE: chown16 fchown16 lchown16 */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/syscall.h> + +int main() +{ + int fd; + + fd = open("foobar",O_WRONLY|O_CREAT, 0666); + // open ("foobar", O_WRONLY|O_CREAT, 0666) = 4 + + chmod("foobar", 0644); + // chmod ("foobar", 0644) = 0 + + fchmod(fd, 0444); + // fchmod (4, 0444) = 0 + + chown("foobar", 5000, -1); +#ifdef __i386__ + // chown ("foobar", 5000, -1) = +#else + // chown ("foobar", 5000, NNNN) = +#endif + + chown("foobar", -1, 5001); +#ifdef __i386__ + // chown ("foobar", -1, 5001) = +#else + // chown ("foobar", NNNN, 5001) = +#endif + + fchown(fd, 5002, -1); +#ifdef __i386__ + // fchown (4, 5002, -1) = +#else + // fchown (4, 5002, NNNN) = +#endif + + fchown(fd, -1, 5003); +#ifdef __i386__ + // fchown (4, -1, 5003) = +#else + // fchown (4, NNNN, 5003) = +#endif + + lchown("foobar", 5004, -1); +#ifdef __i386__ + // lchown ("foobar", 5004, -1) = +#else + // lchown ("foobar", 5004, NNNN) = +#endif + + lchown("foobar", -1, 5005); +#ifdef __i386__ + // lchown ("foobar", -1, 5005) = +#else + // lchown ("foobar", NNNN, 5005) = +#endif + +#ifdef __i386__ + syscall(SYS_chown, "foobar", 5000, -1); + // chown16 ("foobar", 5000, -1) = + syscall(SYS_chown, "foobar", -1, 5001); + // chown16 ("foobar", -1, 5001) = + syscall(SYS_fchown, fd, 5002, -1); + // fchown16 (4, 5002, -1) = + syscall(SYS_fchown, fd, -1, 5003); + // fchown16 (4, -1, 5003) = + syscall(SYS_lchown, "foobar", 5004, -1); + // lchown16 ("foobar", 5004, -1) = + syscall(SYS_lchown, "foobar", -1, 5005); + // lchown16 ("foobar", -1, 5005) = +#endif + + close(fd); + return 0; +} diff --git a/testsuite/systemtap.syscall/clock.c b/testsuite/systemtap.syscall/clock.c new file mode 100644 index 00000000..c6b1302e --- /dev/null +++ b/testsuite/systemtap.syscall/clock.c @@ -0,0 +1,76 @@ +/* COVERAGE: gettimeofday settimeofday clock_gettime clock_settime clock_getres clock_nanosleep time */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <time.h> +#include <sys/syscall.h> + +int main() +{ + int t; + struct timeval tv; + struct timespec ts; + time_t tt; + + syscall(SYS_time, &tt); + // time (XXXX) = NNNN + + syscall(SYS_time, NULL); + // time (0x[0]+) = NNNN + + t = syscall(SYS_gettimeofday, &tv, NULL); + // gettimeofday (XXXX, 0x[0]+) = 0 + + settimeofday(&tv, NULL); + // settimeofday (\[NNNN.NNNN\], NULL) = + + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + // clock_gettime (CLOCK_REALTIME, XXXX) = 0 + + syscall(SYS_clock_settime, CLOCK_REALTIME, &ts); + // clock_settime (CLOCK_REALTIME, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_REALTIME, &ts); + // clock_getres (CLOCK_REALTIME, XXXX) = 0 + + syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts); + // clock_gettime (CLOCK_MONOTONIC, XXXX) = 0 + + syscall(SYS_clock_settime, CLOCK_MONOTONIC, &ts); + // clock_settime (CLOCK_MONOTONIC, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_MONOTONIC, &ts); + // clock_getres (CLOCK_MONOTONIC, XXXX) = 0 + + syscall(SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_gettime (CLOCK_PROCESS_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_settime, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_settime (CLOCK_PROCESS_CPUTIME_ID, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_PROCESS_CPUTIME_ID, &ts); + // clock_getres (CLOCK_PROCESS_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_gettime (CLOCK_THREAD_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_settime, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_settime (CLOCK_THREAD_CPUTIME_ID, \[NNNN.NNNN\]) = + + syscall(SYS_clock_getres, CLOCK_THREAD_CPUTIME_ID, &ts); + // clock_getres (CLOCK_THREAD_CPUTIME_ID, XXXX) = + + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + // clock_gettime (CLOCK_REALTIME, XXXX) = 0 + + ts.tv_sec++; + syscall(SYS_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME, &ts); + // clock_nanosleep (CLOCK_REALTIME, TIMER_ABSTIME, \[NNNN.NNNN\], XXXX) = 0 + + ts.tv_sec = 0; ts.tv_nsec = 10000; + syscall(SYS_clock_nanosleep, CLOCK_REALTIME, 0, &ts); + // clock_nanosleep (CLOCK_REALTIME, 0, \[NNNN.NNNN\], XXXX) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/coverage.tcl b/testsuite/systemtap.syscall/coverage.tcl new file mode 100755 index 00000000..559039c1 --- /dev/null +++ b/testsuite/systemtap.syscall/coverage.tcl @@ -0,0 +1,77 @@ +#!/usr/bin/env tclsh + +# List of systemcalls that may or may not be in kernels. Until we +# fix PR2645, we cannot implement syscall probes for these. + +set badlist { add_key tux } + +foreach f $badlist { + set funcname($f) -1 +} + +set cmd {stap -p2 -e "probe kernel.function(\"sys_*\"), kernel.function(\"sys32_*\") ? \{\}"} +if {[catch {eval exec $cmd} output]} { + puts "ERROR running stap: $output" + exit +} + + +foreach line [split $output "\n"] { + if {[regexp {kernel.function\(\"sys_([^@]+)} $line match fn]} { + if {![info exists funcname($fn)]} { + set funcname($fn) 0 + } + } + if {[regexp {kernel.function\(\"sys32_([^@]+)} $line match fn]} { + set fn "32_$fn" + if {![info exists funcname($fn)]} { + set funcname($fn) 0 + } + } +} + +foreach filename [glob *.c] { + if {[catch {open $filename r} fd]} { + puts "ERROR opening $filename: $fd" + exit + } + while {[gets $fd line] >= 0} { + if {[regexp {/* COVERAGE: ([^\*]*)\*/} $line match res]} { + foreach f [split $res] { + if {[info exists funcname($f)]} { + incr funcname($f) + } + } + } + } + close $fd +} + +set covlist {} +set uncovlist {} +set covered 0 +set uncovered 0 +foreach {func val} [array get funcname] { + if {$val > 0} { + incr covered + lappend covlist $func + } elseif {$val == 0} { + incr uncovered + lappend uncovlist $func + } +} + +set total [expr $covered + $uncovered] +puts "Covered $covered out of $total. [format "%2.1f" [expr ($covered * 100.0)/$total]]%" + +puts "\nUNCOVERED FUNCTIONS" +set i 0 +foreach f [lsort $uncovlist] { + puts -nonewline [format "%-24s" $f] + incr i + if {$i >= 3} { + puts "" + set i 0 + } +} +puts "\n" diff --git a/testsuite/systemtap.syscall/dir.c b/testsuite/systemtap.syscall/dir.c new file mode 100644 index 00000000..3609fecd --- /dev/null +++ b/testsuite/systemtap.syscall/dir.c @@ -0,0 +1,53 @@ +/* COVERAGE: mkdir chdir open fchdir close rmdir mkdirat */ +#define _GNU_SOURCE +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/syscall.h> + +int main() +{ + int fd; + + mkdir("foobar", 0765); + // mkdir ("foobar", 0765) = + + chdir("foobar"); + // chdir ("foobar") = 0 + + chdir(".."); + // chdir ("..") = 0 + + fd = open("foobar", O_RDONLY); + // open ("foobar", O_RDONLY) = 4 + + fchdir(fd); + // fchdir (4) = 0 + + chdir(".."); + // chdir ("..") = 0 + + close(fd); + // close (4) = 0 + + rmdir("foobar"); + // rmdir ("foobar") = 0 + + fd = open(".", O_RDONLY); + // open (".", O_RDONLY) = 4 + +#ifdef SYS_mkdirat + mkdirat(fd, "xyzzy", 0765); + // mkdirat (4, "xyzzy", 0765) = 0 + +#endif + + close(fd); + // close (4) = 0 + + rmdir("xyzzy"); + // rmdir ("xyzzy") = + + return 0; +} diff --git a/testsuite/systemtap.syscall/forkwait.c b/testsuite/systemtap.syscall/forkwait.c new file mode 100644 index 00000000..10f8d6ac --- /dev/null +++ b/testsuite/systemtap.syscall/forkwait.c @@ -0,0 +1,25 @@ +/* COVERAGE: fork wait4 */ +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/wait.h> +#include <stdlib.h> +#include <unistd.h> + +int main () +{ + pid_t child; + int status; + + child = fork(); + // clone (CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID) = NNNN + if (!child) { + int i = 0xfffff; + while (i > 0) i--; + exit(0); + } + wait4(child, &status, WNOHANG, NULL); + // wait4 (NNNN, XXXX, WNOHANG, XXXX) = NNNN + + return 0; +} diff --git a/testsuite/systemtap.syscall/itimer.c b/testsuite/systemtap.syscall/itimer.c new file mode 100644 index 00000000..5cebc902 --- /dev/null +++ b/testsuite/systemtap.syscall/itimer.c @@ -0,0 +1,54 @@ +/* COVERAGE: getitimer setitimer */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <string.h> +#include <signal.h> + +static void +alarm_handler(int signo, siginfo_t *info, void *context) +{ +} + +int main() +{ + struct sigaction act; + struct itimerval itv, old_itv; + + memset(&act, 0, sizeof(act)); + act.sa_handler = (void *)alarm_handler; + sigaction(SIGALRM, &act, NULL); + sigaction(SIGVTALRM, &act, NULL); + sigaction(SIGPROF, &act, NULL); + + + memset(&itv, 0, sizeof(itv)); + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = 500000; + itv.it_value.tv_sec = 1; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, &old_itv); + // setitimer (ITIMER_REAL, \[0.500000,1.000000\], XXXX) = 0 + + itv.it_value.tv_sec = 0; + itv.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &itv, NULL); + // setitimer (ITIMER_REAL, \[0.500000,0.000000\], 0x[0]+) = 0 + + setitimer(ITIMER_VIRTUAL, &itv, NULL); + // setitimer (ITIMER_VIRTUAL, \[0.500000,0.000000\], 0x[0]+) = 0 + + setitimer(ITIMER_PROF, &itv, NULL); + // setitimer (ITIMER_PROF, \[0.500000,0.000000\], 0x[0]+) = 0 + + getitimer(ITIMER_REAL, &itv); + // getitimer (ITIMER_REAL, XXXX) = 0 + + getitimer(ITIMER_VIRTUAL, &itv); + // getitimer (ITIMER_VIRTUAL, XXXX) = 0 + + getitimer(ITIMER_PROF, &itv); + // getitimer (ITIMER_PROF, XXXX) = 0 + return 0; +} + diff --git a/testsuite/systemtap.syscall/link.c b/testsuite/systemtap.syscall/link.c new file mode 100644 index 00000000..072c2440 --- /dev/null +++ b/testsuite/systemtap.syscall/link.c @@ -0,0 +1,31 @@ +/* COVERAGE: link symlink readlink */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main() +{ + int fd; + char buf[128]; + + fd = open("foobar",O_WRONLY|O_CREAT, S_IRWXU); + close(fd); + + link("foobar", "foobar2"); + // link ("foobar", "foobar2") = 0 + + link("foobar", "foobar"); + // link ("foobar", "foobar") = -NNNN (EEXIST) + + link("nonexist", "foo"); + // link ("nonexist", "foo") = -NNNN (ENOENT) + + symlink("foobar", "Sfoobar"); + // symlink ("foobar", "Sfoobar") = 0 + + readlink("Sfoobar", buf, sizeof(buf)); + // readlink ("Sfoobar", XXXX, 128) = 6 + + return 0; +} diff --git a/testsuite/systemtap.syscall/mmap.c b/testsuite/systemtap.syscall/mmap.c new file mode 100644 index 00000000..75563854 --- /dev/null +++ b/testsuite/systemtap.syscall/mmap.c @@ -0,0 +1,53 @@ +/* COVERAGE: mmap2 munmap msync mlock mlockall munlock munlockall fstat open close */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> + +int main() +{ + int fd, ret; + struct stat fs; + void * r; + + /* create a file with something in it */ + fd = creat("foobar",S_IREAD|S_IWRITE); + // open ("foobar", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4 + lseek(fd, 1024, SEEK_SET); + write(fd, "abcdef", 6); + close(fd); + // close (4) = 0 + + fd = open("foobar", O_RDONLY); + // open ("foobar", O_RDONLY) = 4 + + /* stat for file size */ + ret = fstat(fd, &fs); + // fstat (4, XXXX) = 0 + + r = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, fd, 0); + // mmap[2]* (XXXX, 1030, PROT_READ, MAP_SHARED, 4, XXXX) = XXXX + + close(fd); + + mlock(r, fs.st_size); + // mlock (XXXX, 1030) = 0 + + msync(r, fs.st_size, MS_SYNC); + // msync (XXXX, 1030, MS_SYNC) = 0 + + munlock(r, fs.st_size); + // munlock (XXXX, 1030) = 0 + + mlockall(MCL_CURRENT); + // mlockall (MCL_CURRENT) = + + munlockall(); + // munlockall () = 0 + + munmap(r, fs.st_size); + // munmap (XXXX, 1030) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/mount.c b/testsuite/systemtap.syscall/mount.c new file mode 100644 index 00000000..57ae030f --- /dev/null +++ b/testsuite/systemtap.syscall/mount.c @@ -0,0 +1,35 @@ +/* COVERAGE: mount oldumount umount */ +#include <sys/types.h> +#include <sys/mount.h> + +#ifndef MNT_FORCE +#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ +#endif + +#ifndef MNT_DETACH +#define MNT_DETACH 0x00000002 /* Just detach from the tree */ +#endif + +#ifndef MNT_EXPIRE +#define MNT_EXPIRE 0x00000004 /* Mark for expiry */ +#endif + +int main() +{ + mount ("mount_source", "mount_target", "ext2", MS_BIND|MS_NOATIME|MS_NODIRATIME|MS_NOSUID, "some arguments"); + // mount ("mount_source", "mount_target", "ext2", MS_BIND|MS_NOATIME|MS_NODIRATIME|MS_NOSUID, "some arguments") = -NNNN (ENOENT) + + umount("umount_target"); + // umount ("umount_target", 0) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_FORCE); + // umount ("umount2_target", MNT_FORCE) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_DETACH); + // umount ("umount2_target", MNT_DETACH) = -NNNN (ENOENT) + + umount2("umount2_target", MNT_EXPIRE); + // umount ("umount2_target", MNT_EXPIRE) = -NNNN (ENOENT) + + return 0; +} diff --git a/testsuite/systemtap.syscall/net1.c b/testsuite/systemtap.syscall/net1.c new file mode 100644 index 00000000..7ff9a294 --- /dev/null +++ b/testsuite/systemtap.syscall/net1.c @@ -0,0 +1,40 @@ +/* COVERAGE: socket fcntl fcntl64 bind listen accept */ +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <strings.h> + +int main() +{ + struct sockaddr_in sa; + int flags, listenfd, cfd; + + + listenfd = socket(AF_INET, SOCK_STREAM, 0); + // socket (PF_INET, SOCK_STREAM, 0) = NNNN + + flags = fcntl(listenfd, F_GETFL, 0); + // fcntl[64]* (NNNN, F_GETFL, 0x[0]+) = NNNN + fcntl(listenfd, F_SETFL, flags | O_NONBLOCK); + // fcntl[64]* (NNNN, F_SETFL, XXXX) = 0 + + bzero(&sa, sizeof(sa)); + sa.sin_family=AF_INET; + sa.sin_addr.s_addr = htonl(INADDR_ANY); + sa.sin_port = htons(8765); + + bind(listenfd, (struct sockaddr *)&sa, sizeof(sa)); + // bind (NNNN, {AF_INET, 0.0.0.0, 8765}, 16) = 0 + + listen (listenfd, 7); + // listen (4, 7) = 0 + + cfd = accept(listenfd, (struct sockaddr *)NULL, NULL); + // accept (NNNN, 0x[0]+, 0x[0]+) = -NNNN (EAGAIN) + + close(cfd); + close(listenfd); + return 0; +} diff --git a/testsuite/systemtap.syscall/openclose.c b/testsuite/systemtap.syscall/openclose.c new file mode 100644 index 00000000..a35f1a59 --- /dev/null +++ b/testsuite/systemtap.syscall/openclose.c @@ -0,0 +1,58 @@ +/* COVERAGE: open close creat */ +#define _GNU_SOURCE +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> + + +int main() +{ + int fd1, fd2; + + fd2 = creat("foobar1",S_IREAD|S_IWRITE); + // open ("foobar1", O_WRONLY|O_CREAT|O_TRUNC, 0600) = NNNN + + fd1 = open("foobar2",O_WRONLY|O_CREAT, S_IRWXU); + // open ("foobar2", O_WRONLY|O_CREAT, 0700) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_RDONLY); + // open ("foobar2", O_RDONLY) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_RDWR); + // open ("foobar2", O_RDWR) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_APPEND|O_WRONLY); + // open ("foobar2", O_WRONLY|O_APPEND) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_DIRECT|O_RDWR); + // open ("foobar2", O_RDWR|O_DIRECT) = NNNN + close(fd1); + // close (NNNN) = 0 + + fd1 = open("foobar2",O_NOATIME|O_SYNC|O_RDWR); + // open ("foobar2", O_RDWR|O_NOATIME|O_SYNC) = NNNN + close(fd1); + // close (NNNN) = 0 + + /* Now test some bad opens */ + fd1 = open("/",O_WRONLY); + // open ("/", O_WRONLY) = -NNNN (EISDIR) + close (fd1); + // close (NNNN) = -NNNN (EBADF) + + fd1 = open("foobar2",O_WRONLY|O_CREAT|O_EXCL, S_IRWXU); + // open ("foobar2", O_WRONLY|O_CREAT|O_EXCL, 0700) = -NNNN (EEXIST) + + return 0; +} diff --git a/testsuite/systemtap.syscall/readwrite.c b/testsuite/systemtap.syscall/readwrite.c new file mode 100644 index 00000000..88f3a38a --- /dev/null +++ b/testsuite/systemtap.syscall/readwrite.c @@ -0,0 +1,85 @@ +/* COVERAGE: read write readv writev lseek llseek */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/unistd.h> +#include <sys/uio.h> + +#define STRING1 "red" +#define STRING2 "green" +#define STRING3 "blue" +int main() +{ + int fd; + struct iovec v[3], x[3]; + loff_t res; + char buf[64], buf1[32], buf2[32], buf3[32]; + + v[0].iov_base = STRING1; + v[0].iov_len = sizeof(STRING1); + v[1].iov_base = STRING2; + v[1].iov_len = sizeof(STRING2); + v[2].iov_base = STRING3; + v[2].iov_len = sizeof(STRING3); + + fd = open("foobar1",O_WRONLY|O_CREAT, 0666); + // open ("foobar1", O_WRONLY|O_CREAT, 0666) = 4 + + write(fd,"Hello world", 11); + // write (4, "Hello world", 11) = 11 + + write(fd,"Hello world abcdefghijklmnopqrstuvwxyz 01234567890", 50); + // write (4, "Hello world abc"..., 50) = 50 + + writev(fd, v, 3); + // writev (4, XXXX, 3) = 15 + + lseek(fd, 0, SEEK_SET); + // lseek (4, 0, SEEK_SET) = 0 + + lseek(fd, 1, SEEK_CUR); + // lseek (4, 1, SEEK_CUR) = 1 + + lseek(fd, -1, SEEK_END); + // lseek (4, -1, SEEK_END) = 75 + +#ifdef SYS__llseek + syscall(SYS__llseek, fd, 1, 0, &res, SEEK_SET); + // llseek (4, 0x1, 0x0, XXXX, SEEK_SET) = 0 + + syscall(SYS__llseek, fd, 0, 0, &res, SEEK_SET); + // llseek (4, 0x0, 0x0, XXXX, SEEK_SET) = 0 + + syscall(SYS__llseek, fd, 0, 12, &res, SEEK_CUR); + // llseek (4, 0x0, 0xc, XXXX, SEEK_CUR) = 0 + + syscall(SYS__llseek, fd, 8, 1, &res, SEEK_END); + // llseek (4, 0x8, 0x1, XXXX, SEEK_END) = 0 +#endif + + close (fd); + + fd = open("foobar1",O_RDONLY); + // open ("foobar1", O_RDONLY) = 4 + + read(fd, buf, 11); + // read (4, XXXX, 11) = 11 + + read(fd, buf, 50); + // read (4, XXXX, 50) = 50 + + x[0].iov_base = buf1; + x[0].iov_len = sizeof(STRING1); + x[1].iov_base = buf2; + x[1].iov_len = sizeof(STRING2); + x[2].iov_base = buf3; + x[2].iov_len = sizeof(STRING3); + readv(fd, x, 3); + // readv (4, XXXX, 3) = 15 + + close (fd); + + return 0; +} diff --git a/testsuite/systemtap.syscall/rt_signal.c b/testsuite/systemtap.syscall/rt_signal.c new file mode 100644 index 00000000..32eb9a92 --- /dev/null +++ b/testsuite/systemtap.syscall/rt_signal.c @@ -0,0 +1,44 @@ +/* COVERAGE: rt_sigprocmask rt_sigaction */ +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> +#include <sys/syscall.h> + + +static void +sig_act_handler(int signo) +{ +} + + +int main() +{ + sigset_t mask; + struct sigaction sa; + + sigemptyset(&mask); + sigaddset(&mask, SIGUSR1); + sigprocmask(SIG_BLOCK, &mask, NULL); + // rt_sigprocmask (SIG_BLOCK, XXXX, 0x[0]+, 8) = 0 + + sigprocmask(SIG_UNBLOCK, &mask, NULL); + // rt_sigprocmask (SIG_UNBLOCK, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGALRM); + sa.sa_flags = 0; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = SIG_DFL; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + sa.sa_handler = sig_act_handler; + sigaction(SIGUSR1, &sa, NULL); + // rt_sigaction (SIGUSR1, XXXX, 0x[0]+, 8) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/sendfile.c b/testsuite/systemtap.syscall/sendfile.c new file mode 100644 index 00000000..06c6b260 --- /dev/null +++ b/testsuite/systemtap.syscall/sendfile.c @@ -0,0 +1,47 @@ +/* COVERAGE: sendfile */ +#include <fcntl.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/sendfile.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> + +int main () +{ + int fd, read_fd; + int write_fd; + struct stat stat_buf; + off_t offset = 0; + char buff[512]; + int ret; + + memset(buff, 5, sizeof(buff)); + + /* create a file with something in it */ + fd = creat("foobar",S_IREAD|S_IWRITE); + write(fd, buff, sizeof(buff)); + fsync(fd); + close(fd); + read_fd = open ("foobar", O_RDONLY); + if (read_fd < 0) + return 1; + fstat (read_fd, &stat_buf); + /* Open the output file for writing */ + write_fd = creat("foobar2",S_IREAD|S_IWRITE|S_IRWXO); + + /* + * For kernel2.6 the write_fd has to be a socket otherwise + * sendfile will fail. So we test for failure here. + */ + ret = sendfile (write_fd, read_fd, &offset, stat_buf.st_size); + // sendfile (NNNN, NNNN, XXXX, 512) = -22 (EINVAL) + + close (read_fd); + close (write_fd); + unlink("foobar"); + unlink("foobar2"); + + return 0; +} diff --git a/testsuite/systemtap.syscall/signal.c b/testsuite/systemtap.syscall/signal.c new file mode 100644 index 00000000..9c7ace95 --- /dev/null +++ b/testsuite/systemtap.syscall/signal.c @@ -0,0 +1,58 @@ +/* COVERAGE: signal kill tgkill sigprocmask sigaction getpid */ +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> +#include <sys/syscall.h> + +#ifdef SYS_signal + +static void +sig_act_handler(int signo) +{ +} + +int main() +{ + sigset_t mask; + struct sigaction sa; + pid_t pid; + + syscall(SYS_signal, SIGUSR1, SIG_IGN); + // signal (SIGUSR1, 0x00000001) = 0 + + syscall(SYS_signal, SIGUSR1, SIG_DFL); + // signal (SIGUSR1, 0x00000000) = 1 + + syscall(SYS_signal, SIGUSR1, sig_act_handler); + // signal (SIGUSR1, XXXX) = 0 + + sigemptyset(&mask); + sigaddset(&mask, SIGUSR1); + syscall(SYS_sigprocmask,SIG_BLOCK, &mask, NULL); + // sigprocmask (SIG_BLOCK, XXXX, 0x[0]+) = 0 + + syscall(SYS_sigprocmask,SIG_UNBLOCK, &mask, NULL); + // sigprocmask (SIG_UNBLOCK, XXXX, 0x[0]+) = 0 + + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGALRM); + sa.sa_flags = 0; + syscall(SYS_sigaction,SIGUSR1, &sa, NULL); + // sigaction (SIGUSR1, XXXX, 0x[0]+) = 0 + + /* syscall(SYS_kill,0,SIGUSR1); + kill (0, SIGUSR1) = 0 + + pid = getpid(); + getpid () = NNNN + + + syscall(SYS_tgkill,pid,pid,SIGUSR1); + tgkill (NNNN, NNNN, SIGUSR1) = 0 + */ + + return 0; +} + +#endif diff --git a/testsuite/systemtap.syscall/stat.c b/testsuite/systemtap.syscall/stat.c new file mode 100644 index 00000000..16161093 --- /dev/null +++ b/testsuite/systemtap.syscall/stat.c @@ -0,0 +1,47 @@ +/* COVERAGE: getcwd fstat stat lstat utime */ +/* COVERAGE: fstat64 stat64 lstat64 */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <utime.h> +#include <string.h> +#include <time.h> +#include <stdio.h> + +int main() +{ + int fd; + char cwd[128]; + struct stat sbuf; + struct utimbuf ubuf; + + getcwd(cwd, 128); + // getcwd (XXXX, 128) = NNNN + + fd = creat("foobar",S_IREAD|S_IWRITE); + // open ("foobar", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4 + + fstat(fd, &sbuf); + // fstat (4, XXXX) = 0 + + close(fd); + + stat("foobar",&sbuf); + // stat ("foobar", XXXX) = 0 + + lstat("foobar",&sbuf); + // lstat ("foobar", XXXX) = 0 + + ubuf.actime = 1; + ubuf.modtime = 1135641600; + utime("foobar", &ubuf); + // utime ("foobar", \[1970/01/01-00:00:01, 2005/12/27-00:00:00\]) = 0 + + ubuf.actime = 1135690000; + ubuf.modtime = 1135700000; + utime("foobar", &ubuf); + // utime ("foobar", \[2005/12/27-13:26:40, 2005/12/27-16:13:20\]) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/statfs.c b/testsuite/systemtap.syscall/statfs.c new file mode 100644 index 00000000..791d49d3 --- /dev/null +++ b/testsuite/systemtap.syscall/statfs.c @@ -0,0 +1,33 @@ +/* COVERAGE: fstatfs statfs ustat statfs64 */ +#include <sys/types.h> +#include <unistd.h> +#include <ustat.h> +#include <sys/vfs.h> + +int main() +{ + + ustat(42, (struct ustat *)0x12345678); +#if __WORDSIZE == 64 + // ustat (42, 0x0000000012345678) = +#else + // ustat (42, 0x12345678) = +#endif + + statfs("abc", (struct statfs *)0x12345678); +#if __WORDSIZE == 64 + // statfs ("abc", 0x0000000012345678) = +#else + // statfs ("abc", 0x12345678) = +#endif + + fstatfs(77, (struct statfs *)0x12345678); +#if __WORDSIZE == 64 + // fstatfs (77, 0x0000000012345678) = +#else + // fstatfs (77, 0x12345678) = +#endif + + + return 0; +} diff --git a/testsuite/systemtap.syscall/swap.c b/testsuite/systemtap.syscall/swap.c new file mode 100755 index 00000000..a2db301e --- /dev/null +++ b/testsuite/systemtap.syscall/swap.c @@ -0,0 +1,29 @@ +/* COVERAGE: swapon swapoff */ +#include <unistd.h> +#include <asm/page.h> +#include <sys/swap.h> + + +int main() +{ + swapon("foobar_swap", 0); + // swapon ("foobar_swap", 0) = + + swapon("foobar_swap", ((1 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER); + // swapon ("foobar_swap", 32769) = + + swapon("foobar_swap", ((7 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER); + // swapon ("foobar_swap", 32775) = + + swapon(0, 0); + // swapon (NULL, 0) = + + swapoff("foobar_swap"); + // swapoff ("foobar_swap") = + + swapoff(0); + // swapoff (NULL) = + + return 0; +} + diff --git a/testsuite/systemtap.syscall/sync.c b/testsuite/systemtap.syscall/sync.c new file mode 100644 index 00000000..b23d68be --- /dev/null +++ b/testsuite/systemtap.syscall/sync.c @@ -0,0 +1,27 @@ +/* COVERAGE: fdatasync fsync sync */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd; + + fd = creat("foobar",S_IREAD|S_IWRITE); + + sync(); + // sync () = 0 + + fsync(fd); + // fsync (4) = 0 + + fdatasync(fd); + // fdatasync (4) = 0 + + close(fd); + + return 0; +} diff --git a/testsuite/systemtap.syscall/sys.stp b/testsuite/systemtap.syscall/sys.stp new file mode 100755 index 00000000..ab822ebb --- /dev/null +++ b/testsuite/systemtap.syscall/sys.stp @@ -0,0 +1,37 @@ +global indent, indent_str, entry + +probe begin { + indent = 0 + for (i=0; i<20; i++) { + if (i == 0) + indent_str[0] = "" + else + indent_str[i] = indent_str[i-1] . " " + } +} + + +probe syscall.* { + if (pid() == target()) { + if (entry) printf("\n") + printf("%s%s: %s (%s) = ", indent_str[indent], execname(), name, argstr) +# printf("%s%s: %s (%s) = ", indent_str[indent], execname(), probefunc(), argstr) + indent++ + entry = 1 + } +} + +probe syscall.*.return { + if (pid() == target()) { + if (indent) indent-- + if (entry) + printf("%s\n", retstr) + else + printf("%s%s\n", indent_str[indent],retstr) + entry = 0 + } +} + +probe end { + printf("\n") +} diff --git a/testsuite/systemtap.syscall/test-debug.tcl b/testsuite/systemtap.syscall/test-debug.tcl new file mode 100755 index 00000000..1eef509a --- /dev/null +++ b/testsuite/systemtap.syscall/test-debug.tcl @@ -0,0 +1,137 @@ +#!/usr/bin/env wish +package require Expect + +proc cleanup {} { + global dir current_dir + puts "cleanup" + if {$current_dir != ""} { + cd $current_dir + exec rm -rf $dir + set current_dir "" + } + exit 0 +} + +proc usage {progname} { + puts "Usage: $progname testname" + cleanup +} + +proc bgerror {error} { + puts "ERROR: $error" + cleanup +} +trap {cleanup} SIGINT +if {[catch {exec mktemp -d staptestXXXXX} dir]} { + puts "Failed to create temporary directory: $dir" + cleanup +} + +set current_dir "" +set testname [lindex $argv 0] +set modname [lindex $argv 1] + +if {$testname == ""} { + usage $argv0 + cleanup +} +set filename "${testname}.c" +set cmd "stap -c ../${testname} ../sys.stp" + +# extract the expected results +# Use the preprocessor so we can ifdef tests in and out + +set ccmd "gcc -E -C -P $filename" +catch {eval exec $ccmd} output + +set ind 0 +foreach line [split $output "\n"] { + if {[regsub {//} $line {} line]} { + set line "$testname: [string trimleft $line]" + + regsub -all {\(} $line {\\(} line + regsub -all {\)} $line {\\)} line + regsub -all {\|} $line {\|} line + + regsub -all NNNN $line {[\-0-9]+} line + regsub -all XXXX $line {[x0-9a-fA-F]+} line + + set results($ind) $line + incr ind + } +} + +if {$ind == 0} { + puts "UNSUPP" + exit +} + +set current_dir [pwd] +cd $dir +catch {eval exec $cmd} output + +set i 0 +foreach line [split $output "\n"] { + if {[regexp $results($i) $line]} { + incr i + if {$i >= $ind} {break} + } +} +if {$i >= $ind} { + puts "PASS" +} else { + puts "FAIL" +} + + +text .t1 -width 60 -height 20 -wrap none \ + -xscrollcommand {.x1bar set} \ + -yscrollcommand {.ybar set} +text .t2 -width 60 -height 20 -wrap none \ + -xscrollcommand {.x2bar set} \ + -yscrollcommand {.ybar set} + +scrollbar .x1bar -orient horizontal -command {.t1 xview} +scrollbar .x2bar -orient horizontal -command {.t2 xview} +scrollbar .ybar -orient vertical -command [list bindyview [list .t1 .t2]] + +proc bindyview {lists args} { + foreach l $lists { + eval {$l yview} $args + } +} + +grid .t1 .t2 .ybar -sticky nsew +grid .x1bar .x2bar -sticky nsew +grid columnconfigure . 0 -weight 1 +grid columnconfigure . 1 -weight 1 +grid rowconfigure . 0 -weight 1 +.t1 tag configure blue -foreground blue +.t2 tag configure blue -foreground blue +.t1 tag configure red -foreground red +.t2 tag configure red -foreground red + +set i 0 +foreach line [split $output "\n"] { + if {[regexp "${testname}: " $line]} { + if {[regexp $results($i) $line]} { + .t1 insert end ${line} blue + .t2 insert end $results($i) blue + incr i + if {$i >= $ind} {break} + } else { + .t1 insert end ${line} + } + .t1 insert end "\n" + .t2 insert end "\n" + } +} + +for {} {$i < $ind} {incr i} { + .t2 insert end $results($i) red + .t1 insert end "\n" + .t2 insert end "\n" +} + +bind . <Destroy> {cleanup} + diff --git a/testsuite/systemtap.syscall/test.exp b/testsuite/systemtap.syscall/test.exp new file mode 100644 index 00000000..98829cc4 --- /dev/null +++ b/testsuite/systemtap.syscall/test.exp @@ -0,0 +1,71 @@ +return ;# this will need more rework for obj!=src testing + +proc test_procedure {} { +global subdir +if {$subdir != ""} { + cd $subdir +} + +# compile sys.stp and keep it +catch {exec stap -kvvp4 sys.stp} res1 +set path "" +regexp {Keeping temporary directory "([^\"]*)"} $res1 match path +if {$path == ""} { + send_log "ERROR:\n$res1\n" + fail "ERROR:\n$res1\n" + return -1 +} +foreach line [split $res1 \n] { + if {[regexp {Pass 4: compiled C into "([^\"]*)"} $line match module]} { + break + } +} + +if {![info exists module]} { + send_log "Compiling sys.stp failed:\n$res1\n" + fail "Compiling sys.stp failed:\n$res1\n" + return -1 +} + +set flags "" +foreach filename [lsort [glob *.c]] { + set file [string range $filename 0 end-2] + target_compile $filename $file executable $flags + send_log "Testing ${file}\n" + set res [exec ./test.tcl $file $path/$module] + if {$res == "PASS"} { + pass "$file" + } elseif {$res == "UNSUPP"} { + unsupported "$file not supported on this arch" + } else { + fail "$file" + send_log "$res\n" + } +} + +if {$tcl_platform(machine) == "x86_64"} { + # on x86_64, test 32-bit and 64-bit binaries + set flags "additional_flags=-m32" + foreach filename [lsort [glob *.c]] { + set file [string range $filename 0 end-2] + target_compile $filename $file executable $flags + send_log "Testing 32-bit ${file}\n" + set res [exec ./test.tcl $file $path/$module] + if {$res == "PASS"} { + pass "32-bit $file" + } elseif {$res == "UNSUPP"} { + unsupported "$file not supported on this arch" + } else { + fail "32-bit $file" + send_log "$res\n" + } + } +} + +exec rm -rf $path +if {$subdir != ""} { + cd .. +} +} + +test_procedure diff --git a/testsuite/systemtap.syscall/test.tcl b/testsuite/systemtap.syscall/test.tcl new file mode 100755 index 00000000..a73e22c9 --- /dev/null +++ b/testsuite/systemtap.syscall/test.tcl @@ -0,0 +1,122 @@ +#!/usr/bin/env expect + +set dir "" +set current_dir "" + +proc cleanup {} { + global dir current_dir + if {$current_dir != ""} { + cd $current_dir + if {$dir != ""} {exec rm -rf $dir} + set current_dir "" + } + exit 0 +} + +proc usage {progname} { + puts "Usage: $progname testname [modulename]" +} + +proc bgerror {error} { + puts "ERROR: $error" + cleanup +} +trap {cleanup} SIGINT +set testname [lindex $argv 0] +set modname [lindex $argv 1] + +if {$testname == ""} { + usage $argv0 + exit +} +set filename "${testname}.c" + +if {$modname == ""} { + set cmd "stap -c ../${testname} ../sys.stp" +} else { + set stpd "" + set stpd_list "/usr/local/libexec/systemtap/stpd /usr/libexec/systemtap/stpd" + foreach path $stpd_list { + if {[file exists $path]} { + set stpd $path + break + } + } + if {$stpd == ""} { + puts "stpd not found!" + exit + } + set user $::tcl_platform(user) + set cmd "sudo $stpd -rmq -u $user -c ../${testname} ${modname}" +} + +# Extract the expected results +# Use the preprocessor so we can ifdef tests in and out + +set ccmd "gcc -E -C -P $filename" +catch {eval exec $ccmd} output + +set ind 0 +foreach line [split $output "\n"] { + if {[regsub {//} $line {} line]} { + set line "$testname: [string trimleft $line]" + + regsub -all {\(} $line {\\(} line + regsub -all {\)} $line {\\)} line + regsub -all {\|} $line {\|} line + + regsub -all NNNN $line {[\-0-9]+} line + regsub -all XXXX $line {[x0-9a-fA-F]+} line + + set results($ind) $line + incr ind + } +} + +if {$ind == 0} { + puts "UNSUPP" + cleanup + exit +} + +if {[catch {exec mktemp -d staptestXXXXX} dir]} { + puts "Failed to create temporary directory: $dir" + cleanup +} +set current_dir [pwd] +cd $dir + +catch {eval exec $cmd} output + +set i 0 +foreach line [split $output "\n"] { + if {[regexp $results($i) $line]} { + incr i + if {$i >= $ind} {break} + } +} +if {$i >= $ind} { + puts "PASS" +} else { + puts "$testname FAILED" + puts "RESULTS: (\'*\' = MATCHED EXPECTED)" + set i 0 + foreach line [split $output "\n"] { + if {[regexp "${testname}: " $line]} { + if {[regexp $results($i) $line]} { + puts "*$line" + incr i + if {$i >= $ind} {break} + } else { + puts "$line" + } + } + } + if {$i < $ind} { + puts "--------- EXPECTED and NOT MATCHED ----------" + } + for {} {$i < $ind} {incr i} { + puts "$results($i)" + } +} +cleanup diff --git a/testsuite/systemtap.syscall/timer.c b/testsuite/systemtap.syscall/timer.c new file mode 100644 index 00000000..27169b0a --- /dev/null +++ b/testsuite/systemtap.syscall/timer.c @@ -0,0 +1,32 @@ +/* COVERAGE: timer_create timer_gettime timer_settime timer_getoverrun timer_delete */ +#include <sys/types.h> +#include <unistd.h> +#include <sys/time.h> +#include <string.h> +#include <signal.h> +#include <time.h> +#include <sys/syscall.h> + +int main() +{ + timer_t tid; + struct itimerspec val, oval; + + syscall(SYS_timer_create, CLOCK_REALTIME, NULL, &tid); + // timer_create (CLOCK_REALTIME, 0x[0]+, XXXX) + + syscall(SYS_timer_gettime, tid, &val); + // timer_gettime (0, XXXX) = 0 + + syscall(SYS_timer_settime, 0, tid, &val, &oval); + // timer_settime (0, 0, \[0.000000,0.000000\], XXXX) = 0 + + syscall(SYS_timer_getoverrun, tid); + // timer_getoverrun (0) = 0 + + syscall(SYS_timer_delete, tid); + // timer_delete (0) = 0 + + return 0; +} + diff --git a/testsuite/systemtap.syscall/trunc.c b/testsuite/systemtap.syscall/trunc.c new file mode 100644 index 00000000..ff20cb39 --- /dev/null +++ b/testsuite/systemtap.syscall/trunc.c @@ -0,0 +1,23 @@ +/* COVERAGE: ftruncate truncate */ + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd; + + + fd = creat("foobar",S_IREAD|S_IWRITE); + ftruncate(fd, 1024); + // ftruncate (4, 1024) = 0 + close(fd); + + truncate("foobar", 2048); + // truncate ("foobar", 2048) = 0 + + return 0; +} diff --git a/testsuite/systemtap.syscall/uid.c b/testsuite/systemtap.syscall/uid.c new file mode 100644 index 00000000..3acb4cb8 --- /dev/null +++ b/testsuite/systemtap.syscall/uid.c @@ -0,0 +1,64 @@ +/* COVERAGE: getuid geteuid getgid getegid setuid setresuid getresuid setgid */ +/* COVERAGE: setresgid getresgid setreuid setregid setfsuid setfsgid */ +#define _GNU_SOURCE +#include <sys/types.h> +#include <unistd.h> +#include <sys/fsuid.h> + +int main () +{ + uid_t ruid, euid, suid; + gid_t rgid, egid, sgid; + + ruid = getuid(); + // getuid () = NNNN + + euid = geteuid(); + // geteuid () = NNNN + + rgid = getgid(); + // getgid () = NNNN + + egid = getegid(); + // getegid () = NNNN + + + + setuid(4096); + // setuid (4096) = NNNN + + seteuid(4097); + // setresuid (-1, 4097, -1) = NNNN + + getresuid(&ruid, &euid, &suid); + // getresuid (XXXX, XXXX, XXXX) = 0 + + setgid(4098); + // setgid (4098) = NNNN + + setegid(4099); + // setresgid (-1, 4099, -1) = NNNN + + getresgid(&rgid, &egid, &sgid); + // getresgid (XXXX, XXXX, XXXX) = 0 + + setreuid(-1, 5000); + // setreuid (NNNN, 5000) = + + setreuid(5001, -1); + // setreuid (5001, NNNN) = + + setregid(-1, 5002); + // setregid (NNNN, 5002) = + + setregid(5003, -1); + // setregid (5003, NNNN) = + + setfsuid(5004); + // setfsuid (5004) = + + setfsgid(5005); + // setfsgid (5005) = + + return 0; +} diff --git a/testsuite/systemtap.syscall/uid16.c b/testsuite/systemtap.syscall/uid16.c new file mode 100644 index 00000000..1c7f9df3 --- /dev/null +++ b/testsuite/systemtap.syscall/uid16.c @@ -0,0 +1,72 @@ +/* COVERAGE: getuid16 geteuid16 getgid16 getegid16 setuid16 setresuid16 */ +/* COVERAGE: getresuid16 setgid16 setresgid16 getresgid16 setreuid16 setregid16 */ +/* COVERAGE: setfsuid16 setfsgid16 */ + +#ifdef __i386__ + +/* These are all obsolete 16-bit calls that are still there for compatibility. */ + +#include <sys/types.h> +#include <unistd.h> +#include <pwd.h> +#include <sys/syscall.h> + +int main () +{ + uid_t uid, ruid, euid, suid; + gid_t gid, rgid, egid, sgid; + + uid = syscall(__NR_getuid); + // getuid16 () = NNNN + + uid = syscall(__NR_geteuid); + // geteuid16 () = NNNN + + gid = syscall(__NR_getgid); + // getgid16 () = NNNN + + gid = syscall(__NR_getegid); + // getegid16 () = NNNN + + + + syscall(__NR_setuid, 4096); + // setuid16 (4096) = + + syscall(__NR_setresuid, -1, 4097, -1); + // setresuid16 (-1, 4097, -1) = + + syscall(__NR_getresuid, &ruid, &euid, &suid); + // getresuid16 (XXXX, XXXX, XXXX) = + + syscall(__NR_setgid, 4098); + // setgid16 (4098) = + + syscall(__NR_setresgid, -1, 4099, -1); + // setresgid16 (-1, 4099, -1) = + + syscall(__NR_getresgid, &rgid, &egid, &sgid); + // getresgid16 (XXXX, XXXX, XXXX) = + + syscall(__NR_setreuid, -1, 5000); + // setreuid16 (-1, 5000) = + + syscall(__NR_setreuid, 5001, -1); + // setreuid16 (5001, -1) = + + syscall(__NR_setregid, -1, 5002); + // setregid16 (-1, 5002) = + + syscall(__NR_setregid, 5003, -1); + // setregid16 (5003, -1) = + + syscall(__NR_setfsuid, 5004); + // setfsuid16 (5004) = + + syscall(__NR_setfsgid, 5005); + // setfsgid16 (5005) = + + return 0; +} + +#endif /* __i386__ */ diff --git a/testsuite/systemtap.syscall/umask.c b/testsuite/systemtap.syscall/umask.c new file mode 100644 index 00000000..5d13575f --- /dev/null +++ b/testsuite/systemtap.syscall/umask.c @@ -0,0 +1,20 @@ +/* COVERAGE: umask */ +#include <sys/types.h> +#include <sys/stat.h> + +int main() +{ + umask (0); + // umask (00) = NNNN + umask (7); + // umask (07) = 00 + umask (077); + // umask (077) = 07 + umask (0666); + // umask (0666) = 077 + umask (0777); + // umask (0777) = 0666 + umask (01777); + // umask (01777) = 0777 + return 0; +} diff --git a/testsuite/systemtap.syscall/unlink.c b/testsuite/systemtap.syscall/unlink.c new file mode 100644 index 00000000..b0d00be8 --- /dev/null +++ b/testsuite/systemtap.syscall/unlink.c @@ -0,0 +1,35 @@ +/* COVERAGE: unlink */ +#include <stdio.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + + +int main() +{ + int fd1; + + fd1 = creat("foobar1",S_IREAD|S_IWRITE); + close (fd1); + + unlink("foobar1"); + // unlink ("foobar1") = 0 + + unlink("foobar1"); + // unlink ("foobar1") = -NNNN (ENOENT) + + unlink("foobar2"); + // unlink ("foobar2") = -NNNN (ENOENT) + + unlink(0); + // unlink (NULL) = -NNNN (EFAULT) + + unlink(".."); + // unlink ("..") = -NNNN (EISDIR) + + unlink(""); + // unlink ("") = -NNNN (ENOENT) + + return 0; +} diff --git a/testsuite/systemtap/notest.exp b/testsuite/systemtap/notest.exp new file mode 100644 index 00000000..d3353d04 --- /dev/null +++ b/testsuite/systemtap/notest.exp @@ -0,0 +1 @@ +# this is just a placeholder for dejagnu |