# Note that this test is *really* testing the bug fix for pr6503:
#   permit probes on module .init and __exit functions
#   <http://sourceware.org/bugzilla/show_bug.cgi?id=6503>
#
# Not BZ6503:
#   ypserve does not work
#   <https://bugzilla.redhat.com/show_bug.cgi?id=6503>

set test bz6503

if {! [installtest_p]} {
    untested "$test"
    return
}

# If we aren't root, make sure the test still succeeds.
set effective_pid [exec /usr/bin/id -u]
if {$effective_pid != 0} {
    set root_cmd "sudo "
} else {
    set root_cmd ""
}


# jffs2/ext2/fat/vfat should cover a span of kernels.
#
# Note that this test might fail if there is a filesystem of one of
# these types already mounted.  The filesystem mount will be
# unaffected (since the module can't be removed).
spawn stap -t $srcdir/$subdir/bz6503.stp -c "( ($root_cmd /sbin/modprobe jffs2; $root_cmd /sbin/modprobe ext2; $root_cmd /sbin/modprobe fat; $root_cmd /sbin/modprobe vfat); wait; ($root_cmd /sbin/rmmod jffs2; $root_cmd /sbin/rmmod ext2; $root_cmd /sbin/rmmod vfat; $root_cmd /sbin/rmmod fat); wait) 2>/dev/null"

set ok 0
set ko 0
expect {
    -timeout 60
    timeout { fail "$test (timeout)" }
    -re {^-----[^\r\n]*\r\n} { exp_continue }
    -re {^module[^\r\n]*hits:[^\r\n]*\r\n} { incr ok; exp_continue }
    -re {^WARNING:[\r\n]*\r\n} { incr ko; exp_continue }
    -re {^ERROR:[\r\n]*\r\n} { incr ko; exp_continue }
    eof { }
}
catch { close} ; catch { wait }

# Mark kernels < 2.6.29 as xfail
set kv [exec uname -r | grep -o -G  {^[0-9]\+.[0-9]\+.[0-9]\+}]
set kvbits [split $kv .]
set k1 [lindex $kvbits 0]
set k2 [lindex $kvbits 1]
set k3 [lindex $kvbits 2]
verbose -log "xfailing if $k1.$k2.$k3 < 2.6.29"
if {($k1*256*256 + $k2*256 + $k3) < (2*256*256 + 6*256 + 29)} then { setup_xfail *-*-* }

if {$ok > 0 && $ko == 0} then { pass "$test $ok" } else { fail "$test $ok $ko"}


