diff options
Diffstat (limited to 'src/kernel/tests')
-rw-r--r-- | src/kernel/tests/base.h | 4 | ||||
-rw-r--r-- | src/kernel/tests/main.c | 1 | ||||
-rw-r--r-- | src/kernel/tests/tests.h | 1 | ||||
-rw-r--r-- | src/kernel/tests/util.c | 40 | ||||
-rw-r--r-- | src/kernel/tests/vfs.c | 35 |
5 files changed, 59 insertions, 22 deletions
diff --git a/src/kernel/tests/base.h b/src/kernel/tests/base.h index 877b179..4c91d10 100644 --- a/src/kernel/tests/base.h +++ b/src/kernel/tests/base.h @@ -14,10 +14,10 @@ extern bool _did_tests_fail; #define TEST_RUN(name) \ __test_##name(); -#define TEST_IF(cond) \ +#define TEST_COND(cond) \ if (!(cond)) { \ _did_tests_fail = true; \ - log_const("TEST_IF failed at " \ + log_const("test failed at " \ __FILE__ ":" NUM2STR(__LINE__) \ " "); \ } diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c index 8e5842b..db4363f 100644 --- a/src/kernel/tests/main.c +++ b/src/kernel/tests/main.c @@ -8,6 +8,7 @@ void tests_all() { _did_tests_fail = false; tests_utils(); + tests_vfs(); if (_did_tests_fail) panic(); diff --git a/src/kernel/tests/tests.h b/src/kernel/tests/tests.h index 78397da..5b9697c 100644 --- a/src/kernel/tests/tests.h +++ b/src/kernel/tests/tests.h @@ -3,3 +3,4 @@ void tests_all(); void tests_utils(); +void tests_vfs(); diff --git a/src/kernel/tests/util.c b/src/kernel/tests/util.c index 45c728e..3bc2124 100644 --- a/src/kernel/tests/util.c +++ b/src/kernel/tests/util.c @@ -3,34 +3,34 @@ 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_COND(0 == memcmp("some", "thing", 0)); + TEST_COND(0 != memcmp("some", "thing", 1)); + TEST_COND(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_COND(0 == memcmp("test", "tennis", 0)); + TEST_COND(0 == memcmp("test", "tennis", 1)); + TEST_COND(0 == memcmp("test", "tennis", 2)); + TEST_COND(0 != memcmp("test", "tennis", 3)); + TEST_COND(0 != memcmp("test", "tennis", 4)); + TEST_COND(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)); + TEST_COND(0 > memcmp("foo", "moo", 4)); + TEST_COND(0 < memcmp("moo", "foo", 4)); + TEST_COND(0 > memcmp("555", "654", 3)); + TEST_COND(0 < memcmp("654", "555", 3)); } TEST(static_strcmp) { - TEST_IF(0 == static_strcmp("", "")); - TEST_IF(0 == static_strcmp("same", "same")); + TEST_COND(0 == static_strcmp("", "")); + TEST_COND(0 == static_strcmp("same", "same")); - TEST_IF(0 != static_strcmp("same", "diff")); - TEST_IF(0 != static_strcmp("same!", "same")); - TEST_IF(0 != static_strcmp("same", "same!")); + TEST_COND(0 != static_strcmp("same", "diff")); + TEST_COND(0 != static_strcmp("same!", "same")); + TEST_COND(0 != static_strcmp("same", "same!")); - TEST_IF(0 > static_strcmp("555", "654")); - TEST_IF(0 < static_strcmp("654", "555")); + TEST_COND(0 > static_strcmp("555", "654")); + TEST_COND(0 < static_strcmp("654", "555")); } void tests_utils() { diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c new file mode 100644 index 0000000..a5a6848 --- /dev/null +++ b/src/kernel/tests/vfs.c @@ -0,0 +1,35 @@ +#include <kernel/tests/base.h> +#include <kernel/util.h> +#include <kernel/vfs/path.h> + +TEST(path_simplify) { + char buf[256]; + + // some easy valid cases + TEST_COND( path_simplify("/asdf", buf, 5)); + TEST_COND( path_simplify("/asd/", buf, 5)); + TEST_COND( path_simplify("/a/./", buf, 5)); + TEST_COND( path_simplify("/a/..", buf, 5)); + TEST_COND( path_simplify("/a//.", buf, 5)); + + // .. going under the root or close to it + TEST_COND(!path_simplify("/../123456", buf, 10)); + TEST_COND(!path_simplify("/./a/../..", buf, 10)); + TEST_COND( path_simplify("/a/a/../..", buf, 10)); + TEST_COND(!path_simplify("/////../..", buf, 10)); + TEST_COND(!path_simplify("//a//../..", buf, 10)); + + // relative paths aren't allowed + TEST_COND(!path_simplify("apath", buf, 5)); + TEST_COND(!path_simplify("a/pth", buf, 5)); + TEST_COND(!path_simplify("../th", buf, 5)); + + // this includes empty paths + TEST_COND(!path_simplify("", buf, 1)); + + // TODO test if the paths are simplified correctly +} + +void tests_vfs() { + TEST_RUN(path_simplify); +} |