summaryrefslogtreecommitdiff
path: root/src/kernel/tests
diff options
context:
space:
mode:
authordzwdz2021-08-03 18:44:54 +0200
committerdzwdz2021-08-03 18:44:54 +0200
commit5d5b1d775984fe0112c0e1f60500c7d8e9850337 (patch)
tree0c4e160b6559678d9f635ea6e76f9f60dfa34c3c /src/kernel/tests
parent5b2bb4e025919d74090d23cbabadfeec3b1e9dc4 (diff)
kernel: implement memcmp
Diffstat (limited to 'src/kernel/tests')
-rw-r--r--src/kernel/tests/main.c1
-rw-r--r--src/kernel/tests/tests.h2
-rw-r--r--src/kernel/tests/util.c26
3 files changed, 29 insertions, 0 deletions
diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c
index a7e9534..41ebe8d 100644
--- a/src/kernel/tests/main.c
+++ b/src/kernel/tests/main.c
@@ -13,6 +13,7 @@ void tests_all() {
_did_tests_fail = false;
TEST_RUN(basic_math);
+ tests_utils();
if (_did_tests_fail)
panic();
diff --git a/src/kernel/tests/tests.h b/src/kernel/tests/tests.h
index d9abce4..78397da 100644
--- a/src/kernel/tests/tests.h
+++ b/src/kernel/tests/tests.h
@@ -1,3 +1,5 @@
#pragma once
void tests_all();
+
+void tests_utils();
diff --git a/src/kernel/tests/util.c b/src/kernel/tests/util.c
new file mode 100644
index 0000000..5bc8656
--- /dev/null
+++ b/src/kernel/tests/util.c
@@ -0,0 +1,26 @@
+#include <kernel/tests/base.h>
+#include <kernel/util.h>
+
+TEST(memcmp) {
+ // basic equality checks
+ TEST_IF(0 == memcmp("some", "thing", 0))
+ TEST_IF(0 != memcmp("some", "thing", 1))
+ TEST_IF(0 != memcmp("some", "thing", 4))
+
+ TEST_IF(0 == memcmp("test", "tennis", 0));
+ TEST_IF(0 == memcmp("test", "tennis", 1));
+ TEST_IF(0 == memcmp("test", "tennis", 2));
+ TEST_IF(0 != memcmp("test", "tennis", 3));
+ TEST_IF(0 != memcmp("test", "tennis", 4));
+ TEST_IF(0 != memcmp("test", "tennis", 5));
+
+ // test signs. does anyone even use that?
+ TEST_IF(0 > memcmp("foo", "moo", 4));
+ TEST_IF(0 < memcmp("moo", "foo", 4));
+ TEST_IF(0 > memcmp("555", "654", 3));
+ TEST_IF(0 < memcmp("654", "555", 3));
+}
+
+void tests_utils() {
+ TEST_RUN(memcmp);
+}