aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
commit787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6 (patch)
tree7db9f5102adc3d50ca85a8175ce67465256b8908
parentAdd TARGETBIN and TARGETLIB rules (diff)
downloadkernel-787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6.tar.xz
Move all tests next to the code they're testingHEADmaster
-rw-r--r--Makefile8
-rw-r--r--i686/Makefile2
-rw-r--r--i686/gdt.h2
-rw-r--r--i686/test/gdt.c20
-rw-r--r--i686/test_gdt.cc25
-rw-r--r--lib/Makefile10
-rwxr-xr-xlib/blake2/blake2s_genkat.py (renamed from lib/tst/blake2s_genkat.py)0
-rw-r--r--lib/blake2/test_blake2_kat.h (renamed from lib/tst/blake2s_kat.h)0
-rw-r--r--lib/blake2/test_blake2s_selftest.cc (renamed from lib/tst/blake2s_selftest.cc)5
-rw-r--r--lib/libk/endian/test_endian_little.cc (renamed from lib/tst/endian_little.cc)2
-rw-r--r--lib/libk/stdlib/test_allocator.hh (renamed from lib/tst/allocator.hh)0
-rw-r--r--lib/libk/stdlib/test_linked_list_allocator.cc (renamed from lib/tst/linked_list_allocator.cc)4
-rw-r--r--lib/libk/stdlib/test_mem.cc (renamed from lib/tst/mem.cc)4
-rw-r--r--lib/libk/string/test_string.cc (renamed from lib/tst/string.cc)2
-rw-r--r--rules.mk2
-rw-r--r--src/Makefile3
-rw-r--r--src/sched/test_roundrobin.cc (renamed from src/tst/roundrobin.cc)0
-rw-r--r--src/sched/test_taskqueue.cc (renamed from src/tst/taskqueue.cc)0
18 files changed, 53 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 33b5f76..34d166a 100644
--- a/Makefile
+++ b/Makefile
@@ -40,12 +40,16 @@ clean:
@${MAKE} -C src clean
test:
- @echo " -> Running tests in src"
- @make -C src test > /dev/null
+ @echo " -> Running tests in ${ARCH}"
+ @make -C ${ARCH} test > /dev/null
@echo " -> Running tests in lib"
@make -C lib test > /dev/null
+ @echo " -> Running tests in src"
+ @make -C src test > /dev/null
valgrind:
+ @echo " -> Running valgrind on tests in ${ARCH}"
+ @make -C ${ARCH} valgrind &> /dev/null
@echo " -> Running valgrind on tests in lib"
@make -C lib valgrind &> /dev/null
@echo " -> Running valgrind on tests in src"
diff --git a/i686/Makefile b/i686/Makefile
index ba780a9..ede39f0 100644
--- a/i686/Makefile
+++ b/i686/Makefile
@@ -9,5 +9,7 @@ arch.SRCS = boot.S init.s \
gdt.c lgdt.c \
lidt.c isr.c
+TESTS += test_gdt
+
include ../rules.mk
diff --git a/i686/gdt.h b/i686/gdt.h
index f00ff7f..91de365 100644
--- a/i686/gdt.h
+++ b/i686/gdt.h
@@ -16,7 +16,7 @@ struct __attribute__((packed)) Access {
};
_Static_assert(sizeof(struct Access) == 1, "access byte size");
-static const struct Access null_access = {false, false, false, false, false, false, false};
+static const struct Access null_access = {false, false, false, false, false, Ring0, false};
static const struct Access ktext_access = {.readwrite = true, .executable = true, .segment = true, .present = true};
static const struct Access kdata_access = {.readwrite = true, .segment = true, .present = true};
diff --git a/i686/test/gdt.c b/i686/test/gdt.c
deleted file mode 100644
index 2947b42..0000000
--- a/i686/test/gdt.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "gdt.h"
-#include <assert.h>
-#include <stdlib.h>
-
-int
-main()
-{
- assert(*(uint8_t *)&null_access == 0x00);
- assert(*(uint8_t *)&ktext_access == 0x9a);
- assert(*(uint8_t *)&kdata_access == 0x92);
-
- struct SegmentDescriptor_t d;
- SegmentDescriptor(&d, 0, 0, 0);
- assert(*(uint64_t *)&d == 0);
-
- assert(ktextDescriptor == 0x10);
- assert(kdataDescriptor == 0x18);
-
- return EXIT_SUCCESS;
-}
diff --git a/i686/test_gdt.cc b/i686/test_gdt.cc
new file mode 100644
index 0000000..d596c3a
--- /dev/null
+++ b/i686/test_gdt.cc
@@ -0,0 +1,25 @@
+#include <gtest/gtest.h>
+
+#define _Static_assert static_assert
+#include "gdt.c"
+#include "gdt.h"
+
+TEST(i686GDT, KnownAccessByteValues)
+{
+ EXPECT_EQ(*(uint8_t *)&null_access, 0x00);
+ EXPECT_EQ(*(uint8_t *)&ktext_access, 0x9a);
+ EXPECT_EQ(*(uint8_t *)&kdata_access, 0x92);
+}
+
+TEST(i686GDT, NullSegmentDescriptor)
+{
+ struct SegmentDescriptor_t d;
+ SegmentDescriptor(&d, 0, 0, 0);
+ EXPECT_EQ(*(uint64_t *)&d, 0);
+}
+
+TEST(i686GDT, SegmentIndex)
+{
+ EXPECT_EQ(ktextDescriptor, 0x10);
+ EXPECT_EQ(kdataDescriptor, 0x18);
+}
diff --git a/lib/Makefile b/lib/Makefile
index f5eeded..1301e04 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,5 +1,6 @@
include ../Makefile.config
+# minimal C standard library
TARGETLIB += libk
libk.SRCS = \
libk/endian/little.c \
@@ -7,11 +8,16 @@ libk.SRCS = \
libk/stdlib/memcpy.c libk/stdlib/memset.c libk/stdlib/linked_list_allocator.c \
libk/string/itoa.c
-TESTS += tst/endian_little tst/mem tst/string tst/linked_list_allocator
+TESTS += \
+ libk/endian/test_endian_little \
+ libk/stdlib/test_linked_list_allocator libk/stdlib/test_mem \
+ libk/string/test_string
+# blake2s hash algorithm
TARGETLIB += blake2
blake2.SRCS = blake2/blake2s.c
-TESTS += tst/blake2s_selftest
+
+TESTS += blake2/test_blake2s_selftest
include ../rules.mk
diff --git a/lib/tst/blake2s_genkat.py b/lib/blake2/blake2s_genkat.py
index 2dd5370..2dd5370 100755
--- a/lib/tst/blake2s_genkat.py
+++ b/lib/blake2/blake2s_genkat.py
diff --git a/lib/tst/blake2s_kat.h b/lib/blake2/test_blake2_kat.h
index aa42ef5..aa42ef5 100644
--- a/lib/tst/blake2s_kat.h
+++ b/lib/blake2/test_blake2_kat.h
diff --git a/lib/tst/blake2s_selftest.cc b/lib/blake2/test_blake2s_selftest.cc
index 58199f6..2c046b2 100644
--- a/lib/tst/blake2s_selftest.cc
+++ b/lib/blake2/test_blake2s_selftest.cc
@@ -1,9 +1,8 @@
// Self test Modules for BLAKE2s
+#include "blake2s.c"
+#include "test_blake2_kat.h"
#include <gtest/gtest.h>
-#include "../blake2/blake2s.c"
-#include "blake2s_kat.h"
-
static_assert(sizeof(BLAKE2s_param) == (8 * sizeof(uint32_t)), "sizeof struct BLAKE2s_param");
// Deterministic sequences (Fibonacci generator).
diff --git a/lib/tst/endian_little.cc b/lib/libk/endian/test_endian_little.cc
index 9c8c73b..97ee286 100644
--- a/lib/tst/endian_little.cc
+++ b/lib/libk/endian/test_endian_little.cc
@@ -2,7 +2,7 @@
#include <gtest/gtest.h>
namespace libk {
-#include "../libk/endian/little.c"
+#include "little.c"
} // namespace libk
TEST(endian_little, htole16)
diff --git a/lib/tst/allocator.hh b/lib/libk/stdlib/test_allocator.hh
index 3bc1715..3bc1715 100644
--- a/lib/tst/allocator.hh
+++ b/lib/libk/stdlib/test_allocator.hh
diff --git a/lib/tst/linked_list_allocator.cc b/lib/libk/stdlib/test_linked_list_allocator.cc
index a2575d5..5963ce1 100644
--- a/lib/tst/linked_list_allocator.cc
+++ b/lib/libk/stdlib/test_linked_list_allocator.cc
@@ -3,7 +3,7 @@
#include <iostream>
namespace libk {
-#include "../libk/stdlib/linked_list_allocator.c"
+#include "linked_list_allocator.c"
std::ostream &
operator<<(std::ostream &os, const Chunk &b)
@@ -16,7 +16,7 @@ operator<<(std::ostream &os, const Chunk &b)
}
}; // namespace libk
-#include "allocator.hh"
+#include "test_allocator.hh"
TEST(UninitializedAllocator, malloc) { EXPECT_EQ(libk::malloc(1024), nullptr); }
diff --git a/lib/tst/mem.cc b/lib/libk/stdlib/test_mem.cc
index 1ad266c..f8a5e18 100644
--- a/lib/tst/mem.cc
+++ b/lib/libk/stdlib/test_mem.cc
@@ -3,8 +3,8 @@
#define restrict __restrict__
namespace libk {
-#include "../libk/stdlib/memcpy.c"
-#include "../libk/stdlib/memset.c"
+#include "memcpy.c"
+#include "memset.c"
} // namespace libk
TEST(mem, memset)
diff --git a/lib/tst/string.cc b/lib/libk/string/test_string.cc
index f22c123..d12b318 100644
--- a/lib/tst/string.cc
+++ b/lib/libk/string/test_string.cc
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
namespace libk {
-#include "../libk/string/itoa.c"
+#include "itoa.c"
}
char buffer[64];
diff --git a/rules.mk b/rules.mk
index 833664d..eedf27f 100644
--- a/rules.mk
+++ b/rules.mk
@@ -117,7 +117,7 @@ ${ARCH}_CXXFLAGS += -I../lib/libk -Drestrict=__restrict__
@${HOST_CC} ${HOST_CFLAGS} -c -o $@ $<
# test rules
-tst/%: tst/%.cc
+test_%: test_%.cc
@echo ' CXX TEST $@'
@${HOST_CXX} ${HOST_CXXFLAGS} $< -o $@
diff --git a/src/Makefile b/src/Makefile
index f9ab6fe..3a5d41b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,7 +8,8 @@ TARGETLIB += kernel
kernel.SRCS := multiboot2.c mmap.c kernel.cpp mem/vmm.c
kernel.OBJS := conf.h
-TESTS += tst/taskqueue tst/roundrobin
+TESTS += \
+ sched/test_taskqueue sched/test_roundrobin
include ../rules.mk
diff --git a/src/tst/roundrobin.cc b/src/sched/test_roundrobin.cc
index 1431788..1431788 100644
--- a/src/tst/roundrobin.cc
+++ b/src/sched/test_roundrobin.cc
diff --git a/src/tst/taskqueue.cc b/src/sched/test_taskqueue.cc
index 217c44d..217c44d 100644
--- a/src/tst/taskqueue.cc
+++ b/src/sched/test_taskqueue.cc