From 82efaf9e266b8a5dea856e8e4e27e039ef367ca8 Mon Sep 17 00:00:00 2001 From: Nicolas 'Pixel' Noble Date: Wed, 10 Jun 2020 17:07:11 -0700 Subject: [PATCH] Starting to handle mips unit testing. --- .gitmodules | 3 ++ .vscode/launch.json | 22 +++++++++ src/mips/common.mk | 7 ++- src/mips/common/crt0/uC-sdk-crt0.s | 46 ++++++++++++++++++ src/mips/tests/basic/Makefile | 39 ++++++++++++++- src/mips/tests/basic/basic.c | 17 ++++--- src/mips/tests/uC-sdk-glue/BoardConsole.c | 58 +++++++++++++++++++++++ src/mips/tests/uC-sdk-glue/BoardConsole.h | 35 ++++++++++++++ src/mips/tests/uC-sdk-glue/BoardInit.c | 44 +++++++++++++++++ src/mips/tests/uC-sdk-glue/FreeRTOS.h | 28 +++++++++++ src/mips/tests/uC-sdk-glue/init.c | 34 +++++++++++++ src/mips/tests/uC-sdk-glue/semphr.h | 36 ++++++++++++++ tests/pcsxrunner/basic.cc | 2 +- third_party/libcester | 1 + 14 files changed, 363 insertions(+), 9 deletions(-) create mode 100644 src/mips/common/crt0/uC-sdk-crt0.s create mode 100644 src/mips/tests/uC-sdk-glue/BoardConsole.c create mode 100644 src/mips/tests/uC-sdk-glue/BoardConsole.h create mode 100644 src/mips/tests/uC-sdk-glue/BoardInit.c create mode 100644 src/mips/tests/uC-sdk-glue/FreeRTOS.h create mode 100644 src/mips/tests/uC-sdk-glue/init.c create mode 100644 src/mips/tests/uC-sdk-glue/semphr.h create mode 160000 third_party/libcester diff --git a/.gitmodules b/.gitmodules index c7de386f..81310b5a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule "third_party/http-parser"] path = third_party/http-parser url = https://github.com/nodejs/http-parser.git +[submodule "third_party/libcester"] + path = third_party/libcester + url = https://github.com/exoticlibraries/libcester.git diff --git a/.vscode/launch.json b/.vscode/launch.json index 5b913185..89c9aa10 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,6 +26,28 @@ "valuesFormatting": "parseText" }, + { + "type": "gdb", + "request": "launch", + "name": "(gdb) Launch Basic Test", + "target": "./src/mips/tests/basic/basic.elf", + "gdbpath": "/usr/bin/gdb-multiarch", + "windows": { + "gdbpath": "C:/gdb-multiarch/bin/gdb.exe", + }, + "cwd": "${workspaceRoot}", + "autorun": [ + "target remote localhost:3333", + "symbol-file ./src/mips/tests/basic/basic.elf", + "set substitute-path /project .", + "load ./src/mips/tests/basic/basic.elf", + "monitor reset halt", + "tbreak main", + "continue", + ], + "valuesFormatting": "parseText" + }, + { "name": "(gdb) Launch PCSX-Redux", "type": "cppdbg", diff --git a/src/mips/common.mk b/src/mips/common.mk index a6cb3496..15f83c57 100644 --- a/src/mips/common.mk +++ b/src/mips/common.mk @@ -8,9 +8,14 @@ CC = $(PREFIX)-gcc TYPE ?= cpe LDSCRIPT ?= $(ROOTDIR)/$(TYPE).ld +USE_FUNCTION_SECTIONS ?= true + ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32 ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding -CPPFLAGS += -mno-gpopt -fomit-frame-pointer -ffunction-sections +ifeq ($(USE_FUNCTION_SECTIONS),true) +CPPFLAGS += -ffunction-sections +endif +CPPFLAGS += -mno-gpopt -fomit-frame-pointer CPPFLAGS += -fno-builtin -fno-strict-aliasing -Wno-attributes CPPFLAGS += $(ARCHFLAGS) CPPFLAGS += -I$(ROOTDIR) diff --git a/src/mips/common/crt0/uC-sdk-crt0.s b/src/mips/common/crt0/uC-sdk-crt0.s new file mode 100644 index 00000000..41f134d1 --- /dev/null +++ b/src/mips/common/crt0/uC-sdk-crt0.s @@ -0,0 +1,46 @@ +/* + +MIT License + +Copyright (c) 2020 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + .section .start, "ax", @progbits + .align 2 + .global _ucsdk_start + .global _start + .type _start, @function + +_start: + la $t0, __bss_start + la $t1, __bss_end + + beq $t0, $t1, bss_init_skip + +bss_init: + sw $0, 0($t0) + addiu $t0, 4 + bne $t0, $t1, bss_init + +bss_init_skip: + + j _ucsdk_start diff --git a/src/mips/tests/basic/Makefile b/src/mips/tests/basic/Makefile index 3b0065b6..08b69241 100644 --- a/src/mips/tests/basic/Makefile +++ b/src/mips/tests/basic/Makefile @@ -1,8 +1,45 @@ TARGET = basic +USE_FUNCTION_SECTIONS = false +TYPE = ps-exe SRCS = \ +../uC-sdk-glue/BoardConsole.c \ +../uC-sdk-glue/BoardInit.c \ +../uC-sdk-glue/init.c \ +\ +../../../../third_party/uC-sdk/libc/src/cxx-glue.c \ +../../../../third_party/uC-sdk/libc/src/errno.c \ +../../../../third_party/uC-sdk/libc/src/initfini.c \ +../../../../third_party/uC-sdk/libc/src/malloc.c \ +../../../../third_party/uC-sdk/libc/src/qsort.c \ +../../../../third_party/uC-sdk/libc/src/rand.c \ +../../../../third_party/uC-sdk/libc/src/reent.c \ +../../../../third_party/uC-sdk/libc/src/stdio.c \ +../../../../third_party/uC-sdk/libc/src/strto.c \ +../../../../third_party/uC-sdk/libc/src/unistd.c \ +../../../../third_party/uC-sdk/libc/src/xprintf.c \ +../../../../third_party/uC-sdk/libc/src/xscanf.c \ +../../../../third_party/uC-sdk/libc/src/yscanf.c \ +../../../../third_party/uC-sdk/os/src/devfs.c \ +../../../../third_party/uC-sdk/os/src/filesystem.c \ +../../../../third_party/uC-sdk/os/src/fio.c \ +../../../../third_party/uC-sdk/os/src/hash-djb2.c \ +../../../../third_party/uC-sdk/os/src/init.c \ +../../../../third_party/uC-sdk/os/src/osdebug.c \ +../../../../third_party/uC-sdk/os/src/romfs.c \ +../../../../third_party/uC-sdk/os/src/sbrk.c \ + + +CPPFLAGS = -DNOFLOATINGPOINT +CPPFLAGS += -I. +CPPFLAGS += -I../../../../third_party/uC-sdk/libc/include +CPPFLAGS += -I../../../../third_party/uC-sdk/os/include +CPPFLAGS += -I../../../../third_party/libcester/include +CPPFLAGS += -I../../openbios/uC-sdk-glue + +SRCS += \ ../../common/syscalls/printf.s \ -../../common/crt0/crt0.s \ +../../common/crt0/uC-sdk-crt0.s \ basic.c \ include ../../common.mk diff --git a/src/mips/tests/basic/basic.c b/src/mips/tests/basic/basic.c index 4d81b26a..6695aefd 100644 --- a/src/mips/tests/basic/basic.c +++ b/src/mips/tests/basic/basic.c @@ -2,7 +2,7 @@ MIT License -Copyright (c) 2019 PCSX-Redux authors +Copyright (c) 2020 PCSX-Redux authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -24,11 +24,16 @@ SOFTWARE. */ -#include "common/hardware/pcsxhw.h" #include "common/syscalls/syscalls.h" -int main() { +#undef unix +#define CESTER_NO_SIGNAL +#define CESTER_NO_TIME +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 +#include "exotic/cester.h" + +CESTER_TEST(test1, test_instance, ramsyscall_printf("Hello world\n"); - pcsx_exit(0); - while (1); -} + cester_assert_equal(NULL, NULL); +) diff --git a/src/mips/tests/uC-sdk-glue/BoardConsole.c b/src/mips/tests/uC-sdk-glue/BoardConsole.c new file mode 100644 index 00000000..b81065d1 --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/BoardConsole.c @@ -0,0 +1,58 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#include "BoardConsole.h" + +#include "common/syscalls/syscalls.h" + +#include +#include + +void BoardConsoleInit() {} + +void BoardConsolePuts(const char * str) { + char c; + while ((c = *str++)) BoardConsolePutc(c); +} + +void BoardConsolePutc(int c) { + syscall_putchar(c); +} + +static void xprintfCallback(const char * str, int strsize, void * opaque0) { + while (strsize--) + BoardConsolePutc(*str++); +} + +void BoardConsolePrintf(const char * fmt, ...) { + va_list ap; + va_start(ap, fmt); + BoardConsoleVPrintf(fmt, ap); + va_end(ap);} + +void BoardConsoleVPrintf(const char * fmt, va_list ap) { + vxprintf(xprintfCallback, NULL, fmt, ap); +} diff --git a/src/mips/tests/uC-sdk-glue/BoardConsole.h b/src/mips/tests/uC-sdk-glue/BoardConsole.h new file mode 100644 index 00000000..321b683c --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/BoardConsole.h @@ -0,0 +1,35 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#pragma once + +#include + +void BoardConsoleInit(); +void BoardConsolePuts(const char * str); +void BoardConsolePutc(int); +void BoardConsolePrintf(const char * fmt, ...) __attribute__ ((format(printf, 1, 2))); +void BoardConsoleVPrintf(const char * fmt, va_list ap); diff --git a/src/mips/tests/uC-sdk-glue/BoardInit.c b/src/mips/tests/uC-sdk-glue/BoardInit.c new file mode 100644 index 00000000..7acdf263 --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/BoardInit.c @@ -0,0 +1,44 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#include "common/hardware/pcsxhw.h" + +void BoardEarlyInit() { +} + +void BoardInit() { +} + +void BoardLateInit() { +} + +void BoardShutdown() { + pcsx_exit(0); +} + +void BoardExceptionHandler(int code) { + pcsx_exit(code); +} diff --git a/src/mips/tests/uC-sdk-glue/FreeRTOS.h b/src/mips/tests/uC-sdk-glue/FreeRTOS.h new file mode 100644 index 00000000..010cf9d2 --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/FreeRTOS.h @@ -0,0 +1,28 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#pragma once + diff --git a/src/mips/tests/uC-sdk-glue/init.c b/src/mips/tests/uC-sdk-glue/init.c new file mode 100644 index 00000000..27aa4836 --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/init.c @@ -0,0 +1,34 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +void cpu_early_init() { +} + +void cpu_init() { +} + +void cpu_late_init() { +} diff --git a/src/mips/tests/uC-sdk-glue/semphr.h b/src/mips/tests/uC-sdk-glue/semphr.h new file mode 100644 index 00000000..9abd9d47 --- /dev/null +++ b/src/mips/tests/uC-sdk-glue/semphr.h @@ -0,0 +1,36 @@ +/* + +MIT License + +Copyright (c) 2019 PCSX-Redux authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#pragma once + +#include + +#define portMAX_DELAY 0 + +typedef void * xSemaphoreHandle; +static __inline void * xSemaphoreCreateMutex() { return NULL; } +static __inline void xSemaphoreTake(void * semaphore, unsigned timeout) {} +static __inline void xSemaphoreGive(void * semaphore) {} diff --git a/tests/pcsxrunner/basic.cc b/tests/pcsxrunner/basic.cc index cbe739d4..1f1fa5c7 100644 --- a/tests/pcsxrunner/basic.cc +++ b/tests/pcsxrunner/basic.cc @@ -22,7 +22,7 @@ TEST(Basic, Meta) { MainInvoker invoker("-run", "-bios", "src/mips/openbios/openbios.bin", "-loadexe", - "src/mips/tests/basic/basic.cpe"); + "src/mips/tests/basic/basic.ps-exe"); int ret = invoker.invoke(); EXPECT_EQ(ret, 0); } diff --git a/third_party/libcester b/third_party/libcester new file mode 160000 index 00000000..0e0c97df --- /dev/null +++ b/third_party/libcester @@ -0,0 +1 @@ +Subproject commit 0e0c97dfbad6b256646d62ce32824836d87eebb9