Skip to content

Commit

Permalink
trace_calls: fix `v -m32 -trace-calls run vlib/v/tests/testdata/trace…
Browse files Browse the repository at this point in the history
…_calls/simple.vv` (#20556)
  • Loading branch information
spytheman committed Jan 17, 2024
1 parent f543440 commit a79a9cb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
55 changes: 34 additions & 21 deletions vlib/v/tests/trace_calls_test.v
@@ -1,6 +1,8 @@
import os

const vexe = @VEXE
const gcc_path = os.find_abs_path_of_executable('gcc') or { '' }
const cdefs_h_32bit_exists = os.exists('/usr/include/i386-linux-gnu/sys/cdefs.h')

fn test_tracing() {
os.chdir(@VROOT)!
Expand All @@ -12,28 +14,39 @@ fn test_tracing() {
eprintln('> skipping ${fpath}, because ${should_match_fpath} does not exist.')
continue
}
res := os.execute('${os.quoted_path(vexe)} -trace-calls run ${os.quoted_path(fpath)}')
if res.exit_code != 0 {
eprintln('> compilation output:\n${res.output}')
assert res.exit_code == 0, 'compilation of ${fpath} failed'
run_single_program(fpath, should_match_fpath, '', '64bit')
if cdefs_h_32bit_exists && gcc_path != '' {
// try running the same programs, compiled in 32bit mode too, if gcc is available:
run_single_program(fpath, should_match_fpath, '-cc gcc -m32 -gc none', '32bit')
} else {
eprintln('> skipping -m32 compilation since either 32bit headers are not installed, or you do not have gcc installed')
}
lines := os.read_lines(should_match_fpath) or {
assert false, '${fpath} should be readable'
return
}
if lines.len == 0 {
assert false, '${should_match_fpath} should contain at least one line/glob match pattern'
}
mut matched := false
for line in lines {
if res.output.match_glob(line) {
matched = true
println('> trace output of ${fpath} matches line pattern: ${line}')
continue
} else {
eprintln(res.output)
assert false, '> trace output of ${fpath} DID NOT match the line pattern: ${line}'
}
eprintln('-'.repeat(30))
}
}

fn run_single_program(fpath string, should_match_fpath string, compiler_opts string, label string) {
res := os.execute('${os.quoted_path(vexe)} ${compiler_opts} -trace-calls run ${os.quoted_path(fpath)}')
if res.exit_code != 0 {
eprintln('> ${label} compilation output:\n${res.output}')
assert res.exit_code == 0, 'compilation of ${fpath} failed'
}
lines := os.read_lines(should_match_fpath) or {
assert false, '${fpath} should be readable'
return
}
if lines.len == 0 {
assert false, '${should_match_fpath} should contain at least one line/glob match pattern'
}
mut matched := false
for line in lines {
if res.output.match_glob(line) {
matched = true
println('> ${label} trace output of ${fpath} matches line pattern: ${line}')
continue
} else {
eprintln(res.output)
assert false, '> trace output of ${fpath} DID NOT match the line pattern: ${line}'
}
}
}
6 changes: 5 additions & 1 deletion vlib/v/trace_calls/tracing_calls.c.v
Expand Up @@ -25,7 +25,11 @@ pub fn on_call(fname string) {
pfbase = &fbase
ssize = u64(g_stack_base) - u64(pfbase)
}
C.fprintf(C.stderr, c'> trace %8d %8ld %8d %s\n', tid, ns, ssize, fname.str)
$if x64 {
C.fprintf(C.stderr, c'> trace %8d %8ld %8ld %s\n', tid, ns, ssize, fname.str)
} $else {
C.fprintf(C.stderr, c'> trace %8d %8lld %8lld %s\n', tid, ns, ssize, fname.str)
}
C.fflush(C.stderr)
}

Expand Down

0 comments on commit a79a9cb

Please sign in to comment.