diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/user/app/tests/shared | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/user/app/tests/shared')
-rw-r--r-- | src/user/app/tests/shared/printf.c | 55 | ||||
-rw-r--r-- | src/user/app/tests/shared/ringbuf.c | 49 |
2 files changed, 0 insertions, 104 deletions
diff --git a/src/user/app/tests/shared/printf.c b/src/user/app/tests/shared/printf.c deleted file mode 100644 index d8df48a..0000000 --- a/src/user/app/tests/shared/printf.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "../tests.h" -#include <stdio.h> -#include <string.h> - -#pragma GCC diagnostic ignored "-Wformat-truncation" - -static void test_printf(void) { - char buf[64]; - memset(buf, '?', 64); - - /* test proper overflow handling in snprintf */ - test(13 == snprintf(buf, 15, "That's 0x%x", 0x1337)); - test(!memcmp(buf, "That's 0x1337\0??", 16)); - test(17 == snprintf(buf, 15, "%05x %05x %05x", 0, 0, 0)); - test(!memcmp(buf, "00000 00000 00\0?", 16)); - - /* all the other stuff */ - snprintf(buf, sizeof buf, "%010x", 0x1BABE); - test(!strcmp(buf, "000001babe")); - snprintf(buf, sizeof buf, "%10x", 0x1BABE); - test(!strcmp(buf, " 1babe")); - snprintf(buf, sizeof buf, "%10s", "hello"); - test(!strcmp(buf, " hello")); - - snprintf(buf, sizeof buf, "%s%%%s", "ab", "cd"); - test(!strcmp(buf, "ab%cd")); - - snprintf(buf, sizeof buf, "%05u,%05u", 1234, 56789); - test(!strcmp(buf, "01234,56789")); - - snprintf(buf, sizeof buf, "%5d,%5d", 123, 4567); - test(!strcmp(buf, " 123, 4567")); - snprintf(buf, sizeof buf, "%5d,%5d", -123, -4567); - test(!strcmp(buf, " -123,-4567")); - - snprintf(buf, sizeof buf, "%u,%d,%x", 0, 0, 0); - test(!strcmp(buf, "0,0,0")); - - /* precision */ - snprintf(buf, sizeof buf, "%5.2u,%5.2d,%5.2x", 0, 0, 0); - test(!strcmp(buf, " 00, 00, 00")); - snprintf(buf, sizeof buf, "%5.2u,%5.2d,%5.2x", 10, -10, 0x10); - test(!strcmp(buf, " 10, -10, 10")); - snprintf(buf, sizeof buf, "%5.3d", -1); - test(!strcmp(buf, " -001")); - snprintf(buf, sizeof buf, "%.5d", 123); - test(!strcmp(buf, "00123")); - - snprintf(buf, sizeof buf, "%.1s,%.10s,%.*s", "hello", "hello", 3, "hello"); - test(!strcmp(buf, "h,hello,hel")); -} - -void r_s_printf(void) { - run_test(test_printf); -} diff --git a/src/user/app/tests/shared/ringbuf.c b/src/user/app/tests/shared/ringbuf.c deleted file mode 100644 index d2a35a1..0000000 --- a/src/user/app/tests/shared/ringbuf.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "../tests.h" -#include <shared/ring.h> -#include <string.h> - -static void test_ringbuf(void) { - char backbuf[16], cmpbuf[16]; - size_t num_read = 0, num_written = 0; - uint8_t c; - - ring_t r = {backbuf, 16, 0, 0}; - - /* aliasing */ - for (size_t i = 0; i < 16; i++) { - test(ring_used(&r) == 0); - test(ring_avail(&r) == 16); - ring_put(&r, "11 bytes...", 11); - test(ring_used(&r) == 11); - test(ring_avail(&r) == 5); - - memset(cmpbuf, 0, sizeof cmpbuf); - test(ring_get(&r, cmpbuf, 16) == 11); - test(memcmp(cmpbuf, "11 bytes...", 11) == 0); - } - - test(ring_used(&r) == 0); - for (size_t i = 0; i < 7; i++) - ring_put1b(&r, num_written++); - test(ring_used(&r) == 7); - for (size_t i = 0; i < 3; i++) { - ring_get(&r, &c, 1); - test(num_read++ == c); - } - test(ring_used(&r) == 4); - - for (size_t j = 0; j < 40; j++) { - for (size_t i = 0; i < 7; i++) - ring_put1b(&r, num_written++ & 0xff); - test(ring_used(&r) == 11); - for (size_t i = 0; i < 7; i++) { - ring_get(&r, &c, 1); - test((num_read++ & 0xff) == c); - } - test(ring_used(&r) == 4); - } -} - -void r_s_ringbuf(void) { - run_test(test_ringbuf); -} |