Skip to content

Commit c4d31c1

Browse files
committed
Add a CMake based system for integration tests
It tests CPython, LPython/LLVM and LPython/C. One invokes it using: * CPython: cmake . * LPython/LLVM: cmake -DLPYTHON_BACKEND=llvm . * LPython/C: cmake -DLPYTHON_BACKEND=c . Then one does `make` and `ctest`.
1 parent a63b949 commit c4d31c1

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
2+
3+
project(lpython_tests C)
4+
5+
if (NOT CMAKE_BUILD_TYPE)
6+
set(CMAKE_BUILD_TYPE Debug
7+
CACHE STRING "Build type (Debug, Release)" FORCE)
8+
endif ()
9+
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
10+
CMAKE_BUILD_TYPE STREQUAL "Release"))
11+
message("${CMAKE_BUILD_TYPE}")
12+
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')")
13+
endif ()
14+
15+
set(LPYTHON_BACKEND no CACHE STRING "Only compile the LPython subset for the given backend")
16+
17+
find_path(LPYTHON_RTLIB_DIR lfortran_intrinsics.h
18+
${CMAKE_SOURCE_DIR}/../src/runtime/impure)
19+
find_library(LPYTHON_RTLIB_LIBRARY lpython_runtime_static
20+
${CMAKE_SOURCE_DIR}/../src/runtime/)
21+
add_library(lpython_rtlib INTERFACE IMPORTED)
22+
set_property(TARGET lpython_rtlib PROPERTY INTERFACE_INCLUDE_DIRECTORIES
23+
${LPYTHON_RTLIB_DIR})
24+
set_property(TARGET lpython_rtlib PROPERTY INTERFACE_LINK_LIBRARIES
25+
${LPYTHON_RTLIB_LIBRARY})
26+
27+
enable_testing()
28+
29+
message("\n")
30+
message("Configuration results")
31+
message("---------------------")
32+
message("C compiler : ${CMAKE_C_COMPILER}")
33+
message("Build type: ${CMAKE_BUILD_TYPE}")
34+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
35+
message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}")
36+
else ()
37+
message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}")
38+
endif ()
39+
message("Installation prefix: ${CMAKE_INSTALL_PREFIX}")
40+
message("LPYTHON_BACKEND: ${LPYTHON_BACKEND}")
41+
message("LPYTHON_RTLIB_DIR: ${LPYTHON_RTLIB_DIR}")
42+
message("LPYTHON_RTLIB_LIBRARY: ${LPYTHON_RTLIB_LIBRARY}")
43+
44+
45+
46+
macro(RUN)
47+
set(options FAIL)
48+
set(oneValueArgs NAME)
49+
set(multiValueArgs LABELS EXTRAFILES)
50+
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
51+
"${multiValueArgs}" ${ARGN} )
52+
set(name ${RUN_NAME})
53+
if (NOT name)
54+
message(FATAL_ERROR "Must specify the NAME argument")
55+
endif()
56+
if (LPYTHON_BACKEND)
57+
if (${LPYTHON_BACKEND} IN_LIST RUN_LABELS)
58+
# Test is supported by the given LPython backend
59+
if (LPYTHON_BACKEND STREQUAL "llvm")
60+
add_custom_command(
61+
OUTPUT ${name}.o
62+
COMMAND lpython -c ${name}.py -o ${name}.o
63+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
64+
VERBATIM)
65+
add_executable(${name} ${name}.o ${RUN_EXTRAFILES})
66+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
67+
target_link_libraries(${name} lpython_rtlib)
68+
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
69+
if (RUN_LABELS)
70+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
71+
endif()
72+
if (${RUN_FAIL})
73+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
74+
endif()
75+
endif()
76+
if (LPYTHON_BACKEND STREQUAL "c")
77+
add_custom_command(
78+
OUTPUT ${name}.c
79+
COMMAND lpython --show-c ${name}.py > ${name}.c
80+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
81+
VERBATIM)
82+
add_executable(${name} ${name}.c ${RUN_EXTRAFILES})
83+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
84+
target_link_libraries(${name} lpython_rtlib)
85+
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
86+
if (RUN_LABELS)
87+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
88+
endif()
89+
if (${RUN_FAIL})
90+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
91+
endif()
92+
endif()
93+
endif()
94+
else()
95+
if ("cpython" IN_LIST RUN_LABELS)
96+
# CPython test
97+
add_test(${name} python ${CMAKE_CURRENT_BINARY_DIR}/${name}.py)
98+
set_tests_properties(${name} PROPERTIES
99+
ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}/../src/runtime/ltypes)
100+
if (RUN_LABELS)
101+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
102+
endif()
103+
if (${RUN_FAIL})
104+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
105+
endif()
106+
endif()
107+
endif()
108+
109+
# if (ADD_TEST)
110+
# add_executable(${name} ${name}.py ${RUN_EXTRAFILES})
111+
# if ((LPYTHON_BACKEND STREQUAL "cpp") OR (LPYTHON_BACKEND STREQUAL "x86"))
112+
# target_compile_options(${name} PUBLIC --backend=${LPYTHON_BACKEND})
113+
# target_link_options(${name} PUBLIC --backend=${LPYTHON_BACKEND})
114+
# endif()
115+
# add_test(${name} ${CURRENT_BINARY_DIR}/${name})
116+
#
117+
# if (RUN_LABELS)
118+
# set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
119+
# endif()
120+
#
121+
# if (${RUN_FAIL})
122+
# set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
123+
# endif()
124+
#endif()
125+
endmacro(RUN)
126+
127+
128+
# Test zero and non-zero exit code
129+
RUN(NAME exit_01 LABELS cpython llvm)
130+
RUN(NAME exit_02 FAIL LABELS cpython llvm)
131+
132+
# Test all three backends
133+
RUN(NAME print_01 LABELS cpython llvm c)
134+
135+
# CPython and LLVM
136+
RUN(NAME expr_01 LABELS cpython llvm)
137+
RUN(NAME expr_02 LABELS cpython llvm)
138+
RUN(NAME expr_03 LABELS cpython llvm)
139+
RUN(NAME expr_04 LABELS cpython llvm)
140+
RUN(NAME expr_05 LABELS cpython llvm)
141+
RUN(NAME test_types_01 LABELS cpython llvm)
142+
RUN(NAME test_str_01 LABELS cpython llvm)
143+
RUN(NAME test_str_02 LABELS cpython llvm)
144+
RUN(NAME test_list_01 LABELS cpython llvm)
145+
RUN(NAME modules_01 LABELS cpython llvm)
146+
RUN(NAME test_math LABELS cpython llvm)
147+
RUN(NAME test_numpy_01 LABELS cpython llvm)
148+
RUN(NAME test_numpy_02 LABELS cpython llvm)
149+
RUN(NAME test_random LABELS cpython llvm)
150+
RUN(NAME test_os LABELS cpython llvm)
151+
RUN(NAME test_builtin LABELS cpython llvm)
152+
RUN(NAME test_builtin_abs LABELS cpython llvm)
153+
RUN(NAME test_builtin_bool LABELS cpython llvm)
154+
RUN(NAME test_builtin_pow LABELS cpython llvm)
155+
RUN(NAME test_builtin_int LABELS cpython llvm)
156+
RUN(NAME test_builtin_len LABELS cpython llvm)
157+
RUN(NAME test_builtin_float LABELS cpython llvm)
158+
RUN(NAME test_builtin_str_02 LABELS cpython llvm)
159+
RUN(NAME test_builtin_round LABELS cpython llvm)
160+
RUN(NAME test_math1 LABELS cpython llvm)
161+
RUN(NAME test_math_02 LABELS cpython llvm)
162+
RUN(NAME test_c_interop_01 LABELS cpython llvm)
163+
RUN(NAME test_generics_01 LABELS cpython llvm)
164+
RUN(NAME test_cmath LABELS cpython llvm)
165+
RUN(NAME test_complex LABELS cpython llvm)
166+
RUN(NAME test_max_min LABELS cpython llvm)
167+
RUN(NAME test_integer_bitnot LABELS cpython llvm)
168+
RUN(NAME test_unary_minus LABELS cpython llvm)
169+
RUN(NAME test_issue_518 LABELS cpython llvm)
170+
171+
# Just CPython
172+
RUN(NAME test_builtin_bin LABELS cpython)

0 commit comments

Comments
 (0)