set test "at_var_timer_profile"
set testpath "$srcdir/$subdir"
set exefile "[pwd]/$test"
set stap_path $env(SYSTEMTAP_PATH)/stap
set staprun_path $env(SYSTEMTAP_PATH)/staprun

# Test that @var("var@cu", "module") work in the context of
# timer.profile.
# Also ensure that the module argument can be multiple module names
# separated by colon, e.g., "module1:module2:module3".
# Also test that unresolved @var() can be properly caught by @defined().

set ::result_string {@var("foo", @1)->bar: 42
@var("foo@at_var_timer_profile.c", @1)->bar: 42
@var("foo@at_var_timer_profile.c", @2)->bar: 42
@var("foo", @1)$: {.bar=42}
@var("foo", @1)$$: {.bar=42}
@defined(@var("foo", "badmodle")): NO
@defined(@var("foo", @3)): NO}

# Only run on make installcheck and uprobes present.
if {! [installtest_p]} { untested "$test"; return }

set res [target_compile ${testpath}/$test.c $exefile executable "additional_flags=-O2 additional_flags=-g"]
if { $res != "" } {
    verbose "target_compile failed: $res" 2
    fail "unable to compile ${test}.c"
}

foreach runtime [get_runtime_list] {
    if {$runtime != ""} {
        if {$runtime == "dyninst"} {
            # dyninst lacks support for probe timer.profile
            setup_kfail 15540 "*-*-*"
        }

        stap_run3 "$test ($runtime)" $srcdir/$subdir/$test.stp -c ./$test $exefile \
            "$stap_path:$exefile:$staprun_path" "$stap_path:$staprun_path" \
            --runtime=$runtime

    } elseif {[uprobes_p]} {
        stap_run3 $test $srcdir/$subdir/$test.stp -c ./$test $exefile \
            "$stap_path:$exefile:$staprun_path" "$stap_path:$staprun_path"

    } else {
        untested "$test"
    }
}

# Cleanup
if { $verbose == 0 } { catch { exec rm -f $test } }
