init commit
This commit is contained in:
33
tests/test_basic.c
Normal file
33
tests/test_basic.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
/* memcpy */
|
||||
char src[] = "hello world";
|
||||
char dst[64];
|
||||
memcpy(dst, src, 12);
|
||||
dst[12] = 0;
|
||||
assert(strcmp(dst, "hello world") == 0);
|
||||
|
||||
/* strlen */
|
||||
assert(strlen("") == 0);
|
||||
assert(strlen("abc") == 3);
|
||||
|
||||
/* memset */
|
||||
char buf[10];
|
||||
memset(buf, 0xAB, 10);
|
||||
for (int i = 0; i < 10; i++) assert((unsigned char)buf[i] == 0xAB);
|
||||
|
||||
/* memcmp */
|
||||
assert(memcmp("abc", "abc", 3) == 0);
|
||||
assert(memcmp("abc", "abd", 3) < 0);
|
||||
|
||||
/* strcmp */
|
||||
assert(strcmp("hello", "hello") == 0);
|
||||
assert(strcmp("abc", "def") < 0);
|
||||
|
||||
printf("ALL STRING TESTS PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
28
tests/test_string.c
Normal file
28
tests/test_string.c
Normal file
@@ -0,0 +1,28 @@
|
||||
typedef unsigned long size_t;
|
||||
void *memcpy(void *restrict d, const void *restrict s, size_t n);
|
||||
void *memset(void *d, int c, size_t n);
|
||||
int memcmp(const void *l, const void *r, size_t n);
|
||||
size_t strlen(const char *s);
|
||||
int strcmp(const char *l, const char *r);
|
||||
|
||||
void _start(void)
|
||||
{
|
||||
int code = 0;
|
||||
char src[] = "hello world", dst[64];
|
||||
memcpy(dst, src, 12); dst[12] = 0;
|
||||
if (strcmp(dst, "hello world") != 0) code = 1;
|
||||
else if (strlen("") != 0) code = 2;
|
||||
else if (strlen("abc") != 3) code = 3;
|
||||
else {
|
||||
char buf[10];
|
||||
memset(buf, 0xAB, 10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
if ((unsigned char)buf[i] != 0xAB) { code = 4; break; }
|
||||
}
|
||||
if (code == 0 && memcmp("abc", "abc", 3) != 0) code = 5;
|
||||
if (code == 0 && memcmp("abc", "abd", 3) >= 0) code = 6;
|
||||
if (code == 0 && strcmp("hello", "hello") != 0) code = 7;
|
||||
if (code == 0 && strcmp("abc", "def") >= 0) code = 8;
|
||||
|
||||
__asm__ volatile ("mov $60, %%eax\n syscall" : : "D"(code) : "rax");
|
||||
}
|
||||
Reference in New Issue
Block a user