Initial scheduler

Fix TSS

Also change to .{} syntax where appropriate.
Added the SS segment
Fixed spelling

Refactoring GDT


Multitasking working for now


WIP scheduler

Refactored Bitmap a bit

WIP still


Task switching working

Handlers return the stack pointer that will be used to restore the tasks stack, normal handlers will return the same stack pointer it was called with where task switching will return the stack pointer of the next task and restore its state using the interrupt stub.

Initial scheduler done


Created a stage 2 init task


Change u32 to usize


Move Task to arch specific


WIP


WIP2


Removed esp from task, replaced with stack_pointer


Removed the debug logs


Fixed init task stack


Change pickNextTask to pointer manipulation

This allows less allocations so faster switching

Temporary enable interrupts for some runtime tests

PIT and RTC need interrupts enabled to run their runtime tests

Renamed schedule => pickNextTask, comptime bitmap for pids not task init

And some other stuff: No pub for the task anymore
Use the leak detector allocator

Fmt


Fix unit tests

And some other stuff :P

PR review

Moved Task out of arch and have the stack init in the arch file
Mocking clean up
Removed commented code
Renamed createTask to scheduleTask where the user will have to provide a task to schedule
Removed redundant pub in log runtime test
Removed global allocator for scheduler
Cleaner assembly in paging

Fmt


Added new Scheduler test mode


Added new test mode to CI


Removed one of the prints


Added doc comment, task test for i386


Removed test


WIP


Runtime tests work

Have a global set in one task and reacted to in another. Also test that local variables are preserved after a task switch.

Removed new lines


Increased line length


Move the allocation of the bool above the task creation
This commit is contained in:
DrDeano 2020-07-18 22:46:24 +01:00
parent 20826548e8
commit d600be874c
No known key found for this signature in database
GPG key ID: 96188600582B9ED7
30 changed files with 1127 additions and 395 deletions

View file

@ -9,6 +9,8 @@ const paging = @import("paging_mock.zig");
const Serial = @import("../../../src/kernel/serial.zig").Serial;
const TTY = @import("../../../src/kernel/tty.zig").TTY;
pub const task = @import("task_mock.zig");
const mock_framework = @import("mock_framework.zig");
pub const initTest = mock_framework.initTest;
pub const freeTest = mock_framework.freeTest;
@ -16,7 +18,8 @@ pub const addTestParams = mock_framework.addTestParams;
pub const addConsumeFunction = mock_framework.addConsumeFunction;
pub const addRepeatFunction = mock_framework.addRepeatFunction;
pub const InterruptContext = struct {
pub const CpuState = struct {
ss: u32,
gs: u32,
fs: u32,
es: u32,
@ -35,14 +38,16 @@ pub const InterruptContext = struct {
cs: u32,
eflags: u32,
user_esp: u32,
ss: u32,
user_ss: u32,
};
pub const VmmPayload = u8;
pub const KERNEL_VMM_PAYLOAD: usize = 0;
pub const MEMORY_BLOCK_SIZE: u32 = paging.PAGE_SIZE_4KB;
pub const STACK_SIZE: u32 = MEMORY_BLOCK_SIZE / @sizeOf(u32);
pub const VMM_MAPPER: vmm.Mapper(VmmPayload) = undefined;
pub const BootPayload = u8;
pub const Task = task.Task;
// The virtual/physical start/end of the kernel code
var KERNEL_PHYSADDR_START: u32 = 0x00100000;
@ -132,8 +137,13 @@ pub fn initMem(payload: BootPayload) std.mem.Allocator.Error!mem.MemProfile {
};
}
pub fn initTaskStack(entry_point: usize, allocator: *Allocator) Allocator.Error!struct { stack: []u32, pointer: usize } {
const ret = .{ .stack = &([_]u32{}), .pointer = 0 };
return ret;
}
pub fn init(payload: BootPayload, mem_profile: *const MemProfile, allocator: *Allocator) void {
// I'll get back to this as this doesn't effect the GDT testing.
// 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, allocator);
}

View file

@ -35,7 +35,7 @@ const GdtEntry = packed struct {
base_high: u8,
};
const TtsEntry = packed struct {
const Tss = packed struct {
prev_tss: u32,
esp0: u32,
ss0: u32,
@ -160,10 +160,6 @@ pub const USER_CODE_OFFSET: u16 = 0x18;
pub const USER_DATA_OFFSET: u16 = 0x20;
pub const TSS_OFFSET: u16 = 0x28;
pub fn setTssStack(esp0: u32) void {
return mock_framework.performAction("setTssStack", void, esp0);
}
pub fn init() void {
return mock_framework.performAction("init", void);
}

View file

@ -7,7 +7,7 @@ pub const addTestParams = mock_framework.addTestParams;
pub const addConsumeFunction = mock_framework.addConsumeFunction;
pub const addRepeatFunction = mock_framework.addRepeatFunction;
const IdtEntry = packed struct {
pub const IdtEntry = packed struct {
base_low: u16,
selector: u16,
zero: u8,
@ -34,10 +34,14 @@ const PRIVILEGE_RING_1: u2 = 0x1;
const PRIVILEGE_RING_2: u2 = 0x2;
const PRIVILEGE_RING_3: u2 = 0x3;
const NUMBER_OF_ENTRIES: u16 = 256;
pub const NUMBER_OF_ENTRIES: u16 = 256;
const TABLE_SIZE: u16 = @sizeOf(IdtEntry) * NUMBER_OF_ENTRIES - 1;
pub fn isIdtOpen(entry: IdtEntry) bool {
return mock_framework.performAction("isIdtOpen", bool, .{entry});
}
pub fn openInterruptGate(index: u8, handler: InterruptHandler) IdtError!void {
return mock_framework.performAction("openInterruptGate", IdtError!void, .{ index, handler });
}

View file

@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const StringHashMap = std.StringHashMap;
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
@ -8,6 +9,7 @@ const warn = std.debug.warn;
const gdt = @import("gdt_mock.zig");
const idt = @import("idt_mock.zig");
const cmos = @import("cmos_mock.zig");
const task = @import("task_mock.zig");
///
/// The enumeration of types that the mocking framework supports. These include basic types like u8
@ -19,13 +21,18 @@ const DataElementType = enum {
U8,
U16,
U32,
ECmosStatusRegister,
ECmosRtcRegister,
PTR_CONST_GdtPtr,
PTR_CONST_IdtPtr,
GdtPtr,
IdtPtr,
USIZE,
PTR_ALLOCATOR,
ECMOSSTATUSREGISTER,
ECMOSRTCREGISTER,
GDTPTR,
IDTPTR,
IDTENTRY,
PTR_CONST_GDTPTR,
PTR_CONST_IDTPTR,
ERROR_IDTERROR_VOID,
ERROR_MEM_PTRTASK,
PTR_TASK,
EFN_OVOID,
NFN_OVOID,
FN_OVOID,
@ -34,20 +41,26 @@ const DataElementType = enum {
FN_IU8_OBOOL,
FN_IU8_OVOID,
FN_IU16_OVOID,
FN_IUSIZE_OVOID,
FN_IU16_OU8,
FN_IU4_IU4_OU8,
FN_IU8_IU8_OU16,
FN_IU16_IU8_OVOID,
FN_IU16_IU16_OVOID,
FN_IECmosStatusRegister_IBOOL_OU8,
FN_IECmosStatusRegister_IU8_IBOOL_OVOID,
FN_IECmosRtcRegister_OU8,
FN_IECMOSSTATUSREGISTER_IBOOL_OU8,
FN_IECMOSSTATUSREGISTER_IU8_IBOOL_OVOID,
FN_IECMOSRTCREGISTER_OU8,
FN_IU8_IEFNOVOID_OERRORIDTERRORVOID,
FN_IU8_INFNOVOID_OERRORIDTERRORVOID,
FN_IPTRCONSTGDTPTR_OVOID,
FN_IPTRCONSTIDTPTR_OVOID,
FN_OGDTPTR,
FN_OIDTPTR,
FN_IIDTENTRY_OBOOL,
FN_IPTRTask_IUSIZE_OVOID,
FN_IPTRTASK_IPTRALLOCATOR_OVOID,
FN_IFNOVOID_OMEMERRORPTRTASK,
FN_IFNOVOID_IPTRALLOCATOR_OMEMERRORPTRTASK,
};
///
@ -64,13 +77,18 @@ const DataElement = union(DataElementType) {
U8: u8,
U16: u16,
U32: u32,
ECmosStatusRegister: cmos.StatusRegister,
ECmosRtcRegister: cmos.RtcRegister,
PTR_CONST_GdtPtr: *const gdt.GdtPtr,
IdtPtr: idt.IdtPtr,
GdtPtr: gdt.GdtPtr,
PTR_CONST_IdtPtr: *const idt.IdtPtr,
USIZE: usize,
PTR_ALLOCATOR: *std.mem.Allocator,
ECMOSSTATUSREGISTER: cmos.StatusRegister,
ECMOSRTCREGISTER: cmos.RtcRegister,
GDTPTR: gdt.GdtPtr,
IDTPTR: idt.IdtPtr,
IDTENTRY: idt.IdtEntry,
PTR_CONST_GDTPTR: *const gdt.GdtPtr,
PTR_CONST_IDTPTR: *const idt.IdtPtr,
ERROR_IDTERROR_VOID: idt.IdtError!void,
ERROR_MEM_PTRTASK: std.mem.Allocator.Error!*task.Task,
PTR_TASK: *task.Task,
EFN_OVOID: fn () callconv(.C) void,
NFN_OVOID: fn () callconv(.Naked) void,
FN_OVOID: fn () void,
@ -78,21 +96,27 @@ const DataElement = union(DataElementType) {
FN_OU16: fn () u16,
FN_IU8_OBOOL: fn (u8) bool,
FN_IU8_OVOID: fn (u8) void,
FN_IUSIZE_OVOID: fn (usize) void,
FN_IU16_OVOID: fn (u16) void,
FN_IU16_OU8: fn (u16) u8,
FN_IU4_IU4_OU8: fn (u4, u4) u8,
FN_IU8_IU8_OU16: fn (u8, u8) u16,
FN_IU16_IU8_OVOID: fn (u16, u8) void,
FN_IU16_IU16_OVOID: fn (u16, u16) void,
FN_IECmosStatusRegister_IBOOL_OU8: fn (cmos.StatusRegister, bool) u8,
FN_IECmosStatusRegister_IU8_IBOOL_OVOID: fn (cmos.StatusRegister, u8, bool) void,
FN_IECmosRtcRegister_OU8: fn (cmos.RtcRegister) u8,
FN_IECMOSSTATUSREGISTER_IBOOL_OU8: fn (cmos.StatusRegister, bool) u8,
FN_IECMOSSTATUSREGISTER_IU8_IBOOL_OVOID: fn (cmos.StatusRegister, u8, bool) void,
FN_IECMOSRTCREGISTER_OU8: fn (cmos.RtcRegister) u8,
FN_IU8_IEFNOVOID_OERRORIDTERRORVOID: fn (u8, fn () callconv(.C) void) idt.IdtError!void,
FN_IU8_INFNOVOID_OERRORIDTERRORVOID: fn (u8, fn () callconv(.Naked) void) idt.IdtError!void,
FN_IPTRCONSTGDTPTR_OVOID: fn (*const gdt.GdtPtr) void,
FN_IPTRCONSTIDTPTR_OVOID: fn (*const idt.IdtPtr) void,
FN_OGDTPTR: fn () gdt.GdtPtr,
FN_OIDTPTR: fn () idt.IdtPtr,
FN_IIDTENTRY_OBOOL: fn (idt.IdtEntry) bool,
FN_IPTRTask_IUSIZE_OVOID: fn (*task.Task, usize) void,
FN_IPTRTASK_IPTRALLOCATOR_OVOID: fn (*task.Task, *std.mem.Allocator) void,
FN_IFNOVOID_OMEMERRORPTRTASK: fn (fn () void) std.mem.Allocator.Error!*task.Task,
FN_IFNOVOID_IPTRALLOCATOR_OMEMERRORPTRTASK: fn (fn () void, *std.mem.Allocator) std.mem.Allocator.Error!*task.Task,
};
///
@ -173,11 +197,18 @@ fn Mock() type {
u8 => DataElement{ .U8 = arg },
u16 => DataElement{ .U16 = arg },
u32 => DataElement{ .U32 = arg },
cmos.StatusRegister => DataElement{ .ECmosStatusRegister = arg },
cmos.RtcRegister => DataElement{ .ECmosRtcRegister = arg },
*const gdt.GdtPtr => DataElement{ .PTR_CONST_GdtPtr = arg },
*const idt.IdtPtr => DataElement{ .PTR_CONST_IdtPtr = arg },
usize => DataElement{ .USIZE = arg },
*std.mem.Allocator => DataElement{ .PTR_ALLOCATOR = arg },
cmos.StatusRegister => DataElement{ .ECMOSSTATUSREGISTER = arg },
cmos.RtcRegister => DataElement{ .ECMOSRTCREGISTER = arg },
gdt.GdtPtr => DataElement{ .GDTPTR = arg },
idt.IdtPtr => DataElement{ .IDTPTR = arg },
idt.IdtEntry => DataElement{ .IDTENTRY = arg },
*const gdt.GdtPtr => DataElement{ .PTR_CONST_GDTPTR = arg },
*const idt.IdtPtr => DataElement{ .PTR_CONST_IDTPTR = arg },
idt.IdtError!void => DataElement{ .ERROR_IDTERROR_VOID = arg },
std.mem.Allocator.Error!*task.Task => DataElement{ .ERROR_MEM_PTRTASK = arg },
*task.Task => DataElement{ .PTR_TASK = arg },
fn () callconv(.C) void => DataElement{ .EFN_OVOID = arg },
fn () callconv(.Naked) void => DataElement{ .NFN_OVOID = arg },
fn () void => DataElement{ .FN_OVOID = arg },
@ -185,19 +216,27 @@ fn Mock() type {
fn () u16 => DataElement{ .FN_OU16 = arg },
fn (u8) bool => DataElement{ .FN_IU8_OBOOL = arg },
fn (u8) void => DataElement{ .FN_IU8_OVOID = arg },
fn (usize) void => DataElement{ .FN_IUSIZE_OVOID = arg },
fn (u16) void => DataElement{ .FN_IU16_OVOID = arg },
fn (u16) u8 => DataElement{ .FN_IU16_OU8 = arg },
fn (u4, u4) u8 => DataElement{ .FN_IU4_IU4_OU8 = arg },
fn (u8, u8) u16 => DataElement{ .FN_IU8_IU8_OU16 = arg },
fn (u16, u8) void => DataElement{ .FN_IU16_IU8_OVOID = arg },
fn (u16, u16) void => DataElement{ .FN_IU16_IU16_OVOID = arg },
fn (cmos.StatusRegister, bool) u8 => DataElement{ .FN_IECmosStatusRegister_IBOOL_OU8 = arg },
fn (cmos.StatusRegister, u8, bool) void => DataElement{ .FN_IECmosStatusRegister_IU8_IBOOL_OVOID = arg },
fn (cmos.RtcRegister) u8 => DataElement{ .FN_IECmosRtcRegister_OU8 = arg },
fn (cmos.StatusRegister, bool) u8 => DataElement{ .FN_IECMOSSTATUSREGISTER_IBOOL_OU8 = arg },
fn (cmos.StatusRegister, u8, bool) void => DataElement{ .FN_IECMOSSTATUSREGISTER_IU8_IBOOL_OVOID = arg },
fn (cmos.RtcRegister) u8 => DataElement{ .FN_IECMOSRTCREGISTER_OU8 = arg },
fn (*const gdt.GdtPtr) void => DataElement{ .FN_IPTRCONSTGDTPTR_OVOID = arg },
fn () gdt.GdtPtr => DataElement{ .FN_OGDTPTR = arg },
fn (*const idt.IdtPtr) void => DataElement{ .FN_IPTRCONSTIDTPTR_OVOID = arg },
fn () idt.IdtPtr => DataElement{ .FN_OIDTPTR = arg },
fn (u8, fn () callconv(.C) void) idt.IdtError!void => DataElement{ .FN_IU8_IEFNOVOID_OERRORIDTERRORVOID = arg },
fn (u8, fn () callconv(.Naked) void) idt.IdtError!void => DataElement{ .FN_IU8_INFNOVOID_OERRORIDTERRORVOID = arg },
fn (idt.IdtEntry) bool => DataElement{ .FN_IIDTENTRY_OBOOL = arg },
fn (*task.Task, usize) void => DataElement{ .FN_IPTRTask_IUSIZE_OVOID = arg },
fn (*task.Task, *std.mem.Allocator) void => DataElement{ .FN_IPTRTASK_IPTRALLOCATOR_OVOID = arg },
fn (fn () void) std.mem.Allocator.Error!*task.Task => DataElement{ .FN_IFNOVOID_OMEMERRORPTRTASK = arg },
fn (fn () void, *std.mem.Allocator) std.mem.Allocator.Error!*task.Task => DataElement{ .FN_IFNOVOID_IPTRALLOCATOR_OMEMERRORPTRTASK = arg },
else => @compileError("Type not supported: " ++ @typeName(@TypeOf(arg))),
};
}
@ -218,34 +257,46 @@ fn Mock() type {
u8 => DataElementType.U8,
u16 => DataElementType.U16,
u32 => DataElementType.U32,
cmos.StatusRegister => DataElementType.ECmosStatusRegister,
cmos.RtcRegister => DataElementType.ECmosRtcRegister,
*const gdt.GdtPtr => DataElement.PTR_CONST_GdtPtr,
*const idt.IdtPtr => DataElement.PTR_CONST_IdtPtr,
gdt.GdtPtr => DataElement.GdtPtr,
idt.IdtPtr => DataElement.IdtPtr,
idt.IdtError!void => DataElement.ERROR_IDTERROR_VOID,
usize => DataElementType.USIZE,
*std.mem.Allocator => DataElementType.PTR_ALLOCATOR,
cmos.StatusRegister => DataElementType.ECMOSSTATUSREGISTER,
cmos.RtcRegister => DataElementType.ECMOSRTCREGISTER,
gdt.GdtPtr => DataElementType.GDTPTR,
idt.IdtPtr => DataElementType.IDTPTR,
idt.IdtEntry => DataElementType.IDTENTRY,
*const gdt.GdtPtr => DataElementType.PTR_CONST_GDTPTR,
*const idt.IdtPtr => DataElementType.PTR_CONST_IDTPTR,
idt.IdtError!void => DataElementType.ERROR_IDTERROR_VOID,
std.mem.Allocator.Error!*task.Task => DataElementType.ERROR_MEM_PTRTASK,
*task.Task => DataElementType.PTR_TASK,
fn () callconv(.C) void => DataElementType.EFN_OVOID,
fn () callconv(.Naked) void => DataElementType.NFN_OVOID,
fn () void => DataElementType.FN_OVOID,
fn () usize => DataElementType.FN_OUSIZE,
fn () u16 => DataElementType.FN_OU16,
fn (u8) bool => DataElementType.FN_IU8_OBOOL,
fn (u8) void => DataElementType.FN_IU8_OVOID,
fn (u16) void => DataElementType.FN_IU16_OVOID,
fn (usize) void => DataElementType.FN_IUSIZE_OVOID,
fn (u16) u8 => DataElementType.FN_IU16_OU8,
fn (u4, u4) u8 => DataElementType.FN_IU4_IU4_OU8,
fn (u8, u8) u16 => DataElementType.FN_IU8_IU8_OU16,
fn (u16, u8) void => DataElementType.FN_IU16_IU8_OVOID,
fn (u16, u16) void => DataElementType.FN_IU16_IU16_OVOID,
fn (cmos.StatusRegister, bool) u8 => DataElementType.FN_IECmosStatusRegister_IBOOL_OU8,
fn (cmos.StatusRegister, u8, bool) void => DataElementType.FN_IECmosStatusRegister_IU8_IBOOL_OVOID,
fn (cmos.RtcRegister) u8 => DataElementType.FN_IECmosRtcRegister_OU8,
fn (cmos.StatusRegister, bool) u8 => DataElementType.FN_IECMOSSTATUSREGISTER_IBOOL_OU8,
fn (cmos.StatusRegister, u8, bool) void => DataElementType.FN_IECMOSSTATUSREGISTER_IU8_IBOOL_OVOID,
fn (cmos.RtcRegister) u8 => DataElementType.FN_IECMOSRTCREGISTER_OU8,
fn (*const gdt.GdtPtr) void => DataElementType.FN_IPTRCONSTGDTPTR_OVOID,
fn (*const idt.IdtPtr) void => DataElementType.FN_IPTRCONSTIDTPTR_OVOID,
fn () gdt.GdtPtr => DataElementType.FN_OGDTPTR,
fn () idt.IdtPtr => DataElementType.FN_OIDTPTR,
fn (u8, fn () callconv(.C) void) idt.IdtError!void => DataElementType.FN_IU8_IEFNOVOID_OERRORIDTERRORVOID,
fn (u8, fn () callconv(.Naked) void) idt.IdtError!void => DataElementType.FN_IU8_INFNOVOID_OERRORIDTERRORVOID,
fn (idt.IdtEntry) bool => DataElementType.FN_IIDTENTRY_OBOOL,
fn (*task.Task, usize) void => DataElementType.FN_IPTRTask_IUSIZE_OVOID,
fn (*task.Task, *std.mem.Allocator) void => DataElementType.FN_IPTRTASK_IPTRALLOCATOR_OVOID,
fn (fn () void) std.mem.Allocator.Error!*task.Task => DataElementType.FN_IFNOVOID_OMEMERRORPTRTASK,
fn (fn () void, *std.mem.Allocator) std.mem.Allocator.Error!*task.Task => DataElementType.FN_IFNOVOID_IPTRALLOCATOR_OMEMERRORPTRTASK,
else => @compileError("Type not supported: " ++ @typeName(T)),
};
}
@ -268,34 +319,46 @@ fn Mock() type {
u8 => element.U8,
u16 => element.U16,
u32 => element.U32,
cmos.StatusRegister => element.ECmosStatusRegister,
cmos.RtcRegister => element.ECmosRtcRegister,
*const gdt.GdtPtr => element.PTR_CONST_GdtPtr,
*const idt.IdtPtr => element.PTR_CONST_IdtPtr,
gdt.GdtPtr => element.GdtPtr,
idt.IdtPtr => element.IdtPtr,
usize => element.USIZE,
*std.mem.Allocator => element.PTR_ALLOCATOR,
cmos.StatusRegister => element.ECMOSSTATUSREGISTER,
gdt.GdtPtr => element.GDTPTR,
idt.IdtPtr => element.IDTPTR,
idt.IdtEntry => element.IDTENTRY,
cmos.RtcRegister => element.ECMOSRTCREGISTER,
*const gdt.GdtPtr => element.PTR_CONST_GDTPTR,
*const idt.IdtPtr => element.PTR_CONST_IDTPTR,
idt.IdtError!void => element.ERROR_IDTERROR_VOID,
std.mem.Allocator.Error!*task.Task => element.ERROR_MEM_PTRTASK,
*task.Task => element.PTR_TASK,
fn () callconv(.C) void => element.EFN_OVOID,
fn () callconv(.Naked) void => element.NFN_OVOID,
fn () void => element.FN_OVOID,
fn () usize => element.FN_OUSIZE,
fn () u16 => element.FN_OU16,
fn (u8) bool => element.FN_IU8_OBOOL,
fn (u8) void => element.FN_IU8_OVOID,
fn (u16) void => element.FN_IU16_OVOID,
fn (usize) void => element.FN_IUSIZE_OVOID,
fn (u16) u8 => element.FN_IU16_OU8,
fn (u4, u4) u8 => element.FN_IU4_IU4_OU8,
fn (u8, u8) u16 => element.FN_IU8_IU8_OU16,
fn (u16, u8) void => element.FN_IU16_IU8_OVOID,
fn (u16, u16) void => element.FN_IU16_IU16_OVOID,
fn (cmos.StatusRegister, bool) u8 => element.FN_IECmosStatusRegister_IBOOL_OU8,
fn (cmos.StatusRegister, u8, bool) void => element.FN_IECmosStatusRegister_IU8_IBOOL_OVOID,
fn (cmos.RtcRegister) u8 => element.FN_IECmosRtcRegister_OU8,
fn (cmos.StatusRegister, bool) u8 => element.FN_IECMOSSTATUSREGISTER_IBOOL_OU8,
fn (cmos.StatusRegister, u8, bool) void => element.FN_IECMOSSTATUSREGISTER_IU8_IBOOL_OVOID,
fn (cmos.RtcRegister) u8 => element.FN_IECMOSRTCREGISTER_OU8,
fn (*const gdt.GdtPtr) void => element.FN_IPTRCONSTGDTPTR_OVOID,
fn (*const idt.IdtPtr) void => element.FN_IPTRCONSTIDTPTR_OVOID,
fn (u8, fn () callconv(.C) void) idt.IdtError!void => element.FN_IU8_IEFNOVOID_OERRORIDTERRORVOID,
fn (u8, fn () callconv(.Naked) void) idt.IdtError!void => element.FN_IU8_INFNOVOID_OERRORIDTERRORVOID,
fn () gdt.GdtPtr => element.FN_OGDTPTR,
fn () idt.IdtPtr => element.FN_OIDTPTR,
fn (idt.IdtEntry) bool => element.FN_IIDTENTRY_OBOOL,
fn (*task.Task, usize) void => element.FN_IPTRTask_IUSIZE_OVOID,
fn (*task.Task, *std.mem.Allocator) void => element.FN_IPTRTASK_IPTRALLOCATOR_OVOID,
fn (fn () void) std.mem.Allocator.Error!*task.Task => element.FN_IFNOVOID_OMEMERRORPTRTASK,
fn (fn () void, *std.mem.Allocator) std.mem.Allocator.Error!*task.Task => element.FN_IFNOVOID_IPTRALLOCATOR_OMEMERRORPTRTASK,
else => @compileError("Type not supported: " ++ @typeName(T)),
};
}
@ -614,7 +677,7 @@ fn getMockObject() *Mock() {
if (mock) |*m| {
return m;
} else {
warn("MOCK object doesn't exists, please initiate this test\n", .{});
warn("MOCK object doesn't exists, please initialise this test\n", .{});
expect(false);
unreachable;
}

View file

@ -0,0 +1,27 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const mock_framework = @import("mock_framework.zig");
pub const initTest = mock_framework.initTest;
pub const freeTest = mock_framework.freeTest;
pub const addTestParams = mock_framework.addTestParams;
pub const addConsumeFunction = mock_framework.addConsumeFunction;
pub const addRepeatFunction = mock_framework.addRepeatFunction;
const EntryPointFn = fn () void;
pub const Task = struct {
const Self = @This();
pid: u32,
stack: []u32,
stack_pointer: usize,
pub fn create(entry_point: EntryPointFn, allocator: *Allocator) Allocator.Error!*Task {
return mock_framework.performAction("Task.create", Allocator.Error!*Task, .{ entry_point, allocator });
}
pub fn destroy(self: *Self, allocator: *Allocator) void {
return mock_framework.performAction("Task.destroy", void, .{ self, allocator });
}
};

View file

@ -27,6 +27,9 @@ pub const TestMode = enum {
/// Run the panic runtime test.
Panic,
/// Run the scheduler runtime test.
Scheduler,
///
/// Return a string description for the test mode provided.
///
@ -41,6 +44,7 @@ pub const TestMode = enum {
.None => "Runs the OS normally (Default)",
.Initialisation => "Initialisation runtime tests",
.Panic => "Panic runtime tests",
.Scheduler => "Scheduler runtime tests",
};
}
};
@ -143,6 +147,35 @@ pub const RuntimeStep = struct {
}
}
///
/// This tests the OS's scheduling by checking that we schedule a task that prints the success.
///
/// Arguments:
/// IN/OUT self: *RuntimeStep - Self.
///
/// Return: bool
/// Whether the test has passed or failed.
///
fn test_scheduler(self: *RuntimeStep) bool {
var state: usize = 0;
while (true) {
const msg = self.get_msg() catch return false;
defer self.builder.allocator.free(msg);
std.debug.warn("{}\n", .{msg});
// Make sure `[INFO] Switched` then `[INFO] SUCCESS: Scheduler variables preserved` are logged in this order
if (std.mem.eql(u8, msg, "[INFO] Switched") and state == 0) {
state = 1;
} else if (std.mem.eql(u8, msg, "[INFO] SUCCESS: Scheduler variables preserved") and state == 1) {
state = 2;
}
if (state == 2) {
return true;
}
}
}
///
/// The make function that is called by the builder. This will create the qemu process with the
/// stdout as a Pipe. Then create the read thread to read the logs from the qemu stdout. Then
@ -204,7 +237,7 @@ pub const RuntimeStep = struct {
fn read_logs(self: *RuntimeStep) void {
const stream = self.os_proc.stdout.?.reader();
// Line shouldn't be longer than this
const max_line_length: usize = 128;
const max_line_length: usize = 1024;
while (true) {
const line = stream.readUntilDelimiterAlloc(self.builder.allocator, '\n', max_line_length) catch |e| switch (e) {
error.EndOfStream => {
@ -212,7 +245,10 @@ pub const RuntimeStep = struct {
// join the thread to exit nicely :)
return;
},
else => unreachable,
else => {
std.debug.warn("Unexpected error: {}\n", .{e});
unreachable;
},
};
// put line in the queue
@ -270,6 +306,7 @@ pub const RuntimeStep = struct {
.None => print_logs,
.Initialisation => test_init,
.Panic => test_panic,
.Scheduler => test_scheduler,
},
};
return runtime_step;