Update source tree for zig 0.9.1

This commit is contained in:
Kyle Aleshire 2021-06-07 14:00:33 -08:00 committed by Sam Tebbs
parent 2484cb08d0
commit 06f45400bd
49 changed files with 2347 additions and 2211 deletions

View file

@ -1 +0,0 @@
insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long_insanely_long.txt

View file

@ -67,6 +67,8 @@ const types = .{
.{ "fn (usize) bool", "FN_IUSIZE_OBOOL", "", "", "" },
.{ "fn (RtcRegister) u8", "FN_IRTCREGISTER_OU8", "", "", "" },
.{ "fn (IdtEntry) bool", "FN_IIDTENTRY_OBOOL", "idt_mock", "", "IdtEntry" },
.{ "fn (*const GdtPtr) anyerror!void", "FN_IPTRCONSTGDTPTR_EERROR_OVOID", "", "", "" },
.{ "fn (*const IdtPtr) anyerror!void", "FN_IPTRCONSTIDTPTR_EERROR_OVOID", "", "", "" },
.{ "fn (*const GdtPtr) void", "FN_IPTRCONSTGDTPTR_OVOID", "", "", "" },
.{ "fn (*const IdtPtr) void", "FN_IPTRCONSTIDTPTR_OVOID", "", "", "" },
@ -74,6 +76,7 @@ const types = .{
.{ "fn (u8, u8) u16", "FN_IU8_IU8_OU16", "", "", "" },
.{ "fn (u8, fn () callconv(.Naked) void) IdtError!void", "FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID", "", "", "" },
.{ "fn (u16, u8) void", "FN_IU16_IU8_OVOID", "", "", "" },
.{ "fn (u16, u16) anyerror!void", "FN_IU16_IU16_EERROR_OVOID", "", "", "" },
.{ "fn (u16, u16) void", "FN_IU16_IU16_OVOID", "", "", "" },
.{ "fn (u16, u32) void", "FN_IU16_IU32_OVOID", "", "", "" },
.{ "fn (StatusRegister, bool) u8", "FN_ISTATUSREGISTER_IBOOL_OU8", "", "", "" },
@ -179,7 +182,7 @@ pub fn main() (Allocator.Error || File.OpenError || File.WriteError || File.Read
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator;
const allocator = gpa.allocator();
// All the string
const imports_str = comptime genImports();

View file

@ -56,12 +56,12 @@ pub const CpuState = struct {
user_ss: u32,
};
pub const VmmPayload = switch (builtin.arch) {
pub const VmmPayload = switch (builtin.cpu.arch) {
.i386 => *x86_paging.Directory,
else => unreachable,
};
pub const KERNEL_VMM_PAYLOAD: VmmPayload = switch (builtin.arch) {
pub const KERNEL_VMM_PAYLOAD: VmmPayload = switch (builtin.cpu.arch) {
.i386 => &x86_paging.kernel_directory,
else => unreachable,
};
@ -78,8 +78,21 @@ var KERNEL_VADDR_START: u32 = 0xC0100000;
var KERNEL_VADDR_END: u32 = 0xC1100000;
var KERNEL_ADDR_OFFSET: u32 = 0xC0000000;
pub fn map(start: usize, end: usize, p_start: usize, p_end: usize, attrs: vmm.Attributes, allocator: *Allocator, payload: VmmPayload) !void {}
pub fn unmap(start: usize, end: usize, allocator: *Allocator, payload: VmmPayload) !void {}
pub fn map(start: usize, end: usize, p_start: usize, p_end: usize, attrs: vmm.Attributes, allocator: Allocator, payload: VmmPayload) !void {
_ = start;
_ = end;
_ = p_start;
_ = p_end;
_ = attrs;
_ = allocator;
_ = payload;
}
pub fn unmap(start: usize, end: usize, allocator: Allocator, payload: VmmPayload) !void {
_ = start;
_ = end;
_ = allocator;
_ = payload;
}
pub fn out(port: u16, data: anytype) void {
return mock_framework.performAction("out", void, .{ port, data });
@ -134,10 +147,14 @@ pub fn haltNoInterrupts() noreturn {
}
pub fn initSerial(boot_payload: BootPayload) Serial {
// Suppress unused variable warnings
_ = boot_payload;
return .{ .write = undefined };
}
pub fn initTTY(boot_payload: BootPayload) TTY {
// Suppress unused variable warnings
_ = boot_payload;
return .{
.print = undefined,
.setCursor = undefined,
@ -148,6 +165,8 @@ pub fn initTTY(boot_payload: BootPayload) TTY {
}
pub fn initMem(payload: BootPayload) Allocator.Error!mem.MemProfile {
// Suppress unused variable warnings
_ = payload;
return MemProfile{
.vaddr_end = @ptrCast([*]u8, &KERNEL_VADDR_END),
.vaddr_start = @ptrCast([*]u8, &KERNEL_VADDR_START),
@ -162,13 +181,22 @@ pub fn initMem(payload: BootPayload) Allocator.Error!mem.MemProfile {
};
}
pub fn initTask(t: *Task, entry_point: usize, allocator: *Allocator) Allocator.Error!void {}
pub fn initTask(t: *Task, entry_point: usize, allocator: Allocator) Allocator.Error!void {
// Suppress unused variable warnings
_ = t;
_ = entry_point;
_ = allocator;
}
pub fn initKeyboard(allocator: *Allocator) Allocator.Error!?*Keyboard {
pub fn initKeyboard(allocator: Allocator) Allocator.Error!?*Keyboard {
// Suppress unused variable warnings
_ = allocator;
return null;
}
pub fn getDevices(allocator: *Allocator) Allocator.Error![]Device {
pub fn getDevices(allocator: Allocator) Allocator.Error![]Device {
// Suppress unused variable warnings
_ = allocator;
return &[_]Device{};
}
@ -188,6 +216,8 @@ pub fn getDateTime() DateTime {
}
pub fn init(mem_profile: *const MemProfile) void {
// Suppress unused variable warnings
_ = mem_profile;
// I'll get back to this as this doesn't effect the current testing.
// When I come on to the mem.zig testing, I'll fix :)
//return mock_framework.performAction("init", void, mem_profile);

View file

@ -194,7 +194,7 @@ fn Mock() type {
// Test that the types match
const expect_type = comptime getDataElementType(expected_function);
expectEqual(expect_type, @as(DataElementType, test_element));
expectEqual(expect_type, @as(DataElementType, test_element)) catch @panic("Function type is not as expected\n");
// Types match, so can use the expected type to get the actual data
const actual_function = getDataValue(expected_function, test_element);
@ -219,13 +219,13 @@ fn Mock() type {
// Test that the types match
const expect_type = comptime getDataElementType(ExpectedType);
expectEqual(expect_type, @as(DataElementType, elem));
expectEqual(expect_type, @as(DataElementType, elem)) catch std.debug.panic("Expected {}, got {}\n", .{ expect_type, @as(DataElementType, elem) });
// Types match, so can use the expected type to get the actual data
const actual_value = getDataValue(ExpectedType, elem);
// Test the values
expectEqual(expected_value, actual_value);
expectEqual(expected_value, actual_value) catch std.debug.panic("Expected {}, got {}\n", .{ expected_value, actual_value });
}
///
@ -254,7 +254,7 @@ fn Mock() type {
// Test that the data match
const expect_data = comptime getDataElementType(DataType);
expectEqual(expect_data, @as(DataElementType, action.data));
expectEqual(expect_data, @as(DataElementType, action.data)) catch std.debug.panic("Expected {}, got {}\n", .{ expect_data, action.data });
return getDataValue(DataType, action.data);
} else {
std.debug.panic("No more test values for the return of function: " ++ fun_name ++ "\n", .{});
@ -281,7 +281,7 @@ fn Mock() type {
// Get the function mapping to add the parameter to.
if (self.named_actions.getEntry(fun_name)) |actions_kv| {
// Take a reference of the value so the underlying action list will update
var action_list = &actions_kv.value;
var action_list = &actions_kv.value_ptr;
const action = Action{
.action = action_type,
.data = createDataElement(data),
@ -312,7 +312,7 @@ fn Mock() type {
pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: anytype) RetType {
if (self.named_actions.getEntry(fun_name)) |kv_actions_list| {
// Take a reference of the value so the underlying action list will update
var action_list = &kv_actions_list.value;
var action_list = &kv_actions_list.value_ptr;
// Peak the first action to test the action type
if (action_list.*.first) |action_node| {
const action = action_node.data;
@ -331,7 +331,7 @@ fn Mock() type {
expectTest(param_type, param, test_action.data);
}
break :ret expectGetValue(fun_name, action_list, RetType);
break :ret expectGetValue(fun_name, action_list.*, RetType);
},
ActionType.ConsumeFunctionCall => ret: {
// Now pop the action as we are going to use it
@ -383,13 +383,13 @@ fn Mock() type {
var it = self.named_actions.iterator();
while (it.next()) |next| {
// Take a reference so the underlying action list will be updated.
var action_list = &next.value;
var action_list = &next.value_ptr;
if (action_list.*.popFirst()) |action_node| {
const action = action_node.data;
switch (action.action) {
ActionType.TestValue, ActionType.ConsumeFunctionCall => {
// These need to be all consumed
std.debug.panic("Unused testing value: Type: {}, value: {} for function '{s}'\n", .{ action.action, @as(DataElementType, action.data), next.key });
std.debug.panic("Unused testing value: Type: {}, value: {} for function '{s}'\n", .{ action.action, @as(DataElementType, action.data), next.key_ptr.* });
},
ActionType.RepeatFunctionCall => {
// As this is a repeat action, the function will still be here

View file

@ -1,7 +1,7 @@
const std = @import("std");
const expect = std.testing.expect;
const arch = @import("arch.zig").internals;
const arch = @import("arch_mock.zig");
const mock_framework = @import("mock_framework.zig");
pub const initTest = mock_framework.initTest;
@ -79,8 +79,8 @@ pub fn orig_entry(uc: u8, c: u8) u16 {
pub fn mock_updateCursor(x: u16, y: u16) void {
// Here we can do any testing we like with the parameters. e.g. test out of bounds
expect(x < WIDTH);
expect(y < HEIGHT);
expect(x < WIDTH) catch @panic("Cursor x is out of bounds\n");
expect(y < HEIGHT) catch @panic("Cursor x is out of bounds\n");
}
pub fn mock_enableCursor() void {}

View file

@ -99,7 +99,7 @@ pub const RuntimeStep = struct {
while (true) {
const msg = self.get_msg() catch return true;
defer self.builder.allocator.free(msg);
std.debug.warn("{s}\n", .{msg});
std.debug.print("{s}\n", .{msg});
}
}
@ -117,7 +117,7 @@ pub const RuntimeStep = struct {
const msg = self.get_msg() catch return false;
defer self.builder.allocator.free(msg);
// Print the line to see what is going on
std.debug.warn("{s}\n", .{msg});
std.debug.print("{s}\n", .{msg});
if (std.mem.indexOf(u8, msg, "FAILURE")) |_| {
return false;
} else if (std.mem.indexOf(u8, msg, "Kernel panic")) |_| {
@ -142,8 +142,8 @@ pub const RuntimeStep = struct {
const msg = self.get_msg() catch return false;
defer self.builder.allocator.free(msg);
// Print the line to see what is going on
std.debug.warn("{s}\n", .{msg});
if (std.mem.eql(u8, msg, "[emerg] (panic): Kernel panic: integer overflow")) {
std.debug.print("{s}\n", .{msg});
if (std.mem.eql(u8, msg, "[err] (panic): Kernel panic: integer overflow")) {
return true;
}
}
@ -164,7 +164,7 @@ pub const RuntimeStep = struct {
const msg = self.get_msg() catch return false;
defer self.builder.allocator.free(msg);
std.debug.warn("{s}\n", .{msg});
std.debug.print("{s}\n", .{msg});
// Make sure `[INFO] Switched` then `[INFO] SUCCESS: Scheduler variables preserved` are logged in this order
if (std.mem.eql(u8, msg, "[info] (scheduler): Switched") and state == 0) {
@ -206,7 +206,7 @@ pub const RuntimeStep = struct {
try self.os_proc.spawn();
// Start up the read thread
var thread = try Thread.spawn(read_logs, self);
var thread = try Thread.spawn(Thread.SpawnConfig{}, read_logs, .{self});
// Call the testing function
const res = self.test_func(self);
@ -215,7 +215,7 @@ pub const RuntimeStep = struct {
_ = try self.os_proc.kill();
// Join the thread
thread.wait();
thread.join();
// Free the rest of the queue
while (self.msg_queue.get()) |node| {
@ -248,7 +248,7 @@ pub const RuntimeStep = struct {
return;
},
else => {
std.debug.warn("Unexpected error: {}\n", .{e});
std.debug.print("Unexpected error: {}\n", .{e});
unreachable;
},
};
@ -299,7 +299,7 @@ pub const RuntimeStep = struct {
pub fn create(builder: *Builder, test_mode: TestMode, qemu_args: [][]const u8) *RuntimeStep {
const runtime_step = builder.allocator.create(RuntimeStep) catch unreachable;
runtime_step.* = RuntimeStep{
.step = Step.init(.Custom, builder.fmt("Runtime {s}", .{@tagName(test_mode)}), builder.allocator, make),
.step = Step.init(.custom, builder.fmt("Runtime {s}", .{@tagName(test_mode)}), builder.allocator, make),
.builder = builder,
.msg_queue = Queue.init(),
.os_proc = undefined,