set self buildok

set effective_uid [exec /usr/bin/id -u]
foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] {
    set test $self/[file tail $file]
    verbose -log "Running $file"
    set rc [stap_run_batch $file]

    # Use setup_kfail <pr number> <target triplet> for known bugs.
    #
    # (Note that tcl doesn't like comments directly inside the switch
    # statement, but comments can go in sub-blocks.)
    switch $test {
	buildok/memory-write_shared_copy.stp {
	    if {$rc != 0} { setup_kfail 1155 *-*-* } }

	buildok/memory-mmap.stp -
	buildok/memory-write_shared_copy.stp -
	buildok/networking-change_rx_flag.stp -
	buildok/nfs-fop.check_flags.stp -
	buildok/scheduler-cpu_off.stp -
	buildok/scheduler-cpu_on.stp -
	buildok/scheduler-ctxswitch.stp -
	buildok/scheduler-migrate.stp -
	buildok/signal-check_ignored.stp -
	buildok/signal-handle.stp -
	buildok/tty-resize.stp {
	    # (Note that if a test fails because of debuginfo-quality
	    # problems, don't kfail a tapset's entire test. Extract
	    # the failing probe/function's test into a new file and
	    # kfail that.)
	    #
	    # Use setup_kfail GCC <target triplet> for
	    # debuginfo-quality problems.
	    if {$rc != 0} { setup_kfail GCC *-*-* } }

        buildok/per-process-syscall.stp -
        buildok/utrace.stp {
	    # Use setup_kfail UTRACE <target triplet> for systems
	    # without utrace.
	    if {$rc != 0 && ![utrace_p]} { setup_kfail UTRACE *-*-*} }

	buildok/fortyfour.stp -
	buildok/map_probe_cond.stp -
	buildok/pretty-uprobes.stp -
	buildok/ucontext-symbols-embedded.stp -
	buildok/ucontext-unwind-embedded.stp {
	    # Use setup_kfail UPROBES <target triplet> for systems
	    # without uprobes. (ia64 has utrace, but not uprobes.)
	    if {$rc != 0 && ![uprobes_p]} { setup_kfail UPROBES *-*-* } }

	buildok/twentyeightprime.stp {
	    # Use setup_kfail UPROBES <target triplet> for systems
	    # without uprobes. (ia64 has utrace, but not uprobes.)
	    if {$rc != 0 && ![uprobes_p]} { setup_kfail UPROBES *-*-* }

	    # Use setup_kfail INODE_UPROBES <target triplet> for
	    # systems with inode uprobes, where absolute probes don't
	    # work.
	    if {$rc != 0 && [inode_uprobes_p]} {
		setup_kfail INODE_UPROBES *-*-* }
	}

	buildok/context-symbols-embedded.stp -
	buildok/context-unwind-embedded.stp {
	    # Use setup_kfail UNWIND <target triplet> for systems
	    # with an unsupported dwarf unwind architecture
	    if {$rc != 0 && [istarget ia64-*-*]} {
		setup_kfail UNWIND ia64-*-* } }

	buildok/fortyseven.stp {
	    if {$rc != 0} { setup_kfail 15065 *-*-* } }

	buildok/stap_staticmarkers-detailed.stp {
	    # Use setup_kfail ROOT_ONLY for tests that must be run as
	    # root.
	    #
	    # In the case of stap_staticmarkers-detailed.stp, it
	    # probes "staprun", which is only readable by root.
	    if {$rc != 0 && $effective_uid != 0} {
		setup_kfail ROOT_ONLY *-*-* }

	    # Use setup_kfail UPROBES <target triplet> for systems
	    # without uprobes. (ia64 has utrace, but not uprobes.)
	    if {$rc != 0 && ![uprobes_p]} { setup_kfail UPROBES *-*-* }
	}

	buildok/hwbkpt.stp {
	    if {$rc != 0 && ![hwbkpt_probes_p]} { setup_kfail HWBKPT *-*-* } }
    }
    if {$rc == 0} { pass $test } else { fail $test }
}
