From 0040fb1cda318dab665d64f653e3f4056e36a800 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Sat, 30 Oct 2021 15:43:40 +0200 Subject: [PATCH] Add basic test for process --- core/main.c | 2 ++ core/process.h | 1 + tests/test.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/core/main.c b/core/main.c index e3d074e..f261810 100644 --- a/core/main.c +++ b/core/main.c @@ -15,6 +15,7 @@ #include "multiboot.h" #include "paging.h" #include "pit.h" +#include "process.h" #include "serial.h" #include "stack.h" #include "stdarg.h" @@ -170,6 +171,7 @@ void kmain(unsigned long magic, unsigned long addr) printf("[Setup] thread system\n"); threadSetup(_stack_bottom, (_stack_top - _stack_bottom + 1)); threadCreate("idle ", idleThread, NULL); + processSetup(); irqSetRoutine(IRQ_TIMER, pit_handler); diff --git a/core/process.h b/core/process.h index 4c6c9d2..61350bc 100644 --- a/core/process.h +++ b/core/process.h @@ -13,3 +13,4 @@ int processRef(struct process *proc); int processUnref(struct process *proc); int processSetName(struct process *proc, char *name); int processAddThread(struct process *proc, struct thread *th); +int processRemoveThread(struct thread *th); diff --git a/tests/test.c b/tests/test.c index 7bc66a3..4544a77 100644 --- a/tests/test.c +++ b/tests/test.c @@ -9,6 +9,7 @@ #include "mem.h" #include "mmuContext.h" #include "paging.h" +#include "process.h" #include "serial.h" #include "stack.h" #include "synchro.h" @@ -381,6 +382,23 @@ static void testMMUContext() mmuContextUnref(new); } + +static void testProcess(){ + struct process *proc= processCreate("TESTPROCESS"); + struct thread *th1 = threadCreate("th1", sleepThread, NULL); + struct thread *th2 = threadCreate("th2", sleepThread, NULL); + processAddThread(proc, th1); + processAddThread(proc, th2); + processListPrint(); + threadMsleep(600); + + processRemoveThread(th1); + processRemoveThread(th2); + processUnref(proc); + printf("Next process list should be empty\n"); + processListPrint(); +} + void run_test(void) { @@ -420,6 +438,7 @@ void run_test(void) testCoroutine(); testKthread(); testMMUContext(); + testProcess(); memGetStat(&afterFreemem, &afterUsedmem); printf("free %d -> %d\n", freemem, afterFreemem); }