diff --git a/CMakeLists.txt b/CMakeLists.txt index 9acad117..93ee06cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,8 @@ endif() # ############################################################################## option(AL_PYTHON_BINDINGS "Build Python bindings" OFF) +option(AL_BUILD_TESTS "Build the C/C++ low-level ABI smoke tests (tests/)" OFF) + # When ON, the al C++ library is not built here; instead it is located with # find_package(al-core CONFIG). Enables a two-stage build where libimas-core # (the C/C++ library) and imas-core (the Python wrapper) are packaged @@ -225,6 +227,13 @@ if(NOT WIN32 AND NOT APPLE) endif() add_dependencies( imas_print_version al ) +# Low-level ABI smoke tests (opt-in) +# ############################################################################## +if( AL_BUILD_TESTS ) + enable_testing() + add_subdirectory(tests) +endif() + # Install # ############################################################################## diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db5b6b13..8b25dd03 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,73 +1,68 @@ project( lowlevel-tests ) -######################################################################################################################## -# Dependencies - - -######################################################################################################################## -# Sources - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/lowlevel -) - - ######################################################################################################################## # Targets +# +# These smoke tests exercise the public C ABI (al_lowlevel.h) end-to-end and, +# by building the same program as both C++ and C, guard that the header stays +# C-compatible. The `al` target exports its include dirs PUBLICly, so linking +# it is enough to resolve al_lowlevel.h / al_defs.h. set( EXE_FLAG ) set( EXE_EXT ) -if( BUILD_SHARED_LIBS ) - set( LOWLEVEL_LINK lowlevel-shared ) -else() - set( LOWLEVEL_LINK lowlevel-static ) -endif() - add_executable( testlowlevel ${EXE_FLAG} testlowlevel.cpp ) -target_link_libraries( testlowlevel PRIVATE - ${LOWLEVEL_LINK} -) +target_link_libraries( testlowlevel PRIVATE al ) +add_dependencies( testlowlevel al ) +set_target_properties( testlowlevel PROPERTIES OUTPUT_NAME testlowlevel${EXE_EXT} ) -if( BUILD_SHARED_LIBS ) - add_dependencies( testlowlevel lowlevel-shared ) -else() - add_dependencies( testlowlevel lowlevel-static ) +add_executable( testlowlevel_c ${EXE_FLAG} testlowlevel_c.c ) +target_link_libraries( testlowlevel_c PRIVATE al ) +add_dependencies( testlowlevel_c al ) +set_target_properties( testlowlevel_c PROPERTIES OUTPUT_NAME testlowlevel_c${EXE_EXT} ) + +if(NOT WIN32 AND NOT APPLE) + # stdc++fs is only needed on Linux with older GCC + target_link_libraries( testlowlevel PRIVATE stdc++fs ) + target_link_libraries( testlowlevel_c PRIVATE stdc++fs ) endif() -set_target_properties( testlowlevel - PROPERTIES - OUTPUT_NAME testlowlevel${EXE_EXT} - COMPILE_FLAGS -DNOIMPLIB -) -add_executable( testlowlevel_c ${EXE_FLAG} testlowlevel_c.c ) -target_link_libraries( testlowlevel_c PRIVATE - ${LOWLEVEL_LINK} -) +######################################################################################################################## +# CTest registration +# +# The legacy `imas_public` user is not a real account, so the pulse path is +# supplied directly by passing an absolute base directory as the "user" (-u): +# the core then builds ////. Each test gets +# its own base dir (created by a fixture) to stay parallel-safe, and uses the +# DD-agnostic ASCII backend so no MDSplus model tree is required. -set_target_properties( testlowlevel_c - PROPERTIES - OUTPUT_NAME testlowlevel_c${EXE_EXT} - COMPILE_FLAGS -DNOIMPLIB -) +set( _testdb ${CMAKE_CURRENT_BINARY_DIR}/testdb ) + +add_test( NAME testlowlevel_c_setup + COMMAND ${CMAKE_COMMAND} -E make_directory ${_testdb}/c/west/3/12/0 ) +set_tests_properties( testlowlevel_c_setup PROPERTIES FIXTURES_SETUP TESTDB_C ) + +add_test( NAME testlowlevel_cpp_setup + COMMAND ${CMAKE_COMMAND} -E make_directory ${_testdb}/cpp/west/3/12/0 ) +set_tests_properties( testlowlevel_cpp_setup PROPERTIES FIXTURES_SETUP TESTDB_CPP ) + +add_test( NAME testlowlevel_c + COMMAND testlowlevel_c -b=A -s=12 -r=0 -o=C -c=C -u=${_testdb}/c ) +set_tests_properties( testlowlevel_c PROPERTIES FIXTURES_REQUIRED TESTDB_C ) + +add_test( NAME testlowlevel_cpp + COMMAND testlowlevel -b=A -s=12 -r=0 -o=C -c=C -u=${_testdb}/cpp ) +set_tests_properties( testlowlevel_cpp PROPERTIES FIXTURES_REQUIRED TESTDB_CPP ) ######################################################################################################################## # Install install( - TARGETS testlowlevel + TARGETS testlowlevel testlowlevel_c RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) - -install( - TARGETS testlowlevel_c - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) \ No newline at end of file diff --git a/tests/testlowlevel.cpp b/tests/testlowlevel.cpp index 2ffea62d..d2b8e1d8 100644 --- a/tests/testlowlevel.cpp +++ b/tests/testlowlevel.cpp @@ -259,11 +259,11 @@ int main(int argc, char *argv[]) { printf("Pulse number:\t%d\n", iPulse); printf("Run number:\t%d\n", iRun); - printf("Backend:\t%s\n", alconst::backend_id_str[iBackend - BACKEND_ID_0].c_str()); + printf("Backend:\t%d\n", iBackend); printf("User name:\t%s\n", szUser); printf("Machine:\t%s\n", szTokamak); - printf("Open action:\t%s\n", alconst::access_pulse_str[iOpenAction - ACCESS_PULSE_0].c_str()); - printf("Close action:\t%s\n", alconst::access_pulse_str[iCloseAction - ACCESS_PULSE_0].c_str()); + printf("Open action:\t%d\n", iOpenAction); + printf("Close action:\t%d\n", iCloseAction); printf("Parameters:\t%s\n", szParams); // Low Level @@ -309,7 +309,7 @@ int main(int argc, char *argv[]) printf("Writing data...\n"); iGetOpCtx = -1; - alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, WRITE_OP, &iGetOpCtx); + alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, "", WRITE_OP, &iGetOpCtx); if (alStatus.code != 0) { printf("Error opening imas %s for writing: al_begin_global_action = %s\n", szIdsFullName, alStatus.message); @@ -352,7 +352,7 @@ int main(int argc, char *argv[]) printf("Reading data...\n"); iGetOpCtx = -1; - alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, READ_OP, &iGetOpCtx); + alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, "", READ_OP, &iGetOpCtx); if (alStatus.code != 0) { printf("Error opening imas %s for reading: al_begin_global_action = %s\n", szIdsFullName, alStatus.message); diff --git a/tests/testlowlevel_c.c b/tests/testlowlevel_c.c index 3736c1b1..ab3801d5 100644 --- a/tests/testlowlevel_c.c +++ b/tests/testlowlevel_c.c @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) printf("Writing data...\n"); iGetOpCtx = -1; - alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, WRITE_OP, &iGetOpCtx); + alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, "", WRITE_OP, &iGetOpCtx); if (alStatus.code != 0) { printf("Error opening imas %s for writing: al_begin_global_action = %s\n", szIdsFullName, alStatus.message); @@ -319,7 +319,7 @@ int main(int argc, char *argv[]) printf("Reading data...\n"); iGetOpCtx = -1; - alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, READ_OP, &iGetOpCtx); + alStatus = al_begin_global_action(iPulseCtx, szIdsFullName, "", READ_OP, &iGetOpCtx); if (alStatus.code != 0) { printf("Error opening imas %s for reading: al_begin_global_action = %s\n", szIdsFullName, alStatus.message);