Skip to content
Open
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
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# ##############################################################################

Expand Down
91 changes: 43 additions & 48 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <user>/<machine>/<version>/<pulse>/<run>. 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}
)
10 changes: 5 additions & 5 deletions tests/testlowlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/testlowlevel_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading