Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test_runner: change self_exe_dir for test_dir #534

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions test/record_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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,
});
}

Expand All @@ -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)});
Expand All @@ -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.*);
Expand All @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions test/runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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,
};
Expand All @@ -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);

Expand All @@ -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 {
Expand Down Expand Up @@ -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{};
Expand All @@ -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;
Expand Down
Loading