1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-11-20 11:16:10 -05:00

Add test for "kmemset"

This commit is contained in:
Braiden Vasco 2017-11-04 08:04:22 +00:00
parent a090c16af5
commit 63c0b3adf3
4 changed files with 36 additions and 6 deletions

View file

@ -9,13 +9,15 @@ run: run-iso
all: all-kernel all-iso all-libk all-test all: all-kernel all-iso all-libk all-test
clean: clean-kernel clean-iso clean-libk clean-test clean: clean-kernel clean-iso clean-libk clean-test
test: run-test
all-kernel: all-libk all-kernel: all-libk
make all -C arch make all -C arch
clean-kernel: clean-kernel:
make clean -C arch make clean -C arch
run-iso: all-kernel run-iso: all-iso
make run -C iso make run -C iso
all-iso: all-kernel all-iso: all-kernel
@ -30,8 +32,13 @@ all-libk:
clean-libk: clean-libk:
make clean -C libk make clean -C libk
test-libk: all-libk test-libk: all-test
make run -C test/libk make run -C test/libk
run-test: test-libk
all-test: all-libk
make all -C test/libk
clean-test: clean-test:
make clean -C test/libk make clean -C test/libk

View file

@ -1,8 +1,8 @@
void kmemset(void *const buffer, const unsigned char value, const unsigned int size) void kmemset(void *const buffer, const unsigned char value, const unsigned int size)
{ {
const unsigned char *end = buffer + size; unsigned char *const s = buffer;
for (unsigned char *p = buffer; p < end; ++p) { for (unsigned int i = 0; i < size; ++i) {
*p = value; s[i] = value;
} }
} }

View file

@ -2,7 +2,7 @@ CC = $(CCPREFIX)gcc
CFLAGS = -std=gnu99 -Wall -Wextra CFLAGS = -std=gnu99 -Wall -Wextra
BINS = strlen.bin BINS = strlen.bin memset.bin
run: all $(addprefix run-, $(BINS)) run: all $(addprefix run-, $(BINS))

23
test/libk/memset.c Normal file
View file

@ -0,0 +1,23 @@
#include <kernelmq/stdlib.h>
#include <assert.h>
#include <string.h>
int main()
{
char buffer[7];
kmemset(buffer, 0, 1);
assert(strlen(buffer) == 0);
kmemset(buffer, 1, 3);
kmemset(&buffer[3], 0, 4);
assert(strlen(buffer) == 3);
strcpy(buffer, "qwerty");
kmemset(&buffer[2], 'a', 2);
assert(!strcmp(buffer, "qwaaty"));
return 0;
}