Skip to content

Commit dbdd6dc

Browse files
authored
Merge pull request #565 from certik/cmake2
Add a CMake based system for integration tests
2 parents d5532f2 + adec49a commit dbdd6dc

File tree

7 files changed

+184
-119
lines changed

7 files changed

+184
-119
lines changed

ci/test.xsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ src/bin/lpython --show-cpp tests/doconcurrentloop_01.py
1717

1818
if $WIN != "1":
1919
python run_tests.py
20-
python integration_tests/run_tests.py
20+
cd integration_tests
21+
./run_tests.sh

integration_tests/CMakeLists.txt

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
target_link_libraries(lpython_rtlib INTERFACE m)
27+
28+
enable_testing()
29+
30+
message("\n")
31+
message("Configuration results")
32+
message("---------------------")
33+
message("C compiler : ${CMAKE_C_COMPILER}")
34+
message("Build type: ${CMAKE_BUILD_TYPE}")
35+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
36+
message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}")
37+
else ()
38+
message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}")
39+
endif ()
40+
message("Installation prefix: ${CMAKE_INSTALL_PREFIX}")
41+
message("LPYTHON_BACKEND: ${LPYTHON_BACKEND}")
42+
message("LPYTHON_RTLIB_DIR: ${LPYTHON_RTLIB_DIR}")
43+
message("LPYTHON_RTLIB_LIBRARY: ${LPYTHON_RTLIB_LIBRARY}")
44+
45+
46+
47+
macro(RUN)
48+
set(options FAIL)
49+
set(oneValueArgs NAME)
50+
set(multiValueArgs LABELS EXTRAFILES)
51+
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
52+
"${multiValueArgs}" ${ARGN} )
53+
set(name ${RUN_NAME})
54+
if (NOT name)
55+
message(FATAL_ERROR "Must specify the NAME argument")
56+
endif()
57+
if (LPYTHON_BACKEND)
58+
if (${LPYTHON_BACKEND} IN_LIST RUN_LABELS)
59+
# Test is supported by the given LPython backend
60+
if (LPYTHON_BACKEND STREQUAL "llvm")
61+
add_custom_command(
62+
OUTPUT ${name}.o
63+
COMMAND lpython -c ${name}.py -o ${name}.o
64+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
65+
VERBATIM)
66+
add_executable(${name} ${name}.o ${RUN_EXTRAFILES})
67+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
68+
target_link_libraries(${name} lpython_rtlib)
69+
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
70+
if (RUN_LABELS)
71+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
72+
endif()
73+
if (${RUN_FAIL})
74+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
75+
endif()
76+
endif()
77+
if (LPYTHON_BACKEND STREQUAL "c")
78+
add_custom_command(
79+
OUTPUT ${name}.c
80+
COMMAND lpython --show-c ${name}.py > ${name}.c
81+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
82+
VERBATIM)
83+
add_executable(${name} ${name}.c ${RUN_EXTRAFILES})
84+
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
85+
target_link_libraries(${name} lpython_rtlib)
86+
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
87+
if (RUN_LABELS)
88+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
89+
endif()
90+
if (${RUN_FAIL})
91+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
92+
endif()
93+
endif()
94+
endif()
95+
else()
96+
if ("cpython" IN_LIST RUN_LABELS)
97+
# CPython test
98+
add_test(${name} python ${CMAKE_CURRENT_BINARY_DIR}/${name}.py)
99+
set_tests_properties(${name} PROPERTIES
100+
ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}/../src/runtime/ltypes)
101+
if (RUN_LABELS)
102+
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
103+
endif()
104+
if (${RUN_FAIL})
105+
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
106+
endif()
107+
endif()
108+
endif()
109+
endmacro(RUN)
110+
111+
112+
# Test zero and non-zero exit code
113+
RUN(NAME exit_01 LABELS cpython llvm)
114+
RUN(NAME exit_02 FAIL LABELS cpython llvm)
115+
116+
# Test all three backends
117+
RUN(NAME print_01 LABELS cpython llvm c)
118+
119+
# CPython and LLVM
120+
RUN(NAME expr_01 LABELS cpython llvm)
121+
RUN(NAME expr_02 LABELS cpython llvm)
122+
RUN(NAME expr_03 LABELS cpython llvm)
123+
RUN(NAME expr_04 LABELS cpython llvm)
124+
RUN(NAME expr_05 LABELS cpython llvm)
125+
RUN(NAME test_types_01 LABELS cpython llvm)
126+
RUN(NAME test_str_01 LABELS cpython llvm)
127+
RUN(NAME test_str_02 LABELS cpython llvm)
128+
RUN(NAME test_list_01 LABELS cpython llvm)
129+
RUN(NAME modules_01 LABELS cpython llvm)
130+
RUN(NAME test_math LABELS cpython llvm)
131+
RUN(NAME test_numpy_01 LABELS cpython llvm)
132+
RUN(NAME test_numpy_02 LABELS cpython llvm)
133+
RUN(NAME test_random LABELS cpython llvm)
134+
RUN(NAME test_os LABELS cpython llvm)
135+
RUN(NAME test_builtin LABELS cpython llvm)
136+
RUN(NAME test_builtin_abs LABELS cpython llvm)
137+
RUN(NAME test_builtin_bool LABELS cpython llvm)
138+
RUN(NAME test_builtin_pow LABELS cpython llvm)
139+
RUN(NAME test_builtin_int LABELS cpython llvm)
140+
RUN(NAME test_builtin_len LABELS cpython llvm)
141+
RUN(NAME test_builtin_float LABELS cpython llvm)
142+
RUN(NAME test_builtin_str_02 LABELS cpython llvm)
143+
RUN(NAME test_builtin_round LABELS cpython llvm)
144+
RUN(NAME test_math1 LABELS cpython llvm)
145+
RUN(NAME test_math_02 LABELS cpython llvm)
146+
RUN(NAME test_c_interop_01 LABELS cpython llvm)
147+
RUN(NAME test_generics_01 LABELS cpython llvm)
148+
RUN(NAME test_cmath LABELS cpython llvm)
149+
RUN(NAME test_complex LABELS cpython llvm)
150+
RUN(NAME test_max_min LABELS cpython llvm)
151+
RUN(NAME test_integer_bitnot LABELS cpython llvm)
152+
RUN(NAME test_unary_minus LABELS cpython llvm)
153+
RUN(NAME test_issue_518 LABELS cpython llvm)
154+
155+
# Just CPython
156+
RUN(NAME test_builtin_bin LABELS cpython)

integration_tests/exit_02.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from sys import exit
2+
3+
def main0():
4+
print("Before")
5+
exit(1)
6+
print("After")
7+
8+
main0()

integration_tests/print_01.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello World!")

integration_tests/run_tests.py

Lines changed: 0 additions & 117 deletions
This file was deleted.

integration_tests/run_tests.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
export PATH="$(pwd)/../src/bin:$PATH"
6+
7+
cmake .
8+
ctest
9+
10+
cmake -DLPYTHON_BACKEND=llvm .
11+
make
12+
ctest
13+
14+
cmake -DLPYTHON_BACKEND=c .
15+
make
16+
ctest

integration_tests/test_os.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def test():
55
path: str
6-
path = "integration_tests/test_os.py"
6+
path = "test_os.py"
77
fd: i64
88
n: i64
99
fd = open(path, O_RDONLY)

0 commit comments

Comments
 (0)