authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-10 20:27:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-10 20:27:15-04:00
log8197a14ceb2938c64526c7b84e2ac8da343960fa
tree4cab564fe918fcc167bfcd52c3a619607f0fc364
parent574e31f0a046aa6e6fad73fff2cbbb3617fe1bae

self-hosted test: use C allocator since we depend on libc


1 files changed, 14 insertions(+), 26 deletions(-)

src-self-hosted/test.zig+14-26
......@@ -21,12 +21,11 @@ test "compile errors" {
2121}
2222
2323const file1 = "1.zig";
24const allocator = std.heap.c_allocator;
2425
2526const TestContext = struct {
2627 loop: std.event.Loop,
2728 zig_lib_dir: []u8,
28 direct_allocator: std.heap.DirectAllocator,
29 arena: std.heap.ArenaAllocator,
3029 zig_cache_dir: []u8,
3130 file_index: std.atomic.Int(usize),
3231 group: std.event.Group(error!void),
......@@ -37,8 +36,6 @@ const TestContext = struct {
3736 fn init(self: *TestContext) !void {
3837 self.* = TestContext{
3938 .any_err = {},
40 .direct_allocator = undefined,
41 .arena = undefined,
4239 .loop = undefined,
4340 .zig_lib_dir = undefined,
4441 .zig_cache_dir = undefined,
......@@ -46,36 +43,27 @@ const TestContext = struct {
4643 .file_index = std.atomic.Int(usize).init(0),
4744 };
4845
49 self.direct_allocator = std.heap.DirectAllocator.init();
50 errdefer self.direct_allocator.deinit();
51
52 self.arena = std.heap.ArenaAllocator.init(&self.direct_allocator.allocator);
53 errdefer self.arena.deinit();
54
55 // TODO faster allocator for coroutines that is thread-safe/lock-free
56 try self.loop.initMultiThreaded(&self.direct_allocator.allocator);
46 try self.loop.initMultiThreaded(allocator);
5747 errdefer self.loop.deinit();
5848
5949 self.group = std.event.Group(error!void).init(&self.loop);
6050 errdefer self.group.cancelAll();
6151
62 self.zig_lib_dir = try introspect.resolveZigLibDir(&self.arena.allocator);
63 errdefer self.arena.allocator.free(self.zig_lib_dir);
52 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);
53 errdefer allocator.free(self.zig_lib_dir);
6454
65 self.zig_cache_dir = try introspect.resolveZigCacheDir(&self.arena.allocator);
66 errdefer self.arena.allocator.free(self.zig_cache_dir);
55 self.zig_cache_dir = try introspect.resolveZigCacheDir(allocator);
56 errdefer allocator.free(self.zig_cache_dir);
6757
68 try std.os.makePath(&self.arena.allocator, tmp_dir_name);
69 errdefer std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {};
58 try std.os.makePath(allocator, tmp_dir_name);
59 errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {};
7060 }
7161
7262 fn deinit(self: *TestContext) void {
73 std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {};
74 self.arena.allocator.free(self.zig_cache_dir);
75 self.arena.allocator.free(self.zig_lib_dir);
63 std.os.deleteTree(allocator, tmp_dir_name) catch {};
64 allocator.free(self.zig_cache_dir);
65 allocator.free(self.zig_lib_dir);
7666 self.loop.deinit();
77 self.arena.deinit();
78 self.direct_allocator.deinit();
7967 }
8068
8169 fn run(self: *TestContext) !void {
......@@ -99,14 +87,14 @@ const TestContext = struct {
9987 ) !void {
10088 var file_index_buf: [20]u8 = undefined;
10189 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.next());
102 const file1_path = try std.os.path.join(&self.arena.allocator, tmp_dir_name, file_index, file1);
90 const file1_path = try std.os.path.join(allocator, tmp_dir_name, file_index, file1);
10391
10492 if (std.os.path.dirname(file1_path)) |dirname| {
105 try std.os.makePath(&self.arena.allocator, dirname);
93 try std.os.makePath(allocator, dirname);
10694 }
10795
10896 // TODO async I/O
109 try std.io.writeFile(&self.arena.allocator, file1_path, source);
97 try std.io.writeFile(allocator, file1_path, source);
11098
11199 var module = try Module.create(
112100 &self.loop,