| ... | @@ -1927,6 +1927,7 @@ fn pollZigTest( | ... | @@ -1927,6 +1927,7 @@ fn pollZigTest( |
| 1927 | .ns_elapsed = if (timer) |*t| t.read() else 0, | 1927 | .ns_elapsed = if (timer) |*t| t.read() else 0, |
| 1928 | } }; | 1928 | } }; |
| 1929 | const body = stdout.take(header.bytes_len) catch unreachable; | 1929 | const body = stdout.take(header.bytes_len) catch unreachable; |
| | 1930 | var body_r: std.Io.Reader = .fixed(body); |
| 1930 | switch (header.tag) { | 1931 | switch (header.tag) { |
| 1931 | .zig_version => { | 1932 | .zig_version => { |
| 1932 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) return run.step.fail( | 1933 | if (!std.mem.eql(u8, builtin.zig_version_string, body)) return run.step.fail( |
| ... | @@ -1942,29 +1943,23 @@ fn pollZigTest( | ... | @@ -1942,29 +1943,23 @@ fn pollZigTest( |
| 1942 | // restart the test runner). | 1943 | // restart the test runner). |
| 1943 | assert(opt_metadata.* == null); | 1944 | assert(opt_metadata.* == null); |
| 1944 | | 1945 | |
| 1945 | const TmHdr = std.zig.Server.Message.TestMetadata; | 1946 | const tm_hdr = body_r.takeStruct(std.zig.Server.Message.TestMetadata, .little) catch unreachable; |
| 1946 | const tm_hdr: *align(1) const TmHdr = @ptrCast(body); | | |
| 1947 | results.test_count = tm_hdr.tests_len; | 1947 | results.test_count = tm_hdr.tests_len; |
| 1948 | | 1948 | |
| 1949 | const names_bytes = body[@sizeOf(TmHdr)..][0 .. results.test_count * @sizeOf(u32)]; | 1949 | const names = try arena.alloc(u32, results.test_count); |
| 1950 | const expected_panic_msgs_bytes = body[@sizeOf(TmHdr) + names_bytes.len ..][0 .. results.test_count * @sizeOf(u32)]; | 1950 | for (names) |*dest| dest.* = body_r.takeInt(u32, .little) catch unreachable; |
| 1951 | const string_bytes = body[@sizeOf(TmHdr) + names_bytes.len + expected_panic_msgs_bytes.len ..][0..tm_hdr.string_bytes_len]; | | |
| 1952 | | 1951 | |
| 1953 | const names = std.mem.bytesAsSlice(u32, names_bytes); | 1952 | const expected_panic_msgs = try arena.alloc(u32, results.test_count); |
| 1954 | const expected_panic_msgs = std.mem.bytesAsSlice(u32, expected_panic_msgs_bytes); | 1953 | for (expected_panic_msgs) |*dest| dest.* = body_r.takeInt(u32, .little) catch unreachable; |
| 1955 | | 1954 | |
| 1956 | const names_aligned = try arena.alloc(u32, names.len); | 1955 | const string_bytes = body_r.take(tm_hdr.string_bytes_len) catch unreachable; |
| 1957 | for (names_aligned, names) |*dest, src| dest.* = src; | | |
| 1958 | | | |
| 1959 | const expected_panic_msgs_aligned = try arena.alloc(u32, expected_panic_msgs.len); | | |
| 1960 | for (expected_panic_msgs_aligned, expected_panic_msgs) |*dest, src| dest.* = src; | | |
| 1961 | | 1956 | |
| 1962 | options.progress_node.setEstimatedTotalItems(names.len); | 1957 | options.progress_node.setEstimatedTotalItems(names.len); |
| 1963 | opt_metadata.* = .{ | 1958 | opt_metadata.* = .{ |
| 1964 | .string_bytes = try arena.dupe(u8, string_bytes), | 1959 | .string_bytes = try arena.dupe(u8, string_bytes), |
| 1965 | .ns_per_test = try arena.alloc(u64, results.test_count), | 1960 | .ns_per_test = try arena.alloc(u64, results.test_count), |
| 1966 | .names = names_aligned, | 1961 | .names = names, |
| 1967 | .expected_panic_msgs = expected_panic_msgs_aligned, | 1962 | .expected_panic_msgs = expected_panic_msgs, |
| 1968 | .next_index = 0, | 1963 | .next_index = 0, |
| 1969 | .prog_node = options.progress_node, | 1964 | .prog_node = options.progress_node, |
| 1970 | }; | 1965 | }; |
| ... | @@ -1983,8 +1978,7 @@ fn pollZigTest( | ... | @@ -1983,8 +1978,7 @@ fn pollZigTest( |
| 1983 | assert(fuzz_context == null); | 1978 | assert(fuzz_context == null); |
| 1984 | const md = &opt_metadata.*.?; | 1979 | const md = &opt_metadata.*.?; |
| 1985 | | 1980 | |
| 1986 | const TrHdr = std.zig.Server.Message.TestResults; | 1981 | const tr_hdr = body_r.takeStruct(std.zig.Server.Message.TestResults, .little) catch unreachable; |
| 1987 | const tr_hdr: *align(1) const TrHdr = @ptrCast(body); | | |
| 1988 | assert(tr_hdr.index == active_test_index); | 1982 | assert(tr_hdr.index == active_test_index); |
| 1989 | | 1983 | |
| 1990 | switch (tr_hdr.flags.status) { | 1984 | switch (tr_hdr.flags.status) { |
| ... | @@ -2026,18 +2020,21 @@ fn pollZigTest( | ... | @@ -2026,18 +2020,21 @@ fn pollZigTest( |
| 2026 | requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err }; | 2020 | requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err }; |
| 2027 | }, | 2021 | }, |
| 2028 | .coverage_id => { | 2022 | .coverage_id => { |
| 2029 | const fuzz = fuzz_context.?.fuzz; | 2023 | coverage_id = body_r.takeInt(u64, .little) catch unreachable; |
| 2030 | const msg_ptr: *align(1) const [4]u64 = @ptrCast(body); | 2024 | const cumulative_runs = body_r.takeInt(u64, .little) catch unreachable; |
| 2031 | coverage_id = msg_ptr[0]; | 2025 | const cumulative_unique = body_r.takeInt(u64, .little) catch unreachable; |
| | 2026 | const cumulative_coverage = body_r.takeInt(u64, .little) catch unreachable; |
| | 2027 | |
| 2032 | { | 2028 | { |
| | 2029 | const fuzz = fuzz_context.?.fuzz; |
| 2033 | fuzz.queue_mutex.lock(); | 2030 | fuzz.queue_mutex.lock(); |
| 2034 | defer fuzz.queue_mutex.unlock(); | 2031 | defer fuzz.queue_mutex.unlock(); |
| 2035 | try fuzz.msg_queue.append(fuzz.gpa, .{ .coverage = .{ | 2032 | try fuzz.msg_queue.append(fuzz.gpa, .{ .coverage = .{ |
| 2036 | .id = coverage_id.?, | 2033 | .id = coverage_id.?, |
| 2037 | .cumulative = .{ | 2034 | .cumulative = .{ |
| 2038 | .runs = msg_ptr[1], | 2035 | .runs = cumulative_runs, |
| 2039 | .unique = msg_ptr[2], | 2036 | .unique = cumulative_unique, |
| 2040 | .coverage = msg_ptr[3], | 2037 | .coverage = cumulative_coverage, |
| 2041 | }, | 2038 | }, |
| 2042 | .run = run, | 2039 | .run = run, |
| 2043 | } }); | 2040 | } }); |
| ... | @@ -2046,8 +2043,7 @@ fn pollZigTest( | ... | @@ -2046,8 +2043,7 @@ fn pollZigTest( |
| 2046 | }, | 2043 | }, |
| 2047 | .fuzz_start_addr => { | 2044 | .fuzz_start_addr => { |
| 2048 | const fuzz = fuzz_context.?.fuzz; | 2045 | const fuzz = fuzz_context.?.fuzz; |
| 2049 | const msg_ptr: *align(1) const u64 = @ptrCast(body); | 2046 | const addr = body_r.takeInt(u64, .little) catch unreachable; |
| 2050 | const addr = msg_ptr.*; | | |
| 2051 | { | 2047 | { |
| 2052 | fuzz.queue_mutex.lock(); | 2048 | fuzz.queue_mutex.lock(); |
| 2053 | defer fuzz.queue_mutex.unlock(); | 2049 | defer fuzz.queue_mutex.unlock(); |
| ... | @@ -2116,7 +2112,10 @@ fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void { | ... | @@ -2116,7 +2112,10 @@ fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void { |
| 2116 | .tag = tag, | 2112 | .tag = tag, |
| 2117 | .bytes_len = 0, | 2113 | .bytes_len = 0, |
| 2118 | }; | 2114 | }; |
| 2119 | try file.writeAll(@ptrCast(&header)); | 2115 | var w = file.writer(&.{}); |
| | 2116 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| | 2117 | error.WriteFailed => return w.err.?, |
| | 2118 | }; |
| 2120 | } | 2119 | } |
| 2121 | | 2120 | |
| 2122 | fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index: u32) !void { | 2121 | fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index: u32) !void { |
| ... | @@ -2124,8 +2123,13 @@ fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index: | ... | @@ -2124,8 +2123,13 @@ fn sendRunTestMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag, index: |
| 2124 | .tag = tag, | 2123 | .tag = tag, |
| 2125 | .bytes_len = 4, | 2124 | .bytes_len = 4, |
| 2126 | }; | 2125 | }; |
| 2127 | const full_msg = std.mem.asBytes(&header) ++ std.mem.asBytes(&index); | 2126 | var w = file.writer(&.{}); |
| 2128 | try file.writeAll(full_msg); | 2127 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| | 2128 | error.WriteFailed => return w.err.?, |
| | 2129 | }; |
| | 2130 | w.interface.writeInt(u32, index, .little) catch |err| switch (err) { |
| | 2131 | error.WriteFailed => return w.err.?, |
| | 2132 | }; |
| 2129 | } | 2133 | } |
| 2130 | | 2134 | |
| 2131 | fn sendRunFuzzTestMessage( | 2135 | fn sendRunFuzzTestMessage( |
| ... | @@ -2138,10 +2142,19 @@ fn sendRunFuzzTestMessage( | ... | @@ -2138,10 +2142,19 @@ fn sendRunFuzzTestMessage( |
| 2138 | .tag = .start_fuzzing, | 2142 | .tag = .start_fuzzing, |
| 2139 | .bytes_len = 4 + 1 + 8, | 2143 | .bytes_len = 4 + 1 + 8, |
| 2140 | }; | 2144 | }; |
| 2141 | const full_msg = std.mem.asBytes(&header) ++ std.mem.asBytes(&index) ++ | 2145 | var w = file.writer(&.{}); |
| 2142 | std.mem.asBytes(&kind) ++ std.mem.asBytes(&amount_or_instance); | 2146 | w.interface.writeStruct(header, .little) catch |err| switch (err) { |
| 2143 | | 2147 | error.WriteFailed => return w.err.?, |
| 2144 | try file.writeAll(full_msg); | 2148 | }; |
| | 2149 | w.interface.writeInt(u32, index, .little) catch |err| switch (err) { |
| | 2150 | error.WriteFailed => return w.err.?, |
| | 2151 | }; |
| | 2152 | w.interface.writeByte(@intFromEnum(kind)) catch |err| switch (err) { |
| | 2153 | error.WriteFailed => return w.err.?, |
| | 2154 | }; |
| | 2155 | w.interface.writeInt(u64, amount_or_instance, .little) catch |err| switch (err) { |
| | 2156 | error.WriteFailed => return w.err.?, |
| | 2157 | }; |
| 2145 | } | 2158 | } |
| 2146 | | 2159 | |
| 2147 | fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { | 2160 | fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult { |