eliminate os_core, move into base; eliminate regs, move into arch abstraction layer, define x64 regs in x64 layer; move win32 backend for os core (now base) functionality to top-level win32 layer

This commit is contained in:
Ryan Fleury committed 2026-05-08 15:21:21 -07:00
1 parent 24c858171f
commit aea4a4ff9d
148 files changed
+7942 -5268

No files matched your search

+133 -133
View File
@@ -28,9 +28,9 @@ internal char *
t_string_from_result(T_RunStatus v)
{
switch (v) {
case T_RunStatus_Fail: return "FAIL";
case T_RunStatus_Crash: return "CRASH";
case T_RunStatus_Pass: return "PASS";
case T_RunStatus_Fail: return "FAIL";
case T_RunStatus_Crash: return "CRASH";
case T_RunStatus_Pass: return "PASS";
}
return 0;
}
@@ -40,7 +40,7 @@ t_write_file_list(String8 name, String8List data)
{
Temp scratch = scratch_begin(0,0);
String8 path = t_make_file_path(scratch.arena, name);
B32 is_written = os_write_data_list_to_file_path(path, data);
B32 is_written = write_data_list_to_file_path(path, data);
scratch_end(scratch);
return is_written;
}
@@ -50,10 +50,10 @@ t_write_file(String8 name, String8 data)
{
String8Node temp_node = {0};
temp_node.string = data;
String8List temp_list = {0};
str8_list_push_node(&temp_list, &temp_node);
return t_write_file_list(name, temp_list);
}
@@ -62,7 +62,7 @@ t_read_file(Arena *arena, String8 name)
{
Temp scratch = scratch_begin(&arena,1);
String8 path = t_make_file_path(scratch.arena, name);
String8 data = os_data_from_file_path(arena, path);
String8 data = data_from_file_path(arena, path);
scratch_end(scratch);
return data;
}
@@ -72,7 +72,7 @@ t_delete_file(String8 name)
{
Temp scratch = scratch_begin(0,0);
String8 path = t_make_file_path(scratch.arena, name);
B32 is_deleted = os_delete_file_at_path(path);
B32 is_deleted = delete_file_at_path(path);
scratch_end(scratch);
return is_deleted;
}
@@ -81,26 +81,26 @@ internal void
t_delete_dir(String8 path)
{
Temp scratch = scratch_begin(0,0);
OS_FileIter *file_iter = os_file_iter_begin(scratch.arena, path, 0);
FileIter *file_iter = file_iter_begin(scratch.arena, path, 0);
for (;;) {
OS_FileInfo info = {0};
if ( ! os_file_iter_next(scratch.arena, file_iter, &info)) { break; }
FileInfo info = {0};
if ( ! file_iter_next(scratch.arena, file_iter, &info)) { break; }
if (info.props.flags & FilePropertyFlag_IsFolder) {
t_delete_dir(str8f(scratch.arena, "%S/%S", path, info.name));
continue;
}
String8 file_path = str8f(scratch.arena, "%S/%S", path, info.name);
if ( ! os_delete_file_at_path(file_path)) {
if ( ! delete_file_at_path(file_path)) {
fprintf(stderr, "ERROR: unable to delete file %.*s\n", str8_varg(file_path));
}
}
os_file_iter_end(file_iter);
file_iter_end(file_iter);
// TODO: delete directories
scratch_end(scratch);
}
@@ -114,7 +114,7 @@ internal B32
t_make_dir(String8 name)
{
Temp scratch = scratch_begin(0,0);
B32 is_ok = os_make_directory(t_make_file_path(scratch.arena, name));
B32 is_ok = make_directory(t_make_file_path(scratch.arena, name));
scratch_end(scratch);
return is_ok;
}
@@ -148,7 +148,7 @@ internal T_RunResult
t_run(T_Run run)
{
T_RunCtx ctx = { .run = run };
B32 do_safe_call = 1;
#if OS_WINDOWS
if (IsDebuggerPresent()) {
@@ -156,7 +156,7 @@ t_run(T_Run run)
}
#endif
if (do_safe_call) {
os_safe_call(t_run_caller, t_run_fail_handler, &ctx);
safe_call(t_run_caller, t_run_fail_handler, &ctx);
} else {
t_run_caller(&ctx);
}
@@ -172,9 +172,9 @@ t_radbin_path(void)
ArenaParams params = { .reserve_size = sizeof(buffer), .commit_size = sizeof(buffer), .optional_backing_buffer = buffer };
Arena *arena = arena_alloc_(&params);
#if OS_WINDOWS
path = os_full_path_from_path(arena, str8_lit("radbin.exe"));
path = full_path_from_path(arena, str8_lit("radbin.exe"));
#else
path = os_full_path_from_path(arena, str8_lit("radbin"));
path = full_path_from_path(arena, str8_lit("radbin"));
#endif
AssertAlways(path.size);
}
@@ -205,33 +205,33 @@ internal String8
t_cl_version(void)
{
local_persist String8 version;
if ( ! version.size) {
Temp scratch = scratch_begin(0, 0);
String8 output = {0};
t_invoke_(t_cl_path(), str8_zero(), max_U64, scratch.arena, &output);
AssertAlways(g_last_exit_code == 0);
String8 needle = str8_lit("Version");
U64 version_lo = str8_find_needle(output, 0, needle, 0);
version_lo += needle.size + 1;
AssertAlways(version_lo < output.size);
U64 version_hi = str8_find_needle(output, version_lo, str8_lit(" "), 0);
AssertAlways(version_hi < output.size);
version = str8_substr(output, r1u64(version_lo, version_hi));
AssertAlways(version.size > 0);
local_persist U8 buffer[4096];
ArenaParams params = { .reserve_size = sizeof(buffer), .commit_size = sizeof(buffer), .optional_backing_buffer = buffer };
Arena *arena = arena_alloc_(&params);
version = str8_copy(arena, version);
scratch_end(scratch);
}
return version;
}
@@ -244,9 +244,9 @@ t_radlink_path(void)
ArenaParams params = { .reserve_size = sizeof(buffer), .commit_size = sizeof(buffer), .optional_backing_buffer = buffer };
Arena *arena = arena_alloc_(&params);
#if OS_WINDOWS
path = os_full_path_from_path(arena, str8_lit("radlink.exe"));
path = full_path_from_path(arena, str8_lit("radlink.exe"));
#else
path = os_full_path_from_path(arena, str8_lit("radlink"));
path = full_path_from_path(arena, str8_lit("radlink"));
#endif
AssertAlways(path.size);
}
@@ -259,7 +259,7 @@ t_cwd_path(void)
local_persist U8 path[4096] = {0};
if (path[0] == 0) {
Temp scratch = scratch_begin(0, 0);
String8 cwd = os_get_current_path(scratch.arena);
String8 cwd = get_current_path(scratch.arena);
cwd = str8_chop_last_slash(cwd);
cwd = str8f(scratch.arena, "%S", cwd);
MemoryCopyStr8(path, cwd);
@@ -287,26 +287,26 @@ internal B32
t_invoke_env(String8 exe_path, String8 cmdline, String8List env, U64 timeout, Arena *output_arena, String8 *output_out)
{
Temp scratch = scratch_begin(&output_arena,1);
B32 is_ok = 0;
B32 capture_output = output_out || g_redirect_stdout;
g_last_exit_code = -1;
OS_Handle read_pipe_handle = {0}, write_pipe_handle = {0};
File read_pipe_handle = {0}, write_pipe_handle = {0};
if (capture_output) {
HANDLE read_pipe, write_pipe;
SECURITY_ATTRIBUTES at = { .nLength = sizeof(at), .bInheritHandle = 1 };
if (!CreatePipe(&read_pipe, &write_pipe, &at, 0)) {
AssertAlways(0 && "failed to create a pipe");
}
read_pipe_handle = (OS_Handle){ .u64[0] = (U64)read_pipe };
write_pipe_handle = (OS_Handle){ .u64[0] = (U64)write_pipe };
read_pipe_handle = (File){ .u64[0] = (U64)read_pipe };
write_pipe_handle = (File){ .u64[0] = (U64)write_pipe };
}
// Build Launch Options
OS_ProcessLaunchParams launch_opts = {
ProcessLaunchParams launch_opts = {
.path = g_wdir,
.inherit_env = 1,
.env = env,
@@ -315,49 +315,49 @@ t_invoke_env(String8 exe_path, String8 cmdline, String8List env, U64 timeout, Ar
.cmd_line = lnk_arg_list_parse_windows_rules(scratch.arena, cmdline),
};
str8_list_push_front(scratch.arena, &launch_opts.cmd_line, exe_path);
if (g_verbose) {
String8 full_cmd_line = str8_list_join(scratch.arena, &launch_opts.cmd_line, &(StringJoin){ .sep = str8_lit(" ") });
fprintf(stdout, "Command Line: %.*s\n", str8_varg(full_cmd_line));
fprintf(stdout, "Working Dir: %.*s\n", str8_varg(g_wdir));
}
// invoke exe
OS_Handle process_handle = os_process_launch(&launch_opts);
Process process_handle = process_launch(&launch_opts);
// close handle so last to ReadFile does not block
os_file_close(write_pipe_handle);
if ( ! os_handle_match(process_handle, os_handle_zero())) {
file_close(write_pipe_handle);
if ( ! process_match(process_handle, process_zero())) {
if (capture_output) {
// capture process output
String8List output = {0};
for (;;) {
String8 string = os_file_read_cstring(scratch.arena, read_pipe_handle, 0);
String8 string = file_read_cstring(scratch.arena, read_pipe_handle, 0);
if (string.size == 0) { break; }
str8_list_push(scratch.arena, &output, string);
}
os_file_close(read_pipe_handle);
file_close(read_pipe_handle);
if (output_out) {
*output_out = str8_list_join(output_arena, &output, 0);
}
// write to the output file
if (g_redirect_stdout) {
os_write_data_list_to_file_path(g_stdout_file_name, output);
write_data_list_to_file_path(g_stdout_file_name, output);
}
}
U64 exit_code_u64 = 0;
if (os_process_join(process_handle, timeout, &exit_code_u64)) {
if (process_join(process_handle, timeout, &exit_code_u64)) {
g_last_exit_code = (int)exit_code_u64;
is_ok = 1;
} else {
os_process_kill(process_handle);
process_kill(process_handle);
}
}
scratch_end(scratch);
return is_ok;
}
@@ -428,24 +428,24 @@ t_file_paths_from_dir(Arena *arena, String8 dir)
Temp scratch = scratch_begin(&arena, 1);
String8List dirs = {0};
String8List files = {0};
OS_FileIter *iter = os_file_iter_begin(scratch.arena, dir, 0);
OS_FileInfo file;
while (os_file_iter_next(scratch.arena, iter, &file)) {
FileIter *iter = file_iter_begin(scratch.arena, dir, 0);
FileInfo file;
while (file_iter_next(scratch.arena, iter, &file)) {
if (file.props.flags & FilePropertyFlag_IsFolder) {
str8_list_pushf(scratch.arena, &dirs, "%S/%S", dir, file.name);
} else {
str8_list_pushf(arena, &files, "%S/%S", dir, file.name);
}
}
os_file_iter_end(iter);
file_iter_end(iter);
String8List result = {0};
for EachNode(n, String8Node, dirs.first) {
String8List sub_result = t_file_paths_from_dir(arena, n->string);
str8_list_concat_in_place(&result, &sub_result);
}
scratch_end(scratch);
//str8_list_concat_in_place(&result, &dirs);
str8_list_concat_in_place(&result, &files);
@@ -463,12 +463,12 @@ t_match_folders(String8 a, String8 b)
//for EachNode(n, String8Node, files_a.first) printf("%.*s\n", str8_varg(n->string));
String8List files_b = t_file_paths_from_dir(scratch.arena, b);
B32 is_match = 0;
String8Array sorted_a = str8_array_from_list(scratch.arena, &files_a);
String8Array sorted_b = str8_array_from_list(scratch.arena, &files_b);
t_sort_str8_array(sorted_a);
t_sort_str8_array(sorted_b);
if (sorted_a.count == sorted_b.count) {
for EachIndex(i, sorted_a.count) {
Temp temp = temp_begin(scratch.arena);
@@ -477,15 +477,15 @@ t_match_folders(String8 a, String8 b)
if (str8_match(ext_a, ext_b, 0)) {
if (str8_match(ext_a, str8_lit("obj"), StringMatchFlag_CaseInsensitive) ||
str8_match(ext_a, str8_lit("lib"), StringMatchFlag_CaseInsensitive)) {
String8 data_a = os_data_from_file_path(temp.arena, sorted_a.v[i]);
String8 data_b = os_data_from_file_path(temp.arena, sorted_b.v[i]);
String8 data_a = data_from_file_path(temp.arena, sorted_a.v[i]);
String8 data_b = data_from_file_path(temp.arena, sorted_b.v[i]);
is_match = str8_match(data_a, data_b, 0);
if ( ! is_match) {
OS_Handle h;
h = os_cmd_line_launchf("dumpbin /all %S /out:a.txt", sorted_a.v[i]);
os_process_join(h, max_U64, 0);
h = os_cmd_line_launchf("dumpbin /all %S /out:b.txt", sorted_b.v[i]);
os_process_join(h, max_U64, 0);
Process h;
h = launch_cmd_linef("dumpbin /all %S /out:a.txt", sorted_a.v[i]);
process_join(h, max_U64, 0);
h = launch_cmd_linef("dumpbin /all %S /out:b.txt", sorted_b.v[i]);
process_join(h, max_U64, 0);
}
Assert(is_match);
if (!is_match) { break; }
@@ -495,7 +495,7 @@ t_match_folders(String8 a, String8 b)
temp_end(temp);
}
}
scratch_end(scratch);
return is_match;
}
@@ -504,25 +504,25 @@ internal void
t_entry_point(CmdLine *cmdline)
{
Temp scratch = scratch_begin(0,0);
U64 dashes_size = 9999;
U8 *dashes = push_array(scratch.arena, U8, dashes_size);
MemorySet(dashes, '-', dashes_size);
U64 dots_size = 9999;
U8 *dots = push_array(scratch.arena, U8, dots_size);
MemorySet(dots, '.', dots_size);
char *spaces = " ";
#define PrintHeader(p) fprintf(stderr, "--- %s %.*s\n", p, Max((80-4) - (int)strlen(p), 3), dashes)
//
// Handle -help
//
{
B32 print_help = cmd_line_has_flag(cmdline, str8_lit("help")) ||
cmd_line_has_flag(cmdline, str8_lit("h"));
cmd_line_has_flag(cmdline, str8_lit("h"));
if (print_help) {
PrintHeader("Help");
fprintf(stderr, " %s\n\n", BUILD_TITLE_STRING_LITERAL);
@@ -536,10 +536,10 @@ t_entry_point(CmdLine *cmdline)
fprintf(stderr, " -verbose Enable verbose mode\n");
fprintf(stderr, " -print_stdout Print to console stdout and stderr of a run\n");
fprintf(stderr, " -help Print help menu and exit\n");
os_abort(0);
abort_self(0);
}
}
#if 0
//
// config
@@ -564,7 +564,7 @@ t_entry_point(CmdLine *cmdline)
fprintf(stderr, "\n");
}
#endif
//
// Handle -list
//
@@ -574,10 +574,10 @@ t_entry_point(CmdLine *cmdline)
for EachIndex(i, g_torture_test_count) {
fprintf(stdout, " %s\n", g_torture_tests[i].label);
}
os_abort(0);
abort_self(0);
}
}
//
// Handle -linker
//
@@ -591,14 +591,14 @@ t_entry_point(CmdLine *cmdline)
g_linker = linker_opt->value_string;
} else {
fprintf(stderr, "ERROR: -linker has invalid number of arguments\n");
os_abort(1);
abort_self(1);
}
} else {
// assume default linker
g_linker = str8_lit("radlink");
}
}
//
// Handle -test_data
//
@@ -609,7 +609,7 @@ t_entry_point(CmdLine *cmdline)
//fprintf(stderr, "WARNING: The test data folder path was not specified. Specify the path when running the program, assuming: %.*s --test_data:%.*s\n", str8_varg(cmdline->exe_name), str8_varg(g_test_data));
}
}
//
// Handle optional -target
//
@@ -637,31 +637,31 @@ t_entry_point(CmdLine *cmdline)
}
}
}
if (ht->count == 0) {
fprintf(stderr, "ERROR: -target matches not found for the following patterns: ");
for EachNode(n, String8Node, target_opt->value_strings.first) {
fprintf(stderr, "\"%.*s\"\n", str8_varg(n->string));
}
os_abort(1);
abort_self(1);
}
} else {
fprintf(stderr, "ERROR: -target has invalid number of arguments\n");
}
}
}
g_verbose = cmd_line_has_flag(cmdline, str8_lit("verbose"));
g_redirect_stdout = !cmd_line_has_flag(cmdline, str8_lit("print_stdout"));
g_stop_on_first_fail_or_crash = !cmd_line_has_flag(cmdline, str8_lit("keep_going"));
// default options when running under debugger
#if OS_WINDOWS
if (!cmd_line_has_flag(cmdline, str8_lit("print_stdout")) && IsDebuggerPresent()) {
g_redirect_stdout = 0;
}
#endif
// Handle -out
{
CmdLineOpt *out_opt = cmd_line_opt_from_string(cmdline, str8_lit("out"));
@@ -673,27 +673,27 @@ t_entry_point(CmdLine *cmdline)
}
}
}
//
// Make Output Directory
//
os_make_directory(g_out);
if (!os_folder_path_exists(g_out)) {
make_directory(g_out);
if (!folder_path_exists(g_out)) {
fprintf(stderr, "ERROR: unable to create output directory \"%.*s\"\n", str8_varg(g_out));
os_abort(1);
abort_self(1);
}
//
// Clean up output from previous run
//
os_delete_file_at_path(g_stdout_file_name);
delete_file_at_path(g_stdout_file_name);
//
// Run tests
//
{
radsort(g_torture_tests, g_torture_test_count, t_test_is_before);
U64List target_indices_list = {0};
if (target.node_count == 0) {
for EachIndex(i, g_torture_test_count) { u64_list_push(scratch.arena, &target_indices_list, i); }
@@ -712,7 +712,7 @@ t_entry_point(CmdLine *cmdline)
}
}
}
//
// -skip
//
@@ -730,15 +730,15 @@ t_entry_point(CmdLine *cmdline)
break;
}
}
if (include_test) {
u64_list_push(scratch.arena, &final_target_list, n->data);
}
}
U64 skip_count = target_indices_list.count - final_target_list.count;
U64Array target_indices = u64_array_from_list(scratch.arena, &final_target_list);
U64 max_label_size = 0;
U64 max_group_size = 0;
for EachIndex(i, target_indices.count) {
@@ -746,19 +746,19 @@ t_entry_point(CmdLine *cmdline)
max_label_size = Max(max_label_size, cstring8_length((U8*)g_torture_tests[test_idx].label));
max_group_size = Max(max_group_size, cstring8_length((U8*)g_torture_tests[test_idx].group));
}
PrintHeader("Tests");
U64 pass_count = 0;
U64 fail_count = 0;
U64 crash_count = 0;
U64 max_digit_count = count_digits_u64(target_indices.count, 10);
U64 total_time_start = os_now_microseconds();
U64 total_time_start = now_time_us();
typedef struct { U64 target_idx, d; } Slowest;
Slowest slowest[5] = {0};
for EachElement(i, slowest) { slowest[i].target_idx = max_U64; }
for EachIndex(i, target_indices.count) {
U64 target_idx = target_indices.v[i];
// print run progress
U64 dots_min = 10;
U64 dots_count = (max_label_size - cstring8_length((U8*)g_torture_tests[target_idx].label)) + dots_min;
@@ -767,27 +767,27 @@ t_entry_point(CmdLine *cmdline)
fprintf(stdout, "[%.*s%I64u/%I64u] ", idx_align_space_count, spaces, i+1, target_indices.count);
fprintf(stdout, "%s %.*s:: %s", g_torture_tests[target_idx].group, (int)(max_group_size - cstring8_length((U8*)g_torture_tests[target_idx].group)), spaces, g_torture_tests[target_idx].label);
fprintf(stdout, " %.*s ", (int)dots_count, dots);
// setup output directory
g_wdir = push_str8f(scratch.arena, "%S\\%s", g_out, g_torture_tests[target_idx].label);
g_wdir = os_full_path_from_path(scratch.arena, g_wdir);
g_wdir = full_path_from_path(scratch.arena, g_wdir);
// delete files from last run in the work directory
if (os_folder_path_exists(g_wdir)) {
if (folder_path_exists(g_wdir)) {
t_delete_dir(g_wdir);
}
os_make_directory(g_wdir);
if (!os_folder_path_exists(g_out)) {
make_directory(g_wdir);
if (!folder_path_exists(g_out)) {
fprintf(stderr, "ERROR: unable to create output directory for test run %.*s\n", str8_varg(g_wdir));
continue;
}
// run test
U64 run_start_time = os_now_microseconds();
U64 run_start_time = now_time_us();
T_RunResult result = t_run(g_torture_tests[target_idx].r);
U64 run_end_time = os_now_microseconds();
U64 run_end_time = now_time_us();
// print result
if (result.status == T_RunStatus_Pass) {
fprintf(stdout, "\x1b[32m" "%s" "\x1b[0m", t_string_from_result(result.status));
@@ -799,13 +799,13 @@ t_entry_point(CmdLine *cmdline)
fprintf(stdout, "\x1b[33m" "%s" "\x1b[0m", t_string_from_result(result.status));
crash_count += 1;
}
if (result.status == T_RunStatus_Pass) {
U64 d = run_end_time - run_start_time;
DateTime t = date_time_from_micro_seconds(d);
String8 s = string_from_elapsed_time(scratch.arena, t);
fprintf(stdout, " %.*s", str8_varg(s));
U64 insert_idx = max_U64;
for EachElement(i, slowest) {
if (d > slowest[i].d) {
@@ -822,18 +822,18 @@ t_entry_point(CmdLine *cmdline)
}
}
fprintf(stdout, "\n");
if (result.status == T_RunStatus_Fail) {
fprintf(stdout, " ERROR: %s:%d: condition: \"%s\"\n", result.fail_file, result.fail_line, result.fail_cond);
}
if (result.status == T_RunStatus_Fail || result.status == T_RunStatus_Crash) {
if (g_stop_on_first_fail_or_crash) { goto exit; }
}
}
fprintf(stderr, "\n");
U64 total_time_end = os_now_microseconds();
U64 total_time_end = now_time_us();
PrintHeader("Summary");
U64 total_time_dt = total_time_end - total_time_start;
String8 total_time_str = string_from_elapsed_time(scratch.arena, date_time_from_micro_seconds(total_time_dt));
@@ -843,7 +843,7 @@ t_entry_point(CmdLine *cmdline)
fprintf(stderr, " Skipped %llu\n", skip_count);
fprintf(stderr, " Time %.*s\n", str8_varg(total_time_str));
fprintf(stderr, "\n");
{
fprintf(stderr, " Slow Tests\n");
U64 label_max = 0;
@@ -854,7 +854,7 @@ t_entry_point(CmdLine *cmdline)
label_max = Max(strlen(g_torture_tests[s.target_idx].label), label_max);
group_max = Max(strlen(g_torture_tests[s.target_idx].group), group_max);
}
for EachElement(i, slowest) {
Slowest s = slowest[i];
if (s.target_idx >= g_torture_test_count) { break; }
@@ -866,17 +866,17 @@ t_entry_point(CmdLine *cmdline)
(int)(label_max - strlen(g_torture_tests[s.target_idx].label)) + 4, dots,
str8_varg(elapsed_time));
}
fprintf(stderr, "\n");
}
exit:;
if (fail_count + crash_count != 0) {
fflush(stdout);
os_abort(fail_count + crash_count);
abort_self(fail_count + crash_count);
}
}
scratch_end(scratch);
}