]> sourceware.org Git - systemtap.git/commitdiff
Added .thread.begin and .thread.end utrace probe tests.
authorDavid Smith <dsmith@redhat.com>
Wed, 11 Jun 2008 15:37:32 +0000 (10:37 -0500)
committerDavid Smith <dsmith@redhat.com>
Wed, 11 Jun 2008 16:19:26 +0000 (11:19 -0500)
2008-06-11  David Smith  <dsmith@redhat.com>

        * systemtap.base/utrace_p5.exp: Added 'process().thread.begin' and
        'process().thread.end' tests.
        * systemtap.base/utrace_p5_multi.c: Added multi-threaded test
        program for utrace_p5.exp.
        * .gitignore: Updated.

testsuite/.gitignore
testsuite/ChangeLog
testsuite/systemtap.base/utrace_p5.exp
testsuite/systemtap.base/utrace_p5_multi.c [new file with mode: 0644]

index 34a4e8d01d4038097bfb9fec7c94f982982d8c02..19b30bf1e757039d8c472e574eeba278054a2e46 100644 (file)
@@ -1,4 +1,4 @@
-.systemtap
+.systemtap-*
 site.exp
 systemtap.log
 systemtap.sum
index 58f9baff19228088571162e7da7122ccdb07aaed..bf2f7ccae0afbe30309913b5b9c41c534f00c3cf 100644 (file)
@@ -1,3 +1,11 @@
+2008-06-11  David Smith  <dsmith@redhat.com>
+
+       * systemtap.base/utrace_p5.exp: Added 'process().thread.begin' and
+       'process().thread.end' tests.
+       * systemtap.base/utrace_p5_multi.c: Added multi-threaded test
+       program for utrace_p5.exp.
+       * .gitignore: Updated.
+
 2008-06-10  Stan Cox  <scox@redhat.com>
 
        * systemtap.base/warnings.exp: Adjust for duplicate warning elimination.
index 46e3181ba0fa162d722a8fb64e474523468af481..1185f01501b39d04cfa232be2a50d8395ae581d3 100644 (file)
@@ -3,6 +3,9 @@
 # Initialize variables
 set utrace_support_found 0
 set exepath "[pwd]/cat_[pid]"
+set multi_srcpath "systemtap.base/utrace_p5_multi.c"
+set multi_exepath "[pwd]/utrace_p5_multi_[pid]"
+set multi_flags "libs=-lpthread"
 
 set end_script {
     global end_probes_fired = 0
@@ -46,6 +49,30 @@ set syscall_return_script {
 }
 set syscall_return_script_output "syscall_returns = \\d+\r\n"
 
+set thread_begin_script {
+    global thread_begin_probes_fired = 0
+    probe begin { printf("systemtap starting probe\n") }
+    probe process("%s").thread.begin { thread_begin_probes_fired++ }
+    probe end { printf("systemtap ending probe\n")
+       if (thread_begin_probes_fired > 0) {
+           printf("thread_begins = %%d\n", thread_begin_probes_fired)
+       }
+    }
+}
+set thread_begin_script_output "thread_begins = \\d+\r\n"
+
+set thread_end_script {
+    global thread_end_probes_fired = 0
+    probe begin { printf("systemtap starting probe\n") }
+    probe process("%s").thread.end { thread_end_probes_fired++ }
+    probe end { printf("systemtap ending probe\n")
+       if (thread_end_probes_fired > 0) {
+           printf("thread_ends = %%d\n", thread_end_probes_fired)
+       }
+    }
+}
+set thread_end_script_output "thread_ends = \\d+\r\n"
+
 # Try to find utrace_attach symbol in /proc/kallsyms
 set path "/proc/kallsyms"
 if {! [catch {exec grep -q utrace_attach $path} dummy]} {
@@ -74,6 +101,25 @@ proc run_cat_5_sec {} {
     return 0;
 }
 
+# Compile our multi-threaded test program.
+set res [target_compile $multi_srcpath $multi_exepath executable $multi_flags]
+if { $res != "" } {
+    verbose "target_compile failed: $res" 2
+    fail "unable to compile $multi_srcpath"
+    return
+}
+
+# "load" generation function for stap_run.  It spawns our
+# multi-threaded test program and waits for it to finish. 
+proc run_utrace_p5_multi {} {
+    global multi_exepath
+
+    if {[catch {exec $multi_exepath} res]} {
+       verbose "unable to run $multi_exepath: $res"
+    }
+    return 0;
+}
+
 set TEST_NAME "UTRACE_P5_01"
 if {$utrace_support_found == 0} {
     untested "$TEST_NAME : no kernel utrace support found"
@@ -114,7 +160,27 @@ if {$utrace_support_found == 0} {
     stap_run $TEST_NAME run_cat_5_sec $syscall_return_script_output -e $script
 }
 
-# We need thread.begin and thread.end tests!
+set TEST_NAME "UTRACE_P5_05"
+if {$utrace_support_found == 0} {
+    untested "$TEST_NAME : no kernel utrace support found"
+} elseif {![installtest_p]} {
+    untested "$TEST_NAME"
+} else {
+    set script [format $thread_begin_script $multi_exepath]
+    stap_run $TEST_NAME run_utrace_p5_multi $thread_begin_script_output \
+       -e $script
+}
+
+set TEST_NAME "UTRACE_P5_06"
+if {$utrace_support_found == 0} {
+    untested "$TEST_NAME : no kernel utrace support found"
+} elseif {![installtest_p]} {
+    untested "$TEST_NAME"
+} else {
+    set script [format $thread_end_script $multi_exepath]
+    stap_run $TEST_NAME run_utrace_p5_multi $thread_end_script_output \
+       -e $script
+}
 
 # Cleanup
-exec rm -f $exepath
+exec rm -f $exepath $multi_exepath
diff --git a/testsuite/systemtap.base/utrace_p5_multi.c b/testsuite/systemtap.base/utrace_p5_multi.c
new file mode 100644 (file)
index 0000000..03c6eea
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+void *thread_function( void *ptr );
+
+int
+main()
+{
+    pthread_t thread1, thread2;
+    int iret1, iret2;
+
+    /* Create independent threads each of which will execute function */
+    iret1 = pthread_create(&thread1, NULL, thread_function, (void*) 1);
+    iret2 = pthread_create(&thread2, NULL, thread_function, (void*) 2);
+
+    /* Wait till threads are complete before main continues. Unless we
+     * wait we run the risk of executing an exit which will terminate
+     * the process and all threads before the threads have
+     * completed. */
+    pthread_join(thread1, NULL);
+    pthread_join(thread2, NULL); 
+
+    printf("Thread 1 returns: %d\n", iret1);
+    printf("Thread 2 returns: %d\n", iret2);
+    exit(0);
+}
+
+void *thread_function(void *ptr)
+{
+    int tnum = (int)ptr;
+    if (tnum == 1) {
+       int fd = open("/dev/null", O_RDONLY);
+       close(fd);
+    }
+}
This page took 0.035789 seconds and 5 git commands to generate.