set test "at_var_cu"
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") and @var("var@cu") search
# in all the CUs that look like a match for the pattern "cu".

set ::result_string {foo: @var("counter", @1): 0
foo: @var("counter@at_var_cu_2.c", @1): 0
foo: @var("counter@at_var_cu_3.c", @1): 0
foo: @var("counter@at_var_cu*.c", @1): 0
bar: @var("counter", @1): 7
bar: @var("counter@at_var_cu_2.c", @1): 7
bar: @var("counter@at_var_cu_3.c", @1): 0
bar: @var("counter@at_var_cu*.c", @1): 7
baz: @var("counter", @1): 8
baz: @var("counter@at_var_cu_2.c", @1): 8
baz: @var("counter@at_var_cu_3.c", @1): 0
baz: @var("counter@at_var_cu*.c", @1): 8
bah: @var("counter", @1): 8
bah: @var("counter@at_var_cu_2.c", @1): 8
bah: @var("counter@at_var_cu_3.c", @1): 3
bah: @var("counter@at_var_cu*.c", @1): 8
bah': @var("counter@at_var_cu*.c"): 8
bah': @var("main_global"): 5}

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

set sources \
    "$testpath/${test}_1.c $testpath/${test}_2.c $testpath/${test}_3.c"

set res [target_compile "$sources" $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 != ""} {
        stap_run3 "$test ($runtime)" $srcdir/$subdir/$test.stp -c ./$test \
            $exefile --runtime=$runtime

    } elseif {[uprobes_p]} {
        stap_run3 $test $srcdir/$subdir/$test.stp -c ./$test $exefile

    } else {
        untested "$test"
    }
}

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