1 # ---------------------------------------------------------------------------
3 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
4 # ---------------------------------------------------------------------------
5 # SquirrelJME is under the Mozilla Public License Version 2.0.
6 # See license.mkd for licensing and copyright information.
7 # ---------------------------------------------------------------------------
8 # DESCRIPTION: Testing framework for the main library
10 # Decode all of the blobs to binary
11 squirreljme_decode_dir("${CMAKE_CURRENT_SOURCE_DIR}/blobs"
12 "${CMAKE_CURRENT_BINARY_DIR}/blobs/binary")
14 # Then encode them all to source files, for use within tests
15 squirreljme_sourceize_dir("${CMAKE_CURRENT_BINARY_DIR}/blobs/binary"
16 "${CMAKE_CURRENT_BINARY_DIR}/blobs")
18 # Setup main test execution wrapper which runs within TAC
19 add_library(TACTestExecutorCore STATIC
20 $<TARGET_OBJECTS:Base>
21 $<TARGET_OBJECTS:Core>
24 # Make sure we have our headers included accordingly
25 target_include_directories(TACTestExecutorCore PUBLIC
26 "${CMAKE_SOURCE_DIR}/include"
27 "${CMAKE_SOURCE_DIR}/tests/include")
30 target_link_libraries(TACTestExecutorCore PUBLIC
31 ${SQUIRRELJME_EXEC_LINK_LIBRARIES})
33 # Get a list of tests that are not TAC tests, but more general tests
34 file(GLOB basicTestSources
37 squirreljme_list_file_sort(SORT basicTestSources)
39 # Get a list of all the supporting blobs
40 file(GLOB basicTestBlobs
41 "${CMAKE_CURRENT_BINARY_DIR}/blobs/*.c")
43 # Setup base files for auto-generated test launching and method linking
44 set(outTestProtosH "${CMAKE_CURRENT_BINARY_DIR}/proto.h")
45 set(outTestStructH "${CMAKE_CURRENT_BINARY_DIR}/struct.h")
46 configure_file("${CMAKE_SOURCE_DIR}/cmake/blank.in.h"
48 configure_file("${CMAKE_SOURCE_DIR}/cmake/blank.in.h"
51 # Include test header in the prototypes file
52 file(APPEND "${outTestProtosH}"
53 "#include \"test.h\"\n")
56 add_library(BasicTestLib OBJECT
66 add_library(BasicTestLibPIC OBJECT
75 # Initialize executable for basic tests, which contains everything
76 add_executable(BasicTest
78 $<TARGET_OBJECTS:Base>
79 $<TARGET_OBJECTS:Core>
80 $<TARGET_OBJECTS:BasicTestLib>)
83 squirreljme_static_executable(BasicTest)
85 # Make sure we have our headers included accordingly
86 target_include_directories(BasicTestLib PUBLIC
87 "${CMAKE_SOURCE_DIR}/include"
88 "${CMAKE_CURRENT_SOURCE_DIR}/include"
89 "${CMAKE_CURRENT_BINARY_DIR}"
90 "${CMAKE_CURRENT_BINARY_DIR}/blobs")
91 target_include_directories(BasicTestLibPIC PUBLIC
92 "${CMAKE_SOURCE_DIR}/include"
93 "${CMAKE_CURRENT_SOURCE_DIR}/include"
94 "${CMAKE_CURRENT_BINARY_DIR}"
95 "${CMAKE_CURRENT_BINARY_DIR}/blobs")
97 # Make sure the PIC libraries are position independent!
98 set_target_properties(BasicTestLibPIC PROPERTIES
99 POSITION_INDEPENDENT_CODE ON)
101 # Make sure we have our headers included accordingly
102 target_include_directories(BasicTest PUBLIC
103 "${CMAKE_SOURCE_DIR}/include"
104 "${CMAKE_CURRENT_SOURCE_DIR}/include"
105 "${CMAKE_CURRENT_BINARY_DIR}"
106 "${CMAKE_CURRENT_BINARY_DIR}/blobs")
109 target_link_libraries(BasicTest PUBLIC
112 # Include debugging info for tests
113 if(CMAKE_BUILD_TYPE STREQUAL "Release")
114 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
115 target_compile_options(BasicTestLib PRIVATE
117 target_compile_options(BasicTestLibPIC PRIVATE
120 target_compile_options(BasicTestLib PRIVATE
122 target_compile_options(BasicTestLibPIC PRIVATE
127 # Process each individual test accordingly
128 message(DEBUG "Looking for tests...")
129 foreach(basicTestSource ${basicTestSources})
130 # We need to do this because on Windows, CLion+CMake just gives the full
131 # path which we really do not want as it will mess up with tests
132 set(initialBasicTestSource "${basicTestSource}")
133 get_filename_component(basicTestSource
134 "${basicTestSource}" NAME)
136 # Remove the C/C++ to just get the base test
137 string(REPLACE ".cxx" ""
138 basicTestName "${basicTestSource}")
139 string(REPLACE ".c" ""
140 basicTestName "${basicTestSource}")
142 # Long name of the test
143 set(basicTestLongName "basic:${basicTestName}")
145 # Full path, for message output
146 get_filename_component(basicTestFullPath
147 "${initialBasicTestSource}" ABSOLUTE)
150 message(STATUS "Registering test ${basicTestLongName}...")
151 add_test(NAME "${basicTestLongName}"
152 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
153 COMMAND "$<TARGET_FILE:BasicTest>" "${basicTestName}"
154 "${basicTestFullPath}")
156 # Code for skipped tests
157 set_property(TEST "${basicTestLongName}"
158 PROPERTY SKIP_RETURN_CODE 2)
159 set_tests_properties("${basicTestLongName}"
160 PROPERTIES SKIP_RETURN_CODE 2)
162 # Test timeout (to prevent infinite loops)
163 set_property(TEST "${basicTestLongName}"
164 PROPERTY TIMEOUT 180)
165 set_tests_properties("${basicTestLongName}"
166 PROPERTIES TIMEOUT 180)
168 # Label, name of test, used for filtering
169 set_property(TEST "${basicTestLongName}"
170 PROPERTY LABEL "${basicTestSource}")
171 set_tests_properties("${basicTestLongName}"
172 PROPERTIES LABEL "${basicTestSource}")
174 # Add prototype and structures for test
175 file(APPEND "${outTestProtosH}"
176 "SJME_TEST_DECLARE(${basicTestName});\n")
177 file(APPEND "${outTestStructH}"
178 "{\"${basicTestName}\", ${basicTestName}},\n")