1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
set test "memory1"
set ::result_string {Test passed\r\n}
if {![installtest_p]} {
untested $test
return
}
set build_dir ""
set uname [exec /bin/uname -r]
proc build_and_install_module {} {
global build_dir
global srcdir subdir
# Create the build directory and populate it
if {[catch {exec mktemp -d staptestXXXXXX} build_dir]} {
verbose -log "Failed to create temporary directory: $build_dir"
return 0
}
exec cp $srcdir/$subdir/memory1_module.c $build_dir/
exec cp -p $srcdir/$subdir/memory1_module.Makefile $build_dir/Makefile
# Build the module
if {[catch {exec make -C $build_dir clean} res]} {
verbose -log "$res"
return 0
}
catch {exec make -C $build_dir} res
verbose -log "$res"
if {![file exists $build_dir/memory1_module.ko]} {
return 0
}
set res [as_root [list cp $build_dir/memory1_module.ko /lib/modules/$::uname/kernel/]]
if { $res != 0 } {
verbose -log "$res"
return 0
}
# Install the module
set res [as_root [list /sbin/insmod $build_dir/memory1_module.ko]]
if {$res != 0} {
verbose -log "$res"
return 0
}
return 1
}
proc cleanup_module {} {
global build_dir
as_root [list /bin/rm -f /lib/modules/$::uname/kernel/memory1_module.ko]
as_root [list /sbin/rmmod memory1_module]
if {$build_dir != ""} {
catch { exec rm -rf $build_dir }
}
}
proc memory1_load {} {
# Trigger the test module
if {[file exists /proc/stap_memory1_test]} {
exec echo Memory1Test > /proc/stap_memory1_test
return 0
} else {
return 1
}
}
if {[build_and_install_module] == 0} {
verbose -log "BUILD FAILED"
fail "$test (could not build/install module)"
return
} else {
pass "$test (built and installed module)"
}
# Note that we don't test other runtimes here since the script uses a
# kernel module
stap_run $test memory1_load $result_string $srcdir/$subdir/$test.stp
stap_run $test memory1_load $result_string -DSTP_LEGACY_PRINT $srcdir/$subdir/$test.stp
cleanup_module
|