From 854e786e804c6dac927465ebcaac7fca724256cb Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Sat, 20 Jun 2009 15:08:18 +0200 Subject: Add test for target_set tapset. Signed-off-by: Josh Stone --- testsuite/systemtap.base/target_set.exp | 67 +++++++++++++++++++++++++++++++++ testsuite/systemtap.base/target_set.stp | 16 ++++++++ 2 files changed, 83 insertions(+) create mode 100644 testsuite/systemtap.base/target_set.exp create mode 100644 testsuite/systemtap.base/target_set.stp diff --git a/testsuite/systemtap.base/target_set.exp b/testsuite/systemtap.base/target_set.exp new file mode 100644 index 00000000..998fd4a1 --- /dev/null +++ b/testsuite/systemtap.base/target_set.exp @@ -0,0 +1,67 @@ +# Test for target_set tapset + +set test target_set + +if {![installtest_p]} { untested $test; continue } + +set file $srcdir/$subdir/target_set.stp +set time 12345 +set stap_cmd "( ( /bin/sleep $time ) ; ( /bin/sleep $time ) ; ( /bin/sleep $time ) )" +set stap_cmd_sleep_count 3 +set stap_cmd_child_level 3 + +proc failtest {} { + global test + fail $test +} + +proc expect_target_set_string {} { + expect { + "^target set:\r\n" { } + timeout { failtest; return -code return } + } +} + +proc expect_target_set_pids generations { + global test + global stp_pid + for {set i 0} {$i < $generations} {incr i} { + expect { + -re {^([0-9]+) begat ([0-9]+)\r\n} { set pid_array($expect_out(1,string)) $expect_out(2,string) } + timeout { failtest; return -code return } + } + } + set pid_it $stp_pid + while {[info exists pid_array($pid_it)]} { + if {[exec pgrep -P $pid_it] != $pid_array($pid_it)} { + failtest; return -code return + } + set pid_it $pid_array($pid_it) + } + if {$generations > 1} { + exec kill -INT $pid_it + } +} + +spawn stap $file $time -c "$stap_cmd" + +expect { + -re {^(\d+)\r\n} { set stp_pid $expect_out(1,string) } + timeout { failtest; return } +} + +expect_target_set_pids 1 +for {set i 0} {$i < $stap_cmd_sleep_count} {incr i} { + expect_target_set_string + expect_target_set_pids $stap_cmd_child_level +} +expect_target_set_string +expect_target_set_pids 0 + +expect { + eof {} + timeout { failtest; return } +} + +wait +pass $test diff --git a/testsuite/systemtap.base/target_set.stp b/testsuite/systemtap.base/target_set.stp new file mode 100644 index 00000000..002ba897 --- /dev/null +++ b/testsuite/systemtap.base/target_set.stp @@ -0,0 +1,16 @@ +probe begin +{ + stp_pid = stp_pid() + printf("%d\n%d begat %d\n", stp_pid, stp_pid, target()) +} + +probe syscall.nanosleep, syscall.compat_nanosleep ? +{ + if (target_set_pid(pid()) && $rqtp->tv_sec == $1) + target_set_report() +} + +probe end +{ + target_set_report() +} -- cgit From b4b70fe340bb600e95fa46a31e76dc2c28c83f29 Mon Sep 17 00:00:00 2001 From: Stan Cox Date: Mon, 22 Jun 2009 16:25:37 -0400 Subject: Strip -o option suffix dtrace: Strip the -o option suffix. --- dtrace | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dtrace b/dtrace index cdc97c57..0c7711dc 100755 --- a/dtrace +++ b/dtrace @@ -166,6 +166,8 @@ if (filename == ""): else: usage sys.exit(1) +else: + (filename,ext) = os.path.splitext(filename) if (build_header): providers = provider() -- cgit From 417c9d68ac05297024272a0a6f97fe764468e5a5 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Mon, 22 Jun 2009 16:58:51 -0400 Subject: Correct typo in forktracker.meta. --- testsuite/systemtap.examples/process/forktracker.meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/systemtap.examples/process/forktracker.meta b/testsuite/systemtap.examples/process/forktracker.meta index f3ef3709..87d43d7a 100644 --- a/testsuite/systemtap.examples/process/forktracker.meta +++ b/testsuite/systemtap.examples/process/forktracker.meta @@ -10,4 +10,4 @@ output: trace scope: system-wide description: The forktracker.stp script prints out a time-stamped entry showing each fork and exec operation on the machine. This can be useful for determine what process is creating a flurry of short-lived processes. test_check: stap -p4 forktracker.stp -test_installcheck: stap forkracker.stp -c "sleep 1" +test_installcheck: stap forktracker.stp -c "sleep 1" -- cgit From 595d75d80e0301fe7dca9b0614ce58b1e0a5d474 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 22 Jun 2009 13:59:58 -0700 Subject: Bump up the default timeout for target_set test Starting the test with a cold cache can take easily longer than dejagnu's default 10 second timeout. I'm bumping it to 180 seconds, the same as in the stap_run library functions. --- testsuite/systemtap.base/target_set.exp | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/systemtap.base/target_set.exp b/testsuite/systemtap.base/target_set.exp index 998fd4a1..4b6e0a5d 100644 --- a/testsuite/systemtap.base/target_set.exp +++ b/testsuite/systemtap.base/target_set.exp @@ -46,6 +46,7 @@ proc expect_target_set_pids generations { spawn stap $file $time -c "$stap_cmd" expect { + -timeout 180 -re {^(\d+)\r\n} { set stp_pid $expect_out(1,string) } timeout { failtest; return } } -- cgit From 7e788c262ae119a9e1b378605ce649cf1ae3f6cb Mon Sep 17 00:00:00 2001 From: Varun Chandramohan Date: Sat, 20 Jun 2009 09:37:54 +0530 Subject: Add str_replace() To Tapsets This patch adds a search and replace string functionality to existing tapsets. The functionality is as follows: The function takes in a parent string and searches for a substring as specified by the user. If substring not found, the parent string is returned. If substring is found, it is replaced by another string and returned. NOTE: The function will search and replace all the occurrence of substrings in a parent string when matched. Signed-off-by: Varun Chandramohan Signed-off-by: Josh Stone --- tapset/string.stp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tapset/string.stp b/tapset/string.stp index cc842929..e4a5fd39 100644 --- a/tapset/string.stp +++ b/tapset/string.stp @@ -98,6 +98,39 @@ function tokenize:string(input:string, delim:string) } %} +/** @addtogroup library + * @code str_replace:string (prnt_str:string, srch_str:string, rplc_str:string) @endcode + * @param prnt_str The parent string. + * @param srch_str The substring which is used to search in the parent string prnt_str. + * @param rplc_str The substring which is used to replace the searched string srch_str. + * @return Returns the parent string with substrings replaced. Else returns parent string. + */ +function str_replace:string (prnt_str:string, srch_str:string, rplc_str:string) +%{ + char *ptr = THIS->prnt_str; + char *ptr_base = THIS->prnt_str; + int strlen_prnt_str = strlen(THIS->prnt_str); + int strlen_srch_str = strlen(THIS->srch_str); + int strlen_rplc_str = strlen(THIS->rplc_str); + + if(strlen_srch_str == 0) { + strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN); + return; + } + + while((ptr = strstr(ptr, THIS->srch_str)) != NULL) { + + *ptr = '\0'; + strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN); + strlcat(THIS->__retvalue, THIS->rplc_str, MAXSTRINGLEN); + ptr = ptr + strlen_srch_str; + ptr_base = ptr; + } + + strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN); + return; +%} + /* * strtol - Convert a string to a long * str String to convert -- cgit From 6eec708abee9188d74602f2602925edd2daa6342 Mon Sep 17 00:00:00 2001 From: Varun Chandramohan Date: Sat, 20 Jun 2009 09:40:36 +0530 Subject: Testcase For str_replace() This patch adds the test case needed for this function. I have added few tests. If required more can be added in future. As discussed in previous version, the testcase patch has been reverted to the original as the str_replace() functionality has changed wrt to error handle. Signed-off-by: Varun Chandramohan Signed-off-by: Josh Stone --- testsuite/systemtap.string/str_replace.exp | 14 ++++++++++++++ testsuite/systemtap.string/str_replace.stp | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 testsuite/systemtap.string/str_replace.exp create mode 100644 testsuite/systemtap.string/str_replace.stp diff --git a/testsuite/systemtap.string/str_replace.exp b/testsuite/systemtap.string/str_replace.exp new file mode 100644 index 00000000..4eedf1c6 --- /dev/null +++ b/testsuite/systemtap.string/str_replace.exp @@ -0,0 +1,14 @@ +set test "str_replace" + +set ::result_string {Result = hello pointer tap +Result = pointer system tap +Result = hello system pointer +Result = Here I am, on the bored again. there I am, up on the stage, Here I go, playing star again. There I go, turn the page.- Bob Sege +Result = here I am, on the road again. there I am, up on the stage, here I go, playing star again. There I go, turn the page.- Bob Seger +Result = Here I am, on the road again. there I am, up on the stage, Here I go, playing star again. There I go, turn the page.- Metallica +Result = hello tap +Result = hello system tap +Result = +Result = } +stap_run2 $srcdir/$subdir/$test.stp + diff --git a/testsuite/systemtap.string/str_replace.stp b/testsuite/systemtap.string/str_replace.stp new file mode 100644 index 00000000..87e09353 --- /dev/null +++ b/testsuite/systemtap.string/str_replace.stp @@ -0,0 +1,25 @@ +# Test of str_replace() + +global long_str1 = "hello system tap" +global long_str2 = "Here I am, on the road again. there I am, up on the stage, Here I go, playing star again. There I go, turn the page.- Bob Seger" +global long_src_str1 = "system" +global long_src_str2 = "hello" +global long_src_str3 = "tap" +global long_rlpc_str = "pointer" + +probe begin { + printf("Result = %s\n",str_replace(long_str1, long_src_str1, long_rlpc_str)) + printf("Result = %s\n",str_replace(long_str1, long_src_str2, long_rlpc_str)) + printf("Result = %s\n",str_replace(long_str1, long_src_str3, long_rlpc_str)) + + printf("Result = %s\n",str_replace(long_str2, "road", "bored")) + printf("Result = %s\n",str_replace(long_str2, "Here", "here")) + printf("Result = %s\n",str_replace(long_str2, "Bob Seger", "Metallica")) + printf("Result = %s\n",str_replace(long_str1, long_src_str1, "\0")) + printf("Result = %s\n",str_replace(long_str1, "\0", long_rlpc_str)) + printf("Result = %s\n",str_replace("\0", "\0", long_rlpc_str)) + printf("Result = %s\n",str_replace("\0", "\0", "\0")) +} +probe begin { + exit() +} -- cgit From ac72d42e6de0b96fa3e7f9245b50288ad399e4b5 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 22 Jun 2009 14:24:42 -0700 Subject: Remove unused strlens from str_replace --- tapset/string.stp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tapset/string.stp b/tapset/string.stp index e4a5fd39..4b0a2a0d 100644 --- a/tapset/string.stp +++ b/tapset/string.stp @@ -109,9 +109,7 @@ function str_replace:string (prnt_str:string, srch_str:string, rplc_str:string) %{ char *ptr = THIS->prnt_str; char *ptr_base = THIS->prnt_str; - int strlen_prnt_str = strlen(THIS->prnt_str); int strlen_srch_str = strlen(THIS->srch_str); - int strlen_rplc_str = strlen(THIS->rplc_str); if(strlen_srch_str == 0) { strlcat(THIS->__retvalue, ptr_base, MAXSTRINGLEN); -- cgit From fcc30d6d020ebf1df7d05809074015c8f0990c22 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 23 Jun 2009 10:20:07 +0200 Subject: PR 10313 Build error due to deprecation of elf_getshstrndx in elfutils. * dwflpp.h: Check elfutils version, define elf_getshdrstrndx as elf_getshstrndx if elfutils 0.142 detected. * dwflpp.cxx (get_blacklist_section): Use elf_getshdrstrndx. * tapsets.cxx (probe_table): Likewise. (prepare_section_rejection): Likewise. --- dwflpp.cxx | 2 +- dwflpp.h | 7 +++++++ tapsets.cxx | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dwflpp.cxx b/dwflpp.cxx index 61627e16..5991d1a1 100644 --- a/dwflpp.cxx +++ b/dwflpp.cxx @@ -2316,7 +2316,7 @@ dwflpp::get_blacklist_section(Dwarf_Addr addr) { Elf_Scn* scn = 0; size_t shstrndx; - dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); + dwfl_assert ("getshdrstrndx", elf_getshdrstrndx (elf, &shstrndx)); while ((scn = elf_nextscn (elf, scn)) != NULL) { GElf_Shdr shdr_mem; diff --git a/dwflpp.h b/dwflpp.h index 9cd2cb59..7260c417 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -25,6 +25,13 @@ extern "C" { #include +#ifdef HAVE_ELFUTILS_VERSION_H + #include + #if !_ELFUTILS_PREREQ(0,142) + // Always use newer name, old name is deprecated in 0.142. + #define elf_getshdrstrndx elf_getshstrndx + #endif +#endif #include } diff --git a/tapsets.cxx b/tapsets.cxx index 7aee6930..6be7de11 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -699,7 +699,7 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s elf = dwfl_module_getelf (dw->module, &bias); Elf_Scn *probe_scn = NULL; - dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); + dwfl_assert ("getshdrstrndx", elf_getshdrstrndx (elf, &shstrndx)); have_probes = false; @@ -723,7 +723,7 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s elf = dwarf_getelf (dwfl_module_getdwarf (dw->module, &bias)); if (! elf) return; - dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); + dwfl_assert ("getshdrstrndx", elf_getshdrstrndx (elf, &shstrndx)); probe_scn = NULL; while ((probe_scn = elf_nextscn (elf, probe_scn))) { @@ -3702,7 +3702,7 @@ symbol_table::prepare_section_rejection(Dwfl_Module *mod) if (!elf) return; - if (elf_getshstrndx(elf, &shstrndx) != 0) + if (elf_getshdrstrndx (elf, &shstrndx) != 0) return; while ((scn = elf_nextscn(elf, scn)) != NULL) { -- cgit From e89118955d1e9f6f442e9c0f2e918ce9bf9a8529 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 23 Jun 2009 10:32:10 +0200 Subject: PR 10313 Build error due to deprecation of elf_getshstrndx in elfutils (old) Really old versions of elfutils didn't have version.h, but we still want to support them. So add workaround also for that case. * dwflpp.h: Define elf_getshdrstrndx as elf_getshstrndx also for really old elfutils versions. --- dwflpp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dwflpp.h b/dwflpp.h index 7260c417..ec2fc2b9 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -31,6 +31,9 @@ extern "C" { // Always use newer name, old name is deprecated in 0.142. #define elf_getshdrstrndx elf_getshstrndx #endif +#else + // Really old elfutils version, definitely redefine to use old name. + #define elf_getshdrstrndx elf_getshstrndx #endif #include } -- cgit