From 992f292f89944cbbed22ff3643a904c7470ae48e Mon Sep 17 00:00:00 2001 From: fslongjin Date: Tue, 26 Jul 2022 15:43:33 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20ktest=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/Makefile | 4 ++-- kernel/ktest/Makefile | 8 ++++++++ kernel/ktest/ktest.h | 4 ++++ kernel/ktest/ktest_utils.h | 27 +++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 kernel/ktest/Makefile create mode 100644 kernel/ktest/ktest.h create mode 100644 kernel/ktest/ktest_utils.h diff --git a/kernel/Makefile b/kernel/Makefile index 9d11f6b2..390d5dca 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -18,7 +18,7 @@ LD_LIST := head.o OBJ_LIST := head.o -kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall +kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall ktest @@ -47,7 +47,7 @@ all: kernel # 重新链接 echo "Re-Linking kernel..." - ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") -T link.lds + ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ./debug/kallsyms.o -T link.lds echo "Generating kernel ELF file..." # 生成内核文件 objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf diff --git a/kernel/ktest/Makefile b/kernel/ktest/Makefile new file mode 100644 index 00000000..dce56893 --- /dev/null +++ b/kernel/ktest/Makefile @@ -0,0 +1,8 @@ + +CFLAGS += -I . + + +all: bitree.o + +bitree.o: test-bitree.c + gcc $(CFLAGS) -c test-bitree.c -o test-bitree.o \ No newline at end of file diff --git a/kernel/ktest/ktest.h b/kernel/ktest/ktest.h new file mode 100644 index 00000000..a2be05fb --- /dev/null +++ b/kernel/ktest/ktest.h @@ -0,0 +1,4 @@ +#pragma once +#include + +uint64_t ktest_test_bitree(uint64_t arg); \ No newline at end of file diff --git a/kernel/ktest/ktest_utils.h b/kernel/ktest/ktest_utils.h new file mode 100644 index 00000000..b186b6f3 --- /dev/null +++ b/kernel/ktest/ktest_utils.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#define assert(condition) ({ \ + int __condition = !!(condition); \ + if (unlikely(!(__condition))) \ + { \ + printk("[ kTEST FAILED ] Ktest Assertion Failed, file:%s, Line:%d\n", __FILE__, __LINE__); \ + } \ + likely(__condition); \ +}) + +#define kTEST(...) \ + do \ + { \ + printk("[ kTEST ] file:%s, Line:%d\t", __FILE__, __LINE__); \ + printk(__VA_ARGS__); \ + printk("\n"); \ + } while (0); + +/** + * @brief 测试用例函数表 + * + */ +typedef long (*ktest_case_table)(uint64_t arg0, uint64_t arg1); \ No newline at end of file