set test "rep_ret"

# This test is only for i386 and x86_64
# Test 32-on-64 when available
switch -regexp $::tcl_platform(machine) {
    {^i\d86$} { set arches [list "-default"] }
    {^x86_64$} { set arches [list "-m64" "-m32"]}
    default { unsupported "$test"; return }
}

foreach arch $arches {

  set exe ${test}${arch}
  verbose "testing $exe"

  set test_flags "additional_flags=-g"
  set test_flags "$test_flags additional_flags=-fomit-frame-pointer"

  if {$arch != "-default"} {
    set test_flags "$test_flags additional_flags=$arch"
  }

  set res [target_compile $srcdir/$subdir/$test.c $exe executable "$test_flags"]
  if { $res != "" } {
    verbose "target_compile $exe failed: $res" 2
    fail "${test}.c compile ${arch}"
    untested "$exe"
    return
  } else {
    pass "${test}.c compile ${arch}"
  }

  if {[installtest_p] && [uprobes_p]} {
    set ok 0
    set bad 0
    set warn 0

    spawn stap -e {probe process(@1).function("*") { println(probefunc()) }} ./$exe -c ./$exe
    expect {
      -re {^main\r\n} { incr ok; exp_continue }
      -re {^rep_ret\r\n} { incr ok; exp_continue }
      -re {^repnz_ret\r\n} { incr ok; exp_continue }
      -re {^WARNING: Number of errors: 0, skipped probes: [^\r\n]*\r\n} { incr warn; exp_continue }
      timeout { fail "$exe (timeout)" }
      eof { }
    }
    wait

    if {$ok == 3 && $bad == 0 && $warn == 0} {
      pass "$exe"
    } else {
      fail "$exe ($ok, $bad, $warn)"
    }
  } else {
    untested "$exe"
  }
  catch {exec rm -f $exe}

}
