commit
c164f5ee4d
9 changed files with 42 additions and 42 deletions
|
@ -46,9 +46,9 @@ fn logCallback(context: void, str: []const u8) LoggingError!usize {
|
||||||
/// whether it is filtered.
|
/// whether it is filtered.
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
||||||
/// options.
|
/// options.
|
||||||
/// IN args: var - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn log(comptime level: Level, comptime format: []const u8, args: var) void {
|
pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void {
|
||||||
fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
|
fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ pub fn log(comptime level: Level, comptime format: []const u8, args: var) void {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
||||||
/// options.
|
/// options.
|
||||||
/// IN args: var - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn logInfo(comptime format: []const u8, args: var) void {
|
pub fn logInfo(comptime format: []const u8, args: anytype) void {
|
||||||
log(Level.INFO, format, args);
|
log(Level.INFO, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ pub fn logInfo(comptime format: []const u8, args: var) void {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
||||||
/// options.
|
/// options.
|
||||||
/// IN args: var - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn logDebug(comptime format: []const u8, args: var) void {
|
pub fn logDebug(comptime format: []const u8, args: anytype) void {
|
||||||
log(Level.DEBUG, format, args);
|
log(Level.DEBUG, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,9 +82,9 @@ pub fn logDebug(comptime format: []const u8, args: var) void {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
||||||
/// options.
|
/// options.
|
||||||
/// IN args: var - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn logWarning(comptime format: []const u8, args: var) void {
|
pub fn logWarning(comptime format: []const u8, args: anytype) void {
|
||||||
log(Level.WARNING, format, args);
|
log(Level.WARNING, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ pub fn logWarning(comptime format: []const u8, args: var) void {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
/// IN comptime format: []const u8 - The message format. Uses the standard format specification
|
||||||
/// options.
|
/// options.
|
||||||
/// IN args: var - A struct of the parameters for the format string.
|
/// IN args: anytype - A struct of the parameters for the format string.
|
||||||
///
|
///
|
||||||
pub fn logError(comptime format: []const u8, args: var) void {
|
pub fn logError(comptime format: []const u8, args: anytype) void {
|
||||||
log(Level.ERROR, format, args);
|
log(Level.ERROR, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,12 @@ pub var ADDR_OFFSET: usize = undefined;
|
||||||
/// Convert a virtual address to its physical counterpart by subtracting the kernel virtual offset from the virtual address.
|
/// Convert a virtual address to its physical counterpart by subtracting the kernel virtual offset from the virtual address.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN virt: var - The virtual address to covert. Either an integer or pointer.
|
/// IN virt: anytype - The virtual address to covert. Either an integer or pointer.
|
||||||
///
|
///
|
||||||
/// Return: @TypeOf(virt)
|
/// Return: @TypeOf(virt)
|
||||||
/// The physical address.
|
/// The physical address.
|
||||||
///
|
///
|
||||||
pub fn virtToPhys(virt: var) @TypeOf(virt) {
|
pub fn virtToPhys(virt: anytype) @TypeOf(virt) {
|
||||||
const T = @TypeOf(virt);
|
const T = @TypeOf(virt);
|
||||||
return switch (@typeInfo(T)) {
|
return switch (@typeInfo(T)) {
|
||||||
.Pointer => @intToPtr(T, @ptrToInt(virt) - ADDR_OFFSET),
|
.Pointer => @intToPtr(T, @ptrToInt(virt) - ADDR_OFFSET),
|
||||||
|
@ -83,12 +83,12 @@ pub fn virtToPhys(virt: var) @TypeOf(virt) {
|
||||||
/// Convert a physical address to its virtual counterpart by adding the kernel virtual offset to the physical address.
|
/// Convert a physical address to its virtual counterpart by adding the kernel virtual offset to the physical address.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN phys: var - The physical address to covert. Either an integer or pointer.
|
/// IN phys: anytype - The physical address to covert. Either an integer or pointer.
|
||||||
///
|
///
|
||||||
/// Return: @TypeOf(virt)
|
/// Return: @TypeOf(virt)
|
||||||
/// The virtual address.
|
/// The virtual address.
|
||||||
///
|
///
|
||||||
pub fn physToVirt(phys: var) @TypeOf(phys) {
|
pub fn physToVirt(phys: anytype) @TypeOf(phys) {
|
||||||
const T = @TypeOf(phys);
|
const T = @TypeOf(phys);
|
||||||
return switch (@typeInfo(T)) {
|
return switch (@typeInfo(T)) {
|
||||||
.Pointer => @intToPtr(T, @ptrToInt(phys) + ADDR_OFFSET),
|
.Pointer => @intToPtr(T, @ptrToInt(phys) + ADDR_OFFSET),
|
||||||
|
|
|
@ -105,7 +105,7 @@ fn logTraceAddress(addr: usize) void {
|
||||||
log.logError("{x}: {}\n", .{ addr, str });
|
log.logError("{x}: {}\n", .{ addr, str });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn {
|
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn {
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
log.logError("Kernel panic: " ++ format ++ "\n", args);
|
log.logError("Kernel panic: " ++ format ++ "\n", args);
|
||||||
if (trace) |trc| {
|
if (trace) |trc| {
|
||||||
|
|
|
@ -47,9 +47,9 @@ fn printCallback(ctx: void, str: []const u8) !usize {
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN comptime format: []const u8 - The format string to print
|
/// IN comptime format: []const u8 - The format string to print
|
||||||
/// IN args: var - The arguments to be used in the formatted string
|
/// IN args: anytype - The arguments to be used in the formatted string
|
||||||
///
|
///
|
||||||
pub fn print(comptime format: []const u8, args: var) void {
|
pub fn print(comptime format: []const u8, args: anytype) void {
|
||||||
// Printing can't error because of the scrolling, if it does, we have a big problem
|
// Printing can't error because of the scrolling, if it does, we have a big problem
|
||||||
fmt.format(OutStream{ .context = {} }, format, args) catch |e| {
|
fmt.format(OutStream{ .context = {} }, format, args) catch |e| {
|
||||||
log.logError("TTY: Error printing. Error: {}\n", .{e});
|
log.logError("TTY: Error printing. Error: {}\n", .{e});
|
||||||
|
|
|
@ -417,7 +417,7 @@ const TestFS = struct {
|
||||||
self.allocator.destroy(self.fs);
|
self.allocator.destroy(self.fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getTreeNode(test_fs: *Self, node: var) Allocator.Error!?*TreeNode {
|
fn getTreeNode(test_fs: *Self, node: anytype) Allocator.Error!?*TreeNode {
|
||||||
switch (@TypeOf(node)) {
|
switch (@TypeOf(node)) {
|
||||||
*const Node, *const FileNode, *const DirNode => {},
|
*const Node, *const FileNode, *const DirNode => {},
|
||||||
else => @compileError("Node is of type " ++ @typeName(@TypeOf(node)) ++ ". Only *const Node, *const FileNode and *const DirNode are supported"),
|
else => @compileError("Node is of type " ++ @typeName(@TypeOf(node)) ++ ". Only *const Node, *const FileNode and *const DirNode are supported"),
|
||||||
|
|
|
@ -12,22 +12,22 @@ pub const Level = enum {
|
||||||
ERROR,
|
ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn log(comptime level: Level, comptime format: []const u8, args: var) void {
|
pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void {
|
||||||
//return mock_framework.performAction("log", void, level, format, args);
|
//return mock_framework.performAction("log", void, level, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logInfo(comptime format: []const u8, args: var) void {
|
pub fn logInfo(comptime format: []const u8, args: anytype) void {
|
||||||
//return mock_framework.performAction("logInfo", void, format, args);
|
//return mock_framework.performAction("logInfo", void, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logDebug(comptime format: []const u8, args: var) void {
|
pub fn logDebug(comptime format: []const u8, args: anytype) void {
|
||||||
//return mock_framework.performAction("logDebug", void, format, args);
|
//return mock_framework.performAction("logDebug", void, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logWarning(comptime format: []const u8, args: var) void {
|
pub fn logWarning(comptime format: []const u8, args: anytype) void {
|
||||||
//return mock_framework.performAction("logWarning", void, format, args);
|
//return mock_framework.performAction("logWarning", void, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logError(comptime format: []const u8, args: var) void {
|
pub fn logError(comptime format: []const u8, args: anytype) void {
|
||||||
//return mock_framework.performAction("logError", void, format, args);
|
//return mock_framework.performAction("logError", void, format, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub const MemProfile = struct {
|
||||||
// The size of the fixed allocator used before the heap is set up. Set to 1MiB.
|
// The size of the fixed allocator used before the heap is set up. Set to 1MiB.
|
||||||
const FIXED_ALLOC_SIZE = 1024 * 1024;
|
const FIXED_ALLOC_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
pub fn virtToPhys(virt: var) @TypeOf(virt) {
|
pub fn virtToPhys(virt: anytype) @TypeOf(virt) {
|
||||||
const T = @TypeOf(virt);
|
const T = @TypeOf(virt);
|
||||||
return switch (@typeInfo(T)) {
|
return switch (@typeInfo(T)) {
|
||||||
.Pointer => @intToPtr(T, @ptrToInt(virt) - KERNEL_ADDR_OFFSET),
|
.Pointer => @intToPtr(T, @ptrToInt(virt) - KERNEL_ADDR_OFFSET),
|
||||||
|
@ -40,7 +40,7 @@ pub fn virtToPhys(virt: var) @TypeOf(virt) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn physToVirt(phys: var) @TypeOf(phys) {
|
pub fn physToVirt(phys: anytype) @TypeOf(phys) {
|
||||||
const T = @TypeOf(phys);
|
const T = @TypeOf(phys);
|
||||||
return switch (@typeInfo(T)) {
|
return switch (@typeInfo(T)) {
|
||||||
.Pointer => @intToPtr(T, @ptrToInt(phys) + KERNEL_ADDR_OFFSET),
|
.Pointer => @intToPtr(T, @ptrToInt(phys) + KERNEL_ADDR_OFFSET),
|
||||||
|
|
|
@ -161,12 +161,12 @@ fn Mock() type {
|
||||||
/// to have a list of different types.
|
/// to have a list of different types.
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN arg: var - The data, this can be a function or basic type value.
|
/// IN arg: anytype - The data, this can be a function or basic type value.
|
||||||
///
|
///
|
||||||
/// Return: DataElement
|
/// Return: DataElement
|
||||||
/// A DataElement with the data wrapped.
|
/// A DataElement with the data wrapped.
|
||||||
///
|
///
|
||||||
fn createDataElement(arg: var) DataElement {
|
fn createDataElement(arg: anytype) DataElement {
|
||||||
return switch (@TypeOf(arg)) {
|
return switch (@TypeOf(arg)) {
|
||||||
bool => DataElement{ .BOOL = arg },
|
bool => DataElement{ .BOOL = arg },
|
||||||
u4 => DataElement{ .U4 = arg },
|
u4 => DataElement{ .U4 = arg },
|
||||||
|
@ -306,12 +306,12 @@ fn Mock() type {
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN RetType: type - The return type of the function.
|
/// IN RetType: type - The return type of the function.
|
||||||
/// IN params: var - The argument list for the function.
|
/// IN params: anytype - The argument list for the function.
|
||||||
///
|
///
|
||||||
/// Return: type
|
/// Return: type
|
||||||
/// A function type that represents the return type and its arguments.
|
/// A function type that represents the return type and its arguments.
|
||||||
///
|
///
|
||||||
fn getFunctionType(comptime RetType: type, params: var) type {
|
fn getFunctionType(comptime RetType: type, params: anytype) type {
|
||||||
return switch (params.len) {
|
return switch (params.len) {
|
||||||
0 => fn () RetType,
|
0 => fn () RetType,
|
||||||
1 => fn (@TypeOf(params[0])) RetType,
|
1 => fn (@TypeOf(params[0])) RetType,
|
||||||
|
@ -387,10 +387,10 @@ fn Mock() type {
|
||||||
/// IN/OUT self: *Self - Self. This is the mocking object to be modified to add
|
/// IN/OUT self: *Self - Self. This is the mocking object to be modified to add
|
||||||
/// the test data.
|
/// the test data.
|
||||||
/// IN fun_name: []const u8 - The function name to add the test parameters to.
|
/// IN fun_name: []const u8 - The function name to add the test parameters to.
|
||||||
/// IN data: var - The data to add.
|
/// IN data: anytype - The data to add.
|
||||||
/// IN action_type: ActionType - The action type to add.
|
/// IN action_type: ActionType - The action type to add.
|
||||||
///
|
///
|
||||||
pub fn addAction(self: *Self, comptime fun_name: []const u8, data: var, action_type: ActionType) void {
|
pub fn addAction(self: *Self, comptime fun_name: []const u8, data: anytype, action_type: ActionType) void {
|
||||||
// Add a new mapping if one doesn't exist.
|
// Add a new mapping if one doesn't exist.
|
||||||
if (!self.named_actions.contains(fun_name)) {
|
if (!self.named_actions.contains(fun_name)) {
|
||||||
self.named_actions.put(fun_name, TailQueue(Action).init()) catch unreachable;
|
self.named_actions.put(fun_name, TailQueue(Action).init()) catch unreachable;
|
||||||
|
@ -422,12 +422,12 @@ fn Mock() type {
|
||||||
/// perform a action.
|
/// perform a action.
|
||||||
/// IN fun_name: []const u8 - The function name to act on.
|
/// IN fun_name: []const u8 - The function name to act on.
|
||||||
/// IN RetType: type - The return type of the function being mocked.
|
/// IN RetType: type - The return type of the function being mocked.
|
||||||
/// IN params: var - The list of parameters of the mocked function.
|
/// IN params: anytype - The list of parameters of the mocked function.
|
||||||
///
|
///
|
||||||
/// Return: RetType
|
/// Return: RetType
|
||||||
/// The return value of the mocked function. This can be void.
|
/// The return value of the mocked function. This can be void.
|
||||||
///
|
///
|
||||||
pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: var) RetType {
|
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| {
|
if (self.named_actions.getEntry(fun_name)) |kv_actions_list| {
|
||||||
var action_list = kv_actions_list.value;
|
var action_list = kv_actions_list.value;
|
||||||
// Peak the first action to test the action type
|
// Peak the first action to test the action type
|
||||||
|
@ -655,9 +655,9 @@ pub fn freeTest() void {
|
||||||
/// IN/OUT self: *Self - Self. This is the mocking object to be modified to add
|
/// IN/OUT self: *Self - Self. This is the mocking object to be modified to add
|
||||||
/// the test parameters.
|
/// the test parameters.
|
||||||
/// IN fun_name: []const u8 - The function name to add the test parameters to.
|
/// IN fun_name: []const u8 - The function name to add the test parameters to.
|
||||||
/// IN params: var - The parameters to add.
|
/// IN params: anytype - The parameters to add.
|
||||||
///
|
///
|
||||||
pub fn addTestParams(comptime fun_name: []const u8, params: var) void {
|
pub fn addTestParams(comptime fun_name: []const u8, params: anytype) void {
|
||||||
var mock_obj = getMockObject();
|
var mock_obj = getMockObject();
|
||||||
comptime var i = 0;
|
comptime var i = 0;
|
||||||
inline while (i < params.len) : (i += 1) {
|
inline while (i < params.len) : (i += 1) {
|
||||||
|
@ -671,9 +671,9 @@ pub fn addTestParams(comptime fun_name: []const u8, params: var) void {
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN fun_name: []const u8 - The function name to add the function to.
|
/// IN fun_name: []const u8 - The function name to add the function to.
|
||||||
/// IN function: var - The function to add.
|
/// IN function: anytype - The function to add.
|
||||||
///
|
///
|
||||||
pub fn addConsumeFunction(comptime fun_name: []const u8, function: var) void {
|
pub fn addConsumeFunction(comptime fun_name: []const u8, function: anytype) void {
|
||||||
getMockObject().addAction(fun_name, function, ActionType.ConsumeFunctionCall);
|
getMockObject().addAction(fun_name, function, ActionType.ConsumeFunctionCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,9 +683,9 @@ pub fn addConsumeFunction(comptime fun_name: []const u8, function: var) void {
|
||||||
///
|
///
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN fun_name: []const u8 - The function name to add the function to.
|
/// IN fun_name: []const u8 - The function name to add the function to.
|
||||||
/// IN function: var - The function to add.
|
/// IN function: anytype - The function to add.
|
||||||
///
|
///
|
||||||
pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void {
|
pub fn addRepeatFunction(comptime fun_name: []const u8, function: anytype) void {
|
||||||
getMockObject().addAction(fun_name, function, ActionType.RepeatFunctionCall);
|
getMockObject().addAction(fun_name, function, ActionType.RepeatFunctionCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,11 +695,11 @@ pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// IN fun_name: []const u8 - The function name to act on.
|
/// IN fun_name: []const u8 - The function name to act on.
|
||||||
/// IN RetType: type - The return type of the function being mocked.
|
/// IN RetType: type - The return type of the function being mocked.
|
||||||
/// IN params: var - The list of parameters of the mocked function.
|
/// IN params: anytype - The list of parameters of the mocked function.
|
||||||
///
|
///
|
||||||
/// Return: RetType
|
/// Return: RetType
|
||||||
/// The return value of the mocked function. This can be void.
|
/// The return value of the mocked function. This can be void.
|
||||||
///
|
///
|
||||||
pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: var) RetType {
|
pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: anytype) RetType {
|
||||||
return getMockObject().performAction(fun_name, RetType, params);
|
return getMockObject().performAction(fun_name, RetType, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ const builtin = @import("builtin");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const MemProfile = @import("mem_mock.zig").MemProfile;
|
const MemProfile = @import("mem_mock.zig").MemProfile;
|
||||||
|
|
||||||
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn {
|
pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn {
|
||||||
@setCold(true);
|
@setCold(true);
|
||||||
std.debug.panic(format, args);
|
std.debug.panic(format, args);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue