Remove unneeded mocking files

This commit is contained in:
Sam Tebbs 2020-12-07 23:08:23 +00:00
parent 285b8d9579
commit b8ebc5f341
19 changed files with 52 additions and 235 deletions

View file

@ -8,7 +8,7 @@ const log = std.log.scoped(.x86_isr);
const build_options = @import("build_options");
const mock_path = build_options.arch_mock_path;
const syscalls = @import("syscalls.zig");
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
const panic = @import("../../panic.zig").panic;
const idt = if (is_test) @import(mock_path ++ "idt_mock.zig") else @import("idt.zig");
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
const interrupts = @import("interrupts.zig");

View file

@ -12,8 +12,8 @@ const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("ar
const isr = @import("isr.zig");
const MemProfile = @import("../../mem.zig").MemProfile;
const tty = @import("../../tty.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("../../mem.zig");
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("../../vmm.zig");
const mem = @import("../../mem.zig");
const vmm = @import("../../vmm.zig");
const pmm = @import("../../pmm.zig");
const multiboot = @import("multiboot.zig");
const Allocator = std.mem.Allocator;
@ -239,8 +239,10 @@ fn mapDirEntry(dir: *Directory, virt_start: usize, virt_end: usize, phys_start:
// Create a table and put the physical address in the dir entry
table = &(try allocator.alignedAlloc(Table, @truncate(u29, PAGE_SIZE_4KB), 1))[0];
@memset(@ptrCast([*]u8, table), 0, @sizeOf(Table));
const table_phys_addr = vmm.kernel_vmm.virtToPhys(@ptrToInt(table)) catch |e| {
panic(@errorReturnTrace(), "Failed getting the physical address for an allocated page table: {}\n", .{e});
const table_phys_addr = vmm.kernel_vmm.virtToPhys(@ptrToInt(table)) catch |e| blk: {
// When testing this will fail, but that's ok
if (!is_test) panic(@errorReturnTrace(), "Failed getting the physical address for a page table: {}\n", .{e});
break :blk 0;
};
dir_entry.* |= DENTRY_PAGE_ADDR & table_phys_addr;
dir.tables[entry] = table;
@ -535,6 +537,7 @@ test "mapDirEntry" {
defer dir.deinit();
const attrs = vmm.Attributes{ .kernel = false, .writable = false, .cachable = false };
vmm.kernel_vmm = try vmm.VirtualMemoryManager(arch.VmmPayload).init(PAGE_SIZE_4MB, 0xFFFFFFFF, allocator, arch.VMM_MAPPER, undefined);
defer vmm.kernel_vmm.deinit();
{
const phys: usize = 0 * PAGE_SIZE_4MB;
const phys_end: usize = phys + PAGE_SIZE_4MB;
@ -578,6 +581,10 @@ test "map and unmap" {
var allocator = std.testing.allocator;
var dir = Directory{ .entries = [_]DirectoryEntry{0} ** ENTRIES_PER_DIRECTORY, .tables = [_]?*Table{null} ** ENTRIES_PER_DIRECTORY, .allocator = allocator };
defer dir.deinit();
vmm.kernel_vmm = try vmm.VirtualMemoryManager(arch.VmmPayload).init(PAGE_SIZE_4MB, 0xFFFFFFFF, allocator, arch.VMM_MAPPER, undefined);
defer vmm.kernel_vmm.deinit();
const phys_start: usize = PAGE_SIZE_4MB * 2;
const virt_start: usize = PAGE_SIZE_4MB * 4;
const phys_end: usize = PAGE_SIZE_4MB * 4;

View file

@ -9,7 +9,7 @@ const log = std.log.scoped(.x86_pit);
const build_options = @import("build_options");
const mock_path = build_options.arch_mock_path;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig");
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
const panic = @import("../../panic.zig").panic;
const irq = @import("irq.zig");
const pic = @import("pic.zig");

View file

@ -12,7 +12,7 @@ const pic = @import("pic.zig");
const pit = @import("pit.zig");
const irq = @import("irq.zig");
const cmos = if (is_test) @import(mock_path ++ "cmos_mock.zig") else @import("cmos.zig");
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
const panic = @import("../../panic.zig").panic;
const scheduler = @import("../../scheduler.zig");
/// The Century register is unreliable. We need a APIC interface to infer if we have a century

View file

@ -9,7 +9,7 @@ const log = std.log.scoped(.x86_tty);
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const vga = if (is_test) @import("../../" ++ mock_path ++ "vga_mock.zig") else @import("vga.zig");
const panic = if (is_test) @import("../../" ++ mock_path ++ "panic_mock.zig").panic else @import("../../panic.zig").panic;
const panic = @import("../../panic.zig").panic;
/// The error set for if there is an error whiles printing.
const TtyError = error{

View file

@ -11,8 +11,8 @@ const mock_path = build_options.mock_path;
const Allocator = std.mem.Allocator;
const AutoHashMap = std.AutoHashMap;
const vfs = @import("vfs.zig");
const mem = if (is_test) @import("../" ++ mock_path ++ "mem_mock.zig") else @import("../mem.zig");
const panic = if (is_test) @import("../" ++ mock_path ++ "panic_mock.zig").panic else @import("../panic.zig").panic;
const mem = @import("../mem.zig");
const panic = @import("../panic.zig").panic;
/// The Initrd file system struct.
/// Format of raw ramdisk:

View file

@ -6,7 +6,7 @@ const builtin = @import("builtin");
const is_test = builtin.is_test;
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
const vmm = @import("vmm.zig");
const panic = @import("panic.zig").panic;
pub const FreeListAllocator = struct {

View file

@ -10,10 +10,10 @@ const vga = @import("vga.zig");
const log_root = @import("log.zig");
const pmm = @import("pmm.zig");
const serial = @import("serial.zig");
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
const panic_root = if (is_test) @import(mock_path ++ "panic_mock.zig") else @import("panic.zig");
const task = if (is_test) @import(mock_path ++ "task_mock.zig") else @import("task.zig");
const vmm = @import("vmm.zig");
const mem = @import("mem.zig");
const panic_root = @import("panic.zig");
const task = @import("task.zig");
const heap = @import("heap.zig");
const scheduler = @import("scheduler.zig");
const vfs = @import("filesystem/vfs.zig");

View file

@ -4,7 +4,7 @@ const log = std.log.scoped(.pmm);
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig").internals;
const MemProfile = (if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig")).MemProfile;
const MemProfile = @import("mem.zig").MemProfile;
const testing = std.testing;
const panic = @import("panic.zig").panic;
const Bitmap = @import("bitmap.zig").Bitmap;

View file

@ -8,10 +8,10 @@ const is_test = builtin.is_test;
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const arch = @import("arch.zig").internals;
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
const task = if (is_test) @import(mock_path ++ "task_mock.zig") else @import("task.zig");
const vmm = if (is_test) @import(mock_path ++ "vmm_mock.zig") else @import("vmm.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
const panic = @import("panic.zig").panic;
const task = @import("task.zig");
const vmm = @import("vmm.zig");
const mem = @import("mem.zig");
const fs = @import("filesystem/vfs.zig");
const Task = task.Task;
const EntryPoint = task.EntryPoint;
@ -187,13 +187,6 @@ fn destroyTestTask(self: *Task, allocator: *Allocator) void {
}
test "pickNextTask" {
task.initTest();
defer task.freeTest();
task.addConsumeFunction("Task.create", createTestTask);
task.addConsumeFunction("Task.create", createTestTask);
task.addRepeatFunction("Task.destroy", destroyTestTask);
var ctx: arch.CpuState = std.mem.zeroes(arch.CpuState);
var allocator = std.testing.allocator;
@ -216,8 +209,8 @@ test "pickNextTask" {
try scheduleTask(test_fn2_task, allocator);
// Get the stack pointers of the created tasks
const fn1_stack_pointer = tasks.first.?.data.stack_pointer;
const fn2_stack_pointer = tasks.first.?.next.?.data.stack_pointer;
const fn1_stack_pointer = test_fn1_task.stack_pointer;
const fn2_stack_pointer = test_fn2_task.stack_pointer;
expectEqual(pickNextTask(&ctx), fn1_stack_pointer);
// The stack pointer of the re-added task should point to the context
@ -250,12 +243,6 @@ test "pickNextTask" {
}
test "createNewTask add new task" {
task.initTest();
defer task.freeTest();
task.addConsumeFunction("Task.create", createTestTask);
task.addConsumeFunction("Task.destroy", destroyTestTask);
// Set the global allocator
var allocator = std.testing.allocator;
@ -273,18 +260,13 @@ test "createNewTask add new task" {
}
test "init" {
task.initTest();
defer task.freeTest();
task.addConsumeFunction("Task.create", createTestTask);
task.addRepeatFunction("Task.destroy", destroyTestTask);
var allocator = std.testing.allocator;
try init(allocator, undefined);
expectEqual(current_task.pid, 0);
expectEqual(current_task.kernel_stack, @intToPtr([*]u32, @ptrToInt(&KERNEL_STACK_START))[0 .. @ptrToInt(&KERNEL_STACK_END) - @ptrToInt(&KERNEL_STACK_START)]);
expectEqual(@ptrToInt(current_task.kernel_stack.ptr), @ptrToInt(&KERNEL_STACK_START));
expectEqual(current_task.kernel_stack.len, @ptrToInt(&KERNEL_STACK_END) - @ptrToInt(&KERNEL_STACK_START));
expectEqual(tasks.len, 1);

View file

@ -6,7 +6,7 @@ const is_test = builtin.is_test;
const build_options = @import("build_options");
const mock_path = build_options.mock_path;
const arch = @import("arch.zig").internals;
const panic = if (is_test) @import(mock_path ++ "panic_mock.zig").panic else @import("panic.zig").panic;
const panic = @import("panic.zig").panic;
const ComptimeBitmap = @import("bitmap.zig").ComptimeBitmap;
const vmm = @import("vmm.zig");
const Allocator = std.mem.Allocator;
@ -160,7 +160,7 @@ test "create out of memory for task" {
expectEqual(fa.allocated_bytes, fa.freed_bytes);
// Make sure no PIDs were allocated
expectEqual(all_pids.bitmap, 1);
expectEqual(all_pids.bitmap, 0);
}
test "create out of memory for stack" {
@ -174,21 +174,21 @@ test "create out of memory for stack" {
expectEqual(fa.allocated_bytes, fa.freed_bytes);
// Make sure no PIDs were allocated
expectEqual(all_pids.bitmap, 1);
expectEqual(all_pids.bitmap, 0);
}
test "create expected setup" {
var task = try Task.create(@ptrToInt(test_fn1), true, undefined, std.testing.allocator);
defer task.destroy(std.testing.allocator);
// Will allocate the first PID 1, 0 will always be allocated
expectEqual(task.pid, 1);
// Will allocate the first PID 0
expectEqual(task.pid, 0);
expectEqual(task.kernel_stack.len, STACK_SIZE);
expectEqual(task.user_stack.len, 0);
var user_task = try Task.create(@ptrToInt(test_fn1), false, undefined, std.testing.allocator);
defer user_task.destroy(std.testing.allocator);
expectEqual(user_task.pid, 2);
expectEqual(user_task.pid, 1);
expectEqual(user_task.user_stack.len, STACK_SIZE);
expectEqual(user_task.kernel_stack.len, STACK_SIZE);
}
@ -205,42 +205,42 @@ test "destroy cleans up" {
user_task.destroy(allocator);
// All PIDs were freed
expectEqual(all_pids.bitmap, 1);
expectEqual(all_pids.bitmap, 0);
}
test "Multiple create" {
var task1 = try Task.create(@ptrToInt(test_fn1), true, undefined, std.testing.allocator);
var task2 = try Task.create(@ptrToInt(test_fn1), true, undefined, std.testing.allocator);
expectEqual(task1.pid, 1);
expectEqual(task2.pid, 2);
expectEqual(all_pids.bitmap, 7);
expectEqual(task1.pid, 0);
expectEqual(task2.pid, 1);
expectEqual(all_pids.bitmap, 3);
task1.destroy(std.testing.allocator);
expectEqual(all_pids.bitmap, 5);
expectEqual(all_pids.bitmap, 2);
var task3 = try Task.create(@ptrToInt(test_fn1), true, undefined, std.testing.allocator);
expectEqual(task3.pid, 1);
expectEqual(all_pids.bitmap, 7);
expectEqual(task3.pid, 0);
expectEqual(all_pids.bitmap, 3);
task2.destroy(std.testing.allocator);
task3.destroy(std.testing.allocator);
var user_task = try Task.create(@ptrToInt(test_fn1), false, undefined, std.testing.allocator);
expectEqual(user_task.pid, 1);
expectEqual(all_pids.bitmap, 3);
expectEqual(user_task.pid, 0);
expectEqual(all_pids.bitmap, 1);
user_task.destroy(std.testing.allocator);
expectEqual(all_pids.bitmap, 1);
expectEqual(all_pids.bitmap, 0);
}
test "allocatePid and freePid" {
expectEqual(all_pids.bitmap, 1);
expectEqual(all_pids.bitmap, 0);
var i: usize = 1;
var i: usize = 0;
while (i < PidBitmap.NUM_ENTRIES) : (i += 1) {
expectEqual(i, allocatePid());
}

View file

@ -6,7 +6,7 @@ const std = @import("std");
const log = std.log.scoped(.vmm);
const bitmap = @import("bitmap.zig");
const pmm = @import("pmm.zig");
const mem = if (is_test) @import(mock_path ++ "mem_mock.zig") else @import("mem.zig");
const mem = @import("mem.zig");
const tty = @import("tty.zig");
const panic = @import("panic.zig").panic;
const arch = if (is_test) @import(mock_path ++ "arch_mock.zig") else @import("arch.zig").internals;