From 75d5b44130689e6a2df232a1b40a560df0bb0404 Mon Sep 17 00:00:00 2001 From: danielsan901998 Date: Fri, 3 Nov 2023 19:50:34 +0100 Subject: [PATCH] test: change self_exe_dir for test_dir --- test/record_runner.zig | 15 +++++++-------- test/runner.zig | 17 ++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/record_runner.zig b/test/record_runner.zig index 19386e4b..633babbe 100644 --- a/test/record_runner.zig +++ b/test/record_runner.zig @@ -96,9 +96,6 @@ pub fn main() !void { const gpa = general_purpose_allocator.allocator(); defer if (general_purpose_allocator.deinit() == .leak) std.process.exit(1); - const self_exe_dir = try std.fs.selfExePathAlloc(gpa); - defer gpa.free(self_exe_dir); - var args = try std.process.argsAlloc(gpa); defer std.process.argsFree(gpa, args); @@ -107,6 +104,8 @@ pub fn main() !void { return error.InvalidArguments; } + const test_dir = args[1]; + var cases = std.ArrayList([]const u8).init(gpa); defer { for (cases.items) |path| gpa.free(path); @@ -169,7 +168,7 @@ pub fn main() !void { for (0..thread_count) |i| { wait_group.start(); try thread_pool.spawn(runTestCases, .{ - gpa, self_exe_dir, &wait_group, test_cases.items[i..], thread_count, &stats, + gpa, test_dir, &wait_group, test_cases.items[i..], thread_count, &stats, }); } @@ -187,7 +186,7 @@ pub fn main() !void { } } -fn runTestCases(allocator: std.mem.Allocator, self_exe_dir: []const u8, wg: *std.Thread.WaitGroup, test_cases: []const TestCase, stride: usize, stats: *Stats) void { +fn runTestCases(allocator: std.mem.Allocator, test_dir: []const u8, wg: *std.Thread.WaitGroup, test_cases: []const TestCase, stride: usize, stats: *Stats) void { defer wg.finish(); var mem = allocator.alloc(u8, MAX_MEM_PER_TEST) catch |err| { std.log.err("{s}", .{@errorName(err)}); @@ -204,7 +203,7 @@ fn runTestCases(allocator: std.mem.Allocator, self_exe_dir: []const u8, wg: *std if (i % stride != 0) continue; defer fib.end_index = 0; - singleRun(fib.allocator(), self_exe_dir, case, stats) catch |err| { + singleRun(fib.allocator(), test_dir, case, stats) catch |err| { std.log.err("{s}", .{@errorName(err)}); if (@errorReturnTrace()) |trace| { std.debug.dumpStackTrace(trace.*); @@ -215,14 +214,14 @@ fn runTestCases(allocator: std.mem.Allocator, self_exe_dir: []const u8, wg: *std } } -fn singleRun(alloc: std.mem.Allocator, self_exe_dir: []const u8, test_case: TestCase, stats: *Stats) !void { +fn singleRun(alloc: std.mem.Allocator, test_dir: []const u8, test_case: TestCase, stats: *Stats) !void { const path = test_case.path; var comp = aro.Compilation.init(alloc); defer comp.deinit(); try comp.addDefaultPragmaHandlers(); - try comp.defineSystemIncludes(self_exe_dir); + try comp.defineSystemIncludes(test_dir); const target = setTarget(&comp, test_case.target) catch |err| switch (err) { error.UnknownCpuModel => unreachable, diff --git a/test/runner.zig b/test/runner.zig index 2ee5d415..e50f3390 100644 --- a/test/runner.zig +++ b/test/runner.zig @@ -50,12 +50,12 @@ fn addCommandLineArgs(comp: *aro.Compilation, file: aro.Source, macro_buf: anyty return .{ only_preprocess, line_markers }; } -fn testOne(allocator: std.mem.Allocator, path: []const u8, self_exe_dir: []const u8) !void { +fn testOne(allocator: std.mem.Allocator, path: []const u8, test_dir: []const u8) !void { var comp = aro.Compilation.init(allocator); defer comp.deinit(); try comp.addDefaultPragmaHandlers(); - try comp.defineSystemIncludes(self_exe_dir); + try comp.defineSystemIncludes(test_dir); const file = try comp.addSourceFromPath(path); var macro_buf = std.ArrayList(u8).init(comp.gpa); @@ -85,7 +85,7 @@ fn testOne(allocator: std.mem.Allocator, path: []const u8, self_exe_dir: []const tree.dump(false, std.io.null_writer) catch {}; } -fn testAllAllocationFailures(cases: [][]const u8, self_exe_dir: []const u8) !void { +fn testAllAllocationFailures(cases: [][]const u8, test_dir: []const u8) !void { var progress = std.Progress{}; const root_node = progress.start("Memory Allocation Test", cases.len); @@ -96,7 +96,7 @@ fn testAllAllocationFailures(cases: [][]const u8, self_exe_dir: []const u8) !voi defer case_node.end(); progress.refresh(); - std.testing.checkAllAllocationFailures(std.testing.allocator, testOne, .{ case, self_exe_dir }) catch |er| switch (er) { + std.testing.checkAllAllocationFailures(std.testing.allocator, testOne, .{ case, test_dir }) catch |er| switch (er) { error.SwallowedOutOfMemoryError => {}, else => |e| return e, }; @@ -112,9 +112,6 @@ pub fn main() !void { const gpa = general_purpose_allocator.allocator(); defer if (general_purpose_allocator.deinit() == .leak) std.process.exit(1); - const self_exe_dir = try std.fs.selfExePathAlloc(gpa); - defer gpa.free(self_exe_dir); - var args = try std.process.argsAlloc(gpa); defer std.process.argsFree(gpa, args); @@ -123,6 +120,8 @@ pub fn main() !void { return error.InvalidArguments; } + const test_dir = args[1]; + var buf = std.ArrayList(u8).init(gpa); var cases = std.ArrayList([]const u8).init(gpa); defer { @@ -150,7 +149,7 @@ pub fn main() !void { } } if (build_options.test_all_allocation_failures) { - return testAllAllocationFailures(cases.items, self_exe_dir); + return testAllAllocationFailures(cases.items, test_dir); } var progress = std.Progress{}; @@ -171,7 +170,7 @@ pub fn main() !void { try initial_comp.include_dirs.append(cases_next_include_dir); try initial_comp.addDefaultPragmaHandlers(); - try initial_comp.defineSystemIncludes(self_exe_dir); + try initial_comp.defineSystemIncludes(test_dir); // apparently we can't use setAstCwd without libc on windows yet const win = @import("builtin").os.tag == .windows;