From 0b120a722eb63cbd4e41ebb51950a949c575c91d Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Mon, 28 Dec 2020 19:35:51 +0100 Subject: [PATCH] add test cases for r_68k_pc32 --- AutomatedTests/CMakeLists.txt | 4 ++++ AutomatedTests/PCRel32.c | 29 +++++++++++++++++++++++++++++ AutomatedTests/Test.h | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 AutomatedTests/PCRel32.c diff --git a/AutomatedTests/CMakeLists.txt b/AutomatedTests/CMakeLists.txt index 957b25280a..3e670a38a0 100644 --- a/AutomatedTests/CMakeLists.txt +++ b/AutomatedTests/CMakeLists.txt @@ -75,6 +75,10 @@ if(CMAKE_SYSTEM_NAME MATCHES Retro68) LINK_FLAGS "-Wl,-gc-sections -Wl,--mac-segments -Wl,${CMAKE_CURRENT_SOURCE_DIR}/Segments.segmap") add_test(NAME ${TESTCASE_PREFIX}Segments COMMAND ${LAUNCH_APPL} ${LAUNCH_METHOD_FLAG} ${RETRO68_TEST_CONFIG} Segments.bin) + + + test(PCRel32.c PROPERTIES PASS_REGULAR_EXPRESSION "OK") + target_compile_options(PCRel32 PRIVATE -march=68020) endif() test(Exceptions.cc PROPERTIES PASS_REGULAR_EXPRESSION "OK") diff --git a/AutomatedTests/PCRel32.c b/AutomatedTests/PCRel32.c new file mode 100644 index 0000000000..3e040fad4f --- /dev/null +++ b/AutomatedTests/PCRel32.c @@ -0,0 +1,29 @@ +#include "Test.h" +#include + +__attribute__((noinline)) static void* foo(size_t x) +{ + return malloc(x); +} + +int main() +{ + if(*(short*)&foo != 0x60FF) + { + TEST_LOG_NO(); + return 0; + } + + uint32_t offset = *(uint32_t*) ((char*)&foo + 2); + if(((char*)&foo + 2) + offset != (char*)&malloc) + { + TEST_LOG_NO(); + return 0; + } + + char *p = foo(42); + strcpy(p, "OK"); + TestLog(p); + free(p); + return 0; +} diff --git a/AutomatedTests/Test.h b/AutomatedTests/Test.h index ad84002808..05cd052d99 100644 --- a/AutomatedTests/Test.h +++ b/AutomatedTests/Test.h @@ -87,8 +87,8 @@ void TestLog(const char *str); #define TEST_LOG_NO() \ do { \ char no[3]; \ - no[0] = 'O'; \ - no[1] = 'K'; \ + no[0] = 'N'; \ + no[1] = 'O'; \ no[2] = '\0'; \ TEST_LOG_SIZED(no, 2); \ } while(0)