]> git.corax.cc Git - corax/commitdiff
sys/test: Add userspace process for libc testing
authorMatthias Kruk <m@m10k.eu>
Sat, 1 Aug 2020 06:08:47 +0000 (15:08 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 8 Aug 2020 09:49:53 +0000 (18:49 +0900)
sys/Makefile
sys/initfs.c
sys/test/Makefile [new file with mode: 0644]
sys/test/main.c [new file with mode: 0644]

index d8846276cb8f04b0159ad2e3c1069dd68db65bda..8ae819f554e078554b94ce350e7daa07fc4713e9 100644 (file)
@@ -1,4 +1,4 @@
-DEPS = kbd vga io
+DEPS = kbd vga io test
 PHONY = $(DEPS) clean
 OUTPUT = initfs.a
 INCLUDES = -I.. -I../include
@@ -13,7 +13,9 @@ vga.ko: vga
 
 io.ko: io
 
-$(OUTPUT): initfs.o kbd.ko vga.ko io.ko
+test.ko: test
+
+$(OUTPUT): initfs.o kbd.ko vga.ko io.ko test.ko
        ar -rc $@ $^
 
 updateinitfs:
index 13de1c4b97512bb007679bcd587f5b762d41db70..a0ef264045337ab3593828c38e151f397ccc08e4 100644 (file)
@@ -19,6 +19,10 @@ extern const char _binary_io_start[];
 extern const unsigned long _binary_io_size;
 #endif /* FEATURE(VGA) */
 
+extern const char _binary_test_end[];
+extern const char _binary_test_start[];
+extern const unsigned long _binary_test_size;
+
 static struct initfs_entry _ifs_entries[] = {
 #if FEATURE(IO)
        {
@@ -41,6 +45,11 @@ static struct initfs_entry _ifs_entries[] = {
                .ife_limit = (unsigned long)&_binary_vga_size
        },
 #endif /* FEATURE(VGA) */
+       {
+               .ife_name = "test",
+               .ife_base = &_binary_test_start,
+               .ife_limit = (unsigned long)&_binary_test_size
+       }
 };
 
 struct initfs initfs = {
diff --git a/sys/test/Makefile b/sys/test/Makefile
new file mode 100644 (file)
index 0000000..5cf9b78
--- /dev/null
@@ -0,0 +1,26 @@
+OBJECTS = main.o
+OUTPUT = test
+MODULE = test.ko
+
+INCLUDES = -I../../include -I../..
+CFLAGS = -m32 -Wall -nostdlib -nodefaultlibs -nostartfiles -ffreestanding \
+        -nostdinc -fno-builtin -fno-builtin-memcpy
+LIBS = ../../libc/libc.a
+CFLAGS += $(INCLUDES)
+
+ASFLAGS = $(CFLAGS)
+PHONY = clean
+
+all: $(MODULE)
+
+$(MODULE): $(OUTPUT)
+       ld -r --oformat=elf32-i386 -m elf_i386 -b binary -o $@ $<
+       cp $@ ../
+
+$(OUTPUT): $(OBJECTS)
+       gcc -static $(CFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+       rm -f $(OBJECTS) $(OUTPUT)
+
+.PHONY: $(PHONY)
diff --git a/sys/test/main.c b/sys/test/main.c
new file mode 100644 (file)
index 0000000..ecba8fa
--- /dev/null
@@ -0,0 +1,48 @@
+#include <unistd.h>
+#include <crxstd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
+{
+       char buf[128];
+       int fds[2];
+       int ret_val;
+       void *abuf;
+       void *bbuf;
+       void *heap;
+
+       heap = sbrk(0);
+
+       ret_val = snprintf(buf, sizeof(buf), "Heap base: %p / 0x%08lx\n", heap, heap);
+       debug(buf, ret_val);
+
+       abuf = sbrk(2048);
+
+       ret_val = snprintf(buf, sizeof(buf), "Allocated 4096B at %p / 0x%08lx\n", abuf, abuf);
+       debug(buf, ret_val);
+
+       bbuf = malloc(4096);
+
+       ret_val = snprintf(buf, sizeof(buf), "Allocated 4096B at %p / 0x%08x\n", bbuf, buf);
+       debug(buf, ret_val);
+
+       ret_val = snprintf(buf, sizeof(buf), "Calling pipe()\n");
+       debug(buf, ret_val);
+
+       ret_val = pipe(fds);
+
+       ret_val = snprintf(buf, sizeof(buf), "pipe() returned %u\n", ret_val);
+       debug(buf, ret_val);
+
+       while(1) {
+               #if 0
+               struct cxmsg msg;
+
+               /* guaranteed to cause the process to be suspended */
+               cxrecv(PID_IO, &msg);
+               #endif
+       }
+
+       return(0);
+}