Skip to content

Commit

Permalink
[Atari 8-bit] initial compile / no-compile tests (#286)
Browse files Browse the repository at this point in the history
* [atari8'] initial tests

* refactor tests to add add_compile_test

"compile only" test can be used for targets where we don't have a
working emulator or test framework but want to check for possible
regressions in the SDK

* [atari8'] add compile tests

* [atari8'] remove unnecessary __attribute__((used))
  • Loading branch information
cwedgwood authored Jan 8, 2024
1 parent 632c38a commit 7385ba3
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ add_test_target(nes-unrom)
add_test_target(nes-unrom-512)
add_test_target(atari2600-4k)
add_test_target(atari2600-3e)
add_test_target(atari8-dos)
add_test_target(atari8-stdcart)
8 changes: 8 additions & 0 deletions test/atari8-dos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.18)

project(test-atari8-dos LANGUAGES C)

include(../test.cmake)

add_subdirectory(compile)
add_subdirectory(no-compile)
3 changes: 3 additions & 0 deletions test/atari8-dos/compile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON)

add_compile_test(minimal)
6 changes: 6 additions & 0 deletions test/atari8-dos/compile/minimal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#include <stdio.h>

int main(void) {
printf("hello\n");
}
3 changes: 3 additions & 0 deletions test/atari8-dos/no-compile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON)

add_no_compile_test(ram-too-big)
23 changes: 23 additions & 0 deletions test/atari8-dos/no-compile/ram-too-big.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ExpectFailure: ld.lld: error: section '.data' will not fit in region 'ram'

#include <stdint.h>

// atari8-dos; presently we have 40KiB of RAM from 0x2000 to 0xC000,
// array sizes have to be <=32767; use 30+10
uint8_t ram_too_big0[30 * 1024] = { 0x55 };
uint8_t ram_too_big1[10 * 1024] = { 0xAA };

int main(void) {
asm volatile(
""
:
: "r"(ram_too_big0)
:
);
asm volatile(
""
:
: "r"(ram_too_big1)
:
);
}
8 changes: 8 additions & 0 deletions test/atari8-stdcart/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.18)

project(test-atari8-stdcart LANGUAGES C)

include(../test.cmake)

add_subdirectory(compile)
add_subdirectory(no-compile)
6 changes: 6 additions & 0 deletions test/atari8-stdcart/compile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON)

add_compile_test(minimal)
add_compile_test(cart-rom-8-fit-6)
add_compile_test(cart-rom-16-fit-14)
add_compile_test(cart-rom-size-declared)
16 changes: 16 additions & 0 deletions test/atari8-stdcart/compile/cart-rom-16-fit-14.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#include <stdint.h>

asm(".globl __cart_rom_size \n __cart_rom_size = 16");

// atari8-stdcard, 16 KiB
uint8_t data_too_big[14 * 1024] = { 0x55 };

int main(void) {
asm volatile(
""
:
: "r"(data_too_big)
:
);
}
16 changes: 16 additions & 0 deletions test/atari8-stdcart/compile/cart-rom-8-fit-6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#include <stdint.h>

asm(".globl __cart_rom_size \n __cart_rom_size = 8");

// atari8-stdcard, 8 KiB
uint8_t data_too_big[6 * 1024] = { 0x55 };

int main(void) {
asm volatile(
""
:
: "r"(data_too_big)
:
);
}
13 changes: 13 additions & 0 deletions test/atari8-stdcart/compile/cart-rom-size-declared.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#include <stdint.h>

extern int __cart_rom_size;

int main(void) {
asm volatile(
""
:
: "r"(__cart_rom_size)
:
);
}
6 changes: 6 additions & 0 deletions test/atari8-stdcart/compile/minimal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#include <stdio.h>

int main(void) {
printf("hello\n");
}
5 changes: 5 additions & 0 deletions test/atari8-stdcart/no-compile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL ON)

add_no_compile_test(ram-too-big)
add_no_compile_test(cart-rom-8-too-big)
add_no_compile_test(cart-rom-16-too-big)
17 changes: 17 additions & 0 deletions test/atari8-stdcart/no-compile/cart-rom-16-too-big.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ExpectFailure: ld.lld: error: section '.data' will not fit in region 'cart_rom': overflowed

#include <stdint.h>

asm(".globl __cart_rom_size \n __cart_rom_size = 16");

// atari8-stdcard, 16 KiB, this won't fit
uint8_t data_too_big[16 * 1024] = { 0x55 };

int main(void) {
asm volatile(
""
:
: "r"(data_too_big)
:
);
}
17 changes: 17 additions & 0 deletions test/atari8-stdcart/no-compile/cart-rom-8-too-big.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ExpectFailure: ld.lld: error: section '.data' will not fit in region 'cart_rom': overflowed

#include <stdint.h>

asm(".globl __cart_rom_size \n __cart_rom_size = 8");

// atari8-stdcard, 8 KiB, this won't fit
uint8_t data_too_big[8 * 1024] = { 0x55 };

int main(void) {
asm volatile(
""
:
: "r"(data_too_big)
:
);
}
15 changes: 15 additions & 0 deletions test/atari8-stdcart/no-compile/ram-too-big.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ExpectFailure: ld.lld: error: section '.bss' will not fit in region 'ram': overflowed

#include <stdint.h>

// atari8-stdcart; we have 14.25 KiB of RAM from 0x700 to 0x4000
uint8_t ram_too_big[15 * 1024];

int main(void) {
asm volatile(
""
:
: "r"(ram_too_big)
:
);
}
14 changes: 12 additions & 2 deletions test/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function(add_emutest_test name binext source_dir libretro_core)
-t ${CMAKE_CURRENT_SOURCE_DIR}/../emutest.lua)
endfunction()

function(add_no_compile_test target)
function(add_common_compile_test target type)
add_executable(${target} ${target}.c)
add_test(NAME ${target}-no-compile COMMAND ${CMAKE_CTEST_COMMAND}
add_test(NAME ${target}-${type} COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_BINARY_DIR}/${target}
--build-generator ${CMAKE_GENERATOR}
Expand All @@ -28,6 +28,16 @@ function(add_no_compile_test target)
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_EXPORT_COMPILE_COMMANDS=${CMAKE_EXPORT_COMPILE_COMMANDS}
)
endfunction()

# negative (failure) compilation test
function(add_compile_test target)
add_common_compile_test(${target} compile)
endfunction()

# negative (failure) compilation test
function(add_no_compile_test target)
add_common_compile_test(${target} no-compile)
set_property(TEST ${target}-no-compile PROPERTY WILL_FAIL YES)
endfunction()

Expand Down

0 comments on commit 7385ba3

Please sign in to comment.