Skip to content

Add a CMake based system for integration tests #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ci/test.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ src/bin/lpython --show-cpp tests/doconcurrentloop_01.py

if $WIN != "1":
python run_tests.py
python integration_tests/run_tests.py
cd integration_tests
./run_tests.sh
156 changes: 156 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(lpython_tests C)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug
CACHE STRING "Build type (Debug, Release)" FORCE)
endif ()
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "Release"))
message("${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')")
endif ()

set(LPYTHON_BACKEND no CACHE STRING "Only compile the LPython subset for the given backend")

find_path(LPYTHON_RTLIB_DIR lfortran_intrinsics.h
${CMAKE_SOURCE_DIR}/../src/runtime/impure)
find_library(LPYTHON_RTLIB_LIBRARY lpython_runtime_static
${CMAKE_SOURCE_DIR}/../src/runtime/)
add_library(lpython_rtlib INTERFACE IMPORTED)
set_property(TARGET lpython_rtlib PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${LPYTHON_RTLIB_DIR})
set_property(TARGET lpython_rtlib PROPERTY INTERFACE_LINK_LIBRARIES
${LPYTHON_RTLIB_LIBRARY})
target_link_libraries(lpython_rtlib INTERFACE m)

enable_testing()

message("\n")
message("Configuration results")
message("---------------------")
message("C compiler : ${CMAKE_C_COMPILER}")
message("Build type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}")
else ()
message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}")
endif ()
message("Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message("LPYTHON_BACKEND: ${LPYTHON_BACKEND}")
message("LPYTHON_RTLIB_DIR: ${LPYTHON_RTLIB_DIR}")
message("LPYTHON_RTLIB_LIBRARY: ${LPYTHON_RTLIB_LIBRARY}")



macro(RUN)
set(options FAIL)
set(oneValueArgs NAME)
set(multiValueArgs LABELS EXTRAFILES)
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
set(name ${RUN_NAME})
if (NOT name)
message(FATAL_ERROR "Must specify the NAME argument")
endif()
if (LPYTHON_BACKEND)
if (${LPYTHON_BACKEND} IN_LIST RUN_LABELS)
# Test is supported by the given LPython backend
if (LPYTHON_BACKEND STREQUAL "llvm")
add_custom_command(
OUTPUT ${name}.o
COMMAND lpython -c ${name}.py -o ${name}.o
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
VERBATIM)
add_executable(${name} ${name}.o ${RUN_EXTRAFILES})
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(${name} lpython_rtlib)
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
if (RUN_LABELS)
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
endif()
if (${RUN_FAIL})
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
endif()
endif()
if (LPYTHON_BACKEND STREQUAL "c")
add_custom_command(
OUTPUT ${name}.c
COMMAND lpython --show-c ${name}.py > ${name}.c
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py
VERBATIM)
add_executable(${name} ${name}.c ${RUN_EXTRAFILES})
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(${name} lpython_rtlib)
add_test(${name} ${CMAKE_CURRENT_BINARY_DIR}/${name})
if (RUN_LABELS)
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
endif()
if (${RUN_FAIL})
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
endif()
endif()
endif()
else()
if ("cpython" IN_LIST RUN_LABELS)
# CPython test
add_test(${name} python ${CMAKE_CURRENT_BINARY_DIR}/${name}.py)
set_tests_properties(${name} PROPERTIES
ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}/../src/runtime/ltypes)
if (RUN_LABELS)
set_tests_properties(${name} PROPERTIES LABELS "${RUN_LABELS}")
endif()
if (${RUN_FAIL})
set_tests_properties(${name} PROPERTIES WILL_FAIL TRUE)
endif()
endif()
endif()
endmacro(RUN)


# Test zero and non-zero exit code
RUN(NAME exit_01 LABELS cpython llvm)
RUN(NAME exit_02 FAIL LABELS cpython llvm)

# Test all three backends
RUN(NAME print_01 LABELS cpython llvm c)

# CPython and LLVM
RUN(NAME expr_01 LABELS cpython llvm)
RUN(NAME expr_02 LABELS cpython llvm)
RUN(NAME expr_03 LABELS cpython llvm)
RUN(NAME expr_04 LABELS cpython llvm)
RUN(NAME expr_05 LABELS cpython llvm)
RUN(NAME test_types_01 LABELS cpython llvm)
RUN(NAME test_str_01 LABELS cpython llvm)
RUN(NAME test_str_02 LABELS cpython llvm)
RUN(NAME test_list_01 LABELS cpython llvm)
RUN(NAME modules_01 LABELS cpython llvm)
RUN(NAME test_math LABELS cpython llvm)
RUN(NAME test_numpy_01 LABELS cpython llvm)
RUN(NAME test_numpy_02 LABELS cpython llvm)
RUN(NAME test_random LABELS cpython llvm)
RUN(NAME test_os LABELS cpython llvm)
RUN(NAME test_builtin LABELS cpython llvm)
RUN(NAME test_builtin_abs LABELS cpython llvm)
RUN(NAME test_builtin_bool LABELS cpython llvm)
RUN(NAME test_builtin_pow LABELS cpython llvm)
RUN(NAME test_builtin_int LABELS cpython llvm)
RUN(NAME test_builtin_len LABELS cpython llvm)
RUN(NAME test_builtin_float LABELS cpython llvm)
RUN(NAME test_builtin_str_02 LABELS cpython llvm)
RUN(NAME test_builtin_round LABELS cpython llvm)
RUN(NAME test_math1 LABELS cpython llvm)
RUN(NAME test_math_02 LABELS cpython llvm)
RUN(NAME test_c_interop_01 LABELS cpython llvm)
RUN(NAME test_generics_01 LABELS cpython llvm)
RUN(NAME test_cmath LABELS cpython llvm)
RUN(NAME test_complex LABELS cpython llvm)
RUN(NAME test_max_min LABELS cpython llvm)
RUN(NAME test_integer_bitnot LABELS cpython llvm)
RUN(NAME test_unary_minus LABELS cpython llvm)
RUN(NAME test_issue_518 LABELS cpython llvm)

# Just CPython
RUN(NAME test_builtin_bin LABELS cpython)
8 changes: 8 additions & 0 deletions integration_tests/exit_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from sys import exit

def main0():
print("Before")
exit(1)
print("After")

main0()
1 change: 1 addition & 0 deletions integration_tests/print_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello World!")
117 changes: 0 additions & 117 deletions integration_tests/run_tests.py

This file was deleted.

16 changes: 16 additions & 0 deletions integration_tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -ex

export PATH="$(pwd)/../src/bin:$PATH"

cmake .
ctest

cmake -DLPYTHON_BACKEND=llvm .
make
ctest

cmake -DLPYTHON_BACKEND=c .
make
ctest
2 changes: 1 addition & 1 deletion integration_tests/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def test():
path: str
path = "integration_tests/test_os.py"
path = "test_os.py"
fd: i64
n: i64
fd = open(path, O_RDONLY)
Expand Down