summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.context/context.exp
blob: 46b24a2cda5397254e7fa6cf7e5a27a2a7257de6 (plain)
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
83
84
85
86
87
88
89
90
91
set testlist {backtrace args pid num_args}

if {![installtest_p]} { 
    foreach test $testlist {
	untested $test
    }
    return
}

set build_dir ""

proc cleanup {} {
    global build_dir
    catch { exec kill -INT -[exp_pid] }
    foreach n {1 2} {
	as_root  [list /bin/rm -f /lib/modules/$::uname/kernel/systemtap_test_module$n.ko]
	as_root [list /sbin/rmmod systemtap_test_module$n]
    }
    if {$build_dir != ""} {
	catch { exec rm -rf $build_dir }
    }
}

proc build_modules {} {
    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
    }
    foreach f [glob $srcdir/$subdir/systemtap_test_module*.c] {
	exec cp $f $build_dir/
    }

    # Build the modules
    foreach n {2 1} {
	exec cp -p $srcdir/$subdir/makefile$n $build_dir/Makefile
	if {[catch {exec make -C $build_dir clean} res]} {
	    verbose -log "$res"
	    return 0
	}
	catch {exec make -C $build_dir} res
	if {![file exists $build_dir/systemtap_test_module$n.ko]} {
	    verbose -log "$res"
	    return 0
	}
	set res [as_root  [list cp $build_dir/systemtap_test_module$n.ko /lib/modules/$::uname/kernel]]
	if { $res != 0 } {
	    verbose -log "$res"
	    return 0
	}
    }

    # Install the modules
    foreach n {2 1} {
	set res [as_root [list /sbin/insmod $build_dir/systemtap_test_module$n.ko]]
	if {$res != 0} {
	    verbose -log "$res"
	    return 0
	}
    }
    return 1
}

# first build the modules

# NB: We cannot "cd" on behalf the whole dejagnu process, especially
# without going back to the build tree, and especially not to the
# source tree expecting to be able to write there.
#
# cd $srcdir/$subdir

set uname [exec /bin/uname -r]

if {[build_modules] == 0} {
    verbose -log "BUILD FAILED"
    foreach test $testlist {
	fail "$test - could not build modules"
    }
    return
}

foreach test $testlist {
    send_log "sourcing: $srcdir/$subdir/$test.tcl\n"
    source $srcdir/$subdir/$test.tcl
}

cleanup