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

@ -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 {}