finalize DWARF line table conversion test

This commit is contained in:
Nikita Smith
2026-02-24 19:05:22 -08:00
parent 732c73deff
commit 2fc4a3472b
4 changed files with 53 additions and 14 deletions
+1 -1
View File
@@ -536,7 +536,7 @@ rb_thread_entry_point(void *p)
fprintf(stderr, "--breakpad Specifies that the utility should convert debug information\n"); fprintf(stderr, "--breakpad Specifies that the utility should convert debug information\n");
fprintf(stderr, " data to the textual Breakpad format.\n\n"); fprintf(stderr, " data to the textual Breakpad format.\n\n");
fprintf(stderr, "--VOff2Line Specifies that the utility should map virtual offset to source line.\n\n"); fprintf(stderr, "--voff2line Specifies that the utility should map virtual offset to source line.\n\n");
fprintf(stderr, "--out:<path> Specifies the path to which output data should be written. If\n"); fprintf(stderr, "--out:<path> Specifies the path to which output data should be written. If\n");
fprintf(stderr, " not specified, the utility will choose a fallback. If dumping\n"); fprintf(stderr, " not specified, the utility will choose a fallback. If dumping\n");
+30
View File
@@ -213,6 +213,36 @@ t_invoke(String8 exe_path, String8 cmdline, U64 timeout)
return t_invoke_(exe_path, cmdline, timeout, 0, 0); return t_invoke_(exe_path, cmdline, timeout, 0, 0);
} }
internal B32
t_match_line(String8 *output, String8 expected_line)
{
U64 new_line_pos = str8_find_needle(*output, 0, str8_lit("\n"), 0);
String8 line = str8_prefix(*output, new_line_pos);
if (str8_ends_with(line, str8_lit("\r"), 0)) {
line = str8_chop(line, 1);
}
B32 is_match = str8_match(line, expected_line, 0);
if (is_match) {
*output = str8_skip(*output, new_line_pos + 1);
}
return is_match;
}
internal B32
t_match_linef(String8 *output, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 expected_line = push_str8fv(scratch.arena, fmt, args);
B32 is_match = t_match_line(output, expected_line);
va_end(args);
scratch_end(scratch);
return is_match;
}
internal int internal int
t_test_is_before(void *raw_a, void *raw_b) t_test_is_before(void *raw_a, void *raw_b)
{ {
+1
View File
@@ -75,6 +75,7 @@ extern T_Test g_torture_tests[0xffffff];
} }
#define T_Ok(c) do { if (!(c)) { result.fail_file = __FILE__; result.fail_line = __LINE__; result.fail_cond = Stringify(c); goto exit__; } } while(0) #define T_Ok(c) do { if (!(c)) { result.fail_file = __FILE__; result.fail_line = __LINE__; result.fail_cond = Stringify(c); goto exit__; } } while(0)
#define T_MatchLinef(out, ...) T_Ok(t_match_linef(out, __VA_ARGS__))
//////////////////////////////// ////////////////////////////////
+21 -13
View File
@@ -222,24 +222,26 @@ T_BeginTest(d2r_types)
} }
T_EndTest; T_EndTest;
#if 0
T_BeginTest(d2r_line_table) T_BeginTest(d2r_line_table)
{ {
DW_Writer *writer = dw_writer_begin(DW_Format_32Bit, DW_Version_5, DW_CompUnitKind_Compile, Arch_x64); DW_Writer *writer = dw_writer_begin(DW_Format_32Bit, DW_Version_5, DW_CompUnitKind_Compile, Arch_x64);
String8 comp_dir = str8_lit("c:/devel/"); String8 comp_dir = str8_lit("c:/DEVEL/");
String8 comp_name = str8_lit("test.c"); String8 comp_name = str8_lit("test.c");
DW_WriterFile *file = dw_writer_new_file(writer, comp_name); DW_WriterFile *foo_file = dw_writer_new_file(writer, str8_lit("/mnt/C/Devel/foo.c"));
file->md5 = *(U128 *)&(U8[]){ 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }; DW_WriterFile *comp_file = dw_writer_new_file(writer, str8f(scratch.arena, "%S%S", comp_dir, comp_name));
struct { struct {
DW_WriterFile *file; U64 ln; U64 line_size; U64 voff; DW_WriterFile *file; U64 ln; U64 line_size; U64 voff;
} test_table[] = { } test_table[] = {
{ file, 6, 1 }, { comp_file, 6, 1 },
{ file, 4, 2 }, { comp_file, 4, 2 },
{ file, 2, 3 }, { comp_file, 2, 3 },
{ file, 1, 4 }, { comp_file, 1, 4 },
{ file, 8, 5 }, { comp_file, 8, 5 },
{ foo_file, 1, 3 },
{ foo_file, 100, 1 },
{ comp_file, max_U32 - 0x100, 10 },
}; };
U64 exe_base = coff_default_exe_base_from_machine(COFF_MachineType_X64); U64 exe_base = coff_default_exe_base_from_machine(COFF_MachineType_X64);
@@ -250,6 +252,13 @@ T_BeginTest(d2r_line_table)
voff += test_table[i].line_size; voff += test_table[i].line_size;
} }
// emit one past last line
dw_writer_line_emit(writer,
test_table[ArrayCount(test_table) - 1].file,
test_table[ArrayCount(test_table) - 1].ln,
0,
exe_base + voff);
dw_writer_tag_begin(writer, DW_TagKind_CompileUnit); dw_writer_tag_begin(writer, DW_TagKind_CompileUnit);
dw_writer_push_attrib_string(writer, DW_AttribKind_Producer, str8_lit("RAD DWARF WRITER")); dw_writer_push_attrib_string(writer, DW_AttribKind_Producer, str8_lit("RAD DWARF WRITER"));
dw_writer_push_attrib_string(writer, DW_AttribKind_CompDir, comp_dir); dw_writer_push_attrib_string(writer, DW_AttribKind_CompDir, comp_dir);
@@ -263,18 +272,17 @@ T_BeginTest(d2r_line_table)
for EachElement(i, test_table) { for EachElement(i, test_table) {
for EachIndex(k, test_table[i].line_size) { for EachIndex(k, test_table[i].line_size) {
String8 cmd_line = str8f(scratch.arena, "-voff2line -voff:%llx, a.rdi", test_table[i].voff + k); String8 cmd_line = str8f(scratch.arena, "-voff2line -voff:0x%llx a.rdi", test_table[i].voff + k);
String8 output = {0}; String8 output = {0};
t_invoke_(str8_lit("radbin.exe"), cmd_line, max_U64, scratch.arena, &output); t_invoke_(t_radbin_path(), cmd_line, max_U64, scratch.arena, &output);
T_Ok(g_last_exit_code == 0); T_Ok(g_last_exit_code == 0);
T_MatchLinef(&output, "%S:/%llu", test_table[i].file->path, test_table[i].ln); T_MatchLinef(&output, "%S:%llu", test_table[i].file->path, test_table[i].ln);
} }
} }
dw_writer_end(&writer); dw_writer_end(&writer);
} }
T_EndTest; T_EndTest;
#endif
T_BeginTest(d2r_general) T_BeginTest(d2r_general)
{ {