|
| 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) |
0 commit comments