set test "minidebuginfo"

if {![installtest_p]} { untested $test; return }
if {![uprobes_p]} { untested $test; return }

catch { exec gcc -o binary -g $srcdir/$subdir/minidebug.c } err

if {$err == ""} then { pass "$test compile" } else { fail "$test compile $err" }

catch { exec $srcdir/$subdir/create-minidebug.sh } err
if {$err == ""} then { pass "$test create minidebug" } else { fail "$test create-minidebug.sh $err" }
spawn stap $srcdir/$subdir/minidebuginfo.stp -c "./binary.test"
set ok 0
expect {
    -timeout 30
    -re {[^\r\n]*main\r\n} { incr ok; exp_continue }
    -re {[^\r\n]*bar\r\n} { incr ok; exp_continue }
    -re {[^\r\n]*foo\r\n} { incr ok; exp_continue }
    -re {[^\r\n]*return\r\n} { incr ok; exp_continue }
    eof { }
    timeout { fail "$test (timeout)" }
}
catch { close }; wait
if {$ok == 4} then { pass "$test ($ok)" } else { fail "$test ($ok)" }
catch { exec rm binary binary.dynsyms binary.funcsyms binary.keep_symbols binary.mini_debuginfo binary.strip binary.debug binary.mini_debuginfo.xz binary.test } err

set test "symtab-strip"

catch { exec gcc -o binary1 -g $srcdir/$subdir/minidebug.c } err
if {$err == ""} then { pass "$test compile" } else { fail "$test compile $err" }
catch { exec strip -g binary1 } err
if {$err == ""} then { pass "$test strip" } else { fail "$test strip $err" }

spawn stap $srcdir/$subdir/minidebuginfo.stp -c "./binary1"
set ok1 0
expect {
    -timeout 30
    -re {[^\r\n]*main\r\n} { incr ok1; exp_continue }
    -re {[^\r\n]*bar\r\n} { incr ok1; exp_continue }
    -re {[^\r\n]*foo\r\n} { incr ok1; exp_continue }
    -re {[^\r\n]*return\r\n} { incr ok1; exp_continue }
    eof { }
    timeout { fail "$test (timeout)" }
}
catch { close }; wait
if {$ok1 == 4} then { pass "$test ($ok1)" } else { fail "$test ($ok1)" }
catch { exec rm binary1 } err
