diff --git a/CMakeLists.txt b/CMakeLists.txt index 00b78dde..6031b334 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.29.0 FATAL_ERROR) project(LPF C CXX ASM) # Version info @@ -105,18 +105,6 @@ set( INSTALL_HEADERS "${prefix}/include" CACHE PATH "Installation path for header files" ) message( STATUS "Installation directory prefix is ${prefix}") -# C++ standard -find_file(TR1_ARRAY "tr1/array") -if (TR1_ARRAY) - message(STATUS "Governing C++ standard is C++98/TR1") - set(CMAKE_CXX_STANDARD 98) - set(CMAKE_CXX_STANDARD_REQUIRED YES) -else() - message(STATUS "Governing C++ standard is C++11") - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_STANDARD_REQUIRED YES) -endif() - # Dependencies set(ENGINES) find_library( LIB_POSIX_THREADS @@ -173,9 +161,6 @@ if ( MPI_FOUND ) if ( NOT MPI_IS_THREAD_COMPAT OR NOT MPI_IS_NOT_OPENMPI1 ) message( WARNING "MPI implementation does not tolerate any threading. Hybrid implementation will not be built") endif() - if ( NOT MPI_OPEN_PORT ) - message( WARNING "MPI implementation does not support dynamically connecting separate MPI processes. Hence, lpf_mpi_initialize_over_tcp will always fail.") - endif() if ( NOT MPI_IBARRIER ) message( WARNING "MPI implementation does not have MPI_Ibarrier, which is required to use the dense all-to-all algorithm on large (> 2 GB) meta-data exchanges") endif() @@ -189,7 +174,7 @@ if ( LIB_MATH AND LIB_DL AND MPI_FOUND ) list(APPEND ENGINES "mpirma") endif() - if (LIB_IBVERBS) + if (ENABLE_IBVERBS) list(APPEND ENGINES "ibverbs") endif() @@ -198,7 +183,7 @@ endif() #enable the hybrid engine if ( LIB_POSIX_THREADS AND LIB_MATH AND LIB_DL AND MPI_FOUND AND MPI_IS_THREAD_COMPAT AND MPI_IS_NOT_OPENMPI1 - AND LIB_IBVERBS ) + AND ENABLE_IBVERBS ) list(APPEND ENGINES "hybrid") set(HYBRID_ENGINE_ENABLED on) endif() @@ -246,59 +231,19 @@ add_definitions(-DBSPLIB_DLL=1) option(LPF_ENABLE_TESTS "Enable unit and API tests. This uses Google Testing and Mocking Framework" OFF) +option(GTEST_AGREE_TO_LICENSE + "Does the user agree to the GoogleTest license" + OFF) + +# C++ standard -- Google tests require newer C++ standard than C++11 if (LPF_ENABLE_TESTS) -message(STATUS "Unit and API tests will be built") - -# set testing timeout to 60 seconds -set(CMAKE_TESTING_TIMEOUT 60) - -# import Google Testing Framework -include(cmake/googletest.cmake) - -# Have directory to gather all the tests results -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/junit) -set(test_output "${CMAKE_BINARY_DIR}/junit") - -# Have a macro to add a unit test -function(add_gtest testName) - add_executable(${testName} ${ARGN}) - target_link_libraries(${testName} gtest_main) - add_test(${testName} ${testName} --gtest_output=xml:${test_output}/ ) -endfunction(add_gtest) - -# Have a macro to add a unit test that should run with MPI -if (MPI_FOUND) - function(add_gtest_mpi testName nprocs) - add_executable(${testName} ${ARGN}) - target_link_libraries(${testName} ${MPI_C_LIBRARIES} gtest_main) - foreach( p ${nprocs}) - set(mpmd) - foreach( i RANGE 1 ${p}) - if (i GREATER 1) - set(mpmd ${mpmd} ":") - endif() - set(mpmd ${mpmd} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} - ./${testName} --gtest_output=xml:${test_output}/${testName}_${i}of${p}.xml) - endforeach(i) - add_test(NAME ${testName}_${p} - COMMAND ${MPIRUN} ${mpmd} - ) - endforeach(p) - endfunction(add_gtest_mpi) -endif(MPI_FOUND) - -# Enable testing in CMake -enable_testing() -else(LPF_ENABLE_TESTS) - message(STATUS "Unit and API tests will *not* be built") - function(add_gtest testName) - # Do nothing because tests are disabled - endfunction(add_gtest) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED YES) +else() + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED YES) +endif() - function(add_gtest_mpi testName nprocs) - # DO nothing because tests are disabled - endfunction(add_gtest_mpi) -endif(LPF_ENABLE_TESTS) # Handling of compiler flags function(target_add_compilation_flags target visibility) @@ -366,10 +311,7 @@ endfunction(target_compile_flags) # Source set(lpf_cflags) set(lpf_lib_link_flags) -set(lpf_exe_link_flags) -include_directories(include) -include_directories(src/common) -add_subdirectory(src) +set(lpf_exe_link_flags "-rdynamic") # Collating all compile & link flags set(LPF_CORE_COMPILE_FLAGS "${lpf_cflags}" CACHE STRING "Compilation flags for all user code" ) @@ -384,14 +326,119 @@ function( target_link_exe_with_core target ) endif() set(corelib "lpf_core_univ_${engine}_${LPFLIB_CONFIG_NAME}") - target_link_libraries(${target} ${corelib}) + if ("${engine}" STREQUAL "pthread") + target_link_libraries(${target} ${corelib}) + else() + target_link_libraries(${target} ${corelib} ${MPI_C_LIBRARIES}) + endif() target_compile_flags(${target} PRIVATE ${LPF_CORE_COMPILE_FLAGS}) set_target_properties(${target} PROPERTIES - LINK_FLAGS "${LPF_CORE_LIB_LINK_FLAGS} ${LPF_CORE_EXE_LINK_FLAGS}" - LINKER_LANGUAGE CXX - ) + LINK_FLAGS "${LPF_CORE_LIB_LINK_FLAGS} ${LPF_CORE_EXE_LINK_FLAGS}" + LINKER_LANGUAGE CXX + ) endfunction() +if (LPF_ENABLE_TESTS) + message(STATUS "Unit and API tests will be built. This requires CMake version 3.29 or higher, since we use recent features of the GoogleTest package in CMake.") + + if (NOT GTEST_AGREE_TO_LICENSE) + message(FATAL_ERROR "The user needs to agree with the GoogleTest license to use tests (option GTEST_AGREE_TO_LICENSE=TRUE)") + endif() + # Enable testing in CMake + enable_testing() + find_package(GTest) + include(GoogleTest) + if(NOT GTest_FOUND) # if not found, download it and pull it in + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + # This tag corresponds to GoogleTest 1.15.0 release + GIT_TAG e397860 + ) + FetchContent_MakeAvailable(googletest) + + endif() + # set testing timeout to 60 seconds + set(CMAKE_TESTING_TIMEOUT 60) + + # Have directory to gather all the tests results + file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/junit) + set(test_output "${CMAKE_BINARY_DIR}/junit") + + set(MY_TEST_LAUNCHER ${CMAKE_BINARY_DIR}/test_launcher.py) + configure_file( ${CMAKE_SOURCE_DIR}/test_launcher.py ${MY_TEST_LAUNCHER} @ONLY FILE_PERMISSIONS WORLD_EXECUTE OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) + if( NOT Python3_FOUND ) + find_package( Python3 REQUIRED) + endif() + + # Macro for adding a new GoogleTest test + function(add_gtest testName ENGINE debug testSource ) + if ("{$ENGINE}" STREQUAL "") + message(FATAL_ERROR "engine cannot be empty, ever!") + endif() + add_executable(${testName} ${testSource} ${ARGN}) + target_compile_definitions(${testName} PUBLIC LPF_CORE_IMPL_ID=${ENGINE}) + target_compile_definitions(${testName} PUBLIC LPF_CORE_MPI_USES_${ENGINE}) + if (debug) + target_include_directories( ${testName} BEFORE PRIVATE ${CMAKE_SOURCE_DIR}/include/debug ) + target_link_libraries(${testName} lpf_debug lpf_hl_debug GTest::gtest GTest::gtest_main) + else(debug) + target_link_libraries(${testName} GTest::gtest GTest::gtest_main) + endif(debug) + + + # Extract test-specific information from comments of tests + file(READ ${testSource} fileContents) + string(REGEX MATCH "Exit code: ([0-9]+)" _ ${fileContents}) + set(retCode ${CMAKE_MATCH_1}) + string(REGEX MATCH "pre P >= ([0-9]+)" _ ${fileContents}) + set(minProcs ${CMAKE_MATCH_1}) + string(REGEX MATCH "pre P <= ([0-9]+)" _ ${fileContents}) + set(maxProcs ${CMAKE_MATCH_1}) + string(REGEX MATCH "-probe ([0-9]+.[0-9]+)" _ ${fileContents}) + set(lpfProbeSecs ${CMAKE_MATCH_1}) + + target_link_exe_with_core(${testName} ${ENGINE}) + + + if ("${minProcs}" STREQUAL "") + set(minProcs "1") + endif() + if ("${maxProcs}" STREQUAL "") + set(maxProcs "5") + endif() + if ("${lpfProbeSecs}" STREQUAL "") + set(lpfProbeSecs "0.0") + endif() + if ("${retCode}" STREQUAL "") + set(retCode "0") + endif() + + # Most recent approach to Gtests, recommended! + set_property(TARGET ${testName} PROPERTY TEST_LAUNCHER ${MY_TEST_LAUNCHER};-e;${ENGINE};-L;${CMAKE_BINARY_DIR}/lpfrun_build;-p;${minProcs};-P;${maxProcs};-t;${lpfProbeSecs};-R;${retCode}) + gtest_discover_tests(${testName} + TEST_PREFIX ${ENGINE}_ + EXTRA_ARGS --gtest_output=xml:${test_output}/${ENGINE}_${testName} + DISCOVERY_MODE POST_BUILD + DISCOVERY_TIMEOUT 15 + ) + + + endfunction(add_gtest) + +else(LPF_ENABLE_TESTS) + message(STATUS "Unit and API tests will *not* be built") + function(add_gtest testName ENGINE debug testSource ) + # Do nothing because tests are disabled + endfunction(add_gtest) + +endif(LPF_ENABLE_TESTS) + +include_directories(include) +include_directories(src/common) + +add_subdirectory(src) # Apps add_subdirectory(src/utils) @@ -432,7 +479,7 @@ set( lpf_proxy_dummy ${CMAKE_CURRENT_BINARY_DIR}/src/MPI/lpf_proxy_dummy) set( lpf_probe ${CMAKE_CURRENT_BINARY_DIR}/src/utils/lpfprobe) set( lpfrun ${CMAKE_CURRENT_BINARY_DIR}/lpfrun_build) set( lpfcore ${CMAKE_CURRENT_BINARY_DIR}/src/*/liblpf_core_univ_ENGINE_${LPFLIB_CONFIG_NAME}${SOSUFFIX} ) -configure_file( lpfrun.in lpfrun_build @ONLY) +configure_file( lpfrun.in lpfrun_build FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE @ONLY) configure_file( lpfproxy.in lpfproxy_build @ONLY) configure_file( lpfprobe.in lpfprobe_build @ONLY) diff --git a/README b/README index 9fd8463d..bf0b68fd 100644 --- a/README +++ b/README @@ -28,9 +28,9 @@ Prerequisites Mandatory - GNU/Linux, - GNU C compiler, - - GNU C++ compiler (C++03/TR1 or C++11), + - GNU C++ compiler (C++11 compatible; however, C++17 compatible with tests enabled) - GNU Make, - - CMake 3.1 or better. + - CMake 3.29.0 or better. Optional MPI engine requires - MPI-3, such as 'MPICH', 'OpenMPI', or 'MVAPICH'. diff --git a/bootstrap.sh b/bootstrap.sh index e641e56e..60c1ec26 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -87,7 +87,7 @@ installdir="$builddir" config=Release doc=OFF functests=OFF -googletest_license_agreement=NO +googletest_license_agreement=FALSE perftests=OFF reconfig=no CMAKE_EXE=cmake @@ -133,7 +133,7 @@ do ------------------------------------------------------------------------------ The functional test suite requires Google Testing Framework which comes with its own license. The license can be viewed via - https://github.com/google/googletest/blob/release-1.8.1/LICENSE + https://github.com/google/googletest/blob/v1.15.x/LICENSE Do you agree with the license [yes/no] ? EOF read answer @@ -154,7 +154,7 @@ User agrees with Google Testing Framework license. It will be downloaded during the build. ============================================================================== EOF - googletest_license_agreement=YES + googletest_license_agreement=TRUE fi shift @@ -162,7 +162,7 @@ EOF --functests=i-agree-with-googletest-license) functests=ON - googletest_license_agreement=YES + googletest_license_agreement=TRUE shift ;; @@ -281,7 +281,7 @@ ${CMAKE_EXE} -Wno-dev \ -DCMAKE_BUILD_TYPE=$config \ -DLPFLIB_MAKE_DOC=$doc \ -DLPFLIB_MAKE_TEST_DOC=$doc \ - -DLPF_ENABLE_TESTS=$functests \ + -DLPF_ENABLE_TESTS=$functests \ -DGTEST_AGREE_TO_LICENSE=$googletest_license_agreement \ -DLPFLIB_PERFTESTS=$perftests \ -DLPFLIB_CONFIG_NAME=${config_name:-${config}}\ diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake deleted file mode 100644 index 14135c2f..00000000 --- a/cmake/googletest.cmake +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright 2021 Huawei Technologies Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include(ExternalProject) -set(gtest_prefix "${CMAKE_CURRENT_BINARY_DIR}/gtest") -set(GTEST_DOWNLOAD_URL - "https://github.com/google/googletest/archive/release-1.8.1.tar.gz" - CACHE STRING "File location or URL from where to download Google Test") -set(GTEST_LICENSE_URL - "https://github.com/google/googletest/blob/release-1.8.1/LICENSE" - CACHE STRING "File location or URL to license file of Google Test") -option(GTEST_AGREE_TO_LICENSE - "User agreement with license of Google Testing Framework, available at ${GOOGLE_LICENSE_URL}" - OFF) - -if (NOT GTEST_AGREE_TO_LICENSE) - message(SEND_ERROR "The LPF test suite requires agreement with the license of Google Test. Either disable LPF_ENABLE_TESTS or agree with the license by enabling GTEST_AGREE_TO_LICENSE") -endif() - -ExternalProject_Add( - GoogleTest - PREFIX ${gtest_prefix} - INSTALL_DIR ${gtest_prefix} - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${gtest_prefix} - -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} - -Dgtest_disable_pthreads=ON - URL ${GTEST_DOWNLOAD_URL} - EXCLUDE_FROM_ALL YES) -ExternalProject_Add_StepTargets(GoogleTest install) -add_library(gtest_main STATIC IMPORTED) -add_dependencies(gtest_main GoogleTest-install) -add_library(gtest STATIC IMPORTED) -add_dependencies(gtest GoogleTest-install) - -# In order to prevent failure of the next set_target_properties -# INTERFACE_INCLUDE_DIRECTORIES, make this directory before it is made by the -# GoogleTest external project -file(MAKE_DIRECTORY ${gtest_prefix}/include) -set_target_properties(gtest_main - PROPERTIES IMPORTED_LOCATION ${gtest_prefix}/${CMAKE_INSTALL_LIBDIR}/libgtest_main.a - INTERFACE_INCLUDE_DIRECTORIES ${gtest_prefix}/include - INTERFACE_LINK_LIBRARIES ${gtest_prefix}/${CMAKE_INSTALL_LIBDIR}/libgtest.a) -set_target_properties(gtest - PROPERTIES IMPORTED_LOCATION ${gtest_prefix}/${CMAKE_INSTALL_LIBDIR}/libgtest.a - INTERFACE_INCLUDE_DIRECTORIES ${gtest_prefix}/include) diff --git a/cmake/ibverbs_init.c b/cmake/ibverbs_init.c new file mode 100644 index 00000000..f38be9dc --- /dev/null +++ b/cmake/ibverbs_init.c @@ -0,0 +1,19 @@ +#include "infiniband/verbs.h" +#include + +int main(int argc, char** argv) +{ + + int numDevices = -1; + struct ibv_device * * const try_get_device_list = ibv_get_device_list( &numDevices ); + + if (!try_get_device_list) { + abort(); + } + + if (numDevices < 1) { + abort(); + } + + return 0; +} diff --git a/cmake/is_openmpi.c b/cmake/is_openmpi.c new file mode 100644 index 00000000..d3ed13c9 --- /dev/null +++ b/cmake/is_openmpi.c @@ -0,0 +1,12 @@ +#include "mpi.h" +#include + +#ifdef OMPI_MAJOR_VERSION + +int main() { + printf("The OMPI_MAJOR_VERSION is %d\n", OMPI_MAJOR_VERSION); + return 0; +} +#else +#error This is not Open MPI +#endif diff --git a/cmake/mpi.cmake b/cmake/mpi.cmake index 71b184c1..bd7ca9a5 100644 --- a/cmake/mpi.cmake +++ b/cmake/mpi.cmake @@ -78,6 +78,14 @@ if (MPI_FOUND) -DINCLUDE_DIRECTORIES:STRING=${MPI_C_INCLUDE_PATH} ) + try_compile( IS_OPENMPI "${CMAKE_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/is_openmpi.c" + LINK_LIBRARIES ${MPI_C_LIBRARIES} + CMAKE_FLAGS + -DCMAKE_C_FLAGS:STRING=${MPI_C_COMPILE_FLAGS} + -DCMAKE_EXE_LINKER_FLAGS:STRING=${MPI_C_LINK_FLAGS} + -DINCLUDE_DIRECTORIES:STRING=${MPI_C_INCLUDE_PATH} + ) try_run( MPI_IS_THREAD_COMPAT_RC MPI_IS_THREAD_COMPAT_COMPILES ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mpi_is_thread_compat.c @@ -153,4 +161,17 @@ if (MPI_FOUND) endif() +if (LIB_IBVERBS) +try_run( IBVERBS_INIT_RUNS IBVERBS_INIT_COMPILES + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ibverbs_init.c + LINK_LIBRARIES ${LIB_IBVERBS} + ARGS ${MPIRUN} + ) +endif() + +set(ENABLE_IBVERBS FALSE) +if (LIB_IBVERBS AND NOT IBVERBS_INIT_RUNS STREQUAL "FAILED_TO_RUN") + set(ENABLE_IBVERBS TRUE) +endif() + diff --git a/include/debug/lpf/core.h b/include/debug/lpf/core.h index 028e015f..9ee13cf1 100644 --- a/include/debug/lpf/core.h +++ b/include/debug/lpf/core.h @@ -133,6 +133,9 @@ extern _LPFLIB_API lpf_err_t lpf_debug_resize_message_queue( const char * file, int line, lpf_t ctx, size_t max_msgs ); +extern +lpf_err_t lpf_debug_abort(); + #ifdef __cplusplus } #endif diff --git a/include/lpf/mpi.h b/include/lpf/mpi.h index 4de54a2f..97b74708 100644 --- a/include/lpf/mpi.h +++ b/include/lpf/mpi.h @@ -147,6 +147,13 @@ lpf_err_t lpf_mpi_initialize_over_tcp( */ lpf_err_t lpf_mpi_finalize( lpf_init_t init ); +/* + * Portable aborting returning + * predictable error codes (useful for death tests + * in tests/functional/debug) + */ +lpf_err_t lpf_debug_abort(); + /** * @} * diff --git a/include/lpf/pthread.h b/include/lpf/pthread.h index ba68f3f8..4c44abc1 100644 --- a/include/lpf/pthread.h +++ b/include/lpf/pthread.h @@ -78,6 +78,14 @@ lpf_err_t lpf_pthread_initialize( lpf_pid_t pid, lpf_pid_t nprocs, extern _LPFLIB_API lpf_err_t lpf_pthread_finalize( lpf_init_t init ); + +/* + * Portable aborting returning + * predictable error codes (useful for death tests + * in tests/functional/debug) + */ +lpf_err_t lpf_debug_abort(); + /** * @} * diff --git a/include/lpf/static_dispatch.h b/include/lpf/static_dispatch.h index 8df6a092..0cde77d7 100644 --- a/include/lpf/static_dispatch.h +++ b/include/lpf/static_dispatch.h @@ -49,6 +49,7 @@ #undef lpf_exec #undef lpf_hook #undef lpf_rehook +#undef lpf_abort #undef lpf_init_t #undef lpf_pid_t @@ -92,6 +93,7 @@ #define lpf_exec LPF_FUNC(exec) #define lpf_hook LPF_FUNC(hook) #define lpf_rehook LPF_FUNC(rehook) +#define lpf_abort LPF_FUNC(abort) #define lpf_init_t LPF_TYPE(init_t) #define lpf_pid_t LPF_TYPE(pid_t) diff --git a/src/MPI/CMakeLists.txt b/src/MPI/CMakeLists.txt index beca3129..b112f268 100644 --- a/src/MPI/CMakeLists.txt +++ b/src/MPI/CMakeLists.txt @@ -22,13 +22,10 @@ if (MPI_FOUND) list(APPEND MPI_ENGINES mpirma) endif() - if (LIB_IBVERBS) + if (ENABLE_IBVERBS) list(APPEND MPI_ENGINES ibverbs) endif() - if (MPI_OPEN_PORT) - add_definitions("-DMPI_HAS_OPEN_PORT=1") - endif() if (MPI_IBARRIER) add_definitions("-DMPI_HAS_IBARRIER=1") endif() @@ -164,65 +161,63 @@ if (MPI_FOUND) set(lpf_cflags "${lpf_cflags} ${MPI_C_COMPILE_FLAGS} -I${mpi_include_flags} -fPIC" PARENT_SCOPE) set(lpf_lib_link_flags "${lpf_lib_link_flags} ${lib_lflags}" PARENT_SCOPE) - if (UNIX AND NOT APPLE) - set(lpf_exe_link_flags "${lpf_exe_link_flags} -rdynamic" PARENT_SCOPE) - endif() endforeach() include_directories(${MPI_C_INCLUDE_PATH}) # add a test for dynamichook - if (MPI_OPEN_PORT AND LPF_ENABLE_TESTS) - add_executable(dynamichook.t dynamichook.t.cpp dynamichook.cpp - $ ) - - target_include_directories(dynamichook.t PRIVATE ${GTEST_INCLUDE_PATH}) - target_link_libraries(dynamichook.t ${MPI_C_LIBRARIES} gtest) - set_target_properties(dynamichook.t PROPERTIES - COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}" - LINK_FLAGS "${MPI_C_LINK_FLAGS}" - ) - configure_file( dynamichook.t.sh.in dynamichook.t.sh @ONLY) - set( dynamic_hook_t_sh "${CMAKE_CURRENT_BINARY_DIR}/dynamichook.t.sh") - add_test(NAME dynamichook_1proc - COMMAND bash ${dynamic_hook_t_sh} 1) - set_tests_properties( dynamichook_1proc PROPERTIES TIMEOUT 120 ) - add_test(NAME dynamichook_2proc - COMMAND bash ${dynamic_hook_t_sh} 2) - set_tests_properties( dynamichook_2proc PROPERTIES TIMEOUT 240 ) - add_test(NAME dynamichook_3proc - COMMAND bash ${dynamic_hook_t_sh} 3) - set_tests_properties( dynamichook_3proc PROPERTIES TIMEOUT 360 ) - add_test(NAME dynamichook_10proc - COMMAND bash ${dynamic_hook_t_sh} 10) - set_tests_properties( dynamichook_10proc PROPERTIES TIMEOUT 1200 ) + if (NOT IS_OPENMPI AND LPF_ENABLE_TESTS) + add_gtest(dynamichook.t "mpimsg" ON + ${CMAKE_CURRENT_SOURCE_DIR}/dynamichook.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/dynamichook.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mpilib.cpp) + + configure_file( dynamichook.t.sh.in dynamichook.t.sh @ONLY) + set( dynamic_hook_t_sh "${CMAKE_CURRENT_BINARY_DIR}/dynamichook.t.sh") + add_test(NAME dynamichook_1proc + COMMAND bash ${dynamic_hook_t_sh} 1) + set_tests_properties( dynamichook_1proc PROPERTIES TIMEOUT 30 ) + add_test(NAME dynamichook_2proc + COMMAND bash ${dynamic_hook_t_sh} 2) + set_tests_properties( dynamichook_2proc PROPERTIES TIMEOUT 30 ) + add_test(NAME dynamichook_3proc + COMMAND bash ${dynamic_hook_t_sh} 3) + set_tests_properties( dynamichook_3proc PROPERTIES TIMEOUT 30 ) + add_test(NAME dynamichook_10proc + COMMAND bash ${dynamic_hook_t_sh} 10) + set_tests_properties( dynamichook_10proc PROPERTIES TIMEOUT 30 ) endif() # Other unit tests - if (LIB_IBVERBS AND LPF_ENABLE_TESTS) - add_gtest_mpi( ibverbs_test "1;2;5;10" ibverbs.t.cpp ibverbs.cpp - $ mpilib.cpp) - target_link_libraries( ibverbs_test ${LIB_IBVERBS}) + if (ENABLE_IBVERBS AND LPF_ENABLE_TESTS) + add_gtest( ibverbs_test "ibverbs" ON ${CMAKE_CURRENT_SOURCE_DIR}/ibverbs.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ibverbs.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mpilib.cpp) endif() - add_gtest_mpi( spall2all_test "1;2;5;10" spall2all.t.cpp spall2all.c - spall2all.cpp mpilib.cpp - $ - ) - - add_gtest_mpi( dall2all_test "1;2;5;10" dall2all.t.cpp - mpilib.cpp $ - ) - - if (MPI_IBARRIER) - add_gtest_mpi( hall2all_test "1;2;5;10" hall2all.t.cpp - mpilib.cpp $ ) - endif() + foreach (engine ${MPI_ENGINES}) + add_gtest( spall2all_test_${engine} ${engine} ON + ${CMAKE_CURRENT_SOURCE_DIR}/spall2all.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/spall2all.c + ${CMAKE_CURRENT_SOURCE_DIR}/spall2all.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mpilib.cpp) + + add_gtest( dall2all_test_${engine} ${engine} ON + ${CMAKE_CURRENT_SOURCE_DIR}/dall2all.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mpilib.cpp) + + if (MPI_IBARRIER) + add_gtest( hall2all_test_${engine} ${engine} ON + ${CMAKE_CURRENT_SOURCE_DIR}/hall2all.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mpilib.cpp) + endif() - add_gtest( messagesort_test messagesort.t.cpp messagesort.cpp - $ ) + add_gtest( messagesort_test_${engine} ${engine} ON + ${CMAKE_CURRENT_SOURCE_DIR}/messagesort.t.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/messagesort.cpp) - add_gtest( ipcmesg_test ipcmesg.t.cpp - $ ) + add_gtest( ipcmesg_test_${engine} ${engine} ON + ${CMAKE_CURRENT_SOURCE_DIR}/ipcmesg.t.cpp) + endforeach() endif(MPI_FOUND) diff --git a/src/MPI/core.cpp b/src/MPI/core.cpp index 112403e6..8f5844ae 100644 --- a/src/MPI/core.cpp +++ b/src/MPI/core.cpp @@ -290,3 +290,10 @@ lpf_err_t lpf_resize_message_queue( lpf_t ctx, size_t max_msgs ) return i->resizeMesgQueue(max_msgs); } +lpf_err_t lpf_debug_abort() { + std::cout << "Will call MPI_abort\n"; + MPI_Abort(MPI_COMM_WORLD, 6); + return LPF_SUCCESS; +} + + diff --git a/src/MPI/dall2all.t.cpp b/src/MPI/dall2all.t.cpp index 4e5d6172..9754f719 100644 --- a/src/MPI/dall2all.t.cpp +++ b/src/MPI/dall2all.t.cpp @@ -20,121 +20,106 @@ #include #include - using namespace lpf::mpi; -extern "C" const int LPF_MPI_AUTO_INITIALIZE=1; +extern "C" const int LPF_MPI_AUTO_INITIALIZE = 0; +/** + * \pre P >= 1 + * \pre P <= 2 + */ +class DenseAll2AllTests : public testing::Test { +protected: + static void SetUpTestSuite() { -TEST( Dall2all, Create ) -{ - DenseAllToAll x(9, 10); -} + MPI_Init(NULL, NULL); + Lib::instance(); -TEST( Dall2all, Reserve ) -{ - DenseAllToAll x( 4,10); - x.reserve( 50 , 100); -} + MPI_Comm_rank(MPI_COMM_WORLD, &my_pid); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + } -TEST( Dall2all, Send ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); + static void TearDownTestSuite() { MPI_Finalize(); } + static int my_pid; + static int nprocs; +}; - DenseAllToAll x( my_pid, nprocs ); - x.reserve( nprocs , sizeof(int)); - for (int i = 0; i <= my_pid ; ++i) - x.send( (my_pid + 1) % nprocs, &i, sizeof(int) ); +int DenseAll2AllTests::my_pid = -1; +int DenseAll2AllTests::nprocs = -1; - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); -} +TEST_F(DenseAll2AllTests, Create) { DenseAllToAll x(9, 10); } -TEST( Dall2all, Ring ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); +TEST_F(DenseAll2AllTests, Reserve) { + DenseAllToAll x(4, 10); + x.reserve(50, 100); +} - DenseAllToAll x(my_pid, nprocs); - x.reserve( nprocs , sizeof(int)); - x.send( (my_pid + 1) % nprocs, &my_pid, sizeof(my_pid) ); +TEST_F(DenseAll2AllTests, Send) { - EXPECT_FALSE( x.empty() ); + DenseAllToAll x(my_pid, nprocs); + x.reserve(nprocs, sizeof(int)); + for (int i = 0; i <= my_pid; ++i) + x.send((my_pid + 1) % nprocs, &i, sizeof(int)); - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); +} - EXPECT_FALSE( x.empty() ); - - int y = -1; - x.recv( &y, sizeof(y)); - EXPECT_EQ( (my_pid + nprocs -1) % nprocs, y ); +TEST_F(DenseAll2AllTests, Ring) { + DenseAllToAll x(my_pid, nprocs); + x.reserve(nprocs, sizeof(int)); + x.send((my_pid + 1) % nprocs, &my_pid, sizeof(my_pid)); - EXPECT_TRUE( x.empty() ); + EXPECT_FALSE(x.empty()); -} + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); + EXPECT_FALSE(x.empty()); -TEST( Dall2all, ManyMsgs ) -{ - Lib::instance(); + int y = -1; + x.recv(&y, sizeof(y)); + EXPECT_EQ((my_pid + nprocs - 1) % nprocs, y); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - DenseAllToAll x(my_pid, nprocs ); - const int nMsgs = 10000; - x.reserve( nMsgs , sizeof(int)); - - for (int j = 0; j < 10 ; ++j) { - x.clear(); - - for (int i = 0; i < nMsgs; ++i) - { - x.send( (my_pid + i) % nprocs, & i, sizeof(i) ); - } - - bool prerandomize = true; - int trials = 5; - int error = x.exchange( Lib::instance().world(), prerandomize, - NULL, trials); - EXPECT_FALSE( error ); - - for (int i = 0; i < nMsgs; ++i) - { - EXPECT_FALSE( x.empty() ); - int k = -1; - x.recv( &k, sizeof(k)); - EXPECT_GE( k, 0 ); - EXPECT_LT( k, nMsgs ); - } - EXPECT_TRUE( x.empty() ); - } + EXPECT_TRUE(x.empty()); } -TEST( Dall2all, LargeSend ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - DenseAllToAll x( my_pid, nprocs ); +TEST_F(DenseAll2AllTests, ManyMsgs) { + DenseAllToAll x(my_pid, nprocs); + const int nMsgs = 10000; + x.reserve(nMsgs, sizeof(int)); - size_t bigNum = size_t(std::numeric_limits::max()) + 10u ; + for (int j = 0; j < 10; ++j) { + x.clear(); - EXPECT_THROW( x.reserve( 1 , bigNum ), std::bad_alloc ); + for (int i = 0; i < nMsgs; ++i) { + x.send((my_pid + i) % nprocs, &i, sizeof(i)); + } + bool prerandomize = true; + int trials = 5; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL, trials); + EXPECT_FALSE(error); + + for (int i = 0; i < nMsgs; ++i) { + EXPECT_FALSE(x.empty()); + int k = -1; + x.recv(&k, sizeof(k)); + EXPECT_GE(k, 0); + EXPECT_LT(k, nMsgs); + } + EXPECT_TRUE(x.empty()); + } } +TEST_F(DenseAll2AllTests, LargeSend) { + DenseAllToAll x(my_pid, nprocs); + size_t bigNum = size_t(std::numeric_limits::max()) + 10u; + + EXPECT_THROW(x.reserve(1, bigNum), std::bad_alloc); +} diff --git a/src/MPI/dynamichook.cpp b/src/MPI/dynamichook.cpp index 974534fd..930ff420 100644 --- a/src/MPI/dynamichook.cpp +++ b/src/MPI/dynamichook.cpp @@ -52,7 +52,6 @@ struct _LPFLIB_LOCAL HookException : public std::runtime_error { {} }; -#ifdef MPI_HAS_OPEN_PORT namespace { // Compares two sockaddr objects. @@ -514,7 +513,6 @@ namespace { } #endif } -#endif // @@ -525,13 +523,6 @@ MPI_Comm dynamicHook( const std::string & serverNode, ASSERT( nprocs > 0 ); ASSERT( pid < nprocs ); -#ifndef MPI_HAS_OPEN_PORT - (void) serverNode; - (void) serverPort; - (void) timeout; (void) pid; (void) nprocs; - throw HookException("MPI does not support MPI_Open_port"); -#else - #ifdef USE_SIGALRM HookException timeoutException("operation timed out"); struct sigaction oldact; @@ -723,7 +714,6 @@ MPI_Comm dynamicHook( const std::string & serverNode, #endif return result; -#endif } diff --git a/src/MPI/dynamichook.t.cpp b/src/MPI/dynamichook.t.cpp index e7b2e6ca..9e52250b 100644 --- a/src/MPI/dynamichook.t.cpp +++ b/src/MPI/dynamichook.t.cpp @@ -15,48 +15,68 @@ * limitations under the License. */ +#include "assert.hpp" #include "dynamichook.hpp" #include "time.hpp" -#include "assert.hpp" #include #include #include -int main(int argc, char ** argv) -{ - MPI_Init(&argc, &argv); - ASSERT( argc >= 6 && "usage: ./dynamichook.t [server] [port] [pid] [nprocs] [timeout]"); - - std::string server = argv[1]; - std::string port = argv[2]; - int pid = atoi(argv[3]); - int nprocs = atoi(argv[4]); - int timeout = atoi(argv[5]); - - MPI_Comm comm = MPI_COMM_NULL; - - try { - comm = lpf::mpi::dynamicHook( server, port, pid, nprocs, - lpf::Time::fromSeconds( timeout / 1000.0 ) ); - } - catch( std::runtime_error & e) - { - ADD_FAILURE() << "hookup failed. Fatal!: " << e.what() << "\n"; - _exit(EXIT_FAILURE); - } - - int mpiPid = -1, mpiNprocs = -1; - MPI_Comm_rank( comm, &mpiPid); - MPI_Comm_size( comm, &mpiNprocs ); - - EXPECT_EQ( pid, mpiPid ); - EXPECT_EQ( nprocs, mpiNprocs ); - - MPI_Comm_free(&comm); - - MPI_Finalize(); - - return 0; +extern "C" const int LPF_MPI_AUTO_INITIALIZE = 0; +int myArgc; +char **myArgv; + +/** + * \pre P >= 1 + * \pre P <= 1 + * \return Exit code: 1 + */ + +int main(int argc, char **argv) { + myArgc = argc; + myArgv = argv; + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +TEST(API, dynamicHook) { + + /** + * This test is run via following options via + * ./dynamichook.t + * Being run "as is" without all these 5 arguments will lead it + * to fail (which is the normal Google Test case, so we expect exit code 1) + * However, when run via custom add_test tests with correct 5 arguments, it + * shall work + */ + ASSERT_GE(myArgc, 6); + MPI_Init(&myArgc, &myArgv); + std::string server = myArgv[1]; + std::string port = myArgv[2]; + int pid = atoi(myArgv[3]); + int nprocs = atoi(myArgv[4]); + int timeout = atoi(myArgv[5]); + + MPI_Comm comm = MPI_COMM_NULL; + + try { + comm = lpf::mpi::dynamicHook(server, port, pid, nprocs, + lpf::Time::fromSeconds(timeout / 1000.0)); + } catch (std::runtime_error &e) { + ADD_FAILURE() << "hookup failed. Fatal!: " << e.what() << "\n"; + _exit(EXIT_FAILURE); + } + + int mpiPid = -1, mpiNprocs = -1; + MPI_Comm_rank(comm, &mpiPid); + MPI_Comm_size(comm, &mpiNprocs); + + EXPECT_EQ(pid, mpiPid); + EXPECT_EQ(nprocs, mpiNprocs); + + MPI_Comm_free(&comm); + + MPI_Finalize(); } diff --git a/src/MPI/hall2all.t.cpp b/src/MPI/hall2all.t.cpp index a5252792..2b9e7a9f 100644 --- a/src/MPI/hall2all.t.cpp +++ b/src/MPI/hall2all.t.cpp @@ -20,131 +20,122 @@ #include #include - using namespace lpf::mpi; -extern "C" const int LPF_MPI_AUTO_INITIALIZE=1; - +extern "C" const int LPF_MPI_AUTO_INITIALIZE = 0; -TEST( Hall2all, Create ) -{ - HoeflerAllToAll x(9, 10); -} +/** + * \pre P >= 1 + * \pre P <= 2 + */ +class HAll2AllTests : public testing::Test { -TEST( Hall2all, Reserve ) -{ - HoeflerAllToAll x( 4,10); - x.reserve( 50 , 100); -} +protected: + static void SetUpTestSuite() { -TEST( Hall2all, Send ) -{ + MPI_Init(NULL, NULL); Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); + MPI_Comm_rank(MPI_COMM_WORLD, &my_pid); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + } - HoeflerAllToAll x( my_pid, nprocs ); - x.reserve( nprocs , sizeof(int)); - for (int i = 0; i <= my_pid ; ++i) - x.send( (my_pid + 1) % nprocs, &i, sizeof(int) ); + static void TearDownTestSuite() { MPI_Finalize(); } - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + static int my_pid; + static int nprocs; +}; + +int HAll2AllTests::my_pid = -1; +int HAll2AllTests::nprocs = -1; + +TEST_F(HAll2AllTests, Create) { HoeflerAllToAll x(9, 10); } + +TEST_F(HAll2AllTests, Reserve) { + HoeflerAllToAll x(4, 10); + x.reserve(50, 100); } -TEST( Hall2all, Ring ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); +TEST_F(HAll2AllTests, Send) { + HoeflerAllToAll x(my_pid, nprocs); + x.reserve(nprocs, sizeof(int)); + for (int i = 0; i <= my_pid; ++i) + x.send((my_pid + 1) % nprocs, &i, sizeof(int)); - HoeflerAllToAll x(my_pid, nprocs); - x.reserve( nprocs , sizeof(int)); - x.send( (my_pid + 1) % nprocs, &my_pid, sizeof(my_pid) ); + bool prerandomize = true; + int dummyOutput[4]; + int error = x.exchange(Lib::instance().world(), prerandomize, dummyOutput); + EXPECT_TRUE(!error); +} - EXPECT_FALSE( x.empty() ); +TEST_F(HAll2AllTests, Ring) { + int dummyOutput[4]; + HoeflerAllToAll x(my_pid, nprocs); + x.reserve(nprocs, sizeof(int)); + x.send((my_pid + 1) % nprocs, &my_pid, sizeof(my_pid)); - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + EXPECT_FALSE(x.empty()); + + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, dummyOutput); + EXPECT_TRUE(!error); - EXPECT_FALSE( x.empty() ); - - int y = -1; - x.recv( &y, sizeof(y)); - EXPECT_EQ( (my_pid + nprocs -1) % nprocs, y ); + EXPECT_FALSE(x.empty()); - EXPECT_TRUE( x.empty() ); + int y = -1; + x.recv(&y, sizeof(y)); + EXPECT_EQ((my_pid + nprocs - 1) % nprocs, y); + EXPECT_TRUE(x.empty()); } +TEST_F(HAll2AllTests, ManyMsgs) { + HoeflerAllToAll x(my_pid, nprocs); + const int nMsgs = 10000; + x.reserve(nMsgs, sizeof(int)); -TEST( Hall2all, ManyMsgs ) -{ - Lib::instance(); + for (int j = 0; j < 10; ++j) { + x.clear(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - HoeflerAllToAll x(my_pid, nprocs ); - const int nMsgs = 10000; - x.reserve( nMsgs , sizeof(int)); - - for (int j = 0; j < 10 ; ++j) { - x.clear(); - - for (int i = 0; i < nMsgs; ++i) - { - x.send( (my_pid + i) % nprocs, & i, sizeof(i) ); - } - - bool prerandomize = true; - int trials = 5; - int error = x.exchange( Lib::instance().world(), prerandomize, - NULL, trials); - EXPECT_FALSE( error ); - - for (int i = 0; i < nMsgs; ++i) - { - EXPECT_FALSE( x.empty() ); - int k = -1; - x.recv( &k, sizeof(k)); - EXPECT_GE( k, 0 ); - EXPECT_LT( k, nMsgs ); - } - EXPECT_TRUE( x.empty() ); + for (int i = 0; i < nMsgs; ++i) { + x.send((my_pid + i) % nprocs, &i, sizeof(i)); } -} -TEST( Hall2all, LargeSend ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); + bool prerandomize = true; + int trials = 5; + int dummyOutput[4]; + int error = + x.exchange(Lib::instance().world(), prerandomize, dummyOutput, trials); + EXPECT_FALSE(error); + + for (int i = 0; i < nMsgs; ++i) { + EXPECT_FALSE(x.empty()); + int k = -1; + x.recv(&k, sizeof(k)); + EXPECT_GE(k, 0); + EXPECT_LT(k, nMsgs); + } + EXPECT_TRUE(x.empty()); + } +} - HoeflerAllToAll x( my_pid, nprocs ); +TEST_F(HAll2AllTests, LargeSend) { + HoeflerAllToAll x(my_pid, nprocs); - std::vector data( size_t(std::numeric_limits::max()) + 10u ); - for (size_t i = 0; i < data.size(); ++i) - data[i] = char(i + my_pid) ; + std::vector data(size_t(std::numeric_limits::max()) + 10u); + for (size_t i = 0; i < data.size(); ++i) + data[i] = char(i + my_pid); - x.reserve( 1 , data.size() ); - x.send( (my_pid + 1) % nprocs, data.data(), data.size() ); + x.reserve(1, data.size()); + x.send((my_pid + 1) % nprocs, data.data(), data.size()); - bool prerandomize = false; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + bool prerandomize = false; + int dummyOutput[4]; + int error = x.exchange(Lib::instance().world(), prerandomize, dummyOutput); + EXPECT_TRUE(!error); - x.recv( data.data(), data.size() ); - int j = (nprocs != 1?1:0); - for (size_t i = 0; i < data.size(); ++i) - EXPECT_EQ( char(i + (my_pid + nprocs - j) % nprocs), data[i] ) ; + x.recv(data.data(), data.size()); + int j = (nprocs != 1 ? 1 : 0); + for (size_t i = 0; i < data.size(); ++i) + EXPECT_EQ(char(i + (my_pid + nprocs - j) % nprocs), data[i]); } - - diff --git a/src/MPI/ibverbs.hpp b/src/MPI/ibverbs.hpp index b79ec53a..a96030a2 100644 --- a/src/MPI/ibverbs.hpp +++ b/src/MPI/ibverbs.hpp @@ -62,6 +62,10 @@ class _LPFLIB_LOCAL IBVerbs SlotID regGlobal( void * addr, size_t size ); void dereg( SlotID id ); + size_t getMaxMsgSize() const { + return m_maxMsgSize; + } + void put( SlotID srcSlot, size_t srcOffset, int dstPid, SlotID dstSlot, size_t dstOffset, size_t size ); diff --git a/src/MPI/ibverbs.t.cpp b/src/MPI/ibverbs.t.cpp index 65bd4905..b36bfa86 100644 --- a/src/MPI/ibverbs.t.cpp +++ b/src/MPI/ibverbs.t.cpp @@ -15,8 +15,8 @@ * limitations under the License. */ -#include "ibverbs.hpp" #include "assert.hpp" +#include "ibverbs.hpp" #include "mpilib.hpp" #include @@ -24,293 +24,274 @@ using namespace lpf::mpi; -extern "C" const int LPF_MPI_AUTO_INITIALIZE=1; +extern "C" const int LPF_MPI_AUTO_INITIALIZE = 0; -TEST( IBVerbs, init ) -{ - Comm comm = Lib::instance().world(); +/** + * \pre P >= 1 + * \pre P <= 2 + */ +class IBVerbsTests : public testing::Test { - comm.barrier(); - IBVerbs verbs( comm ); - comm.barrier(); -} +protected: + static void SetUpTestSuite() { + MPI_Init(NULL, NULL); + Lib::instance(); + comm = new Comm(); + *comm = Lib::instance().world(); + comm->barrier(); + verbs = new IBVerbs(*comm); + } -TEST( IBVerbs, resizeMemreg ) -{ - Comm comm = Lib::instance().world(); + static void TearDownTestSuite() { + delete verbs; + verbs = nullptr; + delete comm; + comm = nullptr; + MPI_Finalize(); + } - comm.barrier(); - IBVerbs verbs( comm ); + static Comm *comm; + static IBVerbs *verbs; +}; - verbs.resizeMemreg( 2 ); +lpf::mpi::Comm *IBVerbsTests::comm = nullptr; +IBVerbs *IBVerbsTests::verbs = nullptr; - comm.barrier(); -} +TEST_F(IBVerbsTests, init) { comm->barrier(); } +TEST_F(IBVerbsTests, resizeMemreg) { -TEST( IBVerbs, resizeMesgq ) -{ - Comm comm = Lib::instance().world(); + verbs->resizeMemreg(2); - comm.barrier(); - IBVerbs verbs( comm ); + comm->barrier(); +} - verbs.resizeMesgq( 2 ); +TEST_F(IBVerbsTests, resizeMesgq) { - comm.barrier(); -} + verbs->resizeMesgq(2); -TEST( IBVerbs, regVars ) -{ - Comm comm = Lib::instance().world(); + comm->barrier(); +} - comm.barrier(); - IBVerbs verbs( comm ); +TEST_F(IBVerbsTests, regVars) { - char buf1[30] = "Hi"; - char buf2[30] = "Boe"; + char buf1[30] = "Hi"; + char buf2[30] = "Boe"; - verbs.resizeMemreg( 2 ); + verbs->resizeMemreg(2); - verbs.regLocal( buf1, sizeof(buf1) ); - verbs.regGlobal( buf2, sizeof(buf2) ); + IBVerbs::SlotID b1 = verbs->regLocal(buf1, sizeof(buf1)); + IBVerbs::SlotID b2 = verbs->regGlobal(buf2, sizeof(buf2)); - comm.barrier(); + comm->barrier(); + verbs->dereg(b1); + verbs->dereg(b2); } +TEST_F(IBVerbsTests, put) { -TEST( IBVerbs, put ) -{ - Comm comm = Lib::instance().world(); - - comm.barrier(); - IBVerbs verbs( comm ); + char buf1[30] = "Hi"; + char buf2[30] = "Boe"; - char buf1[30] = "Hi"; - char buf2[30] = "Boe"; + verbs->resizeMemreg(2); + verbs->resizeMesgq(1); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( 1 ); + IBVerbs::SlotID b1 = verbs->regLocal(buf1, sizeof(buf1)); + IBVerbs::SlotID b2 = verbs->regGlobal(buf2, sizeof(buf2)); - IBVerbs::SlotID b1 = verbs.regLocal( buf1, sizeof(buf1) ); - IBVerbs::SlotID b2 = verbs.regGlobal( buf2, sizeof(buf2) ); - - comm.barrier(); + comm->barrier(); - verbs.put( b1, 0, (comm.pid() + 1)%comm.nprocs(), b2, 0, sizeof(buf1)); + verbs->put(b1, 0, (comm->pid() + 1) % comm->nprocs(), b2, 0, sizeof(buf1)); - verbs.sync(true); - EXPECT_EQ( "Hi", std::string(buf1) ); - EXPECT_EQ( "Hi", std::string(buf2) ); + verbs->sync(true); + EXPECT_EQ("Hi", std::string(buf1)); + EXPECT_EQ("Hi", std::string(buf2)); + verbs->dereg(b1); + verbs->dereg(b2); } +TEST_F(IBVerbsTests, get) { -TEST( IBVerbs, get ) -{ - Comm comm = Lib::instance().world(); + char buf1[30] = "Hoi"; + char buf2[30] = "Vreemd"; - comm.barrier(); - IBVerbs verbs( comm ); + verbs->resizeMemreg(2); + verbs->resizeMesgq(1); - char buf1[30] = "Hoi"; - char buf2[30] = "Vreemd"; + IBVerbs::SlotID b1 = verbs->regLocal(buf1, sizeof(buf1)); + IBVerbs::SlotID b2 = verbs->regGlobal(buf2, sizeof(buf2)); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( 1 ); + comm->barrier(); - IBVerbs::SlotID b1 = verbs.regLocal( buf1, sizeof(buf1) ); - IBVerbs::SlotID b2 = verbs.regGlobal( buf2, sizeof(buf2) ); - - comm.barrier(); + verbs->get((comm->pid() + 1) % comm->nprocs(), b2, 0, b1, 0, sizeof(buf2)); - verbs.get( (comm.pid() + 1)%comm.nprocs(), b2, 0, - b1, 0, sizeof(buf2)); - - verbs.sync(true); - EXPECT_EQ( "Vreemd", std::string(buf1) ); - EXPECT_EQ( "Vreemd", std::string(buf2) ); + verbs->sync(true); + EXPECT_EQ("Vreemd", std::string(buf1)); + EXPECT_EQ("Vreemd", std::string(buf2)); + verbs->dereg(b1); + verbs->dereg(b2); } +TEST_F(IBVerbsTests, putAllToAll) { + int nprocs = comm->nprocs(); + int pid = comm->pid(); -TEST( IBVerbs, putAllToAll ) -{ - Comm comm = Lib::instance().world(); - int nprocs = comm.nprocs(); - int pid = comm.pid(); - - comm.barrier(); - IBVerbs verbs( comm ); + const int H = 2.5 * nprocs; - const int H = 2.5 * nprocs; + std::vector a(H); + std::vector b(H); - std::vector< int > a(H); - std::vector< int > b(H); + for (int i = 0; i < H; ++i) { + a[i] = i * nprocs + pid; + b[i] = nprocs * nprocs - (i * nprocs + pid); + } - for (int i = 0; i < H; ++i) { - a[i] = i * nprocs + pid ; - b[i] = nprocs*nprocs - ( i * nprocs + pid); - } + verbs->resizeMemreg(2); + verbs->resizeMesgq(H); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( H ); + IBVerbs::SlotID a1 = verbs->regGlobal(a.data(), sizeof(int) * a.size()); + IBVerbs::SlotID b1 = verbs->regGlobal(b.data(), sizeof(int) * b.size()); - IBVerbs::SlotID a1 = verbs.regGlobal( a.data(), sizeof(int)*a.size()); - IBVerbs::SlotID b1 = verbs.regGlobal( b.data(), sizeof(int)*b.size()); - - comm.barrier(); + comm->barrier(); - for (int i = 0; i < H; ++i) { - int dstPid = (pid + i ) % nprocs; - verbs.put( a1, sizeof(int)*i, - dstPid, b1, sizeof(int)*i, sizeof(int)); - } + for (int i = 0; i < H; ++i) { + int dstPid = (pid + i) % nprocs; + verbs->put(a1, sizeof(int) * i, dstPid, b1, sizeof(int) * i, sizeof(int)); + } - verbs.sync(true); - - for (int i = 0; i < H; ++i) { - int srcPid = (nprocs + pid - (i%nprocs)) % nprocs; - EXPECT_EQ( i*nprocs + pid, a[i] ) ; - EXPECT_EQ( i*nprocs + srcPid, b[i] ); - } + verbs->sync(true); + for (int i = 0; i < H; ++i) { + int srcPid = (nprocs + pid - (i % nprocs)) % nprocs; + EXPECT_EQ(i * nprocs + pid, a[i]); + EXPECT_EQ(i * nprocs + srcPid, b[i]); + } + verbs->dereg(a1); + verbs->dereg(b1); } -TEST( IBVerbs, getAllToAll ) -{ - Comm comm = Lib::instance().world(); - int nprocs = comm.nprocs(); - int pid = comm.pid(); +TEST_F(IBVerbsTests, getAllToAll) { + int nprocs = comm->nprocs(); + int pid = comm->pid(); - comm.barrier(); - IBVerbs verbs( comm ); + const int H = 100.3 * nprocs; - const int H = 1000.3 * nprocs; + std::vector a(H), a2(H); + std::vector b(H), b2(H); - std::vector< int > a(H); - std::vector< int > b(H); + for (int i = 0; i < H; ++i) { + a[i] = i * nprocs + pid; + a2[i] = a[i]; + b[i] = nprocs * nprocs - (i * nprocs + pid); + b2[i] = i * nprocs + (nprocs + pid + i) % nprocs; + } - for (int i = 0; i < H; ++i) { - a[i] = i * nprocs + pid ; - b[i] = nprocs*nprocs - ( i * nprocs + pid); - } + verbs->resizeMemreg(2); + verbs->resizeMesgq(H); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( H ); + IBVerbs::SlotID a1 = verbs->regGlobal(a.data(), sizeof(int) * a.size()); + IBVerbs::SlotID b1 = verbs->regGlobal(b.data(), sizeof(int) * b.size()); - IBVerbs::SlotID a1 = verbs.regGlobal( a.data(), sizeof(int)*a.size()); - IBVerbs::SlotID b1 = verbs.regGlobal( b.data(), sizeof(int)*b.size()); - - comm.barrier(); + comm->barrier(); - for (int i = 0; i < H; ++i) { - int srcPid = (pid + i) % nprocs; - verbs.get( srcPid, a1, sizeof(int)*i, - b1, sizeof(int)*i, sizeof(int)); - } + for (int i = 0; i < H; ++i) { + int srcPid = (pid + i) % nprocs; + verbs->get(srcPid, a1, sizeof(int) * i, b1, sizeof(int) * i, sizeof(int)); + } - verbs.sync(true); + verbs->sync(true); - for (int i = 0; i < H; ++i) { - int srcPid = (nprocs + pid + i ) % nprocs; - EXPECT_EQ( i*nprocs + pid, a[i] ) ; - EXPECT_EQ( i*nprocs + srcPid, b[i] ); - } + EXPECT_EQ(a, a2); + EXPECT_EQ(b, b2); + verbs->dereg(a1); + verbs->dereg(b1); } +TEST_F(IBVerbsTests, putHuge) { + std::vector hugeMsg(3 * verbs->getMaxMsgSize()); + std::vector hugeBuf(3 * verbs->getMaxMsgSize()); + LOG(4, "Allocating putHuge with vector size: " << hugeMsg.size()); -TEST( IBVerbs, putHuge ) -{ - Comm comm = Lib::instance().world(); - - comm.barrier(); - IBVerbs verbs( comm ); + for (size_t i = 0; i < hugeMsg.size(); ++i) + hugeMsg[i] = char(i); - LOG(4, "Allocating mem1 "); - std::vector< char > hugeMsg( std::numeric_limits::max() * 1.5l ); - LOG(4, "Allocating mem2 "); - std::vector< char > hugeBuf( hugeMsg.size() ); + verbs->resizeMemreg(2); + verbs->resizeMesgq(1); -#if 0 - LOG(4, "Initializing mem2 "); - for ( size_t i = 0; i < hugeMsg.size() ; ++i) - hugeMsg[i] = char( i ); -#endif + IBVerbs::SlotID b1 = verbs->regLocal(hugeMsg.data(), hugeMsg.size()); + IBVerbs::SlotID b2 = verbs->regGlobal(hugeBuf.data(), hugeBuf.size()); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( 1 ); + comm->barrier(); - IBVerbs::SlotID b1 = verbs.regLocal( hugeMsg.data(), hugeMsg.size() ); - IBVerbs::SlotID b2 = verbs.regGlobal( hugeBuf.data(), hugeBuf.size() ); - - comm.barrier(); + verbs->put(b1, 0, (comm->pid() + 1) % comm->nprocs(), b2, 0, + hugeMsg.size() * sizeof(char)); - verbs.put( b1, 0, (comm.pid() + 1)%comm.nprocs(), b2, 0, hugeMsg.size() ); + verbs->sync(true); - verbs.sync(true); + EXPECT_EQ(hugeMsg, hugeBuf); - EXPECT_EQ( hugeMsg, hugeBuf ); + verbs->dereg(b1); + verbs->dereg(b2); } -TEST( IBVerbs, getHuge ) -{ - Comm comm = Lib::instance().world(); +TEST_F(IBVerbsTests, getHuge) { - comm.barrier(); - IBVerbs verbs( comm ); + std::vector hugeMsg(3 * verbs->getMaxMsgSize()); + std::vector hugeBuf(3 * verbs->getMaxMsgSize()); + LOG(4, "Allocating getHuge with vector size: " << hugeMsg.size()); - std::vector< char > hugeMsg( std::numeric_limits::max() * 1.5 ); - std::vector< char > hugeBuf( hugeMsg.size() ); + for (size_t i = 0; i < hugeMsg.size(); ++i) + hugeMsg[i] = char(i); - for ( size_t i = 0; i < hugeMsg.size() ; ++i) - hugeMsg[i] = char( i ); + verbs->resizeMemreg(2); + verbs->resizeMesgq(1); - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( 1 ); + IBVerbs::SlotID b1 = verbs->regLocal(hugeMsg.data(), hugeMsg.size()); + IBVerbs::SlotID b2 = verbs->regGlobal(hugeBuf.data(), hugeBuf.size()); - IBVerbs::SlotID b1 = verbs.regLocal( hugeBuf.data(), hugeBuf.size() ); - IBVerbs::SlotID b2 = verbs.regGlobal( hugeMsg.data(), hugeMsg.size() ); - - comm.barrier(); + comm->barrier(); - verbs.get( (comm.pid() + 1)%comm.nprocs(), b2, 0, b1, 0, hugeMsg.size() ); + verbs->get((comm->pid() + 1) % comm->nprocs(), b2, 0, b1, 0, + hugeMsg.size() * sizeof(char)); - verbs.sync(true); + verbs->sync(true); - EXPECT_EQ( hugeMsg, hugeBuf ); -} + EXPECT_EQ(hugeMsg, hugeBuf); -TEST( IBVerbs, manyPuts ) -{ - Comm comm = Lib::instance().world(); - - comm.barrier(); - IBVerbs verbs( comm ); - const unsigned N = 100000; - - std::vector< unsigned char > buf1( N ); - std::vector< unsigned char > buf2( N ); - for (unsigned int i = 0 ; i < N; ++ i) - buf1[i] = i + comm.pid() ; - - verbs.resizeMemreg( 2 ); - verbs.resizeMesgq( N ); - - IBVerbs::SlotID b1 = verbs.regLocal( buf1.data(), buf1.size() ); - IBVerbs::SlotID b2 = verbs.regGlobal( buf2.data(), buf1.size() ); - - comm.barrier(); - - for ( unsigned i = 0 ; i < N; ++i) - verbs.put( b1, i, (comm.pid() + 1)%comm.nprocs(), b2, i, 1); - - verbs.sync(true); - for ( unsigned i = 0 ; i < N; ++i) { - unsigned char b2_exp = i + (comm.pid() + comm.nprocs() - 1) % comm.nprocs(); - unsigned char b1_exp = i + comm.pid(); - EXPECT_EQ( b2_exp, buf2[i]); - EXPECT_EQ( b1_exp, buf1[i] ); - } + verbs->dereg(b1); + verbs->dereg(b2); } +TEST_F(IBVerbsTests, manyPuts) { + + const unsigned N = 5000; + std::vector buf1(N); + std::vector buf2(N); + for (unsigned int i = 0; i < N; ++i) + buf1[i] = i + comm->pid(); + + verbs->resizeMemreg(2); + verbs->resizeMesgq(N); + + IBVerbs::SlotID b1 = verbs->regLocal(buf1.data(), buf1.size()); + IBVerbs::SlotID b2 = verbs->regGlobal(buf2.data(), buf1.size()); + + comm->barrier(); + + for (unsigned i = 0; i < N; ++i) + verbs->put(b1, i, (comm->pid() + 1) % comm->nprocs(), b2, i, 1); + + verbs->sync(true); + for (unsigned i = 0; i < N; ++i) { + unsigned char b2_exp = + i + (comm->pid() + comm->nprocs() - 1) % comm->nprocs(); + unsigned char b1_exp = i + comm->pid(); + EXPECT_EQ(b2_exp, buf2[i]); + EXPECT_EQ(b1_exp, buf1[i]); + } + + verbs->dereg(b1); + verbs->dereg(b2); +} diff --git a/src/MPI/interface.cpp b/src/MPI/interface.cpp index f1919f33..30ece40d 100644 --- a/src/MPI/interface.cpp +++ b/src/MPI/interface.cpp @@ -225,6 +225,4 @@ void Interface :: probe( machine_t & machine ) machine.l = &Interface::latency; } - - } // namespace lpf diff --git a/src/MPI/interface.hpp b/src/MPI/interface.hpp index 732f0a9b..1a60d28e 100644 --- a/src/MPI/interface.hpp +++ b/src/MPI/interface.hpp @@ -76,6 +76,8 @@ class _LPFLIB_LOCAL Interface static void doProbe(const mpi::Comm & comm); + void lpf_internal_abort(); + private: mpi::Comm m_comm; Process & m_subprocess; diff --git a/src/MPI/ipcmesg.t.cpp b/src/MPI/ipcmesg.t.cpp index abb91d3d..df059c1c 100644 --- a/src/MPI/ipcmesg.t.cpp +++ b/src/MPI/ipcmesg.t.cpp @@ -22,88 +22,78 @@ using lpf::mpi::IPCMesg; using namespace lpf::mpi::ipc; -enum MesgType { One, Two, Three}; +enum MesgType { One, Two, Three }; enum Prop { A, B, C, D }; -TEST( IPCMesg, empty ) -{ - char buf[80]; - IPCMesg m = newMsg( Two, buf, sizeof(buf)); +TEST(IPCMesg, empty) { + char buf[80]; + IPCMesg m = newMsg(Two, buf, sizeof(buf)); - EXPECT_EQ( Two, m.type() ); + EXPECT_EQ(Two, m.type()); } -TEST( IPCMesg, twoNumbers ) -{ +TEST(IPCMesg, twoNumbers) { - char buf[80]; - IPCMesg m = newMsg( Three, buf, sizeof(buf)) - .write( A, 5 ) - .write( B, 500u ); + char buf[80]; + IPCMesg m = + newMsg(Three, buf, sizeof(buf)).write(A, 5).write(B, 500u); - EXPECT_EQ( Three, m.type() ); - m.rewind(); + EXPECT_EQ(Three, m.type()); + m.rewind(); - int a; - unsigned b; + int a; + unsigned b; - m.read( A, a ).read(B, b ); - EXPECT_EQ( 5, a ); - EXPECT_EQ( 500u, b); + m.read(A, a).read(B, b); + EXPECT_EQ(5, a); + EXPECT_EQ(500u, b); } - -TEST( IPCMesg, threeNumbersAndABlob ) -{ - const char str[] = "Test"; - char strbuf[ sizeof(str) ]; - - char buf[80]; - IPCMesg m = newMsg( One, buf, sizeof(buf)) - .write( B, 5 ) - .write( C, str, sizeof(str) ) - .write( A, 1234567ul ); - - EXPECT_EQ( One, m.type() ); - m.rewind(); - EXPECT_EQ( One, m.type() ); - - int b; - unsigned long a; - - m.read( B, b ) - .read(C, strbuf, sizeof(strbuf)) - .read(A, a ); - - EXPECT_EQ( 5, b ); - EXPECT_EQ( 1234567ul, a); - EXPECT_STREQ( "Test", strbuf ); + +TEST(IPCMesg, threeNumbersAndABlob) { + const char str[] = "Test"; + char strbuf[sizeof(str)]; + + char buf[80]; + IPCMesg m = newMsg(One, buf, sizeof(buf)) + .write(B, 5) + .write(C, str, sizeof(str)) + .write(A, 1234567ul); + + EXPECT_EQ(One, m.type()); + m.rewind(); + EXPECT_EQ(One, m.type()); + + int b; + unsigned long a; + + m.read(B, b).read(C, strbuf, sizeof(strbuf)).read(A, a); + + EXPECT_EQ(5, b); + EXPECT_EQ(1234567ul, a); + EXPECT_STREQ("Test", strbuf); } - -TEST( IPCMesg, blobEnding ) -{ - const char str[] = "Test"; - char strbuf[ sizeof(str) ]; +TEST(IPCMesg, blobEnding) { + const char str[] = "Test"; + char strbuf[sizeof(str)]; - char buf[80]; - IPCMesg m = newMsg( One, buf, sizeof(buf)) - .write( B, 5 ) - .write( A, 1234567ul ) - .write( C, str, sizeof(str) ) ; + char buf[80]; + IPCMesg m = newMsg(One, buf, sizeof(buf)) + .write(B, 5) + .write(A, 1234567ul) + .write(C, str, sizeof(str)); - EXPECT_EQ( One, m.type() ); + EXPECT_EQ(One, m.type()); - int b; - unsigned long a; + int b; + unsigned long a; - IPCMesg m2(buf, m.pos(), 0); - m2.read(B, b ) - .read(A, a ); + IPCMesg m2(buf, m.pos(), 0); + m2.read(B, b).read(A, a); - m2.read(C, strbuf, m2.bytesLeft() ); + m2.read(C, strbuf, m2.bytesLeft()); - EXPECT_EQ( 5, b ); - EXPECT_EQ( 1234567ul, a); - EXPECT_STREQ( "Test", strbuf ); + EXPECT_EQ(5, b); + EXPECT_EQ(1234567ul, a); + EXPECT_STREQ("Test", strbuf); } - diff --git a/src/MPI/messagesort.t.cpp b/src/MPI/messagesort.t.cpp index 8347fd45..f97cd430 100644 --- a/src/MPI/messagesort.t.cpp +++ b/src/MPI/messagesort.t.cpp @@ -15,557 +15,601 @@ * limitations under the License. */ -#include "messagesort.hpp" #include "config.hpp" +#include "messagesort.hpp" #include using namespace lpf; typedef MessageSort::MsgId Id; -const size_t G = (1 << Config::instance().getMpiMsgSortGrainSizePower() ); - -TEST( MessageSort, empty ) -{ - MessageSort empty; +const size_t G = (1 << Config::instance().getMpiMsgSortGrainSizePower()); -} +TEST(MessageSort, empty) { MessageSort empty; } -TEST( MessageSort, oneMsg ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[0], array.size()-G ); - - { size_t o = 1*G, s = 4 * G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 1*G, o ); - EXPECT_EQ( 4*G, s ); - } - - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 1*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +/** + * \pre P >= 1 + * \pre P <= 1 + */ +TEST(MessageSort, oneMsg) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[0], array.size() - G); + + { + size_t o = 1 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(4 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 1 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, oneMsgUnaligned ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[1], array.size()-G ); - - { size_t o = 2*G+10, s = 4 * G+20; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 3*G, o ); - EXPECT_EQ( 3*G, s ); - } - - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[1] + 3*G , writeBase ); - EXPECT_EQ( 3*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, oneMsgUnaligned) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[1], array.size() - G); + + { + size_t o = 2 * G + 10, s = 4 * G + 20; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(3 * G, o); + EXPECT_EQ(3 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[1] + 3 * G, writeBase); + EXPECT_EQ(3 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - -TEST( MessageSort, twoDisjointMsgs ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[0], array.size()-G ); - - { size_t o = 1*G, s=4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 1*G, o ); EXPECT_EQ( 4*G, s); - o = 8*G; s = 10*G; - sort.pushWrite( 1, 0, o, s); - EXPECT_EQ( 8*G, o ); EXPECT_EQ( 10*G, s); } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(0u, msgId ); - EXPECT_EQ( &array[0] + 1*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(1u, msgId ); - EXPECT_EQ( &array[0] + 8*G , writeBase ); - EXPECT_EQ( 10*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, twoDisjointMsgs) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[0], array.size() - G); + + { + size_t o = 1 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(4 * G, s); + o = 8 * G; + s = 10 * G; + sort.pushWrite(1, 0, o, s); + EXPECT_EQ(8 * G, o); + EXPECT_EQ(10 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 1 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 8 * G, writeBase); + EXPECT_EQ(10 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, twoAdjacentMsgs ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[0], array.size()-G ); - - { size_t o = 2*G, s=11*G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 2*G, o ); - EXPECT_EQ( 11*G, s ); - o=13*G; s=5*G; - sort.pushWrite( 1, 0, o, s); - EXPECT_EQ( 13*G, o); - EXPECT_EQ( 5*G, s); } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(0u, msgId ); - EXPECT_EQ( &array[0] + 2*G , writeBase ); - EXPECT_EQ( 11*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(1u, msgId ); - EXPECT_EQ( &array[0] + 13*G , writeBase ); - EXPECT_EQ( 5*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, twoAdjacentMsgs) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[0], array.size() - G); + + { + size_t o = 2 * G, s = 11 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(11 * G, s); + o = 13 * G; + s = 5 * G; + sort.pushWrite(1, 0, o, s); + EXPECT_EQ(13 * G, o); + EXPECT_EQ(5 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 2 * G, writeBase); + EXPECT_EQ(11 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 13 * G, writeBase); + EXPECT_EQ(5 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, twoOverlappingMsgs ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[0], array.size()-G ); - - { size_t o=1*G, s=11*G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 1*G, o ); - EXPECT_EQ( 11*G, s ); - o=8*G; s=10*G; - sort.pushWrite( 1, 0, o, s); - EXPECT_EQ( 8*G, o ); - EXPECT_EQ( 10*G, s ); - } - - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(0u, msgId ); - EXPECT_EQ( &array[0] + 1*G , writeBase ); - EXPECT_EQ( 7*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(1u, msgId ); - EXPECT_EQ( &array[0] + 8*G , writeBase ); - EXPECT_EQ( 10*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, twoOverlappingMsgs) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[0], array.size() - G); + + { + size_t o = 1 * G, s = 11 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(11 * G, s); + o = 8 * G; + s = 10 * G; + sort.pushWrite(1, 0, o, s); + EXPECT_EQ(8 * G, o); + EXPECT_EQ(10 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 1 * G, writeBase); + EXPECT_EQ(7 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 8 * G, writeBase); + EXPECT_EQ(10 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, twoOverlappingMsgsPriority ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 1 ); - sort.addRegister( 0, &array[0], array.size()-G ); - - { size_t o=8*G, s=10*G; - sort.pushWrite( 1, 0, o, s); - EXPECT_EQ( 8*G, o ); - EXPECT_EQ( 10*G, s ); - o=1*G; s=11*G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 1*G, o ); - EXPECT_EQ( 11*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(0u, msgId ); - EXPECT_EQ( &array[0] + 1*G , writeBase ); - EXPECT_EQ( 7*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ(1u, msgId ); - EXPECT_EQ( &array[0] + 8*G , writeBase ); - EXPECT_EQ( 10*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, twoOverlappingMsgsPriority) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(1); + sort.addRegister(0, &array[0], array.size() - G); + + { + size_t o = 8 * G, s = 10 * G; + sort.pushWrite(1, 0, o, s); + EXPECT_EQ(8 * G, o); + EXPECT_EQ(10 * G, s); + o = 1 * G; + s = 11 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(11 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 1 * G, writeBase); + EXPECT_EQ(7 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 8 * G, writeBase); + EXPECT_EQ(10 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - -TEST( MessageSort, TwoDisjointRegsAndTwoMsgs ) -{ - std::vector< char > array( 50 * G); - MessageSort sort; - - sort.setSlotRange( 2 ); - sort.addRegister( 0, &array[0], 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - - { size_t o = 0*G, s = 4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 0*G, o ); - EXPECT_EQ( 4*G, s ); - } - { size_t o = 3*G, s = 4*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ( 3*G, o ); - EXPECT_EQ( 4*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 23*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, TwoDisjointRegsAndTwoMsgs) { + std::vector array(50 * G); + MessageSort sort; + + sort.setSlotRange(2); + sort.addRegister(0, &array[0], 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + + { + size_t o = 0 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(0 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 3 * G, s = 4 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(3 * G, o); + EXPECT_EQ(4 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0], writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 23 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - -TEST( MessageSort, ThreeDisjointRegsAndThreeMsgs ) -{ - std::vector< char > array( 100 * G); - MessageSort sort; - - sort.setSlotRange( 3 ); - sort.addRegister( 0, &array[0], 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - sort.addRegister( 2, &array[0]+70*G, 25*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 2*G, o ); - EXPECT_EQ( 4*G, s ); } - - { size_t o = 10*G, s = 4*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ( 10*G, o) ; - EXPECT_EQ( 4*G, s ); - } - { size_t o = 24*G, s=1*G; - sort.pushWrite( 2, 2, o, s); - EXPECT_EQ( 24*G, o ); - EXPECT_EQ( 1*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 2*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 2u, msgId ); - EXPECT_EQ( &array[0] + 94*G , writeBase ); - EXPECT_EQ( 1*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 30*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, ThreeDisjointRegsAndThreeMsgs) { + std::vector array(100 * G); + MessageSort sort; + + sort.setSlotRange(3); + sort.addRegister(0, &array[0], 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + sort.addRegister(2, &array[0] + 70 * G, 25 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 10 * G, s = 4 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(10 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 24 * G, s = 1 * G; + sort.pushWrite(2, 2, o, s); + EXPECT_EQ(24 * G, o); + EXPECT_EQ(1 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 2 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(2u, msgId); + EXPECT_EQ(&array[0] + 94 * G, writeBase); + EXPECT_EQ(1 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 30 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, ThreeDisjointAndOneHugeOverlapRegsAndThreeMsgs ) -{ - std::vector< char > array( 100 * G); - MessageSort sort; - - sort.setSlotRange( 4 ); - sort.addRegister( 0, &array[0]+1*G, 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - sort.addRegister( 2, &array[0]+70*G, 25*G ); - sort.addRegister( 3, &array[0], 99*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 2*G, o ); - EXPECT_EQ( 4*G, s ); } - - { size_t o = 10*G, s = 4*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ( 10*G, o) ; - EXPECT_EQ( 4*G, s ); - } - { size_t o = 24*G, s=1*G; - sort.pushWrite( 2, 2, o, s); - EXPECT_EQ( 24*G, o ); - EXPECT_EQ( 1*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 3*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 30*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 2u, msgId ); - EXPECT_EQ( &array[0] + 94*G , writeBase ); - EXPECT_EQ( 1*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, ThreeDisjointAndOneHugeOverlapRegsAndThreeMsgs) { + std::vector array(100 * G); + MessageSort sort; + + sort.setSlotRange(4); + sort.addRegister(0, &array[0] + 1 * G, 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + sort.addRegister(2, &array[0] + 70 * G, 25 * G); + sort.addRegister(3, &array[0], 99 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 10 * G, s = 4 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(10 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 24 * G, s = 1 * G; + sort.pushWrite(2, 2, o, s); + EXPECT_EQ(24 * G, o); + EXPECT_EQ(1 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 3 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 30 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(2u, msgId); + EXPECT_EQ(&array[0] + 94 * G, writeBase); + EXPECT_EQ(1 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - -TEST( MessageSort, TheeDisjointAndOneOverlapRegsAndThreeMsgs ) -{ - std::vector< char > array( 100 * G); - MessageSort sort; - - sort.setSlotRange( 4 ); - sort.addRegister( 0, &array[0]+1*G, 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - sort.addRegister( 2, &array[0]+70*G, 25*G ); - sort.addRegister( 3, &array[0]+30*G, 99*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 2*G, o); - EXPECT_EQ( 4*G, s); } - - { size_t o = 5*G, s=10*G; - sort.pushWrite( 1, 1, o , s); - EXPECT_EQ( 5*G, o ); - EXPECT_EQ( 10*G, s ); - } - { size_t o = 1*G, s=1*G; - sort.pushWrite( 2, 3, o, s); - EXPECT_EQ( 1*G, o ); - EXPECT_EQ( 1*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 3*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 25*G , writeBase ); - EXPECT_EQ( 6*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 2u, msgId ); - EXPECT_EQ( &array[0] + 31*G , writeBase ); - EXPECT_EQ( 1*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 32*G , writeBase ); - EXPECT_EQ( 3*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, TheeDisjointAndOneOverlapRegsAndThreeMsgs) { + std::vector array(100 * G); + MessageSort sort; + + sort.setSlotRange(4); + sort.addRegister(0, &array[0] + 1 * G, 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + sort.addRegister(2, &array[0] + 70 * G, 25 * G); + sort.addRegister(3, &array[0] + 30 * G, 99 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 5 * G, s = 10 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(5 * G, o); + EXPECT_EQ(10 * G, s); + } + { + size_t o = 1 * G, s = 1 * G; + sort.pushWrite(2, 3, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(1 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 3 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 25 * G, writeBase); + EXPECT_EQ(6 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(2u, msgId); + EXPECT_EQ(&array[0] + 31 * G, writeBase); + EXPECT_EQ(1 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 32 * G, writeBase); + EXPECT_EQ(3 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - -TEST( MessageSort, clear ) -{ - std::vector< char > array( 100 * G); - MessageSort sort; - - sort.setSlotRange( 4 ); - sort.addRegister( 0, &array[0]+1*G, 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - sort.addRegister( 2, &array[0]+70*G, 25*G ); - sort.addRegister( 3, &array[0]+30*G, 99*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 2*G, o ); - EXPECT_EQ( 4*G, s ); } - - { size_t o = 10*G, s = 4*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ( 10*G, o) ; - EXPECT_EQ( 4*G, s ); - } - { size_t o = 24*G, s=1*G; - sort.pushWrite( 2, 2, o, s); - EXPECT_EQ( 24*G, o ); - EXPECT_EQ( 1*G, s ); - } - - sort.clear(); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o, s); - EXPECT_EQ( 2*G, o); - EXPECT_EQ( 4*G, s); } - - { size_t o = 5*G, s=10*G; - sort.pushWrite( 1, 1, o , s); - EXPECT_EQ( 5*G, o ); - EXPECT_EQ( 10*G, s ); - } - { size_t o = 1*G, s=1*G; - sort.pushWrite( 2, 3, o, s); - EXPECT_EQ( 1*G, o ); - EXPECT_EQ( 1*G, s ); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 3*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 25*G , writeBase ); - EXPECT_EQ( 6*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 2u, msgId ); - EXPECT_EQ( &array[0] + 31*G , writeBase ); - EXPECT_EQ( 1*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 32*G , writeBase ); - EXPECT_EQ( 3*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, clear) { + std::vector array(100 * G); + MessageSort sort; + + sort.setSlotRange(4); + sort.addRegister(0, &array[0] + 1 * G, 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + sort.addRegister(2, &array[0] + 70 * G, 25 * G); + sort.addRegister(3, &array[0] + 30 * G, 99 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 10 * G, s = 4 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(10 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 24 * G, s = 1 * G; + sort.pushWrite(2, 2, o, s); + EXPECT_EQ(24 * G, o); + EXPECT_EQ(1 * G, s); + } + + sort.clear(); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 5 * G, s = 10 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(5 * G, o); + EXPECT_EQ(10 * G, s); + } + { + size_t o = 1 * G, s = 1 * G; + sort.pushWrite(2, 3, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(1 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 3 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 25 * G, writeBase); + EXPECT_EQ(6 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(2u, msgId); + EXPECT_EQ(&array[0] + 31 * G, writeBase); + EXPECT_EQ(1 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 32 * G, writeBase); + EXPECT_EQ(3 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } -TEST( MessageSort, deleteReg ) -{ - std::vector< char > array( 100 * G); - MessageSort sort; - - sort.setSlotRange( 4 ); - sort.addRegister( 0, &array[0]+1*G, 10*G ); - sort.addRegister( 1, &array[0]+20*G, 20*G ); - sort.addRegister( 2, &array[0]+70*G, 25*G ); - sort.addRegister( 3, &array[0]+30*G, 99*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 0, o , s); - EXPECT_EQ( 2*G, o ); - EXPECT_EQ( 4*G, s ); } - - { size_t o = 10*G, s = 4*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ( 10*G, o) ; - EXPECT_EQ( 4*G, s ); - } - { size_t o = 24*G, s=1*G; - sort.pushWrite( 2, 2, o, s); - EXPECT_EQ( 24*G, o ); - EXPECT_EQ( 1*G, s ); - } - - - sort.clear(); - sort.delRegister( 2 ); - sort.addRegister( 2, &array[0]+0*G, 25*G ); - - { size_t o = 2*G, s=4*G; - sort.pushWrite( 0, 2, o, s); - EXPECT_EQ( 2*G, o); - EXPECT_EQ( 4*G, s); - } - { size_t o = 5*G, s=10*G; - sort.pushWrite( 1, 1, o, s); - EXPECT_EQ(5*G, o); - EXPECT_EQ(10*G, s); - } - { size_t o = 1*G, s=1*G; - sort.pushWrite( 2, 3, o, s); - EXPECT_EQ( 1*G, o); - EXPECT_EQ( 1*G, s); - } - - char * writeBase = 0; size_t writeSize; Id msgId=0; - bool s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 0u, msgId ); - EXPECT_EQ( &array[0] + 2*G , writeBase ); - EXPECT_EQ( 4*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 25*G , writeBase ); - EXPECT_EQ( 6*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 2u, msgId ); - EXPECT_EQ( &array[0] + 31*G , writeBase ); - EXPECT_EQ( 1*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_TRUE( s ); - EXPECT_EQ( 1u, msgId ); - EXPECT_EQ( &array[0] + 32*G , writeBase ); - EXPECT_EQ( 3*G, writeSize ); - - s = sort.popWrite( msgId, writeBase, writeSize ); - EXPECT_FALSE( s ); +TEST(MessageSort, deleteReg) { + std::vector array(100 * G); + MessageSort sort; + + sort.setSlotRange(4); + sort.addRegister(0, &array[0] + 1 * G, 10 * G); + sort.addRegister(1, &array[0] + 20 * G, 20 * G); + sort.addRegister(2, &array[0] + 70 * G, 25 * G); + sort.addRegister(3, &array[0] + 30 * G, 99 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 0, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + + { + size_t o = 10 * G, s = 4 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(10 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 24 * G, s = 1 * G; + sort.pushWrite(2, 2, o, s); + EXPECT_EQ(24 * G, o); + EXPECT_EQ(1 * G, s); + } + + sort.clear(); + sort.delRegister(2); + sort.addRegister(2, &array[0] + 0 * G, 25 * G); + + { + size_t o = 2 * G, s = 4 * G; + sort.pushWrite(0, 2, o, s); + EXPECT_EQ(2 * G, o); + EXPECT_EQ(4 * G, s); + } + { + size_t o = 5 * G, s = 10 * G; + sort.pushWrite(1, 1, o, s); + EXPECT_EQ(5 * G, o); + EXPECT_EQ(10 * G, s); + } + { + size_t o = 1 * G, s = 1 * G; + sort.pushWrite(2, 3, o, s); + EXPECT_EQ(1 * G, o); + EXPECT_EQ(1 * G, s); + } + + char *writeBase = 0; + size_t writeSize; + Id msgId = 0; + bool s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(0u, msgId); + EXPECT_EQ(&array[0] + 2 * G, writeBase); + EXPECT_EQ(4 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 25 * G, writeBase); + EXPECT_EQ(6 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(2u, msgId); + EXPECT_EQ(&array[0] + 31 * G, writeBase); + EXPECT_EQ(1 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_TRUE(s); + EXPECT_EQ(1u, msgId); + EXPECT_EQ(&array[0] + 32 * G, writeBase); + EXPECT_EQ(3 * G, writeSize); + + s = sort.popWrite(msgId, writeBase, writeSize); + EXPECT_FALSE(s); } - - diff --git a/src/MPI/spall2all.t.cpp b/src/MPI/spall2all.t.cpp index 42fae2c2..dc10365c 100644 --- a/src/MPI/spall2all.t.cpp +++ b/src/MPI/spall2all.t.cpp @@ -15,134 +15,149 @@ * limitations under the License. */ +#include "assert.hpp" +#include "mpilib.hpp" #include "spall2all.h" #include "spall2all.hpp" -#include "mpilib.hpp" -#include "assert.hpp" -#include +#include #include -#include +#include #include +#include #include #include - using namespace lpf::mpi; -extern "C" const int LPF_MPI_AUTO_INITIALIZE=1; - - -TEST( Spall2allC, EnoughMemory ) -{ - lpf::mpi::Lib::instance().world(); - - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - -using namespace std; -using namespace lpf::mpi; +extern "C" const int LPF_MPI_AUTO_INITIALIZE = 0; -// Parameters -// Maximum number of items to send to any process -const int N = 10; +/** + * \pre P >= 1 + * \pre P <= 2 + */ +class SparseAll2AllTests : public testing::Test { -// The number of bytes to send N items -const int M = N * (6 + 2*(int) ceil(1+log10(nprocs)) ); +protected: + static void SetUpTestSuite() { -// Note: the number of bytes is derived from the message format, as below -#define NEW_MSG( buf, my_pid, dst_pid, character) \ - snprintf( (buf), sizeof(buf), "(%d, %d)%c;", (my_pid), (dst_pid), (character) ) - - sparse_all_to_all_t spt; - double epsilon = 1e-20; // bound of probability of failure (using Chernoff bounds) - size_t max_tmp_bytes = size_t( ceil(3-log(epsilon)/N)*M ); - size_t max_tmp_msgs = size_t( ceil(3-log(epsilon)/N)*N ); - uint64_t rng_seed = 0; - sparse_all_to_all_create( &spt, my_pid, nprocs, rng_seed, 1, - std::numeric_limits::max() ); - int error = sparse_all_to_all_reserve( &spt, max_tmp_bytes, max_tmp_msgs ); - EXPECT_EQ( 0, error ); - - srand(my_pid*1000); - - std::vector a2a_send(nprocs*M); - std::vector a2a_recv(nprocs*M*100); - std::vector a2a_send_counts(nprocs); - std::vector a2a_send_offsets(nprocs); - std::vector a2a_recv_counts(nprocs); - std::vector a2a_recv_offsets(nprocs); - - for (int i = 0; i < nprocs; ++i) - { - a2a_send_counts[i] = 0; - a2a_send_offsets[i] = i*M; - a2a_recv_counts[i] = 100*M; - a2a_recv_offsets[i] = i*100*M; - } + MPI_Init(NULL, NULL); + Lib::instance(); - int n = rand() / (1.0 + RAND_MAX) * N; + MPI_Comm_rank(MPI_COMM_WORLD, &my_pid); + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + } - for (int i = 0; i < n; ++i) { - char c = rand() % 26 + 'A'; - int dst_pid = rand() / (1.0 + RAND_MAX) * nprocs; - char buf[M]; - size_t size = NEW_MSG(buf, my_pid, dst_pid, c); - int rc = sparse_all_to_all_send( &spt, dst_pid, buf, size ); - EXPECT_EQ( 0, rc ); + static void TearDownTestSuite() { MPI_Finalize(); } - char * a2a_buf = &a2a_send[0] + a2a_send_offsets[dst_pid] + a2a_send_counts[dst_pid]; - memcpy( a2a_buf , buf, size ); - a2a_send_counts[dst_pid] += size; - ASSERT( a2a_send_counts[dst_pid] <= M ); - } + static int my_pid; + static int nprocs; +}; +int SparseAll2AllTests::my_pid = -1; +int SparseAll2AllTests::nprocs = -1; +TEST_F(SparseAll2AllTests, EnoughMemory) { - MPI_Barrier(MPI_COMM_WORLD); - MPI_Alltoall( &a2a_send_counts[0], 1, MPI_INT, - &a2a_recv_counts[0], 1, MPI_INT, MPI_COMM_WORLD); - MPI_Alltoallv( &a2a_send[0], &a2a_send_counts[0], &a2a_send_offsets[0], MPI_BYTE, - &a2a_recv[0], &a2a_recv_counts[0], &a2a_recv_offsets[0], MPI_BYTE, - MPI_COMM_WORLD); - MPI_Barrier(MPI_COMM_WORLD); + using namespace std; + using namespace lpf::mpi; + // Parameters + // Maximum number of items to send to any process + const int N = 10; - error = 1; - int vote = my_pid; int ballot = -1; - MPI_Barrier(MPI_COMM_WORLD); - error = sparse_all_to_all( MPI_COMM_WORLD, &spt, 1, &vote, &ballot ); + // The number of bytes to send N items + const int M = N * (6 + 2 * (int)ceil(1 + log10(nprocs))); - EXPECT_GE( error, 0 ); - EXPECT_EQ( (nprocs-1)*nprocs/2, ballot ); - - std::vector< std::string > spall2all_recv_buf(nprocs); +// Note: the number of bytes is derived from the message format, as below +#define NEW_MSG(buf, my_pid, dst_pid, character) \ + snprintf((buf), sizeof(buf), "(%d, %d)%c;", (my_pid), (dst_pid), (character)) + + sparse_all_to_all_t spt; + double epsilon = + 1e-20; // bound of probability of failure (using Chernoff bounds) + size_t max_tmp_bytes = size_t(ceil(3 - log(epsilon) / N) * M); + size_t max_tmp_msgs = size_t(ceil(3 - log(epsilon) / N) * N); + uint64_t rng_seed = 0; + sparse_all_to_all_create(&spt, my_pid, nprocs, rng_seed, 1, + std::numeric_limits::max()); + int error = sparse_all_to_all_reserve(&spt, max_tmp_bytes, max_tmp_msgs); + EXPECT_EQ(0, error); + + srand(my_pid * 1000); + + std::vector a2a_send(nprocs * M); + std::vector a2a_recv(nprocs * M * 100); + std::vector a2a_send_counts(nprocs); + std::vector a2a_send_offsets(nprocs); + std::vector a2a_recv_counts(nprocs); + std::vector a2a_recv_offsets(nprocs); + + for (int i = 0; i < nprocs; ++i) { + a2a_send_counts[i] = 0; + a2a_send_offsets[i] = i * M; + a2a_recv_counts[i] = 100 * M; + a2a_recv_offsets[i] = i * 100 * M; + } + + int n = rand() / (1.0 + RAND_MAX) * N; + + for (int i = 0; i < n; ++i) { + char c = rand() % 26 + 'A'; + int dst_pid = rand() / (1.0 + RAND_MAX) * nprocs; char buf[M]; - size_t size = sizeof(buf); - while (0 == sparse_all_to_all_recv( &spt, buf, &size )) - { - spall2all_recv_buf.push_back( std::string( buf, buf+size) ); - size = sizeof(buf) ; + size_t size = NEW_MSG(buf, my_pid, dst_pid, c); + int rc = sparse_all_to_all_send(&spt, dst_pid, buf, size); + EXPECT_EQ(0, rc); + + char *a2a_buf = + &a2a_send[0] + a2a_send_offsets[dst_pid] + a2a_send_counts[dst_pid]; + memcpy(a2a_buf, buf, size); + a2a_send_counts[dst_pid] += size; + ASSERT(a2a_send_counts[dst_pid] <= M); + } + + MPI_Barrier(MPI_COMM_WORLD); + MPI_Alltoall(&a2a_send_counts[0], 1, MPI_INT, &a2a_recv_counts[0], 1, MPI_INT, + MPI_COMM_WORLD); + MPI_Alltoallv(&a2a_send[0], &a2a_send_counts[0], &a2a_send_offsets[0], + MPI_BYTE, &a2a_recv[0], &a2a_recv_counts[0], + &a2a_recv_offsets[0], MPI_BYTE, MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + + error = 1; + int vote = my_pid; + int ballot = -1; + MPI_Barrier(MPI_COMM_WORLD); + error = sparse_all_to_all(MPI_COMM_WORLD, &spt, 1, &vote, &ballot); + + EXPECT_GE(error, 0); + EXPECT_EQ((nprocs - 1) * nprocs / 2, ballot); + + std::vector spall2all_recv_buf(nprocs); + char buf[M]; + size_t size = sizeof(buf); + while (0 == sparse_all_to_all_recv(&spt, buf, &size)) { + spall2all_recv_buf.push_back(std::string(buf, buf + size)); + size = sizeof(buf); + } + + a2a_recv_offsets.push_back(a2a_recv.size()); + std::vector a2a_recv_buf(nprocs); + for (int i = 0; i < nprocs; ++i) { + const char *ptr = &a2a_recv[0] + a2a_recv_offsets[i]; + while (ptr - &a2a_recv[0] < a2a_recv_offsets[i] + a2a_recv_counts[i]) { + const char *end = &a2a_recv[0] + a2a_recv_offsets[i + 1]; + end = std::find(ptr, end, ';') + 1; + + a2a_recv_buf.push_back(std::string(ptr, end)); + ptr = end; } + } + std::sort(spall2all_recv_buf.begin(), spall2all_recv_buf.end()); + std::sort(a2a_recv_buf.begin(), a2a_recv_buf.end()); - a2a_recv_offsets.push_back( a2a_recv.size() ); - std::vector< std::string > a2a_recv_buf(nprocs); - for ( int i = 0 ; i < nprocs; ++i) - { - const char * ptr = &a2a_recv[0] + a2a_recv_offsets[i] ; - while ( ptr - &a2a_recv[0] < a2a_recv_offsets[i] + a2a_recv_counts[i] ) { - const char * end = &a2a_recv[0] + a2a_recv_offsets[i+1]; - end = std::find( ptr, end, ';')+1; - - a2a_recv_buf.push_back( std::string( ptr, end )); - ptr = end; - } - } - std::sort( spall2all_recv_buf.begin(), spall2all_recv_buf.end() ); - std::sort( a2a_recv_buf.begin(), a2a_recv_buf.end() ); - - EXPECT_EQ( a2a_recv_buf, spall2all_recv_buf ); + EXPECT_EQ(a2a_recv_buf, spall2all_recv_buf); #if 0 std::cout << "[" << my_pid << "] Total elements spall2all: " << spall2all_recv_buf.size() @@ -157,231 +172,162 @@ const int M = N * (6 + 2*(int) ceil(1+log10(nprocs)) ); std::cout << std::endl; #endif - sparse_all_to_all_destroy( &spt ); + sparse_all_to_all_destroy(&spt); } -TEST( Spall2all, Create ) -{ - SparseAllToAll x(9, 10); -} +TEST_F(SparseAll2AllTests, Create) { SparseAllToAll x(9, 10); } -TEST( Spall2all, Reserve ) -{ - SparseAllToAll x( 4,10); -} +TEST_F(SparseAll2AllTests, Reserve) { SparseAllToAll x(4, 10); } -TEST( Spall2all, ReserveUnequal ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - SparseAllToAll x( my_pid, nprocs ); +TEST_F(SparseAll2AllTests, ReserveUnequal) { + SparseAllToAll x(my_pid, nprocs); - // simulate the case where one of the processes can't - // allocate enough buffer space - if (my_pid != 0 ) - x.reserve( nprocs * ceil(1+log2(nprocs)), sizeof(int) ); + // simulate the case where one of the processes can't + // allocate enough buffer space + if (my_pid != 0) + x.reserve(nprocs * ceil(1 + log2(nprocs)), sizeof(int)); - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); } -TEST( Spall2all, Send ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - +TEST_F(SparseAll2AllTests, Send) { + SparseAllToAll x(my_pid, nprocs); + x.reserve(nprocs * ceil(1 + log2(nprocs)), sizeof(int)); + for (int i = 0; i <= my_pid; ++i) + x.send((my_pid + 1) % nprocs, &i, sizeof(i)); - SparseAllToAll x( my_pid, nprocs ); - x.reserve( nprocs * ceil(1+log2(nprocs)) , sizeof(int)); - for (int i = 0; i <= my_pid ; ++i) - x.send( (my_pid + 1) % nprocs, &i, sizeof(i) ); - - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); } -TEST( Spall2all, Ring ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); +TEST_F(SparseAll2AllTests, Ring) { + SparseAllToAll x(my_pid, nprocs); + EXPECT_TRUE(x.empty()); + x.reserve(nprocs * ceil(1 + log2(nprocs)), sizeof(int)); + x.send((my_pid + 1) % nprocs, &my_pid, sizeof(my_pid)); - SparseAllToAll x(my_pid, nprocs); - EXPECT_TRUE( x.empty() ); - x.reserve( nprocs * ceil(1+log2(nprocs)) , sizeof(int)); - x.send( (my_pid + 1) % nprocs, &my_pid, sizeof(my_pid) ); + EXPECT_FALSE(x.empty()); - EXPECT_FALSE( x.empty() ); + bool prerandomize = true; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); + EXPECT_FALSE(x.empty()); - EXPECT_FALSE( x.empty() ); - - int y = -1; - x.recv( &y, sizeof(y)); - EXPECT_EQ( (my_pid + nprocs -1) % nprocs, y ); + int y = -1; + x.recv(&y, sizeof(y)); + EXPECT_EQ((my_pid + nprocs - 1) % nprocs, y); - EXPECT_TRUE( x.empty() ); + EXPECT_TRUE(x.empty()); } +TEST_F(SparseAll2AllTests, Access) { + SparseAllToAll x(my_pid, nprocs); + x.reserve(nprocs * ceil(1 + log2(nprocs)), sizeof(int)); + EXPECT_TRUE(x.empty()); -TEST( Spall2all, Access ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - SparseAllToAll x(my_pid, nprocs); - x.reserve( nprocs * ceil(1+log2(nprocs)) , sizeof(int) ); - EXPECT_TRUE( x.empty() ); + for (int i = 0; i <= my_pid; ++i) + x.send((my_pid + i + 1) % nprocs, &i, sizeof(i)); - for (int i = 0; i <= my_pid ; ++i) - x.send( (my_pid + i + 1) % nprocs, &i, sizeof(i) ); + EXPECT_FALSE(x.empty()); - EXPECT_FALSE( x.empty() ); + for (int i = 0; i <= my_pid; ++i) { + int y; + x.recv(&y, sizeof(y)); + EXPECT_EQ(my_pid - i, y); + } + EXPECT_TRUE(x.empty()); +} - for (int i = 0; i<= my_pid; ++i) { - int y; - x.recv( &y, sizeof(y) ); - EXPECT_EQ( my_pid - i , y); - } - EXPECT_TRUE( x.empty() ); +TEST_F(SparseAll2AllTests, SmallBuf) { + SparseAllToAll x(my_pid, nprocs); + const int nMsgs = 5; + x.reserve(nMsgs, sizeof(int)); + + for (int i = 0; i < nMsgs; ++i) { + x.send((my_pid + i) % nprocs, &i, sizeof(int)); + } + + bool prerandomize = true; + int error = 0; + for (int i = 0; i < 100 && !error; ++i) { + error = x.exchange(Lib::instance().world(), prerandomize, NULL, 1); + } + EXPECT_TRUE(nprocs == 1 || error); } -TEST( Spall2all, SmallBuf ) -{ - Lib::instance(); +TEST_F(SparseAll2AllTests, SmallBufProc1) { - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); + SparseAllToAll x(my_pid, nprocs); + const int nMsgs = 100; + // only one process has a very small buffer space. Still + // that has high likelihood to fail + x.reserve(my_pid == 1 ? nMsgs : (nMsgs * nMsgs), sizeof(int)); - SparseAllToAll x(my_pid, nprocs); - const int nMsgs = 5; - x.reserve( nMsgs , sizeof(int) ); + int failures = 0; + for (int j = 0; j < 100; ++j) { + x.clear(); - for (int i = 0; i < nMsgs; ++i) - { - x.send( (my_pid + i) % nprocs, &i, sizeof(int) ); + for (int i = 0; i < nMsgs; ++i) { + x.send((my_pid + i) % nprocs, &i, sizeof(i)); } bool prerandomize = true; - int error = 0; - for (int i = 0; i < 100 && !error; ++i) - { - error = x.exchange( Lib::instance().world(), prerandomize, NULL, 1 ); - } - EXPECT_TRUE( nprocs == 1 || error ); - + int error = x.exchange(Lib::instance().world(), prerandomize, NULL, 1); + failures += (error ? 1 : 0); + } + EXPECT_GE(90.0 / nprocs + 10, 100.0 - failures); } -TEST( Spall2all, SmallBufProc1 ) -{ - Lib::instance(); +TEST_F(SparseAll2AllTests, ManyMsgs) { + SparseAllToAll x(my_pid, nprocs); + const int nMsgs = 10000; + x.reserve(nMsgs * 2, sizeof(int)); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); + for (int j = 0; j < 10; ++j) { + x.clear(); - SparseAllToAll x(my_pid, nprocs); - const int nMsgs = 100; - // only one process has a very small buffer space. Still - // that has high likelihood to fail - x.reserve( my_pid == 1 ? nMsgs : (nMsgs * nMsgs) , sizeof(int) ); - - int failures = 0; - for (int j = 0; j < 100 ; ++j) { - x.clear(); - - for (int i = 0; i < nMsgs; ++i) - { - x.send( (my_pid + i) % nprocs, & i, sizeof(i) ); - } - - bool prerandomize = true; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL, 1 ); - failures += ( error ? 1 : 0 ) ; + for (int i = 0; i < nMsgs; ++i) { + x.send((my_pid + i) % nprocs, &i, sizeof(i)); } - EXPECT_GE( 90.0 / nprocs + 10 , 100.0-failures ); - -} - -TEST( Spall2all, ManyMsgs ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - SparseAllToAll x(my_pid, nprocs); - const int nMsgs = 10000; - x.reserve( nMsgs * 2 , sizeof(int) ); - - for (int j = 0; j < 10 ; ++j) { - x.clear(); - - for (int i = 0; i < nMsgs; ++i) - { - x.send( (my_pid + i) % nprocs, & i, sizeof(i) ); - } - - bool prerandomize = true; - int trials = 5; - int error = x.exchange( Lib::instance().world(), prerandomize, - NULL, trials); - EXPECT_FALSE( error ); - - for (int i = 0; i < nMsgs; ++i) - { - EXPECT_FALSE( x.empty() ); - int k = -1; - x.recv( &k, sizeof(k)); - EXPECT_GE( k, 0 ); - EXPECT_LT( k, nMsgs ); - } - EXPECT_TRUE( x.empty() ); + bool prerandomize = true; + int trials = 5; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL, trials); + EXPECT_FALSE(error); + + for (int i = 0; i < nMsgs; ++i) { + EXPECT_FALSE(x.empty()); + int k = -1; + x.recv(&k, sizeof(k)); + EXPECT_GE(k, 0); + EXPECT_LT(k, nMsgs); } + EXPECT_TRUE(x.empty()); + } } -TEST( Spall2all, LargeSend ) -{ - Lib::instance(); - int my_pid = -1, nprocs = -1; - MPI_Comm_rank( MPI_COMM_WORLD, &my_pid ); - MPI_Comm_size( MPI_COMM_WORLD, &nprocs ); - - SparseAllToAll x( my_pid, nprocs ); +TEST_F(SparseAll2AllTests, LargeSend) { - std::vector data( size_t(std::numeric_limits::max()) + 10u ); - for (size_t i = 0; i < data.size(); ++i) - data[i] = char(i + my_pid) ; + std::vector data(size_t(std::numeric_limits::max()) + 10u); + for (size_t i = 0; i < data.size(); ++i) + data[i] = char(i + my_pid); - x.reserve( 1 , data.size() ); - x.send( (my_pid + 1) % nprocs, data.data(), data.size() ); + SparseAllToAll x(my_pid, nprocs); + x.reserve(1, data.size()); + x.send((my_pid + 1) % nprocs, data.data(), data.size()); - bool prerandomize = false; - int error = x.exchange( Lib::instance().world(), prerandomize, NULL); - EXPECT_TRUE( !error ); - - std::fill(data.begin(), data.end(), '\0' ); - x.recv( data.data(), data.size() ); - int j = (nprocs != 1?1:0); - for (size_t i = 0; i < data.size(); ++i) - EXPECT_EQ( char(i + (my_pid + nprocs - j) % nprocs), data[i] ) ; + bool prerandomize = false; + int error = x.exchange(Lib::instance().world(), prerandomize, NULL); + EXPECT_TRUE(!error); + std::fill(data.begin(), data.end(), '\0'); + x.recv(data.data(), data.size()); + int j = (nprocs != 1 ? 1 : 0); + for (size_t i = 0; i < data.size(); ++i) + EXPECT_EQ(char(i + (my_pid + nprocs - j) % nprocs), data[i]); } - - diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5932d9db..91eddb06 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -24,7 +24,7 @@ add_library(lpf_common_${LPFLIB_CONFIG_NAME} OBJECT ) -add_gtest(time_test time.t.cpp time.cpp stack.cpp) -add_gtest(memreg_test memreg.t.cpp log.cpp time.cpp config.cpp stack.cpp) -add_gtest(sparseset_test sparseset.t.cpp log.cpp time.cpp config.cpp stack.cpp) +add_gtest(time_test "pthread" OFF time.t.cpp time.cpp stack.cpp) +add_gtest(memreg_test "pthread" OFF memreg.t.cpp log.cpp time.cpp config.cpp stack.cpp) +add_gtest(sparseset_test "pthread" OFF sparseset.t.cpp log.cpp time.cpp config.cpp stack.cpp) diff --git a/src/common/memreg.t.cpp b/src/common/memreg.t.cpp index 492d6e80..5ce76834 100644 --- a/src/common/memreg.t.cpp +++ b/src/common/memreg.t.cpp @@ -25,6 +25,11 @@ using namespace lpf; typedef MemoryRegister Memreg; typedef Memreg::Slot Slot; +/** + * \test Memreg tests + * \pre P <= 1 + * \return Exit code: 0 + */ TEST( MemoryRegister, Empty ) { Memreg empty; diff --git a/src/common/time.t.cpp b/src/common/time.t.cpp index 9e8407a4..d79fd3e7 100644 --- a/src/common/time.t.cpp +++ b/src/common/time.t.cpp @@ -25,6 +25,11 @@ using namespace lpf; const double eps = std::numeric_limits::epsilon(); +/** + * \test Time tests + * \pre P <= 1 + * \return Exit code: 0 + */ TEST( Time, zero) { Time zero = Time::fromSeconds(0.0); diff --git a/src/debug/CMakeLists.txt b/src/debug/CMakeLists.txt index 47c0d57d..a6751c58 100644 --- a/src/debug/CMakeLists.txt +++ b/src/debug/CMakeLists.txt @@ -25,7 +25,8 @@ add_library( ${libname} rwconflict.cpp $ ) -target_link_libraries( ${libname} ${LIB_POSIX_THREADS} ) +target_link_libraries( ${libname} ${LIB_POSIX_THREADS}) +target_include_directories( ${libname} PRIVATE ${MPI_C_INCLUDE_PATH}) set_target_properties(${libname} PROPERTIES SOVERSION ${SOVERSION} ) @@ -36,5 +37,5 @@ install(TARGETS ${libname} EXPORT lpf ARCHIVE DESTINATION ${INSTALL_LIB} ) -add_gtest(rwconflict_test rwconflict.t.cpp rwconflict.cpp - $ ) +add_gtest(rwconflict_test "pthread" rwconflict.t.cpp rwconflict.cpp) + #$ ) diff --git a/src/debug/core.cpp b/src/debug/core.cpp index d120b22b..f9df888d 100644 --- a/src/debug/core.cpp +++ b/src/debug/core.cpp @@ -16,6 +16,7 @@ */ #include "debug/lpf/core.h" + #undef lpf_get #undef lpf_put #undef lpf_sync @@ -78,8 +79,6 @@ #include "memreg.hpp" #include "rwconflict.hpp" - - namespace lpf { namespace debug { @@ -220,7 +219,6 @@ class _LPFLIB_LOCAL Interface { } } - Interface( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs ) : m_ctx( ctx ) , m_pid( pid ) @@ -268,6 +266,7 @@ class _LPFLIB_LOCAL Interface { { } + void cleanup() { if ( m_comm_bufs_registered ) { @@ -429,27 +428,27 @@ class _LPFLIB_LOCAL Interface { if ( P <= 0 && P != LPF_MAX_P ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_exec: P = " << P ); - std::abort(); + lpf_debug_abort(); } if ( spmd == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_exec: NULL spmd argument" ); - std::abort(); + lpf_debug_abort(); } if ( args.input_size != 0 && args.input == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL input argument while input_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } if ( args.output_size != 0 && args.output == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL output argument while output_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } if ( args.f_size != 0 && args.f_symbols == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL f_symbols argument while f_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } lpf_args_t new_args; @@ -545,22 +544,22 @@ class _LPFLIB_LOCAL Interface { if ( spmd == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_rehook: NULL spmd argument" ); - std::abort(); + lpf_debug_abort(); } if ( args.input_size != 0 && args.input == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL input argument while input_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } if ( args.output_size != 0 && args.output == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL output argument while output_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } if ( args.f_size != 0 && args.f_symbols == NULL ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid argument passed to lpf_spmd_t: NULL f_symbols argument while f_size is non-zero" ); - std::abort(); + lpf_debug_abort(); } lpf_args_t new_args; @@ -676,7 +675,7 @@ class _LPFLIB_LOCAL Interface { "which would have taken the " << (m_memreg_size+1) << "-th slot, while only space for " << m_memreg_reserved << " slots has been reserved" ); - std::abort(); + lpf_debug_abort(); } Memslot slot; slot.file = file; @@ -707,7 +706,7 @@ class _LPFLIB_LOCAL Interface { "which would have taken the " << (m_memreg_size+1) << "-th slot, while only space for " << m_memreg_reserved << " slots has been reserved" ); - std::abort(); + lpf_debug_abort(); } Memslot slot; @@ -732,7 +731,7 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Invalid attempt to deregister a memory slot, " "because it has not been registered before" ); - std::abort(); + lpf_debug_abort(); } if ( m_used_regs.find( slot ) != m_used_regs.end() ) { @@ -741,7 +740,7 @@ class _LPFLIB_LOCAL Interface { "because it is in use by the primitive on " << m_used_regs[slot].first << ":" << m_used_regs[slot].second ); - std::abort(); + lpf_debug_abort(); } if ( m_memreg.lookup( slot ).kind == Memslot::Global ) { @@ -778,7 +777,7 @@ class _LPFLIB_LOCAL Interface { if ( dst_pid < 0 || dst_pid >= m_nprocs ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": unknown process ID " << dst_pid << " for data destination " ); - std::abort(); + lpf_debug_abort(); } LPFLIB_RESTORE_WARNINGS @@ -786,26 +785,26 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": numerical overflow while computing src_offset + size = " << src_offset << " + " << size << " > SIZE_MAX" ); - std::abort(); + lpf_debug_abort(); } if ( dst_offset > std::numeric_limits::max() - size ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": numerical overflow while computing dst_offset + size = " << dst_offset << " + " << size << " > SIZE_MAX" ); - std::abort(); + lpf_debug_abort(); } if ( m_active_regs.find( src_slot ) == m_active_regs.end() ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": source memory slot does not exist" ); - std::abort(); + lpf_debug_abort(); } if ( m_active_regs.find( dst_slot ) == m_active_regs.end() ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": destination memory slot does not exist" ); - std::abort(); + lpf_debug_abort(); } const Memslot & ss = m_memreg.lookup( src_slot ); @@ -818,7 +817,7 @@ class _LPFLIB_LOCAL Interface { " A synchronisation is necessary to active" " the memory registration at " << ss.file << ":" << ss.line ); - std::abort(); + lpf_debug_abort(); } if ( ss.kind == Memslot::Local && ss.size[0] < src_offset + size ) { @@ -827,7 +826,7 @@ class _LPFLIB_LOCAL Interface { << ss.file << ":" << ss.line << " ) is read past the end by " << ( src_offset + size - ss.size[0] ) << " bytes. "); - std::abort(); + lpf_debug_abort(); } if ( ss.kind == Memslot::Global && ss.size[m_pid] < src_offset + size ) { @@ -836,7 +835,7 @@ class _LPFLIB_LOCAL Interface { << ss.file << ":" << ss.line << " ) is read past the end by " << ( src_offset + size - ss.size[m_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } if ( ! ds.active ) { @@ -846,7 +845,7 @@ class _LPFLIB_LOCAL Interface { "missing. A synchronisation is necessary " "to active the memory registration at " << ds.file << ":" << ds.line ); - std::abort(); + lpf_debug_abort(); } if ( ds.kind == Memslot::Local ) { @@ -854,7 +853,7 @@ class _LPFLIB_LOCAL Interface { << ": destination memory must be globally registered. " << "Instead, it was only locally registered at " << ds.file << ":" << ds.line ); - std::abort(); + lpf_debug_abort(); } if ( ds.kind == Memslot::Global && ds.size[dst_pid] != size_t(-1) @@ -864,7 +863,7 @@ class _LPFLIB_LOCAL Interface { << ds.file << ":" << ds.line << " ) is written past the end by " << ( dst_offset + size - ds.size[dst_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } if ( m_puts.size() + m_gets.size() >= m_mesgq_reserved ) { @@ -874,7 +873,7 @@ class _LPFLIB_LOCAL Interface { << ": This is the " << (m_puts.size() + m_gets.size() + 1) << "-th message, while space for only " << m_mesgq_reserved << " has been reserved. Request queue follows\n" << t.str() ); - std::abort(); + lpf_debug_abort(); } m_used_regs[src_slot] = std::make_pair( file, line ); @@ -896,7 +895,7 @@ class _LPFLIB_LOCAL Interface { if ( src_pid < 0 || src_pid >= m_nprocs ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": unknown process ID " << src_pid << " for data source" ); - std::abort(); + lpf_debug_abort(); } LPFLIB_RESTORE_WARNINGS @@ -904,26 +903,26 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": numerical overflow while computing src_offset + size = " << src_offset << " + " << size << " > SIZE_MAX" ); - std::abort(); + lpf_debug_abort(); } if ( dst_offset > std::numeric_limits::max() - size ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": numerical overflow while computing dst_offset + size = " << dst_offset << " + " << size << " > SIZE_MAX" ); - std::abort(); + lpf_debug_abort(); } if ( m_active_regs.find( src_slot ) == m_active_regs.end() ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": source memory slot does not exist" ); - std::abort(); + lpf_debug_abort(); } if ( m_active_regs.find( dst_slot ) == m_active_regs.end() ) { LOG( 0, file << ":" << line << ": pid " << m_pid << ": destination memory slot does not exist" ); - std::abort(); + lpf_debug_abort(); } const Memslot & ss = m_memreg.lookup( src_slot ); @@ -936,7 +935,7 @@ class _LPFLIB_LOCAL Interface { " A synchronisation is necessary to active" " the memory registration at " << ss.file << ":" << ss.line ); - std::abort(); + lpf_debug_abort(); } if ( ss.kind == Memslot::Local ) { @@ -945,7 +944,7 @@ class _LPFLIB_LOCAL Interface { "Instead, it was registered only locally at " << ss.file << ":" << ss.line ); - std::abort(); + lpf_debug_abort(); } if ( ss.kind == Memslot::Global && ss.size[src_pid] != size_t(-1) @@ -955,7 +954,7 @@ class _LPFLIB_LOCAL Interface { << ss.file << ":" << ss.line << " ) is read past the end by " << ( src_offset + size - ss.size[src_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } if ( ! ds.active ) { @@ -965,7 +964,7 @@ class _LPFLIB_LOCAL Interface { "missing. A synchronisation is necessary" "to active the memory registration at " << ds.file << ":" << ds.line ); - std::abort(); + lpf_debug_abort(); } if ( ds.kind == Memslot::Local && ds.size[0] < dst_offset + size ) { @@ -974,7 +973,7 @@ class _LPFLIB_LOCAL Interface { << ds.file << ":" << ds.line << " ) is written past the end by " << ( dst_offset + size - ds.size[0] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } if ( ds.kind == Memslot::Global && ds.size[m_pid] < dst_offset + size ) { @@ -983,7 +982,7 @@ class _LPFLIB_LOCAL Interface { << ds.file << ":" << ds.line << " ) is written past the end by " << ( dst_offset + size - ds.size[m_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } if ( m_puts.size() + m_gets.size() >= m_mesgq_reserved ) { @@ -993,7 +992,7 @@ class _LPFLIB_LOCAL Interface { << ": This is the " << (m_puts.size() + m_gets.size() + 1) << "-th message, while space for only " << m_mesgq_reserved << " has been reserved. Request queue follows\n" << t.str() ); - std::abort(); + lpf_debug_abort(); } m_used_regs[src_slot] = std::make_pair( file, line ); @@ -1006,6 +1005,15 @@ class _LPFLIB_LOCAL Interface { return LPF_SUCCESS; } + /* + lpf_err_t abort(const char * file, int line) { + (void) file; + (void) line; + lpf_debug_abort(); + return LPF_SUCCESS; + } + */ + lpf_err_t sync( const char * file, int line, lpf_sync_attr_t attr = LPF_SYNC_DEFAULT ) { @@ -1019,7 +1027,7 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Could not allocate extra debug messages in message queue" ); - std::abort(); + lpf_debug_abort(); } } @@ -1029,7 +1037,7 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": Could not allocate extra debug memory slots in memory registration table" ); - std::abort(); + lpf_debug_abort(); } } @@ -1089,7 +1097,7 @@ class _LPFLIB_LOCAL Interface { << ": Number of global registrations does not match." " I have " << globregs << ", while pid " << p << " has " << m_glob_regs[p] << " global registrations" ); - std::abort(); + lpf_debug_abort(); } if (globderegs != m_glob_deregs[p] ) { @@ -1097,7 +1105,7 @@ class _LPFLIB_LOCAL Interface { << ": Number of deregistrations of global slots does not match." " I have " << globderegs << ", while pid " << p << " has " << m_glob_deregs[p] << " deregistrations" ); - std::abort(); + lpf_debug_abort(); } } @@ -1128,7 +1136,7 @@ class _LPFLIB_LOCAL Interface { LOG( 0, file << ":" << line << ": pid " << m_pid << ": the " << i << "-th global deregistration mismatches " " on pid " << p << " and " << m_pid ); - std::abort(); + lpf_debug_abort(); } } @@ -1181,7 +1189,7 @@ class _LPFLIB_LOCAL Interface { "somehow (other confused pid " << p << " )" ", which makes me think that this is " "an internal error in the debug layer. Sorry!"); - std::abort(); + lpf_debug_abort(); } } @@ -1272,7 +1280,7 @@ class _LPFLIB_LOCAL Interface { "Incoming requests from PIDs 0.." << m_nprocs << " = " << s.str() << ". Local request queue follows (" << m_puts.size() << " puts " << "and " << m_gets.size() << " gets )\n" << t.str() ); - std::abort(); + lpf_debug_abort(); } // reallocate access buffers if they were resized. @@ -1316,7 +1324,7 @@ class _LPFLIB_LOCAL Interface { << " ) is written past the end by " << ( put.dstOffset + put.size - ds.size[m_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } m_rwconflict.insertRead( @@ -1344,7 +1352,7 @@ class _LPFLIB_LOCAL Interface { << " ) is read past the end by " << ( get.srcOffset + get.size - ss.size[m_pid] ) << " bytes"); - std::abort(); + lpf_debug_abort(); } size_t & index = m_remote_access_by_me_offsets_local[ get.srcPid ]; @@ -1398,7 +1406,7 @@ class _LPFLIB_LOCAL Interface { << static_cast(ptr+a.offset+a.size) << "); Reads are " << s.str() ; ); - std::abort(); + lpf_debug_abort(); } } } @@ -1422,7 +1430,7 @@ class _LPFLIB_LOCAL Interface { << static_cast(ptr+get.dstOffset+get.size) << "); Reads are " << s.str() ; ); - std::abort(); + lpf_debug_abort(); } } @@ -1609,6 +1617,10 @@ lpf_err_t lpf_debug_register_local( const char * file, int line, ) { return Interface::lookupCtx( file, line, ctx )->register_local( file, line, pointer, size, memslot); } +//extern _LPFLIB_API +//lpf_err_t lpf_debug_abort( const char * file, int line, lpf_t ctx) +//{ return Interface::lookupCtx( file, line, ctx )->debug_abort( file, line); } + extern _LPFLIB_API lpf_err_t lpf_debug_deregister( const char * file, int line, lpf_t ctx, lpf_memslot_t memslot @@ -1656,7 +1668,6 @@ lpf_err_t lpf_debug_sync( const char * file, int line, lpf_t ctx, lpf_sync_attr_t attr ) { return Interface::lookupCtx( file, line, ctx )->sync( file, line, attr ); } - } // extern "C" diff --git a/src/hybrid/core.cpp b/src/hybrid/core.cpp index 12870298..3b5c8574 100644 --- a/src/hybrid/core.cpp +++ b/src/hybrid/core.cpp @@ -35,7 +35,6 @@ #endif - extern "C" { _LPFLIB_VAR const lpf_err_t LPF_SUCCESS = 0; @@ -384,4 +383,13 @@ _LPFLIB_API lpf_err_t lpf_resize_memory_register( lpf_t ctx, size_t max_regs ) return LPF_SUCCESS; } +lpf_err_t lpf_debug_abort( const char * file, int line, lpf_t ctx) { +{ + using namespace lpf::hybrid; + ThreadState * t = realContext(ctx); + MPI mpi = t->nodeState().mpi(); + mpi.debug_abort(); + return LPF_SUCCESS; +} + } // extern "C" diff --git a/src/hybrid/dispatch.hpp b/src/hybrid/dispatch.hpp index 1235e513..2e31b2a5 100644 --- a/src/hybrid/dispatch.hpp +++ b/src/hybrid/dispatch.hpp @@ -226,6 +226,9 @@ namespace lpf { namespace hybrid { err_t resize_memory_register( size_t max_regs ) { return USE_MPI(resize_memory_register)(m_ctx, max_regs); } + err_t abort( ) + { return USE_MPI(abort)(m_ctx); } + static bool is_linked_correctly() { return SUCCESS != ERR_OUT_OF_MEMORY diff --git a/src/pthreads/core.cpp b/src/pthreads/core.cpp index 1d90588a..6294940d 100644 --- a/src/pthreads/core.cpp +++ b/src/pthreads/core.cpp @@ -378,3 +378,15 @@ lpf_err_t lpf_resize_memory_register( lpf_t ctx, size_t max_regs ) return t->resizeMemreg(max_regs); } +lpf_err_t lpf_debug_abort() { + // Using std::abort is not portable + // SIGABRT code 6 is often coverted to code 134. + // Therefore, use std::quick_exit(6) instead + // The reason we do not use std::exit is that + // it implies calling destructors, and this leads to + // segmentation faults for pthread backend and abnormal + // programs. std::quick_exit does not call destructors + std::quick_exit(6); + return LPF_SUCCESS; +} + diff --git a/test_launcher.py b/test_launcher.py new file mode 100644 index 00000000..a598c6e6 --- /dev/null +++ b/test_launcher.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import argparse +import subprocess +import sys + +parser = argparse.ArgumentParser( description='Death test launcher' ) +parser.add_argument("-e", "--engine", type=str) +parser.add_argument("-L", "--parallel_launcher", type=str) +parser.add_argument("-p", "--min_process_count", type=int) +parser.add_argument("-P", "--max_process_count", type=int) +parser.add_argument("-t", "--lpf_probe_timer", type=float) +parser.add_argument("-R", "--expected_return_code", type=int) +parser.add_argument( 'cmd', nargs=argparse.REMAINDER ) +args = parser.parse_args() + +# This is only for passing Gtest info to CMake +# The parallel launcher is still needed as Open MPI +# binaries terminate without the launcher on our cluster, +# even for single process runs +if args.cmd[-1] == '--gtest_list_tests': + run_cmd = [args.parallel_launcher, '-engine', args.engine, '-n', '1'] + args.cmd + cmd = subprocess.run( run_cmd) + sys.exit(cmd.returncode) +# Actual use of our launcher +else: + for i in range(args.min_process_count, args.max_process_count+1): + if args.lpf_probe_timer > 0.0: + run_cmd = [args.parallel_launcher, '-engine', args.engine, '-probe', str(args.lpf_probe_timer), '-n', str(i)] + args.cmd + else: + run_cmd = [args.parallel_launcher, '-engine', args.engine, '-n', str(i)] + args.cmd + print("Run command: ") + print(run_cmd) + cmd = subprocess.run( run_cmd) + print("Test returned code = " + str(cmd.returncode)) + retcode = cmd.returncode + if (retcode != args.expected_return_code): + print("Test " + args.cmd[0] + args.cmd[1] + "\nreturned\t" + str(retcode) + "\nexpected return code was: " + str(args.expected_return_code)) + sys.exit(1) + print("Test " + args.cmd[0] + args.cmd[1] + " passed") diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index 7aadf7e1..f9bd87e7 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -15,58 +15,136 @@ # limitations under the License. # -# All test sources have file names as bla.c -file(GLOB AllTestSources "*.c" ) -# All test sources which are specific to some engine are of the form -# bla.pthread.c -file(GLOB AllSpecificTestSources "*.*.c") -# All generic test sources don't have the two dots in their name -file(GLOB AllGenericTestSources "*.c") -list(REMOVE_ITEM AllGenericTestSources ${AllSpecificTestSources}) +set(test_sources + func_bsplib_example_lpf_sum.cpp + func_bsplib_example_lpf_sum_unsafemode.cpp + func_bsplib_example_put_array.cpp + func_bsplib_example_put_array_unsafemode.cpp + func_bsplib_example_reverse.cpp + func_bsplib_example_reverse_unsafemode.cpp + func_bsplib_get_exceptions.cpp + func_bsplib_get_normal.cpp + func_bsplib_get_normal_unsafemode.cpp + func_bsplib_get_twice_on_same_remote.cpp + func_bsplib_get_twice_on_same_remote_unsafemode.cpp + func_bsplib_getput_same_dest.cpp + func_bsplib_getput_same_dest_unsafemode.cpp + func_bsplib_getput_same_remote.cpp + func_bsplib_getput_same_remote_unsafemode.cpp + func_bsplib_getput_zero_bytes.cpp + func_bsplib_hpget_many.cpp + func_bsplib_hpput_many.cpp + func_bsplib_hpsend_many.cpp + func_bsplib_nprocs.cpp + func_bsplib_pid.cpp + func_bsplib_pushpopreg_ambiguous.cpp + func_bsplib_pushpopreg_different_variables.cpp + func_bsplib_pushpopreg_exceptions.cpp + func_bsplib_pushpopreg_many_same.cpp + func_bsplib_pushpopreg_normal.cpp + func_bsplib_pushpopreg_normal_unsafemode.cpp + func_bsplib_pushpopreg_null.cpp + func_bsplib_pushpopreg_pop_before_put.cpp + func_bsplib_pushpopreg_pop_before_put_unsafemode.cpp + func_bsplib_pushpopreg_pop_on_one_process.cpp + func_bsplib_pushpopreg_push_on_one_process.cpp + func_bsplib_pushpopreg_same_growing_memory.cpp + func_bsplib_pushpopreg_same_shrinking_memory.cpp + func_bsplib_pushpopreg_two_pops_before_two_puts.cpp + func_bsplib_put_exceptions.cpp + func_bsplib_put_normal.cpp + func_bsplib_put_normal_unsafemode.cpp + func_bsplib_send_empty_tag.cpp + func_bsplib_send_non_empty_tag.cpp + func_bsplib_send_none.cpp + func_bsplib_send_null.cpp + func_bsplib_send_one.cpp + func_bsplib_send_one_unsafemode.cpp + func_bsplib_set_different_tag_size.cpp + func_bsplib_set_tag_size.cpp + func_bsplib_sync_except_p0.cpp + func_bsplib_sync_only_p0.cpp + func_bsplib_time.cpp + func_lpf_deregister_parallel_multiple.cpp + func_lpf_deregister_parallel_single.cpp + func_lpf_exec_multiple_call_single_arg_dual_proc.cpp + func_lpf_exec_nested_call_single_arg_dual_proc.cpp + func_lpf_exec_single_call_no_arg_max_proc.cpp + func_lpf_exec_single_call_no_arg_single_proc.cpp + func_lpf_exec_single_call_single_arg_dual_proc.cpp + func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.cpp + func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.cpp + func_lpf_exec_single_call_single_arg_single_proc.cpp + func_lpf_get_parallel_alltoall.cpp + func_lpf_get_parallel_huge.cpp + func_lpf_get_parallel_overlapping_complete.cpp + func_lpf_get_parallel_overlapping_pyramid.cpp + func_lpf_get_parallel_overlapping_rooftiling.cpp + func_lpf_get_parallel_single.cpp + #func_lpf_hook_simple.mpirma.cpp + #func_lpf_hook_simple.pthread.cpp + #func_lpf_hook_subset.mpimsg.cpp + #func_lpf_hook_tcp.mpirma.cpp + #func_lpf_hook_tcp_timeout.mpirma.cpp + func_lpf_probe_parallel_full.cpp + func_lpf_probe_parallel_nested.cpp + func_lpf_probe_root.cpp + func_lpf_put_and_get_overlapping.cpp + func_lpf_put_parallel_alltoall.cpp + #func_lpf_put_parallel_bad_pattern.cpp <= in exception_list + func_lpf_put_parallel_big.cpp + func_lpf_put_parallel_huge.cpp + func_lpf_put_parallel_overlapping_complete.cpp + func_lpf_put_parallel_overlapping_pyramid.cpp + func_lpf_put_parallel_overlapping_rooftiling.cpp + func_lpf_put_parallel_single.cpp + func_lpf_register_and_deregister_irregularly.cpp + func_lpf_register_and_deregister_many_global.cpp + func_lpf_register_global_parallel_grow.cpp + func_lpf_register_global_parallel_multiple.cpp + func_lpf_register_global_parallel_shrink.cpp + func_lpf_register_global_root_multiple.cpp + func_lpf_register_global_root_single.cpp + func_lpf_register_local_parallel_multiple.cpp + func_lpf_resize_delayed_shrinking_memory_registers.cpp + func_lpf_resize_delayed_shrinking_message_queues.cpp + func_lpf_resize_parallel_five.cpp + func_lpf_resize_root_five.cpp + func_lpf_resize_root_outofmem.cpp + func_lpf_resize_root_zero.cpp + macro_LPF_VERSION.cpp + type_lpf_spmd_t.cpp + type_lpf_t.cpp + ) -foreach(LPF_IMPL_ID ${ENGINES}) -foreach(debug ON OFF) +foreach (LPF_IMPL_ID ${ENGINES}) + set(debug ON) set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) - file(GLOB ThisEngineSources "*.${LPF_IMPL_ID}.c") - set(mode) if (debug) - set(mode "_debug") - endif() + set(mode "_debug") + endif(debug) # add all source files except the ones we don't want - foreach(testSource ${AllGenericTestSources} ${ThisEngineSources}) - string(REGEX REPLACE "(.${LPF_IMPL_ID})?.c$" "" baseName ${testSource}) + foreach(testSource ${test_sources}) + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${testSource}) get_filename_component(baseName ${testSource} NAME_WE ) set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") - set(corelib "lpf_core_univ_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}") - set(hllib "lpf_hl${mode}") - set(debuglib "lpf_debug") - add_executable(${exeName} ${testSource}) - target_link_libraries(${exeName} ${hllib}) - target_link_exe_with_core(${exeName} ${LPF_IMPL_ID}) - target_compile_flags(${exeName} PRIVATE ${hllib} "-DLPF_CORE_IMPL_ID=${LPF_IMPL_ID}" ) + add_gtest(${exeName} ${LPF_IMPL_ID} ${debug} "${CMAKE_CURRENT_SOURCE_DIR}/${testSource}") - if (debug) - target_link_libraries(${exeName} ${debuglib}) - target_include_directories( ${exeName} BEFORE PRIVATE ../../include/debug ) - endif() - - endforeach() - endforeach(debug) + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${testSource}) + get_filename_component(baseName ${testSource} NAME_WE ) + set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") - add_test( NAME "API_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}" - COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" "${LPF_IMPL_ID}" - "${LPF_IMPL_CONFIG}" "${test_output}/api_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}.xml" - ) + endforeach(testSource) endforeach(LPF_IMPL_ID) -include_directories(.) -add_subdirectory(c99) +include_directories(.) add_subdirectory(debug) +add_subdirectory(collectives) option(LPFLIB_MAKE_TEST_DOC "Build the test documentation" OFF) diff --git a/tests/functional/Test.h b/tests/functional/Test.h deleted file mode 100644 index 1b1eb807..00000000 --- a/tests/functional/Test.h +++ /dev/null @@ -1,135 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LPF_TESTS_FUNCTIONAL_TEST_H -#define LPF_TESTS_FUNCTIONAL_TEST_H - -#include -#include -#include - -#include "assert.hpp" - -#define EXPECT_EQ( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( (expected) != (actual) ) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected (%s) which evaluates to " format ", but\n" \ - " actual (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_NE( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( (expected) == (actual) ) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected (%s) which evaluates to " format " to be different from\n" \ - " actual (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_LE( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( !( (expected) <= (actual)) ) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected that (%s) which evaluates to " format ", is less than\n" \ - " or equal to (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_GE( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( !( (expected) >= (actual) )) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected that (%s) which evaluates to " format ", is greater than\n" \ - " or equal to (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_LT( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( !( (expected) < (actual)) ) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected that (%s) which evaluates to " format ", is less than\n" \ - " (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_GT( format, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( !( (expected) > (actual) )) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected that (%s) which evaluates to " format ", is greater than\n" \ - " (%s) which evaluates to " format ".\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#define EXPECT_STREQ( N, expected, actual ) \ - do { LPFLIB_IGNORE_TAUTOLOGIES \ - if ( strncmp( (expected), (actual), (N) ) != 0 ) { \ - fprintf(stderr, "TEST FAILURE in " __FILE__ ":%d\n" \ - " Expected (%s) which evaluates to %s, but\n" \ - " actual (%s) which evaluates to %s.\n", __LINE__, \ - #expected, (expected), #actual, (actual) ); \ - abort(); } \ - LPFLIB_RESTORE_WARNINGS } while(0) - -#ifdef __GNUC__ - #define UNUSED __attribute__((unused)) -#else - #define UNUSED -#endif - -/** \mainpage Test documentation - * - * This documentation lists the tests of the LPF implementation - * - \ref APITests - * - */ - -/** \defgroup APITests API Tests - * A set of small programs to test the LPF API. - */ - -#ifdef DOXYGEN -#define TEST( name ) \ - /** \ingroup APITests */ \ - int name( lpf_pid_t P ) - -#else - -#define TEST( name ) \ - /** \ingroup APITests */ \ - int name(int argc, char ** argv); \ - \ - int main(int argc, char ** argv) \ - { \ - (void) argc; (void) argv; \ - return name (argc, argv); \ - } \ - \ - int name(int argc UNUSED, char ** argv UNUSED) - -#endif - -#endif diff --git a/tests/functional/c99/CMakeLists.txt b/tests/functional/c99/CMakeLists.txt deleted file mode 100644 index 584acb59..00000000 --- a/tests/functional/c99/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ - -# -# Copyright 2021 Huawei Technologies Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -foreach(LPF_IMPL_ID ${ENGINES}) -foreach(debug ON OFF) - set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) - - set(mode) - if (debug) - set(mode "_debug") - endif() - - file(GLOB TestSources "*.c") - foreach(testSource ${TestSources}) - string(REGEX REPLACE ".c$" "" exeName ${testSource}) - get_filename_component(exeName ${testSource} NAME_WE ) - set(exeName "${exeName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") - - set(corelib "lpf_core_univ_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}") - set(hllib "lpf_hl${mode}") - set(debuglib "lpf_debug") - add_executable(${exeName} ${testSource}) - target_link_exe_with_core(${exeName} ${LPF_IMPL_ID}) - target_link_libraries(${exeName} ${hllib}) - set_target_properties(${exeName} PROPERTIES - C_STANDARD 99 - C_STANDARD_REQUIRED YES - ) - target_compile_flags(${exeName} PRIVATE ${hllib}) - if (debug) - target_link_libraries(${exeName} ${debuglib}) - target_include_directories( ${exeName} BEFORE PRIVATE ../../../include/debug ) - endif() - endforeach() -endforeach(debug) -endforeach(LPF_IMPL_ID) - diff --git a/tests/functional/c99/func_lpf_allcombine.c b/tests/functional/c99/func_lpf_allcombine.c deleted file mode 100644 index bdbc5d71..00000000 --- a/tests/functional/c99/func_lpf_allcombine.c +++ /dev/null @@ -1,94 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void elementwise_add( const size_t n, const void * const _in, void * const _out ) { - double * const out = (double*) _out; - const double * const array = (const double*) _in; - for( size_t i = 0; i < n; ++i ) { - out[ i ] += array[ i ]; - } -} - -void spmd( lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, const lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2*p ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const size_t byte_size = (1 << 19) / sizeof(double); - const size_t size = byte_size / sizeof(double); - double * data = malloc( byte_size ); - EXPECT_NE( "%p", NULL, data ); - - for( size_t i = 0; i < size; ++i ) { - data[ i ] = s; - } - - rc = lpf_register_global( ctx, data, byte_size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, byte_size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_allcombine( coll, data, data_slot, size, sizeof(double), &elementwise_add ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( size_t i = 0; i < size; ++i ) { - const double num = (double)(coll.P) / 2.0; - const double max = (double)(coll.P-1); - EXPECT_EQ( "%lf", num * max, data[i] ); - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t objects, performs a combine, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_allcombine ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS ); - EXPECT_EQ("%d", LPF_SUCCESS, rc); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_allgather.c b/tests/functional/c99/func_lpf_allgather.c deleted file mode 100644 index ced82f8a..00000000 --- a/tests/functional/c99/func_lpf_allgather.c +++ /dev/null @@ -1,107 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - const size_t size = (1 << 19); - - lpf_memslot_t src_slot, dst_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2*p); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 3 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char * src = malloc( size ); - EXPECT_NE( "%p", NULL, src ); - - char * dst = malloc( p * size ); - EXPECT_NE( "%p", NULL, dst ); - - for( size_t i = 0; i < size; ++i ) { - src[ i ] = (char)s; - } - rc = lpf_register_global( ctx, src, size, &src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( size_t i = 0; i < p * size; ++i ) { - dst[ i ] = -1; - } - rc = lpf_register_global( ctx, dst, p * size, &dst_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, p * size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_allgather( coll, src_slot, dst_slot, size, true ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( size_t i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char)s, src[ i ] ); - } - - for( lpf_pid_t k = 0; k < p; ++k ) { - for( size_t i = 0; i < size; ++i ) { - const size_t index = k * size + i; - if( k == s ) { - EXPECT_EQ( "%c", (char) -1, dst[ index ] ); - } else { - EXPECT_EQ( "%c", (char)k, dst[ index ] ); - } - } - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, dst_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( src ); - free( dst ); -} - -/** - * \test Initialises one \a lpf_coll_t object, performs an allgather, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_allgather ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_allgather_overlapped.c b/tests/functional/c99/func_lpf_allgather_overlapped.c deleted file mode 100644 index a3a475c4..00000000 --- a/tests/functional/c99/func_lpf_allgather_overlapped.c +++ /dev/null @@ -1,98 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - const size_t size = (1 << 19); - - lpf_memslot_t data_slot, src_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2*p); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 3); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char * data = malloc( p * size ); - EXPECT_NE( "%p", NULL, data ); - - for( lpf_pid_t k = 0; k < p; ++k ) { - for( size_t i = 0; i < size; ++i ) { - if( k == s ) { - data[ k * size + i ] = (char)s; - } else { - data[ k * size + i ] = -1; - } - } - } - rc = lpf_register_global( ctx, data, p * size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( ctx, data + s * size, size, &src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, p * size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_allgather( coll, src_slot, data_slot, size, true ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( lpf_pid_t k = 0; k < p; ++k ) { - for( size_t i = 0; i < size; ++i ) { - const size_t index = k * size + i; - EXPECT_EQ( "%c", (char)k, data[ index ] ); - } - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t object, performs an allgather, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_allgather_overlapped ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_allreduce.c b/tests/functional/c99/func_lpf_allreduce.c deleted file mode 100644 index c7d65b78..00000000 --- a/tests/functional/c99/func_lpf_allreduce.c +++ /dev/null @@ -1,95 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -#include - -void min( const size_t n, const void * const _in, void * const _out ) { - double * const out = (double*) _out; - const double * const array = (const double*) _in; - for( size_t i = 0; i < n; ++i ) { - if( array[ i ] < *out ) { - *out = array[ i ]; - } - } -} - -void spmd( lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, const lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t elem_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2*p - 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - double reduced_value = INFINITY; - const size_t byte_size = (1 << 19) / sizeof(double); - const size_t size = byte_size / sizeof(double); - double * data = malloc( byte_size ); - EXPECT_NE( "%p", NULL, data ); - - for( size_t i = 0; i < size; ++i ) { - data[ i ] = s * size + i; - } - - rc = lpf_register_global( ctx, &reduced_value, sizeof(double), &elem_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, sizeof(double), 0, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - min( size, data, &reduced_value ); - rc = lpf_allreduce( coll, &reduced_value, elem_slot, sizeof(double), &min ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%lf", 0.0, reduced_value ); - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, elem_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t objects, performs an allreduce, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_allreduce ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_alltoall.c b/tests/functional/c99/func_lpf_alltoall.c deleted file mode 100644 index 157056db..00000000 --- a/tests/functional/c99/func_lpf_alltoall.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - const size_t size = (1 << 19); - - lpf_memslot_t src_slot, dst_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2 * p - 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 3 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char * src = malloc( p * size ); - EXPECT_NE( "%p", NULL, src ); - - char * dst = malloc( p * size ); - EXPECT_NE( "%p", NULL, dst ); - - for( size_t i = 0; i < p * size; ++i ) { - src[ i ] = (char)s; - dst[ i ] = -((char)s); - } - - rc = lpf_register_global( ctx, src, p * size, &src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( ctx, dst, p * size, &dst_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_alltoall( coll, src_slot, dst_slot, size ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( size_t i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char)s, src[ i ] ); - } - - for( lpf_pid_t k = 0; k < p; ++k ) { - for( size_t i = 0; i < size; ++i ) { - const size_t index = k * size + i; - if( k == s ) { - EXPECT_EQ( "%c", (char) (-s), dst[ index ] ); - } else { - EXPECT_EQ( "%c", (char)k, dst[ index ] ); - } - } - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, src_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, dst_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( src ); - free( dst ); -} - -/** - * \test Initialises one \a lpf_coll_t object, performs an all-to-all, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_alltoall ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_broadcast.c b/tests/functional/c99/func_lpf_broadcast.c deleted file mode 100644 index 77e4664d..00000000 --- a/tests/functional/c99/func_lpf_broadcast.c +++ /dev/null @@ -1,90 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -long max( long a, long b) { return a < b ? b : a; } - -void spmd( lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, max( p+1, 2*((long)p)-3)); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const long size = (1 << 19); - char * data = malloc( size ); - EXPECT_NE( "%p", NULL, data ); - - if( s == p / 2 ) { - for( long i = 0; i < size; ++i ) { - data[ i ] = -1; - } - } else { - for( long i = 0; i < size; ++i ) { - data[ i ] = +1; - } - } - - rc = lpf_register_global( ctx, data, size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, (1<<19), &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_broadcast( coll, data_slot, data_slot, size, p/2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( long i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char) -1, data[i] ); - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t object, performs a broadcast, and deletes it. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_broadcast ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_broadcast_prime_size_object.c b/tests/functional/c99/func_lpf_broadcast_prime_size_object.c deleted file mode 100644 index 6869063c..00000000 --- a/tests/functional/c99/func_lpf_broadcast_prime_size_object.c +++ /dev/null @@ -1,90 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -long max( long a, long b) { return a < b ? b : a; } - -void spmd( lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, max( p+1, 2*((long)p)-3)); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const long size = 197; - char * data = malloc( size ); - EXPECT_NE( "%p", NULL, data ); - - if( s == p / 2 ) { - for( long i = 0; i < size; ++i ) { - data[ i ] = -1; - } - } else { - for( long i = 0; i < size; ++i ) { - data[ i ] = +1; - } - } - - rc = lpf_register_global( ctx, data, size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_broadcast( coll, data_slot, data_slot, size, p/2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( long i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char) -1, data[i] ); - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Broadcasts an object whose size > P is not (easily) divisible by P - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_broadcast_prime_size_object ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_broadcast_small_prime_size_object.c b/tests/functional/c99/func_lpf_broadcast_small_prime_size_object.c deleted file mode 100644 index 3b043cb3..00000000 --- a/tests/functional/c99/func_lpf_broadcast_small_prime_size_object.c +++ /dev/null @@ -1,90 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -long max( long a, long b) { return a < b ? b : a; } - -void spmd( lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, max( p+1, 2*((long)p)-3)); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const long size = 11; - char * data = malloc( size ); - EXPECT_NE( "%p", NULL, data ); - - if( s == p / 2 ) { - for( long i = 0; i < size; ++i ) { - data[ i ] = -1; - } - } else { - for( long i = 0; i < size; ++i ) { - data[ i ] = +1; - } - } - - rc = lpf_register_global( ctx, data, size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_broadcast( coll, data_slot, data_slot, size, p/2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for( long i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char) -1, data[i] ); - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Broadcasts an object whose size > P is not (easily) divisible by P but also small so that in the second phase of 2-phase broadcast have nothing to send. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_broadcast_small_prime_size_object ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_collectives_init.c b/tests/functional/c99/func_lpf_collectives_init.c deleted file mode 100644 index 0e504f08..00000000 --- a/tests/functional/c99/func_lpf_collectives_init.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_coll_t coll1, coll2, coll3, coll4; - lpf_err_t rc; - - rc = lpf_resize_memory_register( ctx, 4 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, 0, &coll1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 8, 0, &coll2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, (1<<7), 0, (1<<19), &coll3 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, (1<<4), 8, (1<<25), &coll4 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_destroy( coll1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_destroy( coll2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_destroy( coll3 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_destroy( coll4 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Initialises lpf_coll_t objects and deletes them. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_collectives_init ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_collectives_init_overflow.c b/tests/functional/c99/func_lpf_collectives_init_overflow.c deleted file mode 100644 index 7b74da8e..00000000 --- a/tests/functional/c99/func_lpf_collectives_init_overflow.c +++ /dev/null @@ -1,89 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_coll_t coll1, coll2, coll3, coll4, coll5; - lpf_err_t rc; - - rc = lpf_resize_memory_register( ctx, 5 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - //make sure the base case is OK - rc = lpf_collectives_init( ctx, s, p, (1<<7), (1<<7), (1<<7), &coll1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - //now let us create some overflows - const size_t tooBig = (size_t)(-1); - - //overflow in the number of calls: may or may not be encountered by an implementation: - const lpf_err_t rc1 = lpf_collectives_init( ctx, s, p, tooBig, (1<<7), (1<<7), &coll2 ); - bool success = (rc1 == LPF_SUCCESS) || (rc1 == LPF_ERR_OUT_OF_MEMORY); - EXPECT_EQ( "%d", true, success ); - - //overflow in the element size required for reduction buffers: an implementation MUST detect this: - rc = lpf_collectives_init( ctx, s, p, (1<<7), tooBig, (1<<7), &coll3 ); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - - //overflow in the collective buffer size: may or may not be encountered by an implementation: - const lpf_err_t rc2 = lpf_collectives_init( ctx, s, p, (1<<7), (1<<7), tooBig, &coll4 ); - success = (rc2 == LPF_SUCCESS) || (rc2 == LPF_ERR_OUT_OF_MEMORY); - EXPECT_EQ( "%d", true, success ); - - //overflow that if not detected would lead to a very small buffer: an implementation MUST detect this: - if( p > 1 ) { - rc = lpf_collectives_init( ctx, s, p, (1<<7), tooBig / p + 1, (1<<7), &coll5 ); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - } - - rc = lpf_collectives_destroy( coll1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if( rc1 == LPF_SUCCESS ) { - rc = lpf_collectives_destroy( coll2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - if( rc2 == LPF_SUCCESS ) { - rc = lpf_collectives_destroy( coll4 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } -} - -/** - * \test Checks four ways in which a buffer could overflow; two of them MUST be detected-- for the other two ways this test accepts an LPF_ERR_OUT_OF_MEMORY and accepts a LPF_SUCCESS. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_collectives_init_overflow ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_combine.c b/tests/functional/c99/func_lpf_combine.c deleted file mode 100644 index a3ebc808..00000000 --- a/tests/functional/c99/func_lpf_combine.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -#include - -void elementwise_add( const size_t n, const void * const _in, void * const _out ) { - double * const out = (double*) _out; - const double * const array = (const double*) _in; - for( size_t i = 0; i < n; ++i ) { - out[ i ] += array[ i ]; - } -} - -void spmd( lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, const lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, 2*p ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const size_t byte_size = (1 << 19) / sizeof(double); - const size_t size = byte_size / sizeof(double); - double * data = malloc( byte_size ); - EXPECT_NE( "%p", NULL, data ); - - for( size_t i = 0; i < size; ++i ) { - data[ i ] = s; - } - - rc = lpf_register_global( ctx, data, byte_size, &data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, byte_size, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_combine( coll, data, data_slot, size, sizeof(double), &elementwise_add, p / 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if( s == p / 2 ) { - for( size_t i = 0; i < size; ++i ) { - const double num = (double)(coll.P) / 2.0; - const double max = (double)(coll.P-1); - EXPECT_EQ( "%lf", num * max, data[i] ); - } - } else { - //standard declares contents of data as undefined - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t objects, performs a combine, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_combine ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_gather.c b/tests/functional/c99/func_lpf_gather.c deleted file mode 100644 index 7f3b95cf..00000000 --- a/tests/functional/c99/func_lpf_gather.c +++ /dev/null @@ -1,107 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, p-1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const size_t size = (1 << 19); - char * data = NULL; - if( s == p / 2 ) { - data = malloc( size * p ); - } else { - data = malloc( size ); - } - EXPECT_NE( "%p", NULL, data ); - - if( s == p / 2 ) { - for( size_t i = 0; i < size * p; ++i ) { - data[ i ] = -1; - } - rc = lpf_register_global( ctx, data, p * size, &data_slot ); - } else { - for( size_t i = 0; i < size; ++i ) { - data[ i ] = s; - } - rc = lpf_register_global( ctx, data, size, &data_slot ); - } - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, (1<<19), &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_gather( coll, data_slot, data_slot, size, p / 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if( s == p / 2 ) { - for( lpf_pid_t source = 0; source < p; ++source ) { - for( size_t i = 0; i < size; ++i ) { - const size_t index = source * size + i; - if( source == s ) { - EXPECT_EQ( "%c", (char) -1, data[ index ] ); - } else { - EXPECT_EQ( "%c", (char) source, data[ index ] ); - } - } - } - } else { - for( size_t i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char) s, data[i] ); - } - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one lpf_coll_t objects, performs a gather, and deletes them. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_gather ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_reduce.c b/tests/functional/c99/func_lpf_reduce.c deleted file mode 100644 index 404e8f8c..00000000 --- a/tests/functional/c99/func_lpf_reduce.c +++ /dev/null @@ -1,100 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - -#include - -void min( const size_t n, const void * const _in, void * const _out ) { - double * const out = (double*) _out; - const double * const array = (const double*) _in; - for( size_t i = 0; i < n; ++i ) { - if( array[ i ] < *out ) { - *out = array[ i ]; - } - } -} - -void spmd( lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, const lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t element_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, p - 1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - double reduced_value = INFINITY; - const size_t byte_size = (1 << 19) / sizeof(double); - const size_t size = byte_size / sizeof(double); - double * data = malloc( byte_size ); - EXPECT_NE( "%p", NULL, data ); - - for( size_t i = 0; i < size; ++i ) { - data[ i ] = s * size + i; - } - - rc = lpf_register_global( ctx, &reduced_value, sizeof(double), &element_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, sizeof(double), 0, &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - min( size, data, &reduced_value ); - const double local_reduce_value = reduced_value; - rc = lpf_reduce( coll, &reduced_value, element_slot, sizeof(double), &min, p / 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if( s == p / 2 ) { - EXPECT_EQ( "%lf", 0.0, reduced_value ); - } else { - EXPECT_EQ( "%lf", local_reduce_value, reduced_value ); - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, element_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t objects, performs a reduce, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_reduce ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/c99/func_lpf_scatter.c b/tests/functional/c99/func_lpf_scatter.c deleted file mode 100644 index ade4fbab..00000000 --- a/tests/functional/c99/func_lpf_scatter.c +++ /dev/null @@ -1,100 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include "Test.h" - - -void spmd( lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args ) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - lpf_memslot_t data_slot; - lpf_coll_t coll; - lpf_err_t rc; - - rc = lpf_resize_message_queue( ctx, p-1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - const size_t size = (1 << 19); - char * data = NULL; - if( s == p / 2 ) { - data = malloc( size * p ); - } else { - data = malloc( size ); - } - EXPECT_NE( "%p", NULL, data ); - - if( s == p / 2 ) { - for( size_t i = 0; i < size * p; ++i ) { - data[ i ] = (char)i; - } - rc = lpf_register_global( ctx, data, p * size, &data_slot ); - } else { - for( size_t i = 0; i < size; ++i ) { - data[ i ] = -1; - } - rc = lpf_register_global( ctx, data, size, &data_slot ); - } - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_collectives_init( ctx, s, p, 1, 0, (1<<19), &coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_scatter( coll, data_slot, data_slot, size, p / 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if( s == p / 2 ) { - for( size_t i = 0; i < size * p; ++i ) { - EXPECT_EQ( "%c", (char)i, data[i] ); - } - } else { - for( size_t i = 0; i < size; ++i ) { - EXPECT_EQ( "%c", (char)(s * size + i), data[i] ); - } - } - - rc = lpf_collectives_destroy( coll ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( ctx, data_slot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - free( data ); -} - -/** - * \test Initialises one \a lpf_coll_t object, performs a scatter, and deletes the \a lpf_coll_t object. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_scatter ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/collectives/CMakeLists.txt b/tests/functional/collectives/CMakeLists.txt new file mode 100644 index 00000000..463b4de5 --- /dev/null +++ b/tests/functional/collectives/CMakeLists.txt @@ -0,0 +1,59 @@ + +# +# Copyright 2021 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +set(c99_tests_sources +func_lpf_allcombine.cpp +func_lpf_allgather.cpp +func_lpf_allgather_overlapped.cpp +func_lpf_allreduce.cpp +func_lpf_alltoall.cpp +func_lpf_broadcast.cpp +func_lpf_broadcast_prime_size_object.cpp +func_lpf_broadcast_small_prime_size_object.cpp +func_lpf_collectives_init.cpp +func_lpf_collectives_init_overflow.cpp +func_lpf_combine.cpp +func_lpf_gather.cpp +func_lpf_reduce.cpp +func_lpf_scatter.cpp +func_lpf_zero_cost.cpp +) + +foreach (LPF_IMPL_ID ${ENGINES}) + set(debug ON) + set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) + + set(mode) + if (debug) + set(mode "_debug") + endif(debug) + + # add all source files except the ones we don't want + foreach(testSource ${c99_tests_sources}) + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${testSource}) + get_filename_component(baseName ${testSource} NAME_WE ) + set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") + + add_gtest(${exeName} ${LPF_IMPL_ID} ${debug} "${CMAKE_CURRENT_SOURCE_DIR}/${testSource}") + + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${testSource}) + get_filename_component(baseName ${testSource} NAME_WE ) + set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") + + endforeach(testSource) +endforeach(LPF_IMPL_ID) diff --git a/tests/functional/collectives/func_lpf_allcombine.cpp b/tests/functional/collectives/func_lpf_allcombine.cpp new file mode 100644 index 00000000..cdc1cfc0 --- /dev/null +++ b/tests/functional/collectives/func_lpf_allcombine.cpp @@ -0,0 +1,91 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void elementwise_add(const size_t n, const void *const _in, void *const _out) { + double *const out = (double *)_out; + const double *const array = (const double *)_in; + for (size_t i = 0; i < n; ++i) { + out[i] += array[i]; + } +} + +void spmd(lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, + const lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const size_t byte_size = (1 << 19) / sizeof(double); + const size_t size = byte_size / sizeof(double); + double *data = new double[size]; + EXPECT_NE(nullptr, data); + + for (size_t i = 0; i < size; ++i) { + data[i] = s; + } + + rc = lpf_register_global(ctx, data, byte_size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, byte_size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_allcombine(coll, data, data_slot, size, sizeof(double), + &elementwise_add); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (size_t i = 0; i < size; ++i) { + const double num = (double)(coll.P) / 2.0; + const double max = (double)(coll.P - 1); + EXPECT_EQ(num * max, data[i]); + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t objects, performs a combine, and deletes + * the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_allcombine) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_allgather.cpp b/tests/functional/collectives/func_lpf_allgather.cpp new file mode 100644 index 00000000..1ce1fe4c --- /dev/null +++ b/tests/functional/collectives/func_lpf_allgather.cpp @@ -0,0 +1,100 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + const size_t size = (1 << 19); + + lpf_memslot_t src_slot, dst_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 3); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char *src = new char[size]; + EXPECT_NE(nullptr, src); + + char *dst = new char[p * size]; + EXPECT_NE(nullptr, dst); + + for (size_t i = 0; i < size; ++i) { + src[i] = (char)s; + } + rc = lpf_register_global(ctx, src, size, &src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (size_t i = 0; i < p * size; ++i) { + dst[i] = -1; + } + rc = lpf_register_global(ctx, dst, p * size, &dst_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, p * size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_allgather(coll, src_slot, dst_slot, size, true); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (size_t i = 0; i < size; ++i) { + EXPECT_EQ((char)s, src[i]); + } + + for (lpf_pid_t k = 0; k < p; ++k) { + for (size_t i = 0; i < size; ++i) { + const size_t index = k * size + i; + if (k == s) { + EXPECT_EQ((char)-1, dst[index]); + } else { + EXPECT_EQ((char)k, dst[index]); + } + } + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, dst_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] src; + delete[] dst; +} + +/** + * \test Initialises one \a lpf_coll_t object, performs an allgather, and + * deletes the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_allgather) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_allgather_overlapped.cpp b/tests/functional/collectives/func_lpf_allgather_overlapped.cpp new file mode 100644 index 00000000..cb89d10a --- /dev/null +++ b/tests/functional/collectives/func_lpf_allgather_overlapped.cpp @@ -0,0 +1,91 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + const size_t size = (1 << 19); + + lpf_memslot_t data_slot, src_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 3); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char *data = new char[p * size]; + EXPECT_NE(nullptr, data); + + for (lpf_pid_t k = 0; k < p; ++k) { + for (size_t i = 0; i < size; ++i) { + if (k == s) { + data[k * size + i] = (char)s; + } else { + data[k * size + i] = -1; + } + } + } + rc = lpf_register_global(ctx, data, p * size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(ctx, data + s * size, size, &src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, p * size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_allgather(coll, src_slot, data_slot, size, true); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (lpf_pid_t k = 0; k < p; ++k) { + for (size_t i = 0; i < size; ++i) { + const size_t index = k * size + i; + EXPECT_EQ((char)k, data[index]); + } + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t object, performs an allgather, and + * deletes the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_allgather_overlapped) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_allreduce.cpp b/tests/functional/collectives/func_lpf_allreduce.cpp new file mode 100644 index 00000000..dca87a6a --- /dev/null +++ b/tests/functional/collectives/func_lpf_allreduce.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void min(const size_t n, const void *const _in, void *const _out) { + double *const out = (double *)_out; + const double *const array = (const double *)_in; + for (size_t i = 0; i < n; ++i) { + if (array[i] < *out) { + *out = array[i]; + } + } +} + +void spmd(lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, + const lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t elem_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p - 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + double reduced_value = INFINITY; + const size_t byte_size = (1 << 19) / sizeof(double); + const size_t size = byte_size / sizeof(double); + double *data = new double[size]; + EXPECT_NE(nullptr, data); + + for (size_t i = 0; i < size; ++i) { + data[i] = s * size + i; + } + + rc = lpf_register_global(ctx, &reduced_value, sizeof(double), &elem_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, sizeof(double), 0, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + min(size, data, &reduced_value); + rc = lpf_allreduce(coll, &reduced_value, elem_slot, sizeof(double), &min); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(0.0, reduced_value); + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, elem_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t objects, performs an allreduce, and + * deletes the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_allreduce) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_alltoall.cpp b/tests/functional/collectives/func_lpf_alltoall.cpp new file mode 100644 index 00000000..90872351 --- /dev/null +++ b/tests/functional/collectives/func_lpf_alltoall.cpp @@ -0,0 +1,99 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + const size_t size = (1 << 19); + + lpf_memslot_t src_slot, dst_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p - 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 3); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char *src = new char[p * size]; + EXPECT_NE(nullptr, src); + + char *dst = new char[p * size]; + EXPECT_NE(nullptr, dst); + + for (size_t i = 0; i < p * size; ++i) { + src[i] = (char)s; + dst[i] = -((char)s); + } + + rc = lpf_register_global(ctx, src, p * size, &src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(ctx, dst, p * size, &dst_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_alltoall(coll, src_slot, dst_slot, size); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (size_t i = 0; i < size; ++i) { + EXPECT_EQ((char)s, src[i]); + } + + for (lpf_pid_t k = 0; k < p; ++k) { + for (size_t i = 0; i < size; ++i) { + const size_t index = k * size + i; + if (k == s) { + EXPECT_EQ((char)(-s), dst[index]); + } else { + EXPECT_EQ((char)k, dst[index]); + } + } + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, src_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, dst_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] src; + delete[] dst; +} + +/** + * \test Initialises one \a lpf_coll_t object, performs an all-to-all, and + * deletes the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_alltoall) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_broadcast.cpp b/tests/functional/collectives/func_lpf_broadcast.cpp new file mode 100644 index 00000000..78ac76c9 --- /dev/null +++ b/tests/functional/collectives/func_lpf_broadcast.cpp @@ -0,0 +1,84 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +long max(long a, long b) { return a < b ? b : a; } + +void spmd(lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, max(p + 1, 2 * ((long)p) - 3)); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const long size = (1 << 19); + char *data = new char[size]; + EXPECT_NE(nullptr, data); + + if (s == p / 2) { + for (long i = 0; i < size; ++i) { + data[i] = -1; + } + } else { + for (long i = 0; i < size; ++i) { + data[i] = +1; + } + } + + rc = lpf_register_global(ctx, data, size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, (1 << 19), &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_broadcast(coll, data_slot, data_slot, size, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (long i = 0; i < size; ++i) { + EXPECT_EQ((char)-1, data[i]); + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t object, performs a broadcast, and deletes + * it. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_broadcast) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_broadcast_prime_size_object.cpp b/tests/functional/collectives/func_lpf_broadcast_prime_size_object.cpp new file mode 100644 index 00000000..03f8e10e --- /dev/null +++ b/tests/functional/collectives/func_lpf_broadcast_prime_size_object.cpp @@ -0,0 +1,85 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +long max(long a, long b) { return a < b ? b : a; } + +void spmd(lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, max(p + 1, 2 * ((long)p) - 3)); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const long size = 197; + char *data = new char[size]; + EXPECT_NE(nullptr, data); + + if (s == p / 2) { + for (long i = 0; i < size; ++i) { + data[i] = -1; + } + } else { + for (long i = 0; i < size; ++i) { + data[i] = +1; + } + } + + rc = lpf_register_global(ctx, data, size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_broadcast(coll, data_slot, data_slot, size, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (long i = 0; i < size; ++i) { + EXPECT_EQ((char)-1, data[i]); + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Broadcasts an object whose size > P is not (easily) divisible by P + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(COLL, func_lpf_broadcast_prime_size_object) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_broadcast_small_prime_size_object.cpp b/tests/functional/collectives/func_lpf_broadcast_small_prime_size_object.cpp new file mode 100644 index 00000000..6a345349 --- /dev/null +++ b/tests/functional/collectives/func_lpf_broadcast_small_prime_size_object.cpp @@ -0,0 +1,85 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +long max(long a, long b) { return a < b ? b : a; } + +void spmd(lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, max(p + 1, 2 * ((long)p) - 3)); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const long size = 11; + char *data = new char[size]; + EXPECT_NE(nullptr, data); + + if (s == p / 2) { + for (long i = 0; i < size; ++i) { + data[i] = -1; + } + } else { + for (long i = 0; i < size; ++i) { + data[i] = +1; + } + } + + rc = lpf_register_global(ctx, data, size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_broadcast(coll, data_slot, data_slot, size, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (long i = 0; i < size; ++i) { + EXPECT_EQ((char)-1, data[i]); + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Broadcasts an object whose size > P is not (easily) divisible by P but + * also small so that in the second phase of 2-phase broadcast have nothing to + * send. \pre P >= 2 \return Exit code: 0 + */ +TEST(COLL, func_lpf_broadcast_small_prime_size_object) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_collectives_init.cpp b/tests/functional/collectives/func_lpf_collectives_init.cpp new file mode 100644 index 00000000..252e895d --- /dev/null +++ b/tests/functional/collectives/func_lpf_collectives_init.cpp @@ -0,0 +1,66 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_coll_t coll1, coll2, coll3, coll4; + lpf_err_t rc; + + rc = lpf_resize_memory_register(ctx, 4); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, 0, &coll1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 8, 0, &coll2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, (1 << 7), 0, (1 << 19), &coll3); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, (1 << 4), 8, (1 << 25), &coll4); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_destroy(coll1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_destroy(coll2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_destroy(coll3); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_destroy(coll4); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Initialises lpf_coll_t objects and deletes them. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(COLL, func_lpf_collectives_init) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_collectives_init_overflow.cpp b/tests/functional/collectives/func_lpf_collectives_init_overflow.cpp new file mode 100644 index 00000000..06617e60 --- /dev/null +++ b/tests/functional/collectives/func_lpf_collectives_init_overflow.cpp @@ -0,0 +1,91 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t ctx, lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_coll_t coll1, coll2, coll3, coll4, coll5; + lpf_err_t rc; + + rc = lpf_resize_memory_register(ctx, 5); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // make sure the base case is OK + rc = lpf_collectives_init(ctx, s, p, (1 << 7), (1 << 7), (1 << 7), &coll1); + EXPECT_EQ(LPF_SUCCESS, rc); + + // now let us create some overflows + const size_t tooBig = (size_t)(-1); + + // overflow in the number of calls: may or may not be encountered by an + // implementation: + const lpf_err_t rc1 = + lpf_collectives_init(ctx, s, p, tooBig, (1 << 7), (1 << 7), &coll2); + bool success = (rc1 == LPF_SUCCESS) || (rc1 == LPF_ERR_OUT_OF_MEMORY); + EXPECT_EQ(true, success); + + // overflow in the element size required for reduction buffers: an + // implementation MUST detect this: + rc = lpf_collectives_init(ctx, s, p, (1 << 7), tooBig, (1 << 7), &coll3); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); + + // overflow in the collective buffer size: may or may not be encountered by an + // implementation: + const lpf_err_t rc2 = + lpf_collectives_init(ctx, s, p, (1 << 7), (1 << 7), tooBig, &coll4); + success = (rc2 == LPF_SUCCESS) || (rc2 == LPF_ERR_OUT_OF_MEMORY); + EXPECT_EQ(true, success); + + // overflow that if not detected would lead to a very small buffer: an + // implementation MUST detect this: + if (p > 1) { + rc = lpf_collectives_init(ctx, s, p, (1 << 7), tooBig / p + 1, (1 << 7), + &coll5); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); + } + + rc = lpf_collectives_destroy(coll1); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (rc1 == LPF_SUCCESS) { + rc = lpf_collectives_destroy(coll2); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + if (rc2 == LPF_SUCCESS) { + rc = lpf_collectives_destroy(coll4); + EXPECT_EQ(LPF_SUCCESS, rc); + } +} + +/** + * \test Checks four ways in which a buffer could overflow; two of them MUST be + * detected-- for the other two ways this test accepts an LPF_ERR_OUT_OF_MEMORY + * and accepts a LPF_SUCCESS. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_collectives_init_overflow) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_combine.cpp b/tests/functional/collectives/func_lpf_combine.cpp new file mode 100644 index 00000000..871f1fad --- /dev/null +++ b/tests/functional/collectives/func_lpf_combine.cpp @@ -0,0 +1,95 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void elementwise_add(const size_t n, const void *const _in, void *const _out) { + double *const out = (double *)_out; + const double *const array = (const double *)_in; + for (size_t i = 0; i < n; ++i) { + out[i] += array[i]; + } +} + +void spmd(lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, + const lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const size_t byte_size = (1 << 19) / sizeof(double); + const size_t size = byte_size / sizeof(double); + double *data = new double[size]; + EXPECT_NE(nullptr, data); + + for (size_t i = 0; i < size; ++i) { + data[i] = s; + } + + rc = lpf_register_global(ctx, data, byte_size, &data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, byte_size, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_combine(coll, data, data_slot, size, sizeof(double), + &elementwise_add, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (s == p / 2) { + for (size_t i = 0; i < size; ++i) { + const double num = (double)(coll.P) / 2.0; + const double max = (double)(coll.P - 1); + EXPECT_EQ(num * max, data[i]); + } + } else { + // standard declares contents of data as undefined + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t objects, performs a combine, and deletes + * the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_combine) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_gather.cpp b/tests/functional/collectives/func_lpf_gather.cpp new file mode 100644 index 00000000..9b95f8f4 --- /dev/null +++ b/tests/functional/collectives/func_lpf_gather.cpp @@ -0,0 +1,100 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, p - 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const size_t size = (1 << 19); + char *data = nullptr; + if (s == p / 2) { + data = new char[size * p]; + } else { + data = new char[size]; + } + EXPECT_NE(nullptr, data); + + if (s == p / 2) { + for (size_t i = 0; i < size * p; ++i) { + data[i] = -1; + } + rc = lpf_register_global(ctx, data, p * size, &data_slot); + } else { + for (size_t i = 0; i < size; ++i) { + data[i] = s; + } + rc = lpf_register_global(ctx, data, size, &data_slot); + } + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, (1 << 19), &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_gather(coll, data_slot, data_slot, size, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (s == p / 2) { + for (lpf_pid_t source = 0; source < p; ++source) { + for (size_t i = 0; i < size; ++i) { + const size_t index = source * size + i; + if (source == s) { + EXPECT_EQ((char)-1, data[index]); + } else { + EXPECT_EQ((char)source, data[index]); + } + } + } + } else { + for (size_t i = 0; i < size; ++i) { + EXPECT_EQ((char)s, data[i]); + } + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one lpf_coll_t objects, performs a gather, and deletes + * them. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_gather) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_reduce.cpp b/tests/functional/collectives/func_lpf_reduce.cpp new file mode 100644 index 00000000..0b1a8b32 --- /dev/null +++ b/tests/functional/collectives/func_lpf_reduce.cpp @@ -0,0 +1,96 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void min(const size_t n, const void *const _in, void *const _out) { + double *const out = (double *)_out; + const double *const array = (const double *)_in; + for (size_t i = 0; i < n; ++i) { + if (array[i] < *out) { + *out = array[i]; + } + } +} + +void spmd(lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, + const lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t element_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, p - 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + double reduced_value = INFINITY; + const size_t byte_size = (1 << 19) / sizeof(double); + const size_t size = byte_size / sizeof(double); + double *data = new double[size]; + EXPECT_NE(nullptr, data); + + for (size_t i = 0; i < size; ++i) { + data[i] = s * size + i; + } + + rc = lpf_register_global(ctx, &reduced_value, sizeof(double), &element_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, sizeof(double), 0, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + min(size, data, &reduced_value); + const double local_reduce_value = reduced_value; + rc = lpf_reduce(coll, &reduced_value, element_slot, sizeof(double), &min, + p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (s == p / 2) { + EXPECT_EQ(0.0, reduced_value); + } else { + EXPECT_EQ(local_reduce_value, reduced_value); + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, element_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t objects, performs a reduce, and deletes + * the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_reduce) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_scatter.cpp b/tests/functional/collectives/func_lpf_scatter.cpp new file mode 100644 index 00000000..aee8dedd --- /dev/null +++ b/tests/functional/collectives/func_lpf_scatter.cpp @@ -0,0 +1,93 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t ctx, const lpf_pid_t s, lpf_pid_t p, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t data_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, p - 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + const size_t size = (1 << 19); + char *data = NULL; + if (s == p / 2) { + data = new char[size * p]; + } else { + data = new char[size]; + } + EXPECT_NE(nullptr, data); + + if (s == p / 2) { + for (size_t i = 0; i < size * p; ++i) { + data[i] = (char)i; + } + rc = lpf_register_global(ctx, data, p * size, &data_slot); + } else { + for (size_t i = 0; i < size; ++i) { + data[i] = -1; + } + rc = lpf_register_global(ctx, data, size, &data_slot); + } + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, 0, (1 << 19), &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_scatter(coll, data_slot, data_slot, size, p / 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (s == p / 2) { + for (size_t i = 0; i < size * p; ++i) { + EXPECT_EQ((char)i, data[i]); + } + } else { + for (size_t i = 0; i < size; ++i) { + EXPECT_EQ((char)(s * size + i), data[i]); + } + } + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, data_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t object, performs a scatter, and deletes + * the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_scatter) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/collectives/func_lpf_zero_cost.cpp b/tests/functional/collectives/func_lpf_zero_cost.cpp new file mode 100644 index 00000000..4cecbd4e --- /dev/null +++ b/tests/functional/collectives/func_lpf_zero_cost.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void min(const size_t n, const void *const _in, void *const _out) { + double *const out = (double *)_out; + const double *const array = (const double *)_in; + for (size_t i = 0; i < n; ++i) { + if (array[i] < *out) { + *out = array[i]; + } + } +} + +void spmd(lpf_t ctx, const lpf_pid_t s, const lpf_pid_t p, + const lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + lpf_memslot_t elem_slot; + lpf_coll_t coll; + lpf_err_t rc; + + rc = lpf_resize_message_queue(ctx, 2 * p - 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + double reduced_value = INFINITY; + const size_t byte_size = (1 << 19) / sizeof(double); + const size_t size = byte_size / sizeof(double); + double *data = new double[size]; + EXPECT_NE(nullptr, data); + + for (size_t i = 0; i < size; ++i) { + data[i] = s * size + i; + } + + rc = lpf_register_global(ctx, &reduced_value, sizeof(double), &elem_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_collectives_init(ctx, s, p, 1, sizeof(double), 0, &coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + min(size, data, &reduced_value); + rc = lpf_allreduce(coll, &reduced_value, elem_slot, sizeof(double), &min); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(0.0, reduced_value); + + rc = lpf_collectives_destroy(coll); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(ctx, elem_slot); + EXPECT_EQ(LPF_SUCCESS, rc); + + delete[] data; +} + +/** + * \test Initialises one \a lpf_coll_t objects, performs an allreduce, and + * deletes the \a lpf_coll_t object. \pre P >= 1 \return Exit code: 0 + */ +TEST(COLL, func_lpf_zero_cost_sync) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/CMakeLists.txt b/tests/functional/debug/CMakeLists.txt index e9b8e5c7..0292d488 100644 --- a/tests/functional/debug/CMakeLists.txt +++ b/tests/functional/debug/CMakeLists.txt @@ -14,35 +14,86 @@ # See the License for the specific language governing permissions and # limitations under the License. # +set(debug_test_sources + func_lpf_debug_deregister_non_existing_slot.cpp + func_lpf_debug_exec_null_f_symbols.cpp + func_lpf_debug_exec_null_input.cpp + func_lpf_debug_exec_null_output.cpp + func_lpf_debug_exec_null_spmd.cpp + func_lpf_debug_get_local_src_slot.cpp + func_lpf_debug_get_overflow_dst_offset.cpp + func_lpf_debug_get_overflow_src_offset.cpp + func_lpf_debug_get_read_past_source_memory_global_known_at_sync.cpp + func_lpf_debug_get_read_past_source_memory_global_known_before_sync.cpp + func_lpf_debug_get_too_many_requests.cpp + func_lpf_debug_get_too_many_requests_remote.cpp + func_lpf_debug_get_too_many_requests_self.cpp + func_lpf_debug_get_unknown_dest_slot.cpp + func_lpf_debug_get_unknown_source_pid.cpp + func_lpf_debug_get_unknown_source_slot.cpp + func_lpf_debug_get_write_past_dest_memory_global.cpp + func_lpf_debug_get_write_past_dest_memory_local.cpp + func_lpf_debug_global_deregister_mismatch.cpp + func_lpf_debug_global_deregister_order_mismatch.cpp + func_lpf_debug_global_deregister_unequal.cpp + func_lpf_debug_global_register_null_memreg.cpp + #func_lpf_debug_hook_null_f_symbols.pthread.cpp + #func_lpf_debug_hook_null_input.pthread.cpp + #func_lpf_debug_hook_null_output.pthread.cpp + #func_lpf_debug_hook_null_spmd.pthread.cpp + func_lpf_debug_local_register_null_memreg.cpp + func_lpf_debug_put_after_deregister_dest_after_sync.cpp + func_lpf_debug_put_after_deregister_dest.cpp + func_lpf_debug_put_after_deregister_source_after_sync.cpp + func_lpf_debug_put_after_deregister_source.cpp + func_lpf_debug_put_get_too_many_requests.cpp + func_lpf_debug_put_get_too_many_requests_remote.cpp + func_lpf_debug_put_local_dest_slot.cpp + func_lpf_debug_put_overflow_dst_offset.cpp + func_lpf_debug_put_overflow_src_offset.cpp + func_lpf_debug_put_read_past_source_memory_global.cpp + func_lpf_debug_put_read_past_source_memory_local.cpp + func_lpf_debug_put_read_write_conflict_among_many.cpp + func_lpf_debug_put_read_write_conflict.cpp + func_lpf_debug_put_too_many_requests.cpp + func_lpf_debug_put_too_many_requests_remote.cpp + func_lpf_debug_put_too_many_requests_self.cpp + func_lpf_debug_put_unknown_dest_pid.cpp + func_lpf_debug_put_unknown_dest_slot.cpp + func_lpf_debug_put_unknown_source_slot.cpp + func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.cpp + func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.cpp + func_lpf_debug_register_global_dst_unsynced.cpp + func_lpf_debug_register_global_src_unsynced.cpp + func_lpf_debug_register_global_unequal.cpp + func_lpf_debug_rehook_null_f_symbols.cpp + func_lpf_debug_rehook_null_input.cpp + func_lpf_debug_rehook_null_output.cpp + func_lpf_debug_rehook_null_spmd.cpp + func_lpf_debug_resize_memory_register_with_size_max_minus_three.cpp + ) -# All test sources have file names as bla.c -file(GLOB AllTestSources "*.c" ) -# All test sources which are specific to some engine are of the form -# bla.pthread.c -file(GLOB AllSpecificTestSources "*.*.c") -# All generic test sources don't have the two dots in their name -file(GLOB AllGenericTestSources "*.c") -list(REMOVE_ITEM AllGenericTestSources ${AllSpecificTestSources}) -foreach(LPF_IMPL_ID ${ENGINES}) - set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) +set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) +set(debug ON) +set(LPF_IMPL_CONFIG ${LPFLIB_CONFIG_NAME}) +set(mode) +if (debug) + set(mode "_debug") +endif(debug) +foreach (LPF_IMPL_ID ${ENGINES}) + foreach(testSource ${debug_test_sources}) - file(GLOB ThisEngineSources "*.${LPF_IMPL_ID}.c") - - # add all source files except the ones we don't want - foreach(testSource ${AllGenericTestSources} ${ThisEngineSources}) - string(REGEX REPLACE ".c$" "" baseName ${testSource}) + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${testSource}) get_filename_component(baseName ${testSource} NAME_WE ) - set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}") - set(corelib "lpf_core_univ_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}") - set(debuglib "lpf_debug") + set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") + + add_gtest(${exeName} ${LPF_IMPL_ID} ${debug} "${CMAKE_CURRENT_SOURCE_DIR}/${testSource}" ) - add_executable(${exeName} ${testSource}) - target_include_directories( ${exeName} BEFORE PRIVATE ../../../include/debug ) - target_link_libraries(${exeName} ${debuglib}) - target_link_exe_with_core(${exeName} ${LPF_IMPL_ID}) - target_compile_flags(${exeName} PRIVATE "-DLPF_CORE_IMPL_ID=${LPF_IMPL_ID}" ) - endforeach() + string(REGEX REPLACE "(.${LPF_IMPL_ID})?.cpp$" "" baseName ${CMAKE_CURRENT_SOURCE_DIR}/${testSource}) + get_filename_component(baseName ${testSource} NAME_WE ) + set(exeName "${baseName}_${LPF_IMPL_ID}_${LPF_IMPL_CONFIG}${mode}") + endforeach(testSource) endforeach(LPF_IMPL_ID) diff --git a/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.c b/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.c deleted file mode 100644 index 7bf36563..00000000 --- a/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.c +++ /dev/null @@ -1,43 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - lpf_memslot_t slot; - memset( &slot, 1, sizeof(slot)); // init to some weird data - - lpf_deregister( lpf, slot ); -} - -/** - * \test Deregister a non-registered slot - * \pre P >= 1 - * \return Message: Invalid attempt to deregister a memory slot, because it has not been registered before - * \return Exit code: 6 - */ -TEST( func_lpf_debug_deregister_non_existing_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.cpp b/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.cpp new file mode 100644 index 00000000..9bc7939e --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_deregister_non_existing_slot.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 3, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + FAIL(); + // the write error will be detected at this sync + // rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); +} + +/** + * \test Testing for a lpf_get() that reads past globally registered memory + * bounds \pre P >= 2 \return Message: source memory .* is read past the end by + * 3 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_deregister_non_existing_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_exec_null_f_symbols.c b/tests/functional/debug/func_lpf_debug_exec_null_f_symbols.cpp similarity index 63% rename from tests/functional/debug/func_lpf_debug_exec_null_f_symbols.c rename to tests/functional/debug/func_lpf_debug_exec_null_f_symbols.cpp index ac7d0ac7..8b272a2c 100644 --- a/tests/functional/debug/func_lpf_debug_exec_null_f_symbols.c +++ b/tests/functional/debug/func_lpf_debug_exec_null_f_symbols.cpp @@ -15,32 +15,30 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) -{ - (void) a; (void) b; (void) c; (void) d; +void spmd(lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) { + (void)a; + (void)b; + (void)c; + (void)d; } -/** +/** * \test Test lpf_exec error of using NULL output with nonzero size * \pre P >= 1 * \return Message: NULL f_symbols argument while f_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_exec_null_f_symbols ) -{ - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 0; - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 4; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_exec_null_f_symbols) { + lpf_args_t args; + args.input = NULL; + args.input_size = 0; + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 4; + EXPECT_EQ(lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args), LPF_SUCCESS); } diff --git a/tests/functional/debug/func_lpf_debug_exec_null_input.c b/tests/functional/debug/func_lpf_debug_exec_null_input.cpp similarity index 63% rename from tests/functional/debug/func_lpf_debug_exec_null_input.c rename to tests/functional/debug/func_lpf_debug_exec_null_input.cpp index fdc246f3..d91cc085 100644 --- a/tests/functional/debug/func_lpf_debug_exec_null_input.c +++ b/tests/functional/debug/func_lpf_debug_exec_null_input.cpp @@ -15,33 +15,32 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) -{ - (void) a; (void) b; (void) c; (void) d; +void spmd(lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) { + (void)a; + (void)b; + (void)c; + (void)d; } - -/** +/** * \test Test lpf_exec error of using NULL input with nonzero size * \pre P >= 1 * \return Message: NULL input argument while input_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_exec_null_input ) -{ - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 2; - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_exec_null_input) { + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = NULL; + args.input_size = 2; + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + EXPECT_EQ(lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args), rc); + FAIL(); } diff --git a/tests/functional/debug/func_lpf_debug_exec_null_output.c b/tests/functional/debug/func_lpf_debug_exec_null_output.cpp similarity index 63% rename from tests/functional/debug/func_lpf_debug_exec_null_output.c rename to tests/functional/debug/func_lpf_debug_exec_null_output.cpp index cdd09557..1a62020f 100644 --- a/tests/functional/debug/func_lpf_debug_exec_null_output.c +++ b/tests/functional/debug/func_lpf_debug_exec_null_output.cpp @@ -15,33 +15,32 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) -{ - (void) a; (void) b; (void) c; (void) d; +void spmd(lpf_t a, lpf_pid_t b, lpf_pid_t c, lpf_args_t d) { + (void)a; + (void)b; + (void)c; + (void)d; } - -/** +/** * \test Test lpf_exec error of using NULL output with nonzero size * \pre P >= 1 * \return Message: NULL output argument while output_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_exec_null_output ) -{ - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 0; - args.output = NULL; - args.output_size = 10; - args.f_symbols = NULL; - args.f_size = 0; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_exec_null_output) { + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = NULL; + args.input_size = 0; + args.output = NULL; + args.output_size = 10; + args.f_symbols = NULL; + args.f_size = 0; + EXPECT_EQ(lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args), rc); + FAIL(); } diff --git a/tests/functional/debug/func_lpf_debug_exec_null_spmd.c b/tests/functional/debug/func_lpf_debug_exec_null_spmd.cpp similarity index 79% rename from tests/functional/debug/func_lpf_debug_exec_null_spmd.c rename to tests/functional/debug/func_lpf_debug_exec_null_spmd.cpp index a58a868b..bf908478 100644 --- a/tests/functional/debug/func_lpf_debug_exec_null_spmd.c +++ b/tests/functional/debug/func_lpf_debug_exec_null_spmd.cpp @@ -15,21 +15,18 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" - -/** +/** * \test Test lpf_exec error of starting a NULL spmd * \pre P >= 1 * \return Message: NULL spmd argument * \return Exit code: 6 */ -TEST( func_lpf_debug_exec_null_spmd ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, NULL, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_exec_null_spmd) { + lpf_err_t rc = LPF_SUCCESS; + EXPECT_EQ(lpf_exec(LPF_ROOT, LPF_MAX_P, NULL, LPF_NO_ARGS), rc); + FAIL(); } diff --git a/tests/functional/debug/func_lpf_debug_get_local_src_slot.c b/tests/functional/debug/func_lpf_debug_get_local_src_slot.c deleted file mode 100644 index 391e84db..00000000 --- a/tests/functional/debug/func_lpf_debug_get_local_src_slot.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_get with a local source slot - * \pre P >= 1 - * \return Message: source memory must be globally registered. Instead, it was registered only locally - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_local_src_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_local_src_slot.cpp b/tests/functional/debug/func_lpf_debug_get_local_src_slot.cpp new file mode 100644 index 00000000..fa8d4147 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_local_src_slot.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT), + rc); + FAIL(); +} + +/** + * \test Testing a lpf_get with a local source slot + * \pre P >= 1 + * \return Message: source memory must be globally registered. Instead, it was + * registered only locally \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_local_src_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.c b/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.c deleted file mode 100644 index ff397d6e..00000000 --- a/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 2, -1, LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Destination offset + size in lpf_get overflows - * \pre P >= 1 - * \return Message: numerical overflow while computing dst_offset - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_overflow_dst_offset ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.cpp b/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.cpp new file mode 100644 index 00000000..4e2facd5 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_overflow_dst_offset.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = + lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 2, -1, LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Destination offset + size in lpf_get overflows + * \pre P >= 1 + * \return Message: numerical overflow while computing dst_offset + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_overflow_dst_offset) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.c b/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.c deleted file mode 100644 index 01e66483..00000000 --- a/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 2, ySlot, 0, -1, LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Source offset + size in lpf_get overflows - * \pre P >= 1 - * \return Message: numerical overflow while computing src_offset - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_overflow_src_offset ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.cpp b/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.cpp new file mode 100644 index 00000000..4c8cd3a5 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_overflow_src_offset.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = + lpf_get(lpf, (pid + 1) % nprocs, xSlot, 2, ySlot, 0, -1, LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Source offset + size in lpf_get overflows + * \pre P >= 1 + * \return Message: numerical overflow while computing src_offset + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_overflow_src_offset) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.c b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.c deleted file mode 100644 index 5336977b..00000000 --- a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.c +++ /dev/null @@ -1,69 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 3, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - // the write error will be detected at this sync - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_get() that reads past globally registered memory bounds - * \pre P >= 2 - * \return Message: source memory .* is read past the end by 3 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_read_past_source_memory_global_known_at_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.cpp b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.cpp new file mode 100644 index 00000000..98062ea1 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_at_sync.cpp @@ -0,0 +1,67 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 3, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // the write error will be detected at this sync + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(3, y); +} + +/** + * \test Testing for a lpf_get() that reads past globally registered memory + * bounds \pre P >= 2 \return Message: source memory .* is read past the end by + * 3 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_read_past_source_memory_global_known_at_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.c b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.c deleted file mode 100644 index 11244431..00000000 --- a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 1, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_get() that reads past globally registered memory bounds - * \pre P >= 1 - * \return Message: source memory .* is read past the end by 1 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_read_past_source_memory_global_known_before_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.cpp b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.cpp new file mode 100644 index 00000000..a4ee21f0 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_read_past_source_memory_global_known_before_sync.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_get(lpf, (pid + 1) % nprocs, xSlot, 1, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a lpf_get() that reads past globally registered memory + * bounds \pre P >= 1 \return Message: source memory .* is read past the end by + * 1 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_read_past_source_memory_global_known_before_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests.c b/tests/functional/debug/func_lpf_debug_get_too_many_requests.c deleted file mode 100644 index 740fbf41..00000000 --- a/tests/functional/debug/func_lpf_debug_get_too_many_requests.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+2)%nprocs, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that issues more lpf_get requests than allocated with lpf_resize_message_queue() - * \pre P >= 1 - * \return Message: This is the 2-th message, while space for only 1 has been reserved - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_too_many_requests ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests.cpp b/tests/functional/debug/func_lpf_debug_get_too_many_requests.cpp new file mode 100644 index 00000000..a8da6a9a --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_too_many_requests.cpp @@ -0,0 +1,71 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 2) % nprocs, xSlot, sizeof(int), ySlot, sizeof(int), + sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(3, y[0]); + EXPECT_EQ(4, y[1]); + // FAIL(); +} + +/** + * \test Testing for a process that issues more lpf_get requests than allocated + * with lpf_resize_message_queue() \pre P >= 1 \return Message: This is the 2-th + * message, while space for only 1 has been reserved \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_too_many_requests) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.c b/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.c deleted file mode 100644 index 4adf89b0..00000000 --- a/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.c +++ /dev/null @@ -1,77 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - if (pid % 2 == 0 && pid != 0) { - rc = lpf_get( lpf, 0, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - if (pid % 2 == 1) { - rc = lpf_get( lpf, 0, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that issues more lpf_get requests than the source can handle - * \pre P >= 3 - * \return Message: Too many messages on pid 0. Reserved was 1 while there were actually - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_too_many_requests_remote ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.cpp b/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.cpp new file mode 100644 index 00000000..957e63fa --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_too_many_requests_remote.cpp @@ -0,0 +1,75 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid % 2 == 0 && pid != 0) { + rc = lpf_get(lpf, 0, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + if (pid % 2 == 1) { + rc = lpf_get(lpf, 0, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(3, y[0]); + EXPECT_EQ(4, y[1]); +} + +/** + * \test Testing for a process that issues more lpf_get requests than the source + * can handle \pre P >= 3 \return Message: Too many messages on pid 0. Reserved + * was 1 while there were actually \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_too_many_requests_remote) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.c b/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.c deleted file mode 100644 index 29718213..00000000 --- a/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, 0, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a lpf_get to itself, for which it needs an allocation of 2 - * \pre P >= 1 - * \pre P <= 1 - * \return Message: Too many messages on pid 0. Reserved was 1 while there were actually 2 in total - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_too_many_requests_self ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.cpp b/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.cpp new file mode 100644 index 00000000..8ce81efa --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_too_many_requests_self.cpp @@ -0,0 +1,67 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, 0, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a lpf_get to itself, for which it needs an allocation of 2 + * \pre P >= 1 + * \pre P <= 1 + * \return Message: Too many messages on pid 0. Reserved was 1 while there were + * actually 2 in total \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_too_many_requests_self) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.c b/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.c deleted file mode 100644 index 3e0af8ed..00000000 --- a/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = xSlot + 2; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_get with an unknown destination memory slot - * \pre P >= 1 - * \return Message: destination memory slot does not exist - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_unknown_dest_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.cpp b/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.cpp new file mode 100644 index 00000000..23dbda08 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_unknown_dest_slot.cpp @@ -0,0 +1,59 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + (void)y; // this test purposefully tests for the (erroneous) not-use of y + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = xSlot + 2; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing a lpf_get with an unknown destination memory slot + * \pre P >= 1 + * \return Message: destination memory slot does not exist + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_unknown_dest_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.c b/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.c deleted file mode 100644 index f143ec2a..00000000 --- a/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, 6 , xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_get() from another process that does not exist - * \pre P >= 1 - * \pre P <= 5 - * \return Message: unknown process ID 6 for data source - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_unknown_source_pid ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.cpp b/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.cpp new file mode 100644 index 00000000..31faec2c --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_unknown_source_pid.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, 6, xSlot, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_get() from another process that + * does not exist \pre P >= 1 \pre P <= 5 \return Message: unknown process ID 6 + * for data source \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_unknown_source_pid) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.c b/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.c deleted file mode 100644 index 92753779..00000000 --- a/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = xSlot + 2; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, ySlot, 0, xSlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_get with an unknown source memory slot - * \pre P >= 1 - * \return Message: source memory slot does not exist - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_unknown_source_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.cpp b/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.cpp new file mode 100644 index 00000000..e61252b5 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_unknown_source_slot.cpp @@ -0,0 +1,59 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + (void)y; // this test purposefully tests for the (erroneous) not-use of y + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = xSlot + 2; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, ySlot, 0, xSlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing a lpf_get with an unknown source memory slot + * \pre P >= 1 + * \return Message: source memory slot does not exist + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_unknown_source_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.c b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.c deleted file mode 100644 index f7491522..00000000 --- a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 1, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_get() that writes past globally registered memory bounds - * \pre P >= 1 - * \return Message: destination memory .* is written past the end by 1 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_write_past_dest_memory_global ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.cpp b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.cpp new file mode 100644 index 00000000..8512d77c --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_global.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 1, sizeof(x), + LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a lpf_get() that writes past globally registered memory + * bounds \pre P >= 1 \return Message: destination memory .* is written past the + * end by 1 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_write_past_dest_memory_global) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.c b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.c deleted file mode 100644 index b5bab7c5..00000000 --- a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 2, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_get() that writes past locally registered memory bounds - * \pre P >= 1 - * \return Message: destination memory .* is written past the end by 2 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_get_write_past_dest_memory_local ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.cpp b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.cpp new file mode 100644 index 00000000..cc9edcd2 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_get_write_past_dest_memory_local.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 2, sizeof(x), + LPF_MSG_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a lpf_get() that writes past locally registered memory + * bounds \pre P >= 1 \return Message: destination memory .* is written past the + * end by 2 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_get_write_past_dest_memory_local) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.c b/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.c deleted file mode 100644 index 29b2836b..00000000 --- a/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.c +++ /dev/null @@ -1,67 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, pid == 0 ? xSlot : ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); -} - -/** - * \test A program with a lpf_deregister that does not match the same slot - * \pre P >= 2 - * \return Message: global deregistration mismatches - * \return Exit code: 6 - */ -TEST( func_lpf_debug_global_deregister_mismatch ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.cpp b/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.cpp new file mode 100644 index 00000000..d7aaec85 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_global_deregister_mismatch.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, pid == 0 ? xSlot : ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test A program with a lpf_deregister that does not match the same slot + * \pre P >= 2 + * \return Message: global deregistration mismatches + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_global_deregister_mismatch) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.c b/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.c deleted file mode 100644 index 90e12664..00000000 --- a/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.c +++ /dev/null @@ -1,70 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, pid == 0 ? xSlot : ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, pid == 0 ? ySlot : xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); -} - -/** - * \test A program that issues lpf_deregister() not in the same order - * \pre P >= 2 - * \return Message: global deregistration mismatches - * \return Exit code: 6 - */ -TEST( func_lpf_debug_global_deregister_order_mismatch ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.cpp b/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.cpp new file mode 100644 index 00000000..65a0c359 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_global_deregister_order_mismatch.cpp @@ -0,0 +1,66 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, pid == 0 ? xSlot : ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, pid == 0 ? ySlot : xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test A program that issues lpf_deregister() not in the same order + * \pre P >= 2 + * \return Message: global deregistration mismatches + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_global_deregister_order_mismatch) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_unequal.c b/tests/functional/debug/func_lpf_debug_global_deregister_unequal.c deleted file mode 100644 index 9ae4ea00..00000000 --- a/tests/functional/debug/func_lpf_debug_global_deregister_unequal.c +++ /dev/null @@ -1,69 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - if (pid == 0) { - rc = lpf_deregister( lpf, xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); -} - -/** - * \test A program with a lpf_deregister of a global slot that is not executed on all pids - * \pre P >= 2 - * \return Message: Number of deregistrations of global slots does not match. - * \return Exit code: 6 - */ -TEST( func_lpf_debug_deregister_global_unequal ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_global_deregister_unequal.cpp b/tests/functional/debug/func_lpf_debug_global_deregister_unequal.cpp new file mode 100644 index 00000000..c334008e --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_global_deregister_unequal.cpp @@ -0,0 +1,66 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid == 0) { + rc = lpf_deregister(lpf, xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test A program with a lpf_deregister of a global slot that is not executed + * on all pids \pre P >= 2 \return Message: Number of deregistrations of global + * slots does not match. \return Exit code: 6 + */ +TEST(API, func_lpf_debug_deregister_global_unequal) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_global_register_null_memreg.c b/tests/functional/debug/func_lpf_debug_global_register_null_memreg.cpp similarity index 59% rename from tests/functional/debug/func_lpf_debug_global_register_null_memreg.c rename to tests/functional/debug/func_lpf_debug_global_register_null_memreg.cpp index 25f4641a..50368c12 100644 --- a/tests/functional/debug/func_lpf_debug_global_register_null_memreg.c +++ b/tests/functional/debug/func_lpf_debug_global_register_null_memreg.cpp @@ -15,28 +15,29 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x = 0; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_register_global( lpf, &x, sizeof(x), &xSlot ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x = 0; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_register_global(lpf, &x, sizeof(x), &xSlot); + FAIL(); } -/** +/** * \test Register a memory region globally without allocating space * \pre P >= 1 - * \return Message: Invalid global memory registration, which would have taken the 1-th slot, while only space for 0 slots has been reserved - * \return Exit code: 6 + * \return Message: Invalid global memory registration, which would have taken + * the 1-th slot, while only space for 0 slots has been reserved \return Exit + * code: 6 */ -TEST( func_lpf_debug_global_register_null_memreg ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_global_register_null_memreg) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.c b/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.c deleted file mode 100644 index ecaad199..00000000 --- a/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -pthread_key_t pid_key; - -struct thread_local_data { - long P, s; -}; - -void lpf_spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ (void) ctx; (void) pid; (void) nprocs; (void) args; } - -void * pthread_spmd( void * _data ) { - EXPECT_NE( "%p", _data, NULL ); - - const struct thread_local_data data = * ((struct thread_local_data*) _data); - const int pts_rc = pthread_setspecific( pid_key, _data ); - lpf_args_t args; - args.input = _data; - args.input_size = sizeof(data); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 5; - lpf_init_t init; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ( "%d", pts_rc, 0 ); - - rc = lpf_pthread_initialize( - (lpf_pid_t)data.s, - (lpf_pid_t)data.P, - &init - ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, &lpf_spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_pthread_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - return NULL; -} - -/** - * \test Tests lpf_hook on pthread implementation with NULL f_symbols - * \pre P <= 1 - * \pre P >= 1 - * \return Message: NULL f_symbols argument while f_size is non-zero - * \return Exit code: 6 - */ -TEST( func_lpf_hook_null_f_symbols ) -{ - long k = 0; - const long P = sysconf( _SC_NPROCESSORS_ONLN ); - - const int ptc_rc = pthread_key_create( &pid_key, NULL ); - EXPECT_EQ( "%d", ptc_rc, 0 ); - - pthread_t * const threads = (pthread_t*) malloc( P * sizeof(pthread_t) ); - EXPECT_NE( "%p", threads, NULL ); - - struct thread_local_data * const data = (struct thread_local_data*) malloc( P * sizeof(struct thread_local_data) ); - EXPECT_NE( "%p", data, NULL ); - - for( k = 0; k < P; ++k ) { - data[ k ].P = P; - data[ k ].s = k; - const int rval = pthread_create( threads + k, NULL, &pthread_spmd, data + k ); - EXPECT_EQ( "%d", rval, 0 ); - } - - for( k = 0; k < P; ++k ) { - const int rval = pthread_join( threads[ k ], NULL ); - EXPECT_EQ( "%d", rval, 0 ); - } - - const int ptd_rc = pthread_key_delete( pid_key ); - EXPECT_EQ( "%d", ptd_rc, 0 ); - - return 0; -} - - diff --git a/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.cpp b/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.cpp new file mode 100644 index 00000000..c0d66c5c --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_hook_null_f_symbols.pthread.cpp @@ -0,0 +1,97 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include +#include + +pthread_key_t pid_key; + +struct thread_local_data { + long P, s; +}; + +void lpf_spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)ctx; + (void)pid; + (void)nprocs; + (void)args; +} + +void *pthread_spmd(void *_data) { + EXPECT_NE(_data, nullptr); + + const struct thread_local_data data = *((struct thread_local_data *)_data); + const int pts_rc = pthread_setspecific(pid_key, _data); + lpf_args_t args; + args.input = _data; + args.input_size = sizeof(data); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 5; + lpf_init_t init; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ(pts_rc, 0); + + rc = lpf_pthread_initialize((lpf_pid_t)data.s, (lpf_pid_t)data.P, &init); + EXPECT_EQ(rc, LPF_SUCCESS); + FAIL(); + + return NULL; +} + +/** + * \test Tests lpf_hook on pthread implementation with NULL f_symbols + * \pre P <= 1 + * \pre P >= 1 + * \return Message: NULL f_symbols argument while f_size is non-zero + * \return Exit code: 6 + */ +TEST(API, func_lpf_hook_null_f_symbols) { + long k = 0; + const long P = sysconf(_SC_NPROCESSORS_ONLN); + + const int ptc_rc = pthread_key_create(&pid_key, NULL); + EXPECT_EQ(ptc_rc, 0); + + pthread_t *const threads = (pthread_t *)malloc(P * sizeof(pthread_t)); + EXPECT_NE(threads, nullptr); + + struct thread_local_data *const data = + (struct thread_local_data *)malloc(P * sizeof(struct thread_local_data)); + EXPECT_NE(data, nullptr); + + for (k = 0; k < P; ++k) { + data[k].P = P; + data[k].s = k; + const int rval = pthread_create(threads + k, NULL, &pthread_spmd, data + k); + EXPECT_EQ(rval, 0); + } + + for (k = 0; k < P; ++k) { + const int rval = pthread_join(threads[k], NULL); + EXPECT_EQ(rval, 0); + } + + const int ptd_rc = pthread_key_delete(pid_key); + EXPECT_EQ(ptd_rc, 0); +} diff --git a/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.c b/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.c deleted file mode 100644 index 04c7c355..00000000 --- a/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -pthread_key_t pid_key; - -struct thread_local_data { - long P, s; -}; - -void lpf_spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ (void) ctx; (void) pid; (void) nprocs; (void) args; } - -void * pthread_spmd( void * _data ) { - EXPECT_NE( "%p", _data, NULL ); - - const struct thread_local_data data = * ((struct thread_local_data*) _data); - const int pts_rc = pthread_setspecific( pid_key, _data ); - lpf_args_t args; - args.input = NULL; - args.input_size = sizeof(data); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - lpf_init_t init; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ( "%d", pts_rc, 0 ); - - rc = lpf_pthread_initialize( - (lpf_pid_t)data.s, - (lpf_pid_t)data.P, - &init - ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, &lpf_spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_pthread_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - return NULL; -} - -/** - * \test Tests lpf_hook on pthread implementation with NULL input - * \pre P <= 1 - * \pre P >= 1 - * \return Message: NULL input argument while input_size is non-zero - * \return Exit code: 6 - */ -TEST( func_lpf_hook_null_input ) -{ - long k = 0; - const long P = sysconf( _SC_NPROCESSORS_ONLN ); - - const int ptc_rc = pthread_key_create( &pid_key, NULL ); - EXPECT_EQ( "%d", ptc_rc, 0 ); - - pthread_t * const threads = (pthread_t*) malloc( P * sizeof(pthread_t) ); - EXPECT_NE( "%p", threads, NULL ); - - struct thread_local_data * const data = (struct thread_local_data*) malloc( P * sizeof(struct thread_local_data) ); - EXPECT_NE( "%p", data, NULL ); - - for( k = 0; k < P; ++k ) { - data[ k ].P = P; - data[ k ].s = k; - const int rval = pthread_create( threads + k, NULL, &pthread_spmd, data + k ); - EXPECT_EQ( "%d", rval, 0 ); - } - - for( k = 0; k < P; ++k ) { - const int rval = pthread_join( threads[ k ], NULL ); - EXPECT_EQ( "%d", rval, 0 ); - } - - const int ptd_rc = pthread_key_delete( pid_key ); - EXPECT_EQ( "%d", ptd_rc, 0 ); - - return 0; -} - - diff --git a/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.cpp b/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.cpp new file mode 100644 index 00000000..f83017be --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_hook_null_input.pthread.cpp @@ -0,0 +1,104 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +pthread_key_t pid_key; + +struct thread_local_data { + long P, s; +}; + +void lpf_spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)ctx; + (void)pid; + (void)nprocs; + (void)args; +} + +void *pthread_spmd(void *_data) { + EXPECT_NE("%p", _data, NULL); + + const struct thread_local_data data = *((struct thread_local_data *)_data); + const int pts_rc = pthread_setspecific(pid_key, _data); + lpf_args_t args; + args.input = NULL; + args.input_size = sizeof(data); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + lpf_init_t init; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ("%d", pts_rc, 0); + + rc = lpf_pthread_initialize((lpf_pid_t)data.s, (lpf_pid_t)data.P, &init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_hook(init, &lpf_spmd, args); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_pthread_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + return NULL; +} + +/** + * \test Tests lpf_hook on pthread implementation with NULL input + * \pre P <= 1 + * \pre P >= 1 + * \return Message: NULL input argument while input_size is non-zero + * \return Exit code: 6 + */ +TEST(func_lpf_hook_null_input) { + long k = 0; + const long P = sysconf(_SC_NPROCESSORS_ONLN); + + const int ptc_rc = pthread_key_create(&pid_key, NULL); + EXPECT_EQ("%d", ptc_rc, 0); + + pthread_t *const threads = (pthread_t *)malloc(P * sizeof(pthread_t)); + EXPECT_NE("%p", threads, NULL); + + struct thread_local_data *const data = + (struct thread_local_data *)malloc(P * sizeof(struct thread_local_data)); + EXPECT_NE("%p", data, NULL); + + for (k = 0; k < P; ++k) { + data[k].P = P; + data[k].s = k; + const int rval = pthread_create(threads + k, NULL, &pthread_spmd, data + k); + EXPECT_EQ("%d", rval, 0); + } + + for (k = 0; k < P; ++k) { + const int rval = pthread_join(threads[k], NULL); + EXPECT_EQ("%d", rval, 0); + } + + const int ptd_rc = pthread_key_delete(pid_key); + EXPECT_EQ("%d", ptd_rc, 0); + + return 0; +} diff --git a/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.c b/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.c deleted file mode 100644 index 02268258..00000000 --- a/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -pthread_key_t pid_key; - -struct thread_local_data { - long P, s; -}; - -void lpf_spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ (void) ctx; (void) pid; (void) nprocs; (void) args; } - -void * pthread_spmd( void * _data ) { - EXPECT_NE( "%p", _data, NULL ); - - const struct thread_local_data data = * ((struct thread_local_data*) _data); - const int pts_rc = pthread_setspecific( pid_key, _data ); - lpf_args_t args; - args.input = _data; - args.input_size = sizeof(data); - args.output = NULL; - args.output_size = 2; - args.f_symbols = NULL; - args.f_size = 0; - lpf_init_t init; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ( "%d", pts_rc, 0 ); - - rc = lpf_pthread_initialize( - (lpf_pid_t)data.s, - (lpf_pid_t)data.P, - &init - ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, &lpf_spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_pthread_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - return NULL; -} - -/** - * \test Tests lpf_hook on pthread implementation with NULL output - * \pre P <= 1 - * \pre P >= 1 - * \return Message: NULL output argument while output_size is non-zero - * \return Exit code: 6 - */ -TEST( func_lpf_hook_null_output ) -{ - long k = 0; - const long P = sysconf( _SC_NPROCESSORS_ONLN ); - - const int ptc_rc = pthread_key_create( &pid_key, NULL ); - EXPECT_EQ( "%d", ptc_rc, 0 ); - - pthread_t * const threads = (pthread_t*) malloc( P * sizeof(pthread_t) ); - EXPECT_NE( "%p", threads, NULL ); - - struct thread_local_data * const data = (struct thread_local_data*) malloc( P * sizeof(struct thread_local_data) ); - EXPECT_NE( "%p", data, NULL ); - - for( k = 0; k < P; ++k ) { - data[ k ].P = P; - data[ k ].s = k; - const int rval = pthread_create( threads + k, NULL, &pthread_spmd, data + k ); - EXPECT_EQ( "%d", rval, 0 ); - } - - for( k = 0; k < P; ++k ) { - const int rval = pthread_join( threads[ k ], NULL ); - EXPECT_EQ( "%d", rval, 0 ); - } - - const int ptd_rc = pthread_key_delete( pid_key ); - EXPECT_EQ( "%d", ptd_rc, 0 ); - - return 0; -} - - diff --git a/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.cpp b/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.cpp new file mode 100644 index 00000000..4ed31b70 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_hook_null_output.pthread.cpp @@ -0,0 +1,104 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +pthread_key_t pid_key; + +struct thread_local_data { + long P, s; +}; + +void lpf_spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)ctx; + (void)pid; + (void)nprocs; + (void)args; +} + +void *pthread_spmd(void *_data) { + EXPECT_NE("%p", _data, NULL); + + const struct thread_local_data data = *((struct thread_local_data *)_data); + const int pts_rc = pthread_setspecific(pid_key, _data); + lpf_args_t args; + args.input = _data; + args.input_size = sizeof(data); + args.output = NULL; + args.output_size = 2; + args.f_symbols = NULL; + args.f_size = 0; + lpf_init_t init; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ("%d", pts_rc, 0); + + rc = lpf_pthread_initialize((lpf_pid_t)data.s, (lpf_pid_t)data.P, &init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_hook(init, &lpf_spmd, args); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_pthread_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + return NULL; +} + +/** + * \test Tests lpf_hook on pthread implementation with NULL output + * \pre P <= 1 + * \pre P >= 1 + * \return Message: NULL output argument while output_size is non-zero + * \return Exit code: 6 + */ +TEST(func_lpf_hook_null_output) { + long k = 0; + const long P = sysconf(_SC_NPROCESSORS_ONLN); + + const int ptc_rc = pthread_key_create(&pid_key, NULL); + EXPECT_EQ("%d", ptc_rc, 0); + + pthread_t *const threads = (pthread_t *)malloc(P * sizeof(pthread_t)); + EXPECT_NE("%p", threads, NULL); + + struct thread_local_data *const data = + (struct thread_local_data *)malloc(P * sizeof(struct thread_local_data)); + EXPECT_NE("%p", data, NULL); + + for (k = 0; k < P; ++k) { + data[k].P = P; + data[k].s = k; + const int rval = pthread_create(threads + k, NULL, &pthread_spmd, data + k); + EXPECT_EQ("%d", rval, 0); + } + + for (k = 0; k < P; ++k) { + const int rval = pthread_join(threads[k], NULL); + EXPECT_EQ("%d", rval, 0); + } + + const int ptd_rc = pthread_key_delete(pid_key); + EXPECT_EQ("%d", ptd_rc, 0); + + return 0; +} diff --git a/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.c b/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.c deleted file mode 100644 index 20209c16..00000000 --- a/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.c +++ /dev/null @@ -1,104 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -pthread_key_t pid_key; - -struct thread_local_data { - long P, s; -}; - - -void * pthread_spmd( void * _data ) { - EXPECT_NE( "%p", _data, NULL ); - - const struct thread_local_data data = * ((struct thread_local_data*) _data); - const int pts_rc = pthread_setspecific( pid_key, _data ); - lpf_args_t args; - args.input = _data; - args.input_size = sizeof(data); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - lpf_init_t init; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ( "%d", pts_rc, 0 ); - - rc = lpf_pthread_initialize( - (lpf_pid_t)data.s, - (lpf_pid_t)data.P, - &init - ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, NULL, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_pthread_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - return NULL; -} - -/** - * \test Tests lpf_hook on pthread implementation with NULL spmd - * \pre P <= 1 - * \pre P >= 1 - * \return Message: NULL spmd argument - * \return Exit code: 6 - */ -TEST( func_lpf_hook_null_spmd ) -{ - long k = 0; - const long P = sysconf( _SC_NPROCESSORS_ONLN ); - - const int ptc_rc = pthread_key_create( &pid_key, NULL ); - EXPECT_EQ( "%d", ptc_rc, 0 ); - - pthread_t * const threads = (pthread_t*) malloc( P * sizeof(pthread_t) ); - EXPECT_NE( "%p", threads, NULL ); - - struct thread_local_data * const data = (struct thread_local_data*) malloc( P * sizeof(struct thread_local_data) ); - EXPECT_NE( "%p", data, NULL ); - - for( k = 0; k < P; ++k ) { - data[ k ].P = P; - data[ k ].s = k; - const int rval = pthread_create( threads + k, NULL, &pthread_spmd, data + k ); - EXPECT_EQ( "%d", rval, 0 ); - } - - for( k = 0; k < P; ++k ) { - const int rval = pthread_join( threads[ k ], NULL ); - EXPECT_EQ( "%d", rval, 0 ); - } - - const int ptd_rc = pthread_key_delete( pid_key ); - EXPECT_EQ( "%d", ptd_rc, 0 ); - - return 0; -} - - diff --git a/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.cpp b/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.cpp new file mode 100644 index 00000000..1aac8b49 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_hook_null_spmd.pthread.cpp @@ -0,0 +1,97 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +pthread_key_t pid_key; + +struct thread_local_data { + long P, s; +}; + +void *pthread_spmd(void *_data) { + EXPECT_NE("%p", _data, NULL); + + const struct thread_local_data data = *((struct thread_local_data *)_data); + const int pts_rc = pthread_setspecific(pid_key, _data); + lpf_args_t args; + args.input = _data; + args.input_size = sizeof(data); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + lpf_init_t init; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ("%d", pts_rc, 0); + + rc = lpf_pthread_initialize((lpf_pid_t)data.s, (lpf_pid_t)data.P, &init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_hook(init, NULL, args); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_pthread_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + return NULL; +} + +/** + * \test Tests lpf_hook on pthread implementation with NULL spmd + * \pre P <= 1 + * \pre P >= 1 + * \return Message: NULL spmd argument + * \return Exit code: 6 + */ +TEST(func_lpf_hook_null_spmd) { + long k = 0; + const long P = sysconf(_SC_NPROCESSORS_ONLN); + + const int ptc_rc = pthread_key_create(&pid_key, NULL); + EXPECT_EQ("%d", ptc_rc, 0); + + pthread_t *const threads = (pthread_t *)malloc(P * sizeof(pthread_t)); + EXPECT_NE("%p", threads, NULL); + + struct thread_local_data *const data = + (struct thread_local_data *)malloc(P * sizeof(struct thread_local_data)); + EXPECT_NE("%p", data, NULL); + + for (k = 0; k < P; ++k) { + data[k].P = P; + data[k].s = k; + const int rval = pthread_create(threads + k, NULL, &pthread_spmd, data + k); + EXPECT_EQ("%d", rval, 0); + } + + for (k = 0; k < P; ++k) { + const int rval = pthread_join(threads[k], NULL); + EXPECT_EQ("%d", rval, 0); + } + + const int ptd_rc = pthread_key_delete(pid_key); + EXPECT_EQ("%d", ptd_rc, 0); + + return 0; +} diff --git a/tests/functional/debug/func_lpf_debug_local_register_null_memreg.c b/tests/functional/debug/func_lpf_debug_local_register_null_memreg.cpp similarity index 59% rename from tests/functional/debug/func_lpf_debug_local_register_null_memreg.c rename to tests/functional/debug/func_lpf_debug_local_register_null_memreg.cpp index b4fd8ea1..9776ffa9 100644 --- a/tests/functional/debug/func_lpf_debug_local_register_null_memreg.c +++ b/tests/functional/debug/func_lpf_debug_local_register_null_memreg.cpp @@ -15,28 +15,27 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x = 0; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_register_local( lpf, &x, sizeof(x), &xSlot ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x = 0; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_register_local(lpf, &x, sizeof(x), &xSlot); } -/** +/** * \test Register a memory region locally without allocating space * \pre P >= 1 - * \return Message: Invalid local memory registration, which would have taken the 1-th slot, while only space for 0 slots has been reserved - * \return Exit code: 6 + * \return Message: Invalid local memory registration, which would have taken + * the 1-th slot, while only space for 0 slots has been reserved \return Exit + * code: 6 */ -TEST( func_lpf_debug_local_register_null_memreg ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_local_register_null_memreg) { + lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + FAIL(); } diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.c b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.c deleted file mode 100644 index 8862f3ef..00000000 --- a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put on a slot after it has been deregistered - * \pre P >= 1 - * \return Message: Invalid attempt to deregister a memory slot, because it is in use - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_after_deregister_dest ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.cpp b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.cpp new file mode 100644 index 00000000..df0820ff --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_put on a slot after it has been + * deregistered \pre P >= 1 \return Message: Invalid attempt to deregister a + * memory slot, because it is in use \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_after_deregister_dest) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.c b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.c deleted file mode 100644 index 1374428d..00000000 --- a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put on a slot after it has been deregistered - * \pre P >= 1 - * \return Message: Invalid attempt to deregister a memory slot, because it is in use - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_after_deregister_dest_after_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.cpp b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.cpp new file mode 100644 index 00000000..e36a36ab --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_after_deregister_dest_after_sync.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_put on a slot after it has been + * deregistered \pre P >= 1 \return Message: Invalid attempt to deregister a + * memory slot, because it is in use \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_after_deregister_dest_after_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_source.c b/tests/functional/debug/func_lpf_debug_put_after_deregister_source.c deleted file mode 100644 index b6283b00..00000000 --- a/tests/functional/debug/func_lpf_debug_put_after_deregister_source.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put on a slot after it has been deregistered - * \pre P >= 1 - * \return Message: Invalid attempt to deregister a memory slot, because it is in use - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_after_deregister_source ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_source.cpp b/tests/functional/debug/func_lpf_debug_put_after_deregister_source.cpp new file mode 100644 index 00000000..6a767a78 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_after_deregister_source.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_put on a slot after it has been + * deregistered \pre P >= 1 \return Message: Invalid attempt to deregister a + * memory slot, because it is in use \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_after_deregister_source) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.c b/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.c deleted file mode 100644 index bbfd5abc..00000000 --- a/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put on a slot after it has been deregistered - * \pre P >= 1 - * \return Message: Invalid attempt to deregister a memory slot, because it is in use - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_after_deregister_source_after_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.cpp b/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.cpp new file mode 100644 index 00000000..5b9ede07 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_after_deregister_source_after_sync.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_put on a slot after it has been + * deregistered \pre P >= 1 \return Message: Invalid attempt to deregister a + * memory slot, because it is in use \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_after_deregister_source_after_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.c b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.c deleted file mode 100644 index cba34714..00000000 --- a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+2)%nprocs, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put and a lpf_get while only space for 1 request has been allocated - * \pre P >= 1 - * \return Message: This is the 2-th message, while space for only 1 has been reserved - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_get_too_many_requests ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.cpp b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.cpp new file mode 100644 index 00000000..a59093cd --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests.cpp @@ -0,0 +1,69 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 2) % nprocs, xSlot, sizeof(int), ySlot, sizeof(int), + sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a process that does a lpf_put and a lpf_get while only + * space for 1 request has been allocated \pre P >= 1 \return Message: This is + * the 2-th message, while space for only 1 has been reserved \return Exit code: + * 6 + */ +TEST(API, func_lpf_debug_put_get_too_many_requests) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.c b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.c deleted file mode 100644 index b8c78d74..00000000 --- a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.c +++ /dev/null @@ -1,77 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - if (pid % 2 == 0) { - rc = lpf_put( lpf, xSlot, 0, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - if (pid % 2 == 1 ) { - rc = lpf_get( lpf, 0, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a program with a lpf_put and a lpf_get to a remote process which can only handle 2 requests - * \pre P >= 3 - * \return Message: Too many messages on pid 0. Reserved was 2 while there were actually - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_get_too_many_requests_remote ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.cpp b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.cpp new file mode 100644 index 00000000..6d964141 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_get_too_many_requests_remote.cpp @@ -0,0 +1,72 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid % 2 == 0) { + rc = lpf_put(lpf, xSlot, 0, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + if (pid % 2 == 1) { + rc = lpf_get(lpf, 0, xSlot, sizeof(int), ySlot, sizeof(int), sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a program with a lpf_put and a lpf_get to a remote process + * which can only handle 2 requests \pre P >= 3 \return Message: Too many + * messages on pid 0. Reserved was 2 while there were actually \return Exit + * code: 6 + */ +TEST(API, func_lpf_debug_put_get_too_many_requests_remote) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_local_dest_slot.c b/tests/functional/debug/func_lpf_debug_put_local_dest_slot.c deleted file mode 100644 index 4bca087f..00000000 --- a/tests/functional/debug/func_lpf_debug_put_local_dest_slot.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_put with a local destination slot - * \pre P >= 1 - * \return Message: destination memory must be globally registered. Instead, it was only locally registered - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_local_dest_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_local_dest_slot.cpp b/tests/functional/debug/func_lpf_debug_put_local_dest_slot.cpp new file mode 100644 index 00000000..a3f2e154 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_local_dest_slot.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing a lpf_put with a local destination slot + * \pre P >= 1 + * \return Message: destination memory must be globally registered. Instead, it + * was only locally registered \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_local_dest_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.c b/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.c deleted file mode 100644 index 210e8828..00000000 --- a/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 2, -1, LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Destination offset + size in lpf_put overflows - * \pre P >= 1 - * \return Message: numerical overflow while computing dst_offset - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_overflow_dst_offset ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.cpp b/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.cpp new file mode 100644 index 00000000..0c2fc19f --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_overflow_dst_offset.cpp @@ -0,0 +1,64 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = + lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 2, -1, LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Destination offset + size in lpf_put overflows + * \pre P >= 1 + * \return Message: numerical overflow while computing dst_offset + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_overflow_dst_offset) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.c b/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.c deleted file mode 100644 index 58c92f55..00000000 --- a/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 2, (pid+1)%nprocs, ySlot, 0, -1, LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Source offset + size in lpf_put overflows - * \pre P >= 1 - * \return Message: numerical overflow while computing src_offset - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_overflow_src_offset ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.cpp b/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.cpp new file mode 100644 index 00000000..a693290f --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_overflow_src_offset.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = + lpf_put(lpf, xSlot, 2, (pid + 1) % nprocs, ySlot, 0, -1, LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Source offset + size in lpf_put overflows + * \pre P >= 1 + * \return Message: numerical overflow while computing src_offset + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_overflow_src_offset) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.c b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.c deleted file mode 100644 index ecb33959..00000000 --- a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 1, (pid+1)%nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_put() that reads past globally registered memory bounds - * \pre P >= 1 - * \return Message: source memory .* is read past the end by 1 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_read_past_source_memory_global ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.cpp b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.cpp new file mode 100644 index 00000000..85c4b367 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_global.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 1, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a lpf_put() that reads past globally registered memory + * bounds \pre P >= 1 \return Message: source memory .* is read past the end by + * 1 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_read_past_source_memory_global) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.c b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.c deleted file mode 100644 index beba4d76..00000000 --- a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 2, (pid+1)%nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_put() that reads past locally registered memory bounds - * \pre P >= 1 - * \return Message: source memory .* is read past the end by 2 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_read_past_source_memory_local ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.cpp b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.cpp new file mode 100644 index 00000000..8bd1a861 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_read_past_source_memory_local.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 2, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a lpf_put() that reads past locally registered memory + * bounds \pre P >= 1 \return Message: source memory .* is read past the end by + * 2 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_read_past_source_memory_local) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_read_write_conflict.c b/tests/functional/debug/func_lpf_debug_put_read_write_conflict.c deleted file mode 100644 index bbd979fa..00000000 --- a/tests/functional/debug/func_lpf_debug_put_read_write_conflict.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, pid%2?&y:&x, sizeof(x), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - // ySlot and xSlot are aliases of 'x' - // The following put will have a read-write conflict - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); -} - -/** - * \test Testing a read-write conflict between two lpf_puts - * \pre P >= 2 - * \return Message: Read-write conflict detected - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_read_write_conflict ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_read_write_conflict.cpp b/tests/functional/debug/func_lpf_debug_put_read_write_conflict.cpp new file mode 100644 index 00000000..89218a20 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_read_write_conflict.cpp @@ -0,0 +1,67 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, pid % 2 ? &y : &x, sizeof(x), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // ySlot and xSlot are aliases of 'x' + // The following put will have a read-write conflict + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing a read-write conflict between two lpf_puts + * \pre P >= 2 + * \return Message: Read-write conflict detected + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_read_write_conflict) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.c b/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.c deleted file mode 100644 index 6430757d..00000000 --- a/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - const int N = 10; - int * xs = calloc( N, sizeof(int)); - int * ys = calloc( N, sizeof(int)); - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, N+2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, xs, sizeof(int)*N, &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, ys, sizeof(int)*N, &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - int i; - for ( i = 0; i < N/2; ++i) { - rc = lpf_put( lpf, xSlot, sizeof(int)*2*i, - (pid+1)%nprocs, ySlot, sizeof(int)*i, - sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - // this causes a read-write conflict on elements xs[1] and xs[2] - rc = lpf_get( lpf, (pid+nprocs-1)%nprocs, ySlot, sizeof(int)*(N-3), - xSlot, sizeof(int)+2, sizeof(int)*3, LPF_MSG_DEFAULT ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - free(xs); - free(ys); -} - -/** - * \test Testing a read-write conflict between among many reads - * \pre P >= 2 - * \return Message: Read-write conflict detected - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_read_write_conflict_among_many ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.cpp b/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.cpp new file mode 100644 index 00000000..85a66758 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_read_write_conflict_among_many.cpp @@ -0,0 +1,73 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + const int N = 10; + int *xs = new int[N]; + int *ys = new int[N]; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, N + 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, xs, sizeof(int) * N, &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, ys, sizeof(int) * N, &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + int i; + for (i = 0; i < N / 2; ++i) { + rc = lpf_put(lpf, xSlot, sizeof(int) * 2 * i, (pid + 1) % nprocs, ySlot, + sizeof(int) * i, sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + // this causes a read-write conflict on elements xs[1] and xs[2] + rc = lpf_get(lpf, (pid + nprocs - 1) % nprocs, ySlot, sizeof(int) * (N - 3), + xSlot, sizeof(int) + 2, sizeof(int) * 3, LPF_MSG_DEFAULT); + + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing a read-write conflict between among many reads + * \pre P >= 2 + * \return Message: Read-write conflict detected + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_read_write_conflict_among_many) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests.c b/tests/functional/debug/func_lpf_debug_put_too_many_requests.c deleted file mode 100644 index aaa5cda4..00000000 --- a/tests/functional/debug/func_lpf_debug_put_too_many_requests.c +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, sizeof(int), (pid+2)%nprocs, ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that sends more requests than allocated with lpf_resize_message_queue() - * \pre P >= 1 - * \return Message: This is the 2-th message, while space for only 1 has been reserved - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_too_many_requests ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests.cpp b/tests/functional/debug/func_lpf_debug_put_too_many_requests.cpp new file mode 100644 index 00000000..b63ac1eb --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_too_many_requests.cpp @@ -0,0 +1,66 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, sizeof(int), (pid + 2) % nprocs, ySlot, sizeof(int), + sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a process that sends more requests than allocated with + * lpf_resize_message_queue() \pre P >= 1 \return Message: This is the 2-th + * message, while space for only 1 has been reserved \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_too_many_requests) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.c b/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.c deleted file mode 100644 index ade556d0..00000000 --- a/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.c +++ /dev/null @@ -1,77 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - if (pid % 2 == 0 ) { - rc = lpf_put( lpf, xSlot, 0, (pid+1) % 2, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - if (pid % 2 == 1) { - rc = lpf_put( lpf, xSlot, sizeof(int), pid % 2, ySlot, sizeof(int), sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a destination process receives too many lpf_put() requests - * \pre P >= 2 - * \return Message: Too many messages on pid 1. Reserved was 1 while there were actually - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_too_many_requests_remote ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.cpp b/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.cpp new file mode 100644 index 00000000..ca2e1e8f --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_too_many_requests_remote.cpp @@ -0,0 +1,73 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid % 2 == 0) { + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % 2, ySlot, 0, sizeof(int), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + if (pid % 2 == 1) { + rc = lpf_put(lpf, xSlot, sizeof(int), pid % 2, ySlot, sizeof(int), + sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a destination process receives too many lpf_put() requests + * \pre P >= 2 + * \return Message: Too many messages on pid 1. Reserved was 1 while there were + * actually \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_too_many_requests_remote) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.c b/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.c deleted file mode 100644 index 3e6690e1..00000000 --- a/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a lpf_put to itself, for which it needs an allocation of 2 - * \pre P >= 1 - * \pre P <= 1 - * \return Message: Too many messages on pid 0. Reserved was 1 while there were actually 2 in total - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_too_many_requests_self ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.cpp b/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.cpp new file mode 100644 index 00000000..25534522 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_too_many_requests_self.cpp @@ -0,0 +1,67 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, 0, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); +} + +/** + * \test Testing for a lpf_put to itself, for which it needs an allocation of 2 + * \pre P >= 1 + * \pre P <= 1 + * \return Message: Too many messages on pid 0. Reserved was 1 while there were + * actually 2 in total \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_too_many_requests_self) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.c b/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.c deleted file mode 100644 index 56142f4f..00000000 --- a/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, 6, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y[0] ); - EXPECT_EQ("%d", 4, y[1] ); -} - -/** - * \test Testing for a process that does a lpf_put() to another process that does not exist - * \pre P >= 1 - * \pre P <= 5 - * \return Message: unknown process ID 6 for data destination - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_unknown_dest_pid ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.cpp b/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.cpp new file mode 100644 index 00000000..d6d17138 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_unknown_dest_pid.cpp @@ -0,0 +1,69 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, 6, ySlot, 0, sizeof(int), LPF_MSG_DEFAULT); + FAIL(); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + FAIL(); + + EXPECT_EQ(3, y[0]); + EXPECT_EQ(4, y[1]); +} + +/** + * \test Testing for a process that does a lpf_put() to another process that + * does not exist \pre P >= 1 \pre P <= 5 \return Message: unknown process ID 6 + * for data destination \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_unknown_dest_pid) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.c b/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.c deleted file mode 100644 index 153f1177..00000000 --- a/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = xSlot + 2; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_put with an unknown destination memory slot - * \pre P >= 1 - * \return Message: destination memory slot does not exist - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_unknown_dest_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.cpp b/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.cpp new file mode 100644 index 00000000..c02a4946 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_unknown_dest_slot.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + (void)y; // this field is (erroneously) not used, and the test checks for + // finding precisely that error + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = xSlot + 2; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing a lpf_put with an unknown destination memory slot + * \pre P >= 1 + * \return Message: destination memory slot does not exist + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_unknown_dest_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.c b/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.c deleted file mode 100644 index 9b274863..00000000 --- a/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = xSlot + 2; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, ySlot, 0, (pid+1)%nprocs, xSlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_put with an unknown source memory slot - * \pre P >= 1 - * \return Message: source memory slot does not exist - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_unknown_source_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.cpp b/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.cpp new file mode 100644 index 00000000..b63fd75f --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_unknown_source_slot.cpp @@ -0,0 +1,63 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = xSlot + 2; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, ySlot, 0, (pid + 1) % nprocs, xSlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(3, y); +} + +/** + * \test Testing a lpf_put with an unknown source memory slot + * \pre P >= 1 + * \return Message: source memory slot does not exist + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_unknown_source_slot) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.c b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.c deleted file mode 100644 index 38771cbb..00000000 --- a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.c +++ /dev/null @@ -1,69 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 3, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - // the write error will be detected at this sync - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_put() that writes past globally registered memory bounds - * \pre P >= 1 - * \return Message: destination memory .* is written past the end by 3 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_write_past_dest_memory_global_known_at_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.cpp b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.cpp new file mode 100644 index 00000000..0596657a --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_at_sync.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 3, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a lpf_put() that writes past globally registered memory + * bounds \pre P >= 1 \return Message: destination memory .* is written past the + * end by 3 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_write_past_dest_memory_global_known_at_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.c b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.c deleted file mode 100644 index e98cb529..00000000 --- a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3; int y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, xSlot, 0, (pid+1)%nprocs, ySlot, 1, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing for a lpf_put() that writes past globally registered memory bounds - * \pre P >= 1 - * \return Message: destination memory .* is written past the end by 1 bytes - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_write_past_dest_memory_global_known_before_sync ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.cpp b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.cpp new file mode 100644 index 00000000..1f12bca0 --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_put_write_past_dest_memory_global_known_before_sync.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3; + int y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, xSlot, 0, (pid + 1) % nprocs, ySlot, 1, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing for a lpf_put() that writes past globally registered memory + * bounds \pre P >= 1 \return Message: destination memory .* is written past the + * end by 1 bytes \return Exit code: 6 + */ +TEST(API, func_lpf_debug_put_write_past_dest_memory_global_known_before_sync) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.c b/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.c deleted file mode 100644 index 8a4ec260..00000000 --- a/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &y, sizeof(x), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, ySlot, 0, (pid+1)%nprocs, xSlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_put with an inactive destination memory slot - * \pre P >= 1 - * \return Message: destination memory slot was not yet active - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_unknown_source_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.cpp b/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.cpp new file mode 100644 index 00000000..37d24d6d --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_register_global_dst_unsynced.cpp @@ -0,0 +1,59 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &y, sizeof(x), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, ySlot, 0, (pid + 1) % nprocs, xSlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing a lpf_put with an inactive destination memory slot + * \pre P >= 1 + * \return Message: destination memory slot was not yet active + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_register_global_dst_unsynced) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.c b/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.c deleted file mode 100644 index 79ddcdff..00000000 --- a/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.c +++ /dev/null @@ -1,65 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - int x = 3, y = 6; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( lpf, &y, sizeof(x), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_get( lpf, (pid+1)%nprocs, xSlot, 0, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - EXPECT_EQ("%d", 3, y ); -} - -/** - * \test Testing a lpf_put with an inactive source memory slot - * \pre P >= 1 - * \return Message: source memory slot was not yet active - * \return Exit code: 6 - */ -TEST( func_lpf_debug_put_unknown_source_slot ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.cpp b/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.cpp new file mode 100644 index 00000000..09fccdbd --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_register_global_src_unsynced.cpp @@ -0,0 +1,59 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + int x = 3, y = 6; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(lpf, &y, sizeof(x), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xSlot, 0, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + FAIL(); +} + +/** + * \test Testing a lpf_put with an inactive source memory slot + * \pre P >= 1 + * \return Message: source memory slot was not yet active + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_register_global_src_unsynced) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_register_global_unequal.c b/tests/functional/debug/func_lpf_debug_register_global_unequal.c deleted file mode 100644 index 4efeadef..00000000 --- a/tests/functional/debug/func_lpf_debug_register_global_unequal.c +++ /dev/null @@ -1,63 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) nprocs; (void) args; - int x[2] = {3, 4}; - int y[2] = {6, 7}; - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - lpf_err_t rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, 1 ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &x, sizeof(x), &xSlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - - if (pid != 0) { - rc = lpf_register_global( lpf, &y, sizeof(y), &ySlot ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); -} - -/** - * \test A program with a lpf_register_global that is not executed on all pids - * \pre P >= 2 - * \return Message: Number of global registrations does not match. - * \return Exit code: 6 - */ -TEST( func_lpf_debug_register_global_unequal ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/debug/func_lpf_debug_register_global_unequal.cpp b/tests/functional/debug/func_lpf_debug_register_global_unequal.cpp new file mode 100644 index 00000000..7ed52d9c --- /dev/null +++ b/tests/functional/debug/func_lpf_debug_register_global_unequal.cpp @@ -0,0 +1,61 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)nprocs; + (void)args; + int x[2] = {3, 4}; + int y[2] = {6, 7}; + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + lpf_err_t rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &x, sizeof(x), &xSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid != 0) { + rc = lpf_register_global(lpf, &y, sizeof(y), &ySlot); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test A program with a lpf_register_global that is not executed on all pids + * \pre P >= 2 + * \return Message: Number of global registrations does not match. + * \return Exit code: 6 + */ +TEST(API, func_lpf_debug_register_global_unequal) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.c b/tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.cpp similarity index 58% rename from tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.c rename to tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.cpp index 8ee0e0cb..3a1bcc6b 100644 --- a/tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.c +++ b/tests/functional/debug/func_lpf_debug_rehook_null_f_symbols.cpp @@ -15,35 +15,34 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) -{ - (void) pid; (void) nprocs; (void) a; - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 0; - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 2; - rc = lpf_rehook( lpf, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) { + (void)pid; + (void)nprocs; + (void)a; + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = NULL; + args.input_size = 0; + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 2; + rc = lpf_rehook(lpf, &spmd, args); + EXPECT_EQ(LPF_SUCCESS, rc); } -/** +/** * \test Test lpf_rehook error of using NULL f_symbols with nonzero size * \pre P >= 1 * \return Message: NULL f_symbols argument while f_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_rehook_null_f_symbols ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_rehook_null_f_symbols) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/debug/func_lpf_debug_rehook_null_input.c b/tests/functional/debug/func_lpf_debug_rehook_null_input.cpp similarity index 58% rename from tests/functional/debug/func_lpf_debug_rehook_null_input.c rename to tests/functional/debug/func_lpf_debug_rehook_null_input.cpp index ad265bdd..a50cde6a 100644 --- a/tests/functional/debug/func_lpf_debug_rehook_null_input.c +++ b/tests/functional/debug/func_lpf_debug_rehook_null_input.cpp @@ -15,35 +15,34 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) -{ - (void) pid; (void) nprocs; (void) a; - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 2; - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - rc = lpf_rehook( lpf, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) { + (void)pid; + (void)nprocs; + (void)a; + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = NULL; + args.input_size = 2; + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + rc = lpf_rehook(lpf, &spmd, args); + EXPECT_EQ(LPF_SUCCESS, rc); } -/** +/** * \test Test lpf_rehook error of using NULL input with nonzero size * \pre P >= 1 * \return Message: NULL input argument while input_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_rehook_null_input ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_rehook_null_input) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/debug/func_lpf_debug_rehook_null_output.c b/tests/functional/debug/func_lpf_debug_rehook_null_output.cpp similarity index 58% rename from tests/functional/debug/func_lpf_debug_rehook_null_output.c rename to tests/functional/debug/func_lpf_debug_rehook_null_output.cpp index f809c4d6..e4e9b0c8 100644 --- a/tests/functional/debug/func_lpf_debug_rehook_null_output.c +++ b/tests/functional/debug/func_lpf_debug_rehook_null_output.cpp @@ -15,35 +15,34 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) -{ - (void) pid; (void) nprocs; (void) a; - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = NULL; - args.input_size = 0; - args.output = NULL; - args.output_size = 3; - args.f_symbols = NULL; - args.f_size = 0; - rc = lpf_rehook( lpf, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) { + (void)pid; + (void)nprocs; + (void)a; + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = NULL; + args.input_size = 0; + args.output = NULL; + args.output_size = 3; + args.f_symbols = NULL; + args.f_size = 0; + rc = lpf_rehook(lpf, &spmd, args); + EXPECT_EQ(LPF_SUCCESS, rc); } -/** +/** * \test Test lpf_rehook error of using NULL output with nonzero size * \pre P >= 1 * \return Message: NULL output argument while output_size is non-zero * \return Exit code: 6 */ -TEST( func_lpf_debug_rehook_null_output ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_rehook_null_output) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/debug/func_lpf_debug_rehook_null_spmd.c b/tests/functional/debug/func_lpf_debug_rehook_null_spmd.cpp similarity index 60% rename from tests/functional/debug/func_lpf_debug_rehook_null_spmd.c rename to tests/functional/debug/func_lpf_debug_rehook_null_spmd.cpp index eafc39b7..e9f7f7de 100644 --- a/tests/functional/debug/func_lpf_debug_rehook_null_spmd.c +++ b/tests/functional/debug/func_lpf_debug_rehook_null_spmd.cpp @@ -15,28 +15,27 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) -{ - (void) pid; (void) nprocs; (void) a; - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_rehook( lpf, NULL, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t a) { + (void)pid; + (void)nprocs; + (void)a; + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_rehook(lpf, NULL, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } -/** - * \test Test rehook error of using NULL spmd +/** + * \test Test rehook error of using NULL spmd * \pre P >= 1 * \return Message: NULL spmd argument * \return Exit code: 6 */ -TEST( func_lpf_debug_rehook_null_spmd ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_rehook_null_spmd) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.c b/tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.cpp similarity index 55% rename from tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.c rename to tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.cpp index 05c21b8f..61a0c13f 100644 --- a/tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.c +++ b/tests/functional/debug/func_lpf_debug_resize_memory_register_with_size_max_minus_three.cpp @@ -15,27 +15,25 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) pid; (void) nprocs; (void) args; - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_resize_memory_register( lpf, ((size_t) -1) - 3 ); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY , rc ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)pid; + (void)nprocs; + (void)args; + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_resize_memory_register(lpf, ((size_t)-1) - 3); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); } -/** - * \test Resize the memory register to SIZE_MAX - 3, in order to test integer overflow detection - * \pre P >= 1 - * \return Exit code: 0 +/** + * \test Resize the memory register to SIZE_MAX - 3, in order to test integer + * overflow detection \pre P >= 1 \return Exit code: 0 */ -TEST( func_lpf_debug_resize_memory_register_with_size_max_minus_three ) -{ - lpf_err_t rc = LPF_SUCCESS; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_debug_resize_memory_register_with_size_max_minus_three) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/func_bsplib_example_lpf_sum.c b/tests/functional/func_bsplib_example_lpf_sum.c deleted file mode 100644 index 68677450..00000000 --- a/tests/functional/func_bsplib_example_lpf_sum.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i, j; - int n = 5; - int result = 0, p = bsplib_nprocs(bsplib); - int local_sums[p]; - int xs[n]; - memset( local_sums, 0, sizeof( local_sums ) ); - - for ( j = 0; j < n; ++j ) - xs[j] = j + bsplib_pid(bsplib); - - // All-set. Now compute the sum - - for ( j = 0; j < n; ++j ) - result += xs[j]; - - rc = bsplib_push_reg(bsplib, &result, sizeof( result ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < p; ++i ) { - rc = bsplib_hpget(bsplib, i, &result, 0, &local_sums[i], sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - result = 0; - for ( i = 0; i < p; ++i ) - result += local_sums[i]; - rc = bsplib_pop_reg(bsplib, &result ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", - p * ( n - 1 ) * n / 2 + n * ( p - 1 ) * p / 2, - result ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests an example from Hill's BSPlib paper - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_example_bsp_sum) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_lpf_sum.cpp b/tests/functional/func_bsplib_example_lpf_sum.cpp new file mode 100644 index 00000000..b0a75578 --- /dev/null +++ b/tests/functional/func_bsplib_example_lpf_sum.cpp @@ -0,0 +1,79 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i, j; + int n = 5; + int result = 0, p = bsplib_nprocs(bsplib); + int local_sums[p]; + int xs[n]; + memset(local_sums, 0, sizeof(local_sums)); + + for (j = 0; j < n; ++j) + xs[j] = j + bsplib_pid(bsplib); + + // All-set. Now compute the sum + + for (j = 0; j < n; ++j) + result += xs[j]; + + rc = bsplib_push_reg(bsplib, &result, sizeof(result)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < p; ++i) { + rc = bsplib_hpget(bsplib, i, &result, 0, &local_sums[i], sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + result = 0; + for (i = 0; i < p; ++i) + result += local_sums[i]; + rc = bsplib_pop_reg(bsplib, &result); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(p * (n - 1) * n / 2 + n * (p - 1) * p / 2, result); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests an example from Hill's BSPlib paper + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_example_bsp_sum) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_example_lpf_sum_unsafemode.c b/tests/functional/func_bsplib_example_lpf_sum_unsafemode.c deleted file mode 100644 index e81c1576..00000000 --- a/tests/functional/func_bsplib_example_lpf_sum_unsafemode.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 2, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i, j; - int n = 5; - int result = 0, p = bsplib_nprocs(bsplib); - int local_sums[p]; - int xs[n]; - memset( local_sums, 0, sizeof( local_sums ) ); - - for ( j = 0; j < n; ++j ) - xs[j] = j + bsplib_pid(bsplib); - - // All-set. Now compute the sum - - for ( j = 0; j < n; ++j ) - result += xs[j]; - - rc = bsplib_push_reg(bsplib, &result, sizeof( result ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < p; ++i ) { - rc = bsplib_hpget(bsplib, i, &result, 0, &local_sums[i], sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - result = 0; - for ( i = 0; i < p; ++i ) - result += local_sums[i]; - rc = bsplib_pop_reg(bsplib, &result ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", - p * ( n - 1 ) * n / 2 + n * ( p - 1 ) * p / 2, - result ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests an example from Hill's BSPlib paper in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_example_bsp_sum_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_lpf_sum_unsafemode.cpp b/tests/functional/func_bsplib_example_lpf_sum_unsafemode.cpp new file mode 100644 index 00000000..f39267ff --- /dev/null +++ b/tests/functional/func_bsplib_example_lpf_sum_unsafemode.cpp @@ -0,0 +1,79 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 2, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i, j; + int n = 5; + int result = 0, p = bsplib_nprocs(bsplib); + int local_sums[p]; + int xs[n]; + memset(local_sums, 0, sizeof(local_sums)); + + for (j = 0; j < n; ++j) + xs[j] = j + bsplib_pid(bsplib); + + // All-set. Now compute the sum + + for (j = 0; j < n; ++j) + result += xs[j]; + + rc = bsplib_push_reg(bsplib, &result, sizeof(result)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < p; ++i) { + rc = bsplib_hpget(bsplib, i, &result, 0, &local_sums[i], sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + result = 0; + for (i = 0; i < p; ++i) + result += local_sums[i]; + rc = bsplib_pop_reg(bsplib, &result); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(p * (n - 1) * n / 2 + n * (p - 1) * p / 2, result); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests an example from Hill's BSPlib paper in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_example_bsp_sum_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_example_put_array.c b/tests/functional/func_bsplib_example_put_array.c deleted file mode 100644 index 3d448091..00000000 --- a/tests/functional/func_bsplib_example_put_array.c +++ /dev/null @@ -1,82 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int n = 5 * bsplib_nprocs(bsplib); - int i, dst_pid, dst_idx, p = bsplib_nprocs(bsplib), n_over_p = n / p; - - int xs[n_over_p]; - for ( i = 0; i < n_over_p; ++i ) - { - xs[i] = n - ( i + bsplib_pid(bsplib) * n_over_p ) - 1; - } - - EXPECT_EQ("%d", 0, n % p ); - rc = bsplib_push_reg(bsplib, xs, n_over_p * sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n_over_p; ++i ) - { - dst_pid = xs[i] / n_over_p; - dst_idx = xs[i] % n_over_p; - rc = bsplib_put(bsplib, dst_pid, - &xs[i], xs, dst_idx * sizeof( int ), - sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, xs ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n_over_p; ++i ) - { - EXPECT_EQ("%d", i + (int) bsplib_pid(bsplib) * n_over_p, xs[i] ); - } - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests the put array example from Hill's BSPlib paper - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_put_array) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_put_array.cpp b/tests/functional/func_bsplib_example_put_array.cpp new file mode 100644 index 00000000..07218220 --- /dev/null +++ b/tests/functional/func_bsplib_example_put_array.cpp @@ -0,0 +1,73 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int n = 5 * bsplib_nprocs(bsplib); + int i, dst_pid, dst_idx, p = bsplib_nprocs(bsplib), n_over_p = n / p; + + int xs[n_over_p]; + for (i = 0; i < n_over_p; ++i) { + xs[i] = n - (i + bsplib_pid(bsplib) * n_over_p) - 1; + } + + EXPECT_EQ(0, n % p); + rc = bsplib_push_reg(bsplib, xs, n_over_p * sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n_over_p; ++i) { + dst_pid = xs[i] / n_over_p; + dst_idx = xs[i] % n_over_p; + rc = bsplib_put(bsplib, dst_pid, &xs[i], xs, dst_idx * sizeof(int), + sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, xs); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n_over_p; ++i) { + EXPECT_EQ(i + (int)bsplib_pid(bsplib) * n_over_p, xs[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests the put array example from Hill's BSPlib paper + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_put_array) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_example_put_array_unsafemode.c b/tests/functional/func_bsplib_example_put_array_unsafemode.c deleted file mode 100644 index e4adb988..00000000 --- a/tests/functional/func_bsplib_example_put_array_unsafemode.c +++ /dev/null @@ -1,82 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int n = 5 * bsplib_nprocs(bsplib); - int i, dst_pid, dst_idx, p = bsplib_nprocs(bsplib), n_over_p = n / p; - - int xs[n_over_p]; - for ( i = 0; i < n_over_p; ++i ) - { - xs[i] = n - ( i + bsplib_pid(bsplib) * n_over_p ) - 1; - } - - EXPECT_EQ("%d", 0, n % p ); - rc = bsplib_push_reg(bsplib, xs, n_over_p * sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n_over_p; ++i ) - { - dst_pid = xs[i] / n_over_p; - dst_idx = xs[i] % n_over_p; - rc = bsplib_put(bsplib, dst_pid, - &xs[i], xs, dst_idx * sizeof( int ), - sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, xs ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n_over_p; ++i ) - { - EXPECT_EQ("%d", i + (int) bsplib_pid(bsplib) * n_over_p, xs[i] ); - } - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests the put array example from Hill's BSPlib paper in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_put_array_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_put_array_unsafemode.cpp b/tests/functional/func_bsplib_example_put_array_unsafemode.cpp new file mode 100644 index 00000000..42738690 --- /dev/null +++ b/tests/functional/func_bsplib_example_put_array_unsafemode.cpp @@ -0,0 +1,73 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int n = 5 * bsplib_nprocs(bsplib); + int i, dst_pid, dst_idx, p = bsplib_nprocs(bsplib), n_over_p = n / p; + + int xs[n_over_p]; + for (i = 0; i < n_over_p; ++i) { + xs[i] = n - (i + bsplib_pid(bsplib) * n_over_p) - 1; + } + + EXPECT_EQ(0, n % p); + rc = bsplib_push_reg(bsplib, xs, n_over_p * sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n_over_p; ++i) { + dst_pid = xs[i] / n_over_p; + dst_idx = xs[i] % n_over_p; + rc = bsplib_put(bsplib, dst_pid, &xs[i], xs, dst_idx * sizeof(int), + sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, xs); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n_over_p; ++i) { + EXPECT_EQ(i + (int)bsplib_pid(bsplib) * n_over_p, xs[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests the put array example from Hill's BSPlib paper in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_put_array_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_example_reverse.c b/tests/functional/func_bsplib_example_reverse.c deleted file mode 100644 index d170bccf..00000000 --- a/tests/functional/func_bsplib_example_reverse.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - lpf_pid_t x = bsplib_pid(bsplib); - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_put(bsplib, - bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, - &x, &x, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%u", bsplib_pid(bsplib), x ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg(bsplib, &x ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%u", bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, x ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests the reverse example from Hill's BSPlib paper - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_exampl_reverse ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_reverse.cpp b/tests/functional/func_bsplib_example_reverse.cpp new file mode 100644 index 00000000..abcdf230 --- /dev/null +++ b/tests/functional/func_bsplib_example_reverse.cpp @@ -0,0 +1,63 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + lpf_pid_t x = bsplib_pid(bsplib); + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_put(bsplib, bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, &x, + &x, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib), x); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, &x); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, x); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests the reverse example from Hill's BSPlib paper + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_exampl_reverse) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_example_reverse_unsafemode.c b/tests/functional/func_bsplib_example_reverse_unsafemode.c deleted file mode 100644 index 09d338b8..00000000 --- a/tests/functional/func_bsplib_example_reverse_unsafemode.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - lpf_pid_t x = bsplib_pid(bsplib); - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_put(bsplib, - bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, - &x, &x, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%u", bsplib_pid(bsplib), x ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg(bsplib, &x ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%u", bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, x ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests the reverse example from Hill's BSPlib paper in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_exampl_reverse_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_example_reverse_unsafemode.cpp b/tests/functional/func_bsplib_example_reverse_unsafemode.cpp new file mode 100644 index 00000000..c2172066 --- /dev/null +++ b/tests/functional/func_bsplib_example_reverse_unsafemode.cpp @@ -0,0 +1,63 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + lpf_pid_t x = bsplib_pid(bsplib); + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_put(bsplib, bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, &x, + &x, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib), x); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, &x); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_nprocs(bsplib) - bsplib_pid(bsplib) - 1, x); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests the reverse example from Hill's BSPlib paper in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_exampl_reverse_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_get_exceptions.c b/tests/functional/func_bsplib_get_exceptions.c deleted file mode 100644 index 4fa597e8..00000000 --- a/tests/functional/func_bsplib_get_exceptions.c +++ /dev/null @@ -1,70 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char a = 'a'; - char b = 'b'; - - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get( bsplib, - bsplib_nprocs( bsplib ) + 1, - &a, 0, &b, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_PID_OUT_OF_RANGE, rc ); - - rc = bsplib_get( bsplib, -1, - &a, 0, &b, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_PID_OUT_OF_RANGE, rc ); - - rc = bsplib_get( bsplib, 0, &a, 1, &b, sizeof(a) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - rc = bsplib_get( bsplib, 0, &a, 0, &b, 2*sizeof(a) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests some error cases of a bsplib_get - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_get_exceptions ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_get_exceptions.cpp b/tests/functional/func_bsplib_get_exceptions.cpp new file mode 100644 index 00000000..126f6ae3 --- /dev/null +++ b/tests/functional/func_bsplib_get_exceptions.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char a = 'a'; + char b = 'b'; + + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, bsplib_nprocs(bsplib) + 1, &a, 0, &b, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_PID_OUT_OF_RANGE, rc); + + rc = bsplib_get(bsplib, -1, &a, 0, &b, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_PID_OUT_OF_RANGE, rc); + + rc = bsplib_get(bsplib, 0, &a, 1, &b, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + rc = bsplib_get(bsplib, 0, &a, 0, &b, 2 * sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests some error cases of a bsplib_get + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_get_exceptions) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_get_normal.c b/tests/functional/func_bsplib_get_normal.c deleted file mode 100644 index 71299665..00000000 --- a/tests/functional/func_bsplib_get_normal.c +++ /dev/null @@ -1,84 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i; - int p = bsplib_nprocs(bsplib); - int a[p]; - int b[p]; - memset( b, 0, sizeof( b ) ); - - for ( i = 0; i < p; ++i ) - { - a[i] = bsplib_pid(bsplib) * i; - } - - rc = bsplib_push_reg(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < p; ++i ) - { - lpf_pid_t srcPid = i; - size_t srcOffset = i; - - rc = bsplib_get(bsplib, - srcPid, a, srcOffset * sizeof( a[0] ), b + i, - sizeof( a[0] ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_pop_reg(bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - for ( i = 0; i < p; ++i ) - { - EXPECT_EQ( "%d", i * i, b[i] ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a common case of a bsplib_get - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_get_normal) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_get_normal.cpp b/tests/functional/func_bsplib_get_normal.cpp new file mode 100644 index 00000000..1376b234 --- /dev/null +++ b/tests/functional/func_bsplib_get_normal.cpp @@ -0,0 +1,76 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i; + int p = bsplib_nprocs(bsplib); + int a[p]; + int b[p]; + memset(b, 0, sizeof(b)); + + for (i = 0; i < p; ++i) { + a[i] = bsplib_pid(bsplib) * i; + } + + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < p; ++i) { + lpf_pid_t srcPid = i; + size_t srcOffset = i; + + rc = bsplib_get(bsplib, srcPid, a, srcOffset * sizeof(a[0]), b + i, + sizeof(a[0])); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + for (i = 0; i < p; ++i) { + EXPECT_EQ(i * i, b[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a common case of a bsplib_get + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_get_normal) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_get_normal_unsafemode.c b/tests/functional/func_bsplib_get_normal_unsafemode.c deleted file mode 100644 index e7377df1..00000000 --- a/tests/functional/func_bsplib_get_normal_unsafemode.c +++ /dev/null @@ -1,84 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i; - int p = bsplib_nprocs(bsplib); - int a[p]; - int b[p]; - memset( b, 0, sizeof( b ) ); - - for ( i = 0; i < p; ++i ) - { - a[i] = bsplib_pid(bsplib) * i; - } - - rc = bsplib_push_reg(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < p; ++i ) - { - lpf_pid_t srcPid = i; - size_t srcOffset = i; - - rc = bsplib_get(bsplib, - srcPid, a, srcOffset * sizeof( a[0] ), b + i, - sizeof( a[0] ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_pop_reg(bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - for ( i = 0; i < p; ++i ) - { - EXPECT_EQ( "%d", i * i, b[i] ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a common case of a bsplib_get in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_get_normal_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_get_normal_unsafemode.cpp b/tests/functional/func_bsplib_get_normal_unsafemode.cpp new file mode 100644 index 00000000..3946fabf --- /dev/null +++ b/tests/functional/func_bsplib_get_normal_unsafemode.cpp @@ -0,0 +1,76 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i; + int p = bsplib_nprocs(bsplib); + int a[p]; + int b[p]; + memset(b, 0, sizeof(b)); + + for (i = 0; i < p; ++i) { + a[i] = bsplib_pid(bsplib) * i; + } + + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < p; ++i) { + lpf_pid_t srcPid = i; + size_t srcOffset = i; + + rc = bsplib_get(bsplib, srcPid, a, srcOffset * sizeof(a[0]), b + i, + sizeof(a[0])); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + for (i = 0; i < p; ++i) { + EXPECT_EQ(i * i, b[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a common case of a bsplib_get in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_get_normal_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_get_twice_on_same_remote.c b/tests/functional/func_bsplib_get_twice_on_same_remote.c deleted file mode 100644 index d57efaa3..00000000 --- a/tests/functional/func_bsplib_get_twice_on_same_remote.c +++ /dev/null @@ -1,109 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &y, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid(bsplib) == 0 ) - rc = bsplib_get(bsplib, 1, &x, 0, &y, sizeof( x ) ); - else if ( bsplib_pid(bsplib) == 1 ) - rc = bsplib_get(bsplib, 0, &y, 0, &z, sizeof( y ) ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'x' : 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 1 ? 'y' : 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // redo the previous but now the order of pid 0 and 1 reversed - - x = 'x'; - y = 'y'; - z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &y, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid(bsplib) == 1 ) - rc = bsplib_get(bsplib, 0, &x, 0, &y, sizeof( x ) ); - else if ( bsplib_pid(bsplib) == 0 ) - rc = bsplib_get(bsplib, 1, &y, 0, &z, sizeof( y ) ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 1 ? 'x' : 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'y' : 'z', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests two lpf_gets where one memory location serves as source and destination for two gets - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_get_twice_on_same_remote ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_get_twice_on_same_remote.cpp b/tests/functional/func_bsplib_get_twice_on_same_remote.cpp new file mode 100644 index 00000000..33a5833a --- /dev/null +++ b/tests/functional/func_bsplib_get_twice_on_same_remote.cpp @@ -0,0 +1,103 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &y, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) == 0) + rc = bsplib_get(bsplib, 1, &x, 0, &y, sizeof(x)); + else if (bsplib_pid(bsplib) == 1) + rc = bsplib_get(bsplib, 0, &y, 0, &z, sizeof(y)); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'x' : 'y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 1 ? 'y' : 'z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // redo the previous but now the order of pid 0 and 1 reversed + + x = 'x'; + y = 'y'; + z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &y, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) == 1) + rc = bsplib_get(bsplib, 0, &x, 0, &y, sizeof(x)); + else if (bsplib_pid(bsplib) == 0) + rc = bsplib_get(bsplib, 1, &y, 0, &z, sizeof(y)); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ(bsplib_pid(bsplib) == 1 ? 'x' : 'y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'y' : 'z', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests two lpf_gets where one memory location serves as source and + * destination for two gets \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_get_twice_on_same_remote) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.c b/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.c deleted file mode 100644 index 0553d7f7..00000000 --- a/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.c +++ /dev/null @@ -1,109 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &y, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid(bsplib) == 0 ) - rc = bsplib_get(bsplib, 1, &x, 0, &y, sizeof( x ) ); - else if ( bsplib_pid(bsplib) == 1 ) - rc = bsplib_get(bsplib, 0, &y, 0, &z, sizeof( y ) ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'x' : 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 1 ? 'y' : 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // redo the previous but now the order of pid 0 and 1 reversed - - x = 'x'; - y = 'y'; - z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &y, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid(bsplib) == 1 ) - rc = bsplib_get(bsplib, 0, &x, 0, &y, sizeof( x ) ); - else if ( bsplib_pid(bsplib) == 0 ) - rc = bsplib_get(bsplib, 1, &y, 0, &z, sizeof( y ) ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 1 ? 'x' : 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'y' : 'z', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests two lpf_gets where one memory location serves as source and destination for two gets in unsafe mode - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_get_twice_on_same_remote_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.cpp b/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.cpp new file mode 100644 index 00000000..8a094fce --- /dev/null +++ b/tests/functional/func_bsplib_get_twice_on_same_remote_unsafemode.cpp @@ -0,0 +1,103 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &y, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) == 0) + rc = bsplib_get(bsplib, 1, &x, 0, &y, sizeof(x)); + else if (bsplib_pid(bsplib) == 1) + rc = bsplib_get(bsplib, 0, &y, 0, &z, sizeof(y)); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'x' : 'y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 1 ? 'y' : 'z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // redo the previous but now the order of pid 0 and 1 reversed + + x = 'x'; + y = 'y'; + z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &y, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) == 1) + rc = bsplib_get(bsplib, 0, &x, 0, &y, sizeof(x)); + else if (bsplib_pid(bsplib) == 0) + rc = bsplib_get(bsplib, 1, &y, 0, &z, sizeof(y)); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ(bsplib_pid(bsplib) == 1 ? 'x' : 'y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'y' : 'z', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests two lpf_gets where one memory location serves as source and + * destination for two gets in unsafe mode \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_get_twice_on_same_remote_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_getput_same_dest.c b/tests/functional/func_bsplib_getput_same_dest.c deleted file mode 100644 index d4915613..00000000 --- a/tests/functional/func_bsplib_getput_same_dest.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 2, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &y, &z, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'y' : 'x', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a bsplib_get and a lpf_put to the same destination - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_getput_same_dest ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_getput_same_dest.cpp b/tests/functional/func_bsplib_getput_same_dest.cpp new file mode 100644 index 00000000..47e29155 --- /dev/null +++ b/tests/functional/func_bsplib_getput_same_dest.cpp @@ -0,0 +1,70 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 2, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &y, &z, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'y' : 'x', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a bsplib_get and a lpf_put to the same destination + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_getput_same_dest) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_getput_same_dest_unsafemode.c b/tests/functional/func_bsplib_getput_same_dest_unsafemode.c deleted file mode 100644 index 05a62af2..00000000 --- a/tests/functional/func_bsplib_getput_same_dest_unsafemode.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &y, &z, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'y' : 'x', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a bsplib_get and a lpf_put to the same destination in unsafe mode - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_getput_same_dest_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_getput_same_dest_unsafemode.cpp b/tests/functional/func_bsplib_getput_same_dest_unsafemode.cpp new file mode 100644 index 00000000..f1a58733 --- /dev/null +++ b/tests/functional/func_bsplib_getput_same_dest_unsafemode.cpp @@ -0,0 +1,70 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &y, &z, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'y' : 'x', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a bsplib_get and a lpf_put to the same destination in unsafe mode + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_getput_same_dest_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_getput_same_remote.c b/tests/functional/func_bsplib_getput_same_remote.c deleted file mode 100644 index 8c796925..00000000 --- a/tests/functional/func_bsplib_getput_same_remote.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &z, &x, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'z' : 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'x', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a common case of a bsplib_get - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_getput_same_remote ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_getput_same_remote.cpp b/tests/functional/func_bsplib_getput_same_remote.cpp new file mode 100644 index 00000000..937af563 --- /dev/null +++ b/tests/functional/func_bsplib_getput_same_remote.cpp @@ -0,0 +1,68 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, -1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &z, &x, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'z' : 'x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('x', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a common case of a bsplib_get + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_getput_same_remote) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_getput_same_remote_unsafemode.c b/tests/functional/func_bsplib_getput_same_remote_unsafemode.c deleted file mode 100644 index fb8eb18e..00000000 --- a/tests/functional/func_bsplib_getput_same_remote_unsafemode.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - char y = 'y'; - char z = 'z'; - - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &z, &x, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'z', z ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", bsplib_pid(bsplib) == 0 ? 'z' : 'x', x ); - EXPECT_EQ( "%c", 'y', y ); - EXPECT_EQ( "%c", 'x', z ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a common case of a bsplib_get in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_getput_same_remote_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_getput_same_remote_unsafemode.cpp b/tests/functional/func_bsplib_getput_same_remote_unsafemode.cpp new file mode 100644 index 00000000..c4aeb04c --- /dev/null +++ b/tests/functional/func_bsplib_getput_same_remote_unsafemode.cpp @@ -0,0 +1,68 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + char z = 'z'; + + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, 0, &x, 0, &z, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &z, &x, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('z', z); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 'z' : 'x', x); + EXPECT_EQ('y', y); + EXPECT_EQ('x', z); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a common case of a bsplib_get in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_getput_same_remote_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_getput_zero_bytes.c b/tests/functional/func_bsplib_getput_zero_bytes.c deleted file mode 100644 index 4403462c..00000000 --- a/tests/functional/func_bsplib_getput_zero_bytes.c +++ /dev/null @@ -1,94 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 3, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - char y = 'y'; - rc = bsplib_push_reg(bsplib, &x, sizeof( x ) ); - rc = bsplib_sync(bsplib); - - const size_t zero_bytes = 0; - - // the following puts and gets are no-ops, despite some - // other illegal arguments, because they all write zero bytes - rc = bsplib_put(bsplib, 0, &y, NULL, 10, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &y, &x, -5, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &y, &y, 0, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put(bsplib, 0, &y, &x, sizeof(x)+1, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_hpput(bsplib, 0, &y, NULL, 10, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpput(bsplib, 0, &y, &x, -5, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpput(bsplib, 0, &y, &y, 0, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpput(bsplib, 0, &y, &x, sizeof(x)+1, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_get(bsplib, 0, NULL, 10, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_get(bsplib, 0, &x, -5, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_get(bsplib, 0, &y, 0, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_get(bsplib, 0, &x, sizeof(x)+1, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_hpget(bsplib, 0, NULL, 10, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpget(bsplib, 0, &x, -5, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpget(bsplib, 0, &y, 0, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_hpget(bsplib, 0, &x, sizeof(x)+1, &y, zero_bytes); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Any put or get with zero bytes is legal - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_getput_zero_bytes ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_getput_zero_bytes.cpp b/tests/functional/func_bsplib_getput_zero_bytes.cpp new file mode 100644 index 00000000..ad6b71b1 --- /dev/null +++ b/tests/functional/func_bsplib_getput_zero_bytes.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "gtest/gtest.h" + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 3, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + char y = 'y'; + rc = bsplib_push_reg(bsplib, &x, sizeof(x)); + rc = bsplib_sync(bsplib); + + const size_t zero_bytes = 0; + + // the following puts and gets are no-ops, despite some + // other illegal arguments, because they all write zero bytes + rc = bsplib_put(bsplib, 0, &y, NULL, 10, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &y, &x, -5, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &y, &y, 0, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &y, &x, sizeof(x) + 1, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_hpput(bsplib, 0, &y, NULL, 10, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpput(bsplib, 0, &y, &x, -5, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpput(bsplib, 0, &y, &y, 0, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpput(bsplib, 0, &y, &x, sizeof(x) + 1, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_get(bsplib, 0, NULL, 10, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_get(bsplib, 0, &x, -5, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_get(bsplib, 0, &y, 0, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_get(bsplib, 0, &x, sizeof(x) + 1, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_hpget(bsplib, 0, NULL, 10, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpget(bsplib, 0, &x, -5, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpget(bsplib, 0, &y, 0, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_hpget(bsplib, 0, &x, sizeof(x) + 1, &y, zero_bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Any put or get with zero bytes is legal + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_getput_zero_bytes) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_hpget_many.c b/tests/functional/func_bsplib_hpget_many.c deleted file mode 100644 index d46bb231..00000000 --- a/tests/functional/func_bsplib_hpget_many.c +++ /dev/null @@ -1,104 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i, j; - const int m = 1000; - const int n = m*(m+1)/2; - uint32_t * memory = malloc( 2 + n *sizeof(uint32_t) ); - uint32_t *array = memory + 2; - uint32_t value[m]; - rc = bsplib_push_reg(bsplib, value, sizeof(value)); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - memory[i] = 0xAAAAAAAAu; - } - - for (i = 0; i < m; ++i) - { - value[i] = 0x12345678; - } - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - for (i = 1, j=0; i <= m; j += i, ++i) { - rc = bsplib_hpget(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - value, 0, array + j, - i*sizeof( uint32_t ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_pop_reg(bsplib, value ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - if ( i < 2) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - else - { - EXPECT_EQ( "%u", 0x12345678u, memory[i] ); - } - } - - for ( i = 0; i < m; ++i ) { - EXPECT_EQ( "%u", 0x12345678u, value[i] ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - free(memory); -} - -/** - * \test Tests sending a lot of messages through bsp_hpget - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_hpget_many) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_hpget_many.cpp b/tests/functional/func_bsplib_hpget_many.cpp new file mode 100644 index 00000000..9cdd95d3 --- /dev/null +++ b/tests/functional/func_bsplib_hpget_many.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i, j; + const int m = 100; + const int n = m * (m + 1) / 2; + uint32_t *memory = (uint32_t *)malloc(2 + n * sizeof(uint32_t)); + uint32_t *array = memory + 2; + uint32_t value[m]; + rc = bsplib_push_reg(bsplib, value, sizeof(value)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + memory[i] = 0xAAAAAAAAu; + } + + for (i = 0; i < m; ++i) { + value[i] = 0x12345678; + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 1, j = 0; i <= m; j += i, ++i) { + rc = bsplib_hpget(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), + value, 0, array + j, i * sizeof(uint32_t)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_pop_reg(bsplib, value); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + if (i < 2) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } else { + EXPECT_EQ(0x12345678u, memory[i]); + } + } + + for (i = 0; i < m; ++i) { + EXPECT_EQ(0x12345678u, value[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + free(memory); +} + +/** + * \test Tests sending a lot of messages through bsp_hpget + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_hpget_many) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_hpput_many.c b/tests/functional/func_bsplib_hpput_many.c deleted file mode 100644 index 8c92a5ec..00000000 --- a/tests/functional/func_bsplib_hpput_many.c +++ /dev/null @@ -1,104 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 10, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i, j; - const int m = 1000; - const int n = m*(m+1)/2; - uint32_t * memory = malloc( 2 + n *sizeof(uint32_t) ); - uint32_t *array = memory + 2; - rc = bsplib_push_reg(bsplib, array, n*sizeof(uint32_t)); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - memory[i] = 0xAAAAAAAAu; - } - - uint32_t value[m]; - for (i = 0; i < m; ++i) - { - value[i] = 0x12345678; - } - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - for (i = 1, j=0; i <= m; j += i, ++i) { - rc = bsplib_hpput(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - value, array, j*sizeof(uint32_t), - i*sizeof( uint32_t ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_pop_reg(bsplib, array ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - if ( i < 2) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - else - { - EXPECT_EQ( "%u", 0x12345678u, memory[i] ); - } - } - - for ( i = 0; i < m; ++i ) { - EXPECT_EQ( "%u", 0x12345678u, value[i] ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - free(memory); -} - -/** - * \test Tests sending a lot of messages through bsp_hpput - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_hpput_many) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_hpput_many.cpp b/tests/functional/func_bsplib_hpput_many.cpp new file mode 100644 index 00000000..a0e9996e --- /dev/null +++ b/tests/functional/func_bsplib_hpput_many.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 10, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i, j; + const int m = 100; + const int n = m * (m + 1) / 2; + uint32_t *memory = (uint32_t *)malloc(2 + n * sizeof(uint32_t)); + uint32_t *array = memory + 2; + rc = bsplib_push_reg(bsplib, array, n * sizeof(uint32_t)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + memory[i] = 0xAAAAAAAAu; + } + + uint32_t value[m]; + for (i = 0; i < m; ++i) { + value[i] = 0x12345678; + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 1, j = 0; i <= m; j += i, ++i) { + rc = bsplib_hpput(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), + value, array, j * sizeof(uint32_t), i * sizeof(uint32_t)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_pop_reg(bsplib, array); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + if (i < 2) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } else { + EXPECT_EQ(0x12345678u, memory[i]); + } + } + + for (i = 0; i < m; ++i) { + EXPECT_EQ(0x12345678u, value[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + free(memory); +} + +/** + * \test Tests sending a lot of messages through bsp_hpput + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_hpput_many) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_hpsend_many.c b/tests/functional/func_bsplib_hpsend_many.c deleted file mode 100644 index fc1f5089..00000000 --- a/tests/functional/func_bsplib_hpsend_many.c +++ /dev/null @@ -1,131 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - size_t maxhpregs = (size_t) -1; - - const int pthread = 1, mpirma = 2, mpimsg = 3, hybrid = 4, ibverbs=5; - (void) pthread; (void) mpirma; (void) mpimsg; (void) hybrid; (void) ibverbs; - LPFLIB_IGNORE_TAUTOLOGIES - if (LPF_CORE_IMPL_ID == mpirma ) - { - maxhpregs = 10; // because MPI RMA only supports a limited number - // of memory registrations - } - LPFLIB_RESTORE_WARNINGS - - rc = bsplib_create( lpf, pid, nprocs, 1, maxhpregs, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i, j; - size_t size; - const int m = 1000; - const int n = m*(m+1)/2; - uint32_t * memory = malloc( 2 + n *sizeof(uint32_t) ); - uint32_t *array = memory + 2; - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - memory[i] = 0xAAAAAAAAu; - } - - uint32_t value[m]; - for (i = 0; i < m; ++i) - { - value[i] = 0x12345678; - } - - size = bsplib_set_tagsize( bsplib, sizeof(j)); - EXPECT_EQ( "%zu", (size_t) 0, size); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - for (i = 1, j=0; i <= m; j += i, ++i) { - rc = bsplib_hpsend(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &j, value, i*sizeof( uint32_t ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - const void * tag, *payload; - for ( i = 1; i <= m; ++i) { - size = bsplib_hpmove( bsplib, &tag, &payload); - EXPECT_NE("%zu", (size_t) -1, size ); - memcpy( &j, tag, sizeof(j)); - double size_approx = (1 + sqrt(1 + 8*j))/2; - size_t k = (size_t) (size_approx + 0.5*(1.0 - 1e-15)); - - EXPECT_EQ("%zu", k*sizeof(uint32_t), size ); - memcpy( array + j, payload, sizeof(uint32_t)*k); - } - size =bsplib_hpmove( bsplib, &tag, &payload); - EXPECT_EQ( "%zu", (size_t) -1, size ); - - for ( i = 0; i < n; ++i ) - { - if ( i < 2) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - else - { - EXPECT_EQ( "%u", 0x12345678u, memory[i] ); - } - } - - for ( i = 0; i < m; ++i ) { - EXPECT_EQ( "%u", 0x12345678u, value[i] ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - free(memory); -} - -/** - * \test Tests sending a lot of messages through bsp_hpsend - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_hpsend_many) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_hpsend_many.cpp b/tests/functional/func_bsplib_hpsend_many.cpp new file mode 100644 index 00000000..9bc9f387 --- /dev/null +++ b/tests/functional/func_bsplib_hpsend_many.cpp @@ -0,0 +1,119 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + size_t maxhpregs = (size_t)-1; + + const int pthread = 1, mpirma = 2, mpimsg = 3, hybrid = 4, ibverbs = 5; + (void)pthread; + (void)mpirma; + (void)mpimsg; + (void)hybrid; + (void)ibverbs; + if (LPF_CORE_IMPL_ID == mpirma) { + maxhpregs = 10; // because MPI RMA only supports a limited number + // of memory registrations + } + + rc = bsplib_create(lpf, pid, nprocs, 1, maxhpregs, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i, j; + size_t size; + const int m = 100; + const int n = m * (m + 1) / 2; + uint32_t *memory = (uint32_t *)malloc(2 + n * sizeof(uint32_t)); + uint32_t *array = memory + 2; + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + memory[i] = 0xAAAAAAAAu; + } + + uint32_t value[m]; + for (i = 0; i < m; ++i) { + value[i] = 0x12345678; + } + + size = bsplib_set_tagsize(bsplib, sizeof(j)); + EXPECT_EQ((size_t)0, size); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 1, j = 0; i <= m; j += i, ++i) { + rc = bsplib_hpsend(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), + &j, value, i * sizeof(uint32_t)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + const void *tag, *payload; + for (i = 1; i <= m; ++i) { + size = bsplib_hpmove(bsplib, &tag, &payload); + EXPECT_NE((size_t)-1, size); + memcpy(&j, tag, sizeof(j)); + double size_approx = (1 + sqrt(1 + 8 * j)) / 2; + size_t k = (size_t)(size_approx + 0.5 * (1.0 - 1e-15)); + + EXPECT_EQ(k * sizeof(uint32_t), size); + memcpy(array + j, payload, sizeof(uint32_t) * k); + } + size = bsplib_hpmove(bsplib, &tag, &payload); + EXPECT_EQ((size_t)-1, size); + + for (i = 0; i < n; ++i) { + if (i < 2) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } else { + EXPECT_EQ(0x12345678u, memory[i]); + } + } + + for (i = 0; i < m; ++i) { + EXPECT_EQ(0x12345678u, value[i]); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + free(memory); +} + +/** + * \test Tests sending a lot of messages through bsp_hpsend + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_hpsend_many) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_nprocs.c b/tests/functional/func_bsplib_nprocs.cpp similarity index 53% rename from tests/functional/func_bsplib_nprocs.c rename to tests/functional/func_bsplib_nprocs.cpp index 441123ee..b01e3083 100644 --- a/tests/functional/func_bsplib_nprocs.c +++ b/tests/functional/func_bsplib_nprocs.cpp @@ -15,36 +15,32 @@ * limitations under the License. */ -#include +#include "gtest/gtest.h" #include -#include "Test.h" +#include -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 10, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + bsplib_err_t rc = BSPLIB_SUCCESS; - lpf_pid_t nprocs2 = bsplib_nprocs( bsplib ); - EXPECT_EQ( "%u", nprocs, nprocs2); + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 10, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + lpf_pid_t nprocs2 = bsplib_nprocs(bsplib); + EXPECT_EQ(nprocs, nprocs2); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); } -/** +/** * \test Test bsp_nprocs * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_bsplib_nprocs ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_bsplib_nprocs) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } - diff --git a/tests/functional/func_bsplib_pid.c b/tests/functional/func_bsplib_pid.cpp similarity index 53% rename from tests/functional/func_bsplib_pid.c rename to tests/functional/func_bsplib_pid.cpp index c4b40958..3a6a5c8e 100644 --- a/tests/functional/func_bsplib_pid.c +++ b/tests/functional/func_bsplib_pid.cpp @@ -15,36 +15,32 @@ * limitations under the License. */ -#include +#include "gtest/gtest.h" #include -#include "Test.h" +#include -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + bsplib_err_t rc = BSPLIB_SUCCESS; - lpf_pid_t pid2 = bsplib_pid( bsplib ); - EXPECT_EQ( "%u", pid, pid2); + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + lpf_pid_t pid2 = bsplib_pid(bsplib); + EXPECT_EQ(pid, pid2); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); } -/** +/** * \test Test bsp_pid * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_bsplib_pid ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_bsplib_pid) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } - diff --git a/tests/functional/func_bsplib_pushpopreg_ambiguous.c b/tests/functional/func_bsplib_pushpopreg_ambiguous.c deleted file mode 100644 index fc1c44f6..00000000 --- a/tests/functional/func_bsplib_pushpopreg_ambiguous.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - // This example is a variation of an example in - // the BSPlib paper (Hill et al. 1998) - int a, b; - - rc = bsplib_push_reg(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - if ( bsplib_pid(bsplib) == 0 ) - { - rc = bsplib_push_reg(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - else - { - rc = bsplib_push_reg(bsplib, &b, sizeof( b ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_ERR_POPREG_MISMATCH, rc ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests whether BSPlib can detect whether registrations of variables with different memory slots are deregistered. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_ambiguous ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_ambiguous.cpp b/tests/functional/func_bsplib_pushpopreg_ambiguous.cpp new file mode 100644 index 00000000..64701796 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_ambiguous.cpp @@ -0,0 +1,63 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // This example is a variation of an example in + // the BSPlib paper (Hill et al. 1998) + int a, b; + + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + if (bsplib_pid(bsplib) == 0) { + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } else { + rc = bsplib_push_reg(bsplib, &b, sizeof(b)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_POPREG_MISMATCH, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests whether BSPlib can detect whether registrations of variables with + * different memory slots are deregistered. \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_ambiguous) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_different_variables.c b/tests/functional/func_bsplib_pushpopreg_different_variables.c deleted file mode 100644 index 086ceac7..00000000 --- a/tests/functional/func_bsplib_pushpopreg_different_variables.c +++ /dev/null @@ -1,69 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 10, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - // This example comes from the BSPlib paper (Hill et al. 1998) - int a, b; - rc = bsplib_push_reg(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg(bsplib, &b, sizeof( b ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - if ( bsplib_pid(bsplib) == 0 ) - { - rc = bsplib_pop_reg(bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - else - { - rc = bsplib_pop_reg(bsplib, &b ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_ERR_POPREG_MISMATCH, rc ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests whether BSPlib can detect whether registrations of variables with different memory slots are deregistered. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_different_variables) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_different_variables.cpp b/tests/functional/func_bsplib_pushpopreg_different_variables.cpp new file mode 100644 index 00000000..a7ff19e3 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_different_variables.cpp @@ -0,0 +1,60 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 10, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // This example comes from the BSPlib paper (Hill et al. 1998) + int a, b; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &b, sizeof(b)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + if (bsplib_pid(bsplib) == 0) { + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } else { + rc = bsplib_pop_reg(bsplib, &b); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_POPREG_MISMATCH, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests whether BSPlib can detect whether registrations of variables with + * different memory slots are deregistered. \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_different_variables) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_exceptions.c b/tests/functional/func_bsplib_pushpopreg_exceptions.c deleted file mode 100644 index 16b469cb..00000000 --- a/tests/functional/func_bsplib_pushpopreg_exceptions.c +++ /dev/null @@ -1,75 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, (size_t) -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int a; - // Use of variable without definition - rc = bsplib_put( bsplib, 0, &a, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc ); - - // Tests use of put directly after registration before sync - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put( bsplib, 0, &a, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_put( bsplib, 0, &a, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // Tests detection of NULL ptr - rc = bsplib_push_reg( bsplib, NULL, 1); - EXPECT_EQ( "%d", BSPLIB_ERR_NULL_POINTER, rc ); - - // Tests deregistration of non-existent registration - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests whether push_reg and pop_reg can detect various illegal uses. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_exception ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_exceptions.cpp b/tests/functional/func_bsplib_pushpopreg_exceptions.cpp new file mode 100644 index 00000000..8ec83b1b --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_exceptions.cpp @@ -0,0 +1,70 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, (size_t)-1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a; + // Use of variable without definition + rc = bsplib_put(bsplib, 0, &a, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc); + + // Tests use of put directly after registration before sync + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &a, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_put(bsplib, 0, &a, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // Tests detection of NULL ptr + rc = bsplib_push_reg(bsplib, NULL, 1); + EXPECT_EQ(BSPLIB_ERR_NULL_POINTER, rc); + + // Tests deregistration of non-existent registration + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests whether push_reg and pop_reg can detect various illegal uses. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_exception) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_many_same.c b/tests/functional/func_bsplib_pushpopreg_many_same.c deleted file mode 100644 index d478cd4a..00000000 --- a/tests/functional/func_bsplib_pushpopreg_many_same.c +++ /dev/null @@ -1,94 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - - int a[1000]; - memset( &a, 0, sizeof(a) ); - int n = sizeof(a)/sizeof(a[0]); - int i; - - - while (1) - { - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) { - rc = bsplib_push_reg( bsplib, a, i ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_sync( bsplib ); - - if (rc == BSPLIB_SUCCESS ) - { - break; - } - else if (rc == BSPLIB_ERR_OUT_OF_MEMORY ) - { - // reinitialize BSPlib - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // reduce number of registers - n /= 2; - } - else - { - break; - } - } - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) { - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Performance test data-structure for managing memory registrations - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_many_same) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_many_same.cpp b/tests/functional/func_bsplib_pushpopreg_many_same.cpp new file mode 100644 index 00000000..94f4bcb6 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_many_same.cpp @@ -0,0 +1,83 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + + int a[1000]; + memset(&a, 0, sizeof(a)); + int n = sizeof(a) / sizeof(a[0]); + int i; + + while (1) { + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + rc = bsplib_push_reg(bsplib, a, i); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_sync(bsplib); + + if (rc == BSPLIB_SUCCESS) { + break; + } else if (rc == BSPLIB_ERR_OUT_OF_MEMORY) { + // reinitialize BSPlib + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // reduce number of registers + n /= 2; + } else { + break; + } + } + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_ERR_MEMORY_NOT_REGISTERED, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Performance test data-structure for managing memory registrations + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_many_same) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_normal.c b/tests/functional/func_bsplib_pushpopreg_normal.c deleted file mode 100644 index 905b5c79..00000000 --- a/tests/functional/func_bsplib_pushpopreg_normal.c +++ /dev/null @@ -1,78 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - int a = 0; - int c = -1; - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg( bsplib, &c, sizeof( c ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int b = 2; - rc = bsplib_put( bsplib, 0, &b, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", 0, a ); - EXPECT_EQ( "%d", 2, b ); - EXPECT_EQ( "%d", -1, c ); - - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg( bsplib, &c ); // non-stack order! - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", bsplib_pid( bsplib ) == 0 ? 2 : 0, a ); - EXPECT_EQ( "%d", 2, b ); - EXPECT_EQ( "%d", -1, c ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test a basic use case with bsp_push_reg and bsp_pop_reg - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_normal ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_normal.cpp b/tests/functional/func_bsplib_pushpopreg_normal.cpp new file mode 100644 index 00000000..2d9f0d8a --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_normal.cpp @@ -0,0 +1,72 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a = 0; + int c = -1; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &c, sizeof(c)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int b = 2; + rc = bsplib_put(bsplib, 0, &b, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(0, a); + EXPECT_EQ(2, b); + EXPECT_EQ(-1, c); + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &c); // non-stack order! + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 : 0, a); + EXPECT_EQ(2, b); + EXPECT_EQ(-1, c); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test a basic use case with bsp_push_reg and bsp_pop_reg + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_normal) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.c b/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.c deleted file mode 100644 index 8ffac504..00000000 --- a/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.c +++ /dev/null @@ -1,78 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - int a = 0; - int c = -1; - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg( bsplib, &c, sizeof( c ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int b = 2; - rc = bsplib_put( bsplib, 0, &b, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", 0, a ); - EXPECT_EQ( "%d", 2, b ); - EXPECT_EQ( "%d", -1, c ); - - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg( bsplib, &c ); // non-stack order! - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", bsplib_pid( bsplib ) == 0 ? 2 : 0, a ); - EXPECT_EQ( "%d", 2, b ); - EXPECT_EQ( "%d", -1, c ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test a basic use case with bsp_push_reg and bsp_pop_reg in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_normal_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.cpp b/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.cpp new file mode 100644 index 00000000..8122cdf8 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_normal_unsafemode.cpp @@ -0,0 +1,72 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a = 0; + int c = -1; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, &c, sizeof(c)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int b = 2; + rc = bsplib_put(bsplib, 0, &b, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(0, a); + EXPECT_EQ(2, b); + EXPECT_EQ(-1, c); + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &c); // non-stack order! + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 : 0, a); + EXPECT_EQ(2, b); + EXPECT_EQ(-1, c); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test a basic use case with bsp_push_reg and bsp_pop_reg in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_normal_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_null.c b/tests/functional/func_bsplib_pushpopreg_null.c deleted file mode 100644 index 51370136..00000000 --- a/tests/functional/func_bsplib_pushpopreg_null.c +++ /dev/null @@ -1,118 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // register NULL once - rc = bsplib_push_reg( bsplib, NULL, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, NULL ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - // register NULL twice - rc = bsplib_push_reg( bsplib, NULL, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_push_reg( bsplib, NULL, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, NULL ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg( bsplib, NULL ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // use of NULL with comm primitives - - char x = 'x'; - char y = 'y'; - char *p = bsplib_pid(bsplib) == 0 ? &x : NULL; - - rc = bsplib_push_reg(bsplib, p, bsplib_pid(bsplib) == 0 ? 1 : 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid(bsplib) == 1 ) - { - rc = bsplib_put(bsplib, 0, &y, p, 0, 1 ); - EXPECT_EQ( "%d", BSPLIB_ERR_NULL_POINTER , rc ); - - rc = bsplib_hpput(bsplib, 0, &y, p, 0, 1 ); - EXPECT_EQ( "%d", BSPLIB_ERR_NULL_POINTER , rc ); - - rc = bsplib_get(bsplib, 0, p, 0, &y, 1 ); - EXPECT_EQ( "%d", BSPLIB_ERR_NULL_POINTER , rc ); - - rc = bsplib_hpget(bsplib, 0, p, 0, &y, 1 ); - EXPECT_EQ( "%d", BSPLIB_ERR_NULL_POINTER , rc ); - } - - if ( bsplib_pid(bsplib) == 0 ) - { - EXPECT_EQ( "%c", 'x', *p ); - rc = bsplib_put(bsplib, 0, &y, p, 0, 1 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - if ( bsplib_pid(bsplib) == 0 ) - { - EXPECT_EQ( "%c", 'y', *p ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests BSPlib's handling of register the NULL address - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_null ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_null.cpp b/tests/functional/func_bsplib_pushpopreg_null.cpp new file mode 100644 index 00000000..e6e636f7 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_null.cpp @@ -0,0 +1,110 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // register NULL once + rc = bsplib_push_reg(bsplib, NULL, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, NULL); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // register NULL twice + rc = bsplib_push_reg(bsplib, NULL, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_push_reg(bsplib, NULL, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, NULL); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, NULL); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // use of NULL with comm primitives + + char x = 'x'; + char y = 'y'; + char *p = bsplib_pid(bsplib) == 0 ? &x : NULL; + + rc = bsplib_push_reg(bsplib, p, bsplib_pid(bsplib) == 0 ? 1 : 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) == 1) { + rc = bsplib_put(bsplib, 0, &y, p, 0, 1); + EXPECT_EQ(BSPLIB_ERR_NULL_POINTER, rc); + + rc = bsplib_hpput(bsplib, 0, &y, p, 0, 1); + EXPECT_EQ(BSPLIB_ERR_NULL_POINTER, rc); + + rc = bsplib_get(bsplib, 0, p, 0, &y, 1); + EXPECT_EQ(BSPLIB_ERR_NULL_POINTER, rc); + + rc = bsplib_hpget(bsplib, 0, p, 0, &y, 1); + EXPECT_EQ(BSPLIB_ERR_NULL_POINTER, rc); + } + + if (bsplib_pid(bsplib) == 0) { + EXPECT_EQ('x', *p); + rc = bsplib_put(bsplib, 0, &y, p, 0, 1); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + if (bsplib_pid(bsplib) == 0) { + EXPECT_EQ('y', *p); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests BSPlib's handling of register the NULL address + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_null) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_pop_before_put.c b/tests/functional/func_bsplib_pushpopreg_pop_before_put.c deleted file mode 100644 index c9733fc4..00000000 --- a/tests/functional/func_bsplib_pushpopreg_pop_before_put.c +++ /dev/null @@ -1,70 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, (size_t) -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - int a = 0; - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int b = 2; - rc = bsplib_put( bsplib, 0, &b, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", 0, a ); - EXPECT_EQ( "%d", 2, b ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", bsplib_pid( bsplib ) == 0 ? 2 : 0, a ); - EXPECT_EQ( "%d", 2, b ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test a case where the pop_reg is issued before the put - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_pop_before_put ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_pop_before_put.cpp b/tests/functional/func_bsplib_pushpopreg_pop_before_put.cpp new file mode 100644 index 00000000..fbf25332 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_pop_before_put.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, (size_t)-1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a = 0; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int b = 2; + rc = bsplib_put(bsplib, 0, &b, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(0, a); + EXPECT_EQ(2, b); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 : 0, a); + EXPECT_EQ(2, b); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test a case where the pop_reg is issued before the put + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_pop_before_put) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.c b/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.c deleted file mode 100644 index 9d901e13..00000000 --- a/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.c +++ /dev/null @@ -1,70 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 2, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - int a = 0; - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int b = 2; - rc = bsplib_put( bsplib, 0, &b, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", 0, a ); - EXPECT_EQ( "%d", 2, b ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", bsplib_pid( bsplib ) == 0 ? 2 : 0, a ); - EXPECT_EQ( "%d", 2, b ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test a case where the pop_reg is issued before the put in unsafe mode - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_pop_before_put_unsafemode ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.cpp b/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.cpp new file mode 100644 index 00000000..2ae23112 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_pop_before_put_unsafemode.cpp @@ -0,0 +1,65 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 2, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a = 0; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int b = 2; + rc = bsplib_put(bsplib, 0, &b, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(0, a); + EXPECT_EQ(2, b); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 : 0, a); + EXPECT_EQ(2, b); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test a case where the pop_reg is issued before the put in unsafe mode + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_pop_before_put_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.c b/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.c deleted file mode 100644 index 62c121f7..00000000 --- a/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.c +++ /dev/null @@ -1,63 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int a; - rc = bsplib_push_reg( bsplib, &a, sizeof(a) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if ( bsplib_pid( bsplib ) != 0 ) - { - rc = bsplib_pop_reg( bsplib, &a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_ERR_POPREG_MISMATCH, rc ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests whether BSPlib detects whether the number of pop_regs are consistent - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_pop_on_one_process ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.cpp b/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.cpp new file mode 100644 index 00000000..d47c3615 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_pop_on_one_process.cpp @@ -0,0 +1,57 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (bsplib_pid(bsplib) != 0) { + rc = bsplib_pop_reg(bsplib, &a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_POPREG_MISMATCH, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests whether BSPlib detects whether the number of pop_regs are + * consistent \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_pop_on_one_process) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_push_on_one_process.c b/tests/functional/func_bsplib_pushpopreg_push_on_one_process.c deleted file mode 100644 index 617c843d..00000000 --- a/tests/functional/func_bsplib_pushpopreg_push_on_one_process.c +++ /dev/null @@ -1,58 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int a; - if ( bsplib_pid( bsplib ) != 0 ) - { - rc = bsplib_push_reg( bsplib, &a, sizeof(a) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - } - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_ERR_PUSHREG_MISMATCH, rc ); - - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests whether BSPlib detects whether the number of push_regs are consistent - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_on_one_process ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_push_on_one_process.cpp b/tests/functional/func_bsplib_pushpopreg_push_on_one_process.cpp new file mode 100644 index 00000000..36a02412 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_push_on_one_process.cpp @@ -0,0 +1,51 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int a; + if (bsplib_pid(bsplib) != 0) { + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + } + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_PUSHREG_MISMATCH, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests whether BSPlib detects whether the number of push_regs are + * consistent \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_on_one_process) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_same_growing_memory.c b/tests/functional/func_bsplib_pushpopreg_same_growing_memory.c deleted file mode 100644 index fc13c316..00000000 --- a/tests/functional/func_bsplib_pushpopreg_same_growing_memory.c +++ /dev/null @@ -1,102 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, (size_t) -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // first register a bit of memory - char memory[10]; - memset( memory, 0, sizeof( memory ) ); - rc = bsplib_push_reg( bsplib, &memory[0], 3 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - - rc = bsplib_put( bsplib, - ( bsplib_pid( bsplib ) + 1 ) % bsplib_nprocs( bsplib ), - &x, memory, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%c", '\0', memory[0] ); - EXPECT_EQ( "%c", 'x', x ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", 'x', memory[0] ); - EXPECT_EQ( "%d", 'x', x ); - - EXPECT_EQ( "%d", '\0', memory[4] ); - - rc = bsplib_put( bsplib, - ( bsplib_pid( bsplib ) + 1 ) % bsplib_nprocs( bsplib ), - &x, memory, 4, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - EXPECT_EQ( "%c", '\0', memory[4] ); - - // now register the memory again, but with larger extent - rc = bsplib_push_reg( bsplib, &memory[0], 5 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_put( bsplib, - ( bsplib_pid( bsplib ) + 1 ) % bsplib_nprocs( bsplib ), - &x, memory, 4, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%c", '\0', memory[4] ); - EXPECT_EQ( "%c", 'x', x ); - - rc = bsplib_pop_reg( bsplib, &memory[0] ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg( bsplib, &memory[0] ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%c", 'x', memory[4] ); - EXPECT_EQ( "%c", 'x', x ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test stack like behaviour of bsp_push_reg to confirm that last registration takes precedence. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_same_growing_memory) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_same_growing_memory.cpp b/tests/functional/func_bsplib_pushpopreg_same_growing_memory.cpp new file mode 100644 index 00000000..82b6fef1 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_same_growing_memory.cpp @@ -0,0 +1,94 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, (size_t)-1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // first register a bit of memory + char memory[10]; + memset(memory, 0, sizeof(memory)); + rc = bsplib_push_reg(bsplib, &memory[0], 3); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ('\0', memory[0]); + EXPECT_EQ('x', x); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', memory[0]); + EXPECT_EQ('x', x); + + EXPECT_EQ('\0', memory[4]); + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 4, sizeof(x)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + EXPECT_EQ('\0', memory[4]); + + // now register the memory again, but with larger extent + rc = bsplib_push_reg(bsplib, &memory[0], 5); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 4, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ('\0', memory[4]); + EXPECT_EQ('x', x); + + rc = bsplib_pop_reg(bsplib, &memory[0]); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &memory[0]); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ('x', memory[4]); + EXPECT_EQ('x', x); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test stack like behaviour of bsp_push_reg to confirm that last + * registration takes precedence. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_same_growing_memory) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.c b/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.c deleted file mode 100644 index f6a0ef56..00000000 --- a/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.c +++ /dev/null @@ -1,118 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 2, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // first register a bit of memory - char memory[10]; - memset( memory, 0, sizeof( memory ) ); - rc = bsplib_push_reg(bsplib, &memory[0], 8 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char x = 'x'; - - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &x, memory, 0, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%c", '\0', memory[0] ); - EXPECT_EQ( "%c", 'x', x ); - - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &x, memory, 4, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%c", '\0', memory[4] ); - EXPECT_EQ( "%c", 'x', x ); - - rc = bsplib_sync(bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', memory[0] ); - EXPECT_EQ( "%c", 'x', x ); - - EXPECT_EQ( "%c", 'x', memory[4] ); - EXPECT_EQ( "%c", 'x', x ); - - // now register the memory again, but with smaller extent - rc = bsplib_push_reg(bsplib, &memory[0], 2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib ); - - x = 'a'; - - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &x, memory, 4, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - - EXPECT_EQ( "%c", 'x', memory[4] ); - EXPECT_EQ( "%c", 'a', x ); - - rc = bsplib_pop_reg(bsplib, &memory[0] ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync(bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // Stack order of registering the same memory! - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &x, memory, 4, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, &memory[0] ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'x', memory[4] ); - - rc = bsplib_sync(bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'a', x ); - EXPECT_EQ( "%c", 'a', memory[4] ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test stack like behaviour of bsp_push_reg to confirm that last registration takes precedence. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_same_shrinking_memory) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.cpp b/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.cpp new file mode 100644 index 00000000..a414f939 --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_same_shrinking_memory.cpp @@ -0,0 +1,109 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 2, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // first register a bit of memory + char memory[10]; + memset(memory, 0, sizeof(memory)); + rc = bsplib_push_reg(bsplib, &memory[0], 8); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char x = 'x'; + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 0, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ('\0', memory[0]); + EXPECT_EQ('x', x); + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 4, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ('\0', memory[4]); + EXPECT_EQ('x', x); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', memory[0]); + EXPECT_EQ('x', x); + + EXPECT_EQ('x', memory[4]); + EXPECT_EQ('x', x); + + // now register the memory again, but with smaller extent + rc = bsplib_push_reg(bsplib, &memory[0], 2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + + x = 'a'; + + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 4, sizeof(x)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + + EXPECT_EQ('x', memory[4]); + EXPECT_EQ('a', x); + + rc = bsplib_pop_reg(bsplib, &memory[0]); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // Stack order of registering the same memory! + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), &x, + memory, 4, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, &memory[0]); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('x', memory[4]); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ('a', x); + EXPECT_EQ('a', memory[4]); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test stack like behaviour of bsp_push_reg to confirm that last + * registration takes precedence. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_same_shrinking_memory) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.c b/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.c deleted file mode 100644 index 29cdea32..00000000 --- a/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.c +++ /dev/null @@ -1,81 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - - int c[2] = { 0, 0}; - int a[2]; - memset( a, 0, sizeof(a)); - rc = bsplib_push_reg( bsplib, a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_push_reg( bsplib, a, sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_pop_reg( bsplib, a ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int b = 2; - rc = bsplib_put( bsplib, 0, &b, a, 0, sizeof( int ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_put( bsplib, 0, c, a, 0, sizeof( c) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - - EXPECT_EQ( "%d", 0, a[0] ); - EXPECT_EQ( "%d", 2, b ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", bsplib_pid( bsplib ) == 0 ? 2 : 0, a[0] ); - EXPECT_EQ( "%d", 2, b ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Test a case where two pop_regs are issued before the two puts - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_pushpopreg_two_pops_before_two_puts ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.cpp b/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.cpp new file mode 100644 index 00000000..7d6c4a6a --- /dev/null +++ b/tests/functional/func_bsplib_pushpopreg_two_pops_before_two_puts.cpp @@ -0,0 +1,76 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int c[2] = {0, 0}; + int a[2]; + memset(a, 0, sizeof(a)); + rc = bsplib_push_reg(bsplib, a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_push_reg(bsplib, a, sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_pop_reg(bsplib, a); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int b = 2; + rc = bsplib_put(bsplib, 0, &b, a, 0, sizeof(int)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_put(bsplib, 0, c, a, 0, sizeof(c)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + + EXPECT_EQ(0, a[0]); + EXPECT_EQ(2, b); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 : 0, a[0]); + EXPECT_EQ(2, b); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Test a case where two pop_regs are issued before the two puts + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_pushpopreg_two_pops_before_two_puts) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_put_exceptions.c b/tests/functional/func_bsplib_put_exceptions.c deleted file mode 100644 index da7102c7..00000000 --- a/tests/functional/func_bsplib_put_exceptions.c +++ /dev/null @@ -1,62 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - char a = 'a'; - char b = 'b'; - rc = bsplib_push_reg( bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc =bsplib_put( bsplib, 0, &b, &a, 1, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - rc =bsplib_put( bsplib, 0, &b, &a, 0, sizeof( a ) * 2 ); - EXPECT_EQ( "%d", BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc ); - - rc = bsplib_put( bsplib, - bsplib_nprocs( bsplib ), &b, &a, 0, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_ERR_PID_OUT_OF_RANGE, rc ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests some common illegal cases with lpf_put. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_put_exceptions ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_put_exceptions.cpp b/tests/functional/func_bsplib_put_exceptions.cpp new file mode 100644 index 00000000..7abcd79c --- /dev/null +++ b/tests/functional/func_bsplib_put_exceptions.cpp @@ -0,0 +1,57 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + char a = 'a'; + char b = 'b'; + rc = bsplib_push_reg(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_put(bsplib, 0, &b, &a, 1, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + rc = bsplib_put(bsplib, 0, &b, &a, 0, sizeof(a) * 2); + EXPECT_EQ(BSPLIB_ERR_MEMORY_ACCESS_OUT_OF_RANGE, rc); + + rc = bsplib_put(bsplib, bsplib_nprocs(bsplib), &b, &a, 0, sizeof(a)); + EXPECT_EQ(BSPLIB_ERR_PID_OUT_OF_RANGE, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests some common illegal cases with lpf_put. + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_put_exceptions) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_put_normal.c b/tests/functional/func_bsplib_put_normal.c deleted file mode 100644 index f5a72d3c..00000000 --- a/tests/functional/func_bsplib_put_normal.c +++ /dev/null @@ -1,96 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i; - const int n = 10; - uint32_t memory[n]; - uint32_t *array = memory + 2; - int length = 5; - rc = bsplib_push_reg(bsplib, array, length ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - uint32_t value = 0x12345678; - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &value, array, 0, - sizeof( value ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, array ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - memory[i] = 0xAAAAAAAAu; - } - - for ( i = 0; i < n; ++i ) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - EXPECT_EQ( "%u", 0x12345678u, value ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - if ( 2 != i ) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - else - { - EXPECT_EQ( "%u", 0x12345678u, memory[i] ); - } - } - EXPECT_EQ( "%u", 0x12345678u, value ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a normal lpf_put case. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_put_normal) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_put_normal.cpp b/tests/functional/func_bsplib_put_normal.cpp new file mode 100644 index 00000000..46f6d600 --- /dev/null +++ b/tests/functional/func_bsplib_put_normal.cpp @@ -0,0 +1,84 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i; + const int n = 10; + uint32_t memory[n]; + uint32_t *array = memory + 2; + int length = 5; + rc = bsplib_push_reg(bsplib, array, length); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + uint32_t value = 0x12345678; + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), + &value, array, 0, sizeof(value)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, array); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + memory[i] = 0xAAAAAAAAu; + } + + for (i = 0; i < n; ++i) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } + EXPECT_EQ(0x12345678u, value); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + if (2 != i) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } else { + EXPECT_EQ(0x12345678u, memory[i]); + } + } + EXPECT_EQ(0x12345678u, value); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a normal lpf_put case. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_put_normal) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_put_normal_unsafemode.c b/tests/functional/func_bsplib_put_normal_unsafemode.c deleted file mode 100644 index ebce8aa7..00000000 --- a/tests/functional/func_bsplib_put_normal_unsafemode.c +++ /dev/null @@ -1,96 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - int i; - const int n = 10; - uint32_t memory[n]; - uint32_t *array = memory + 2; - int length = 5; - rc = bsplib_push_reg(bsplib, array, length ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - uint32_t value = 0x12345678; - rc = bsplib_put(bsplib, - ( bsplib_pid(bsplib) + 1 ) % bsplib_nprocs(bsplib), - &value, array, 0, - sizeof( value ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_pop_reg(bsplib, array ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - memory[i] = 0xAAAAAAAAu; - } - - for ( i = 0; i < n; ++i ) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - EXPECT_EQ( "%u", 0x12345678u, value ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - for ( i = 0; i < n; ++i ) - { - if ( 2 != i ) - { - EXPECT_EQ( "%u", 0xAAAAAAAAu, memory[i] ); - } - else - { - EXPECT_EQ( "%u", 0x12345678u, memory[i] ); - } - } - EXPECT_EQ( "%u", 0x12345678u, value ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests a normal lpf_put case in unsafe mode. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_put_normal_unsafemode) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_put_normal_unsafemode.cpp b/tests/functional/func_bsplib_put_normal_unsafemode.cpp new file mode 100644 index 00000000..d27b4d69 --- /dev/null +++ b/tests/functional/func_bsplib_put_normal_unsafemode.cpp @@ -0,0 +1,84 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + int i; + const int n = 10; + uint32_t memory[n]; + uint32_t *array = memory + 2; + int length = 5; + rc = bsplib_push_reg(bsplib, array, length); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + uint32_t value = 0x12345678; + rc = bsplib_put(bsplib, (bsplib_pid(bsplib) + 1) % bsplib_nprocs(bsplib), + &value, array, 0, sizeof(value)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_pop_reg(bsplib, array); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + memory[i] = 0xAAAAAAAAu; + } + + for (i = 0; i < n; ++i) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } + EXPECT_EQ(0x12345678u, value); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + if (2 != i) { + EXPECT_EQ(0xAAAAAAAAu, memory[i]); + } else { + EXPECT_EQ(0x12345678u, memory[i]); + } + } + EXPECT_EQ(0x12345678u, value); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests a normal lpf_put case in unsafe mode. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_put_normal_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_empty_tag.c b/tests/functional/func_bsplib_send_empty_tag.c deleted file mode 100644 index 78f64daf..00000000 --- a/tests/functional/func_bsplib_send_empty_tag.c +++ /dev/null @@ -1,136 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t oldTagSize = 0; - size_t nmsg = -1, bytes = -1; - size_t status = -1; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - // assert that messages queue is empty - rc = bsplib_get_tag(bsplib, &status, NULL ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) - 1, status ); - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) 0, nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0, bytes ); - - // send two messages - const int x = 0x12345678; - const int y = 0x87654321; - rc = bsplib_send(bsplib, 0, &x, &y, sizeof( y ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_send(bsplib, 0, &x, &y, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // message queue is still empty, of course - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) 0, nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0, bytes ); - - // Barrier synchronization - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == - 0 ? bsplib_nprocs(bsplib) * sizeof( y ) : 0 ), bytes ); - - int z = 0; - size_t nMessages = 0; - while ( rc = bsplib_get_tag(bsplib, &status, &z ), status != (size_t) -1 ) - { - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%d", 0, z ); - EXPECT_NE( "%zu", ( size_t ) -1, status ); - - // before the move qsize should return - size_t msgs2 = -1; - size_t bytes2 = -1; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, 2 * bsplib_nprocs(bsplib) - nMessages ); - - // dequeue the message - int a = -1; - rc = bsplib_move(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - ++nMessages; - - // after the move the values returned by qsize decrease - bytes -= status; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, 2 * bsplib_nprocs(bsplib) - nMessages ); - - if ( status == sizeof( y ) ) - { - EXPECT_EQ( "%d", y, a ); - } - else - { - EXPECT_EQ( "%zu", ( size_t ) 0, status ); - EXPECT_EQ( "%d", -1, a ); - } - } - - - EXPECT_EQ( "%u", - bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0, - (lpf_pid_t) nMessages ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests sending messages with empty tag - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_empty_tag ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_empty_tag.cpp b/tests/functional/func_bsplib_send_empty_tag.cpp new file mode 100644 index 00000000..d61d3317 --- /dev/null +++ b/tests/functional/func_bsplib_send_empty_tag.cpp @@ -0,0 +1,127 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t oldTagSize = 0; + size_t nmsg = -1, bytes = -1; + size_t status = -1; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + // assert that messages queue is empty + rc = bsplib_get_tag(bsplib, &status, NULL); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)-1, status); + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)0, nmsg); + EXPECT_EQ((size_t)0, bytes); + + // send two messages + const int x = 0x12345678; + const int y = 0x87654321; + rc = bsplib_send(bsplib, 0, &x, &y, sizeof(y)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_send(bsplib, 0, &x, &y, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // message queue is still empty, of course + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)0, nmsg); + EXPECT_EQ((size_t)0, bytes); + + // Barrier synchronization + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ( + (size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) * sizeof(y) : 0), + bytes); + + int z = 0; + size_t nMessages = 0; + while (rc = bsplib_get_tag(bsplib, &status, &z), status != (size_t)-1) { + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(0, z); + EXPECT_NE((size_t)-1, status); + + // before the move qsize should return + size_t msgs2 = -1; + size_t bytes2 = -1; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, 2 * bsplib_nprocs(bsplib) - nMessages); + + // dequeue the message + int a = -1; + rc = bsplib_move(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + ++nMessages; + + // after the move the values returned by qsize decrease + bytes -= status; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, 2 * bsplib_nprocs(bsplib) - nMessages); + + if (status == sizeof(y)) { + EXPECT_EQ(y, a); + } else { + EXPECT_EQ((size_t)0, status); + EXPECT_EQ(-1, a); + } + } + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0, + (lpf_pid_t)nMessages); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests sending messages with empty tag + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_empty_tag) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_non_empty_tag.c b/tests/functional/func_bsplib_send_non_empty_tag.c deleted file mode 100644 index a003d2c8..00000000 --- a/tests/functional/func_bsplib_send_non_empty_tag.c +++ /dev/null @@ -1,139 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t oldTagSize = -1; - size_t nmsg = -1, bytes = -1; - size_t status = -1; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // assert that messages queue is empty - rc = bsplib_get_tag(bsplib, &status, NULL ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) - 1, status ); - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) 0, nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0, bytes ); - - // send two messages - const int x = 0x12345678; - const int y = 0x87654321; - rc = bsplib_send(bsplib, 0, &x, &y, sizeof( y ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - rc = bsplib_send(bsplib, 0, &x, &y, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - // message queue is still empty, of course - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) 0, nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0, bytes ); - - // Barrier synchronization - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == - 0 ? bsplib_nprocs(bsplib) * sizeof( y ) : 0 ), bytes ); - - int z = 0; - size_t nMessages = 0; - while ( rc = bsplib_get_tag(bsplib, &status, &z ), status != (size_t) -1 ) - { - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", x, z ); - EXPECT_NE( "%zu", ( size_t ) -1, status ); - - // before the move qsize should return - size_t msgs2 = -1; - size_t bytes2 = -1; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, 2 * bsplib_nprocs(bsplib) - nMessages ); - - // dequeue the message - int a = -1; - rc = bsplib_move(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - ++nMessages; - - // after the move the values returned by qsize decrease - bytes -= status; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, 2 * bsplib_nprocs(bsplib) - nMessages ); - - if ( status == sizeof( y ) ) - { - EXPECT_EQ( "%d", y, a ); - } - else - { - EXPECT_EQ( "%zu", ( size_t ) 0, status ); - EXPECT_EQ( "%d", -1, a ); - } - } - - EXPECT_EQ( "%u", - bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0, - (unsigned) nMessages ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests bsplib_send with non empty tag - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_non_empty_tag ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_non_empty_tag.cpp b/tests/functional/func_bsplib_send_non_empty_tag.cpp new file mode 100644 index 00000000..b10db62c --- /dev/null +++ b/tests/functional/func_bsplib_send_non_empty_tag.cpp @@ -0,0 +1,131 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t oldTagSize = -1; + size_t nmsg = -1, bytes = -1; + size_t status = -1; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // assert that messages queue is empty + rc = bsplib_get_tag(bsplib, &status, NULL); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)-1, status); + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)0, nmsg); + EXPECT_EQ((size_t)0, bytes); + + // send two messages + const int x = 0x12345678; + const int y = 0x87654321; + rc = bsplib_send(bsplib, 0, &x, &y, sizeof(y)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + rc = bsplib_send(bsplib, 0, &x, &y, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + // message queue is still empty, of course + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)0, nmsg); + EXPECT_EQ((size_t)0, bytes); + + // Barrier synchronization + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ( + (size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) * sizeof(y) : 0), + bytes); + + int z = 0; + size_t nMessages = 0; + while (rc = bsplib_get_tag(bsplib, &status, &z), status != (size_t)-1) { + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(x, z); + EXPECT_NE((size_t)-1, status); + + // before the move qsize should return + size_t msgs2 = -1; + size_t bytes2 = -1; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, 2 * bsplib_nprocs(bsplib) - nMessages); + + // dequeue the message + int a = -1; + rc = bsplib_move(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + ++nMessages; + + // after the move the values returned by qsize decrease + bytes -= status; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, 2 * bsplib_nprocs(bsplib) - nMessages); + + if (status == sizeof(y)) { + EXPECT_EQ(y, a); + } else { + EXPECT_EQ((size_t)0, status); + EXPECT_EQ(-1, a); + } + } + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? 2 * bsplib_nprocs(bsplib) : 0, + (unsigned)nMessages); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests bsplib_send with non empty tag + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_non_empty_tag) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_none.c b/tests/functional/func_bsplib_send_none.c deleted file mode 100644 index 14314afe..00000000 --- a/tests/functional/func_bsplib_send_none.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t nmsg = -1, bytes = -1; - size_t oldTagSize = 0; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", (size_t) 0, nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0 , bytes ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests an empty bsmp queue - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_none) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_none.cpp b/tests/functional/func_bsplib_send_none.cpp new file mode 100644 index 00000000..d0163359 --- /dev/null +++ b/tests/functional/func_bsplib_send_none.cpp @@ -0,0 +1,60 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t nmsg = -1, bytes = -1; + size_t oldTagSize = 0; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)0, nmsg); + EXPECT_EQ((size_t)0, bytes); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests an empty bsmp queue + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_none) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_null.c b/tests/functional/func_bsplib_send_null.c deleted file mode 100644 index 30bfbda7..00000000 --- a/tests/functional/func_bsplib_send_null.c +++ /dev/null @@ -1,143 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t nmsg = -1, bytes = -1; - size_t status = -1; - size_t oldTagSize = 0; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - const int x = 0x12345678; - //const int y = 0x87654321; - const int z = 0x12344321; - - rc = bsplib_send(bsplib, 0, NULL, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_send(bsplib, 1, &z, NULL, 0 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == - 0 ? bsplib_nprocs(bsplib) * sizeof( x ) : 0 ), bytes ); - - int tag = -1; - size_t nMessages = 0; - while ( rc = bsplib_get_tag(bsplib, &status, &tag ), status != (size_t) -1 ) - { - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - EXPECT_EQ( "%d", -1, tag ); - EXPECT_NE( "%zu", ( size_t ) -1, status ); - - int a = -1; - rc = bsplib_move(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - ++nMessages; - - // after the move the values returned by qsize decrease - bytes -= status; - size_t msgs2 = -1, bytes2 = -1; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, bsplib_nprocs(bsplib) - nMessages ); - EXPECT_EQ( "%zu", ( size_t ) sizeof( x ), status ); - EXPECT_EQ( "%d", x, a ); - } - - EXPECT_EQ( "%u", - bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0, - (unsigned) nMessages ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 1 ? bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) 0, bytes ); - - tag = -1; - nMessages = 0; - while ( rc = bsplib_get_tag(bsplib, &status, &tag ), status != (size_t) -1 ) - { - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%d", z, tag ); - EXPECT_NE( "%zu", ( size_t ) -1, status ); - - int a = -1; - rc = bsplib_move(bsplib, &a, sizeof( a ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - ++nMessages; - - // after the move the values returned by qsize decrease - bytes -= status; - size_t msgs2 = -1, bytes2 = -1; - rc = bsplib_qsize(bsplib, &msgs2, &bytes2 ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", bytes, bytes2 ); - EXPECT_EQ( "%zu", msgs2, bsplib_nprocs(bsplib) - nMessages ); - EXPECT_EQ( "%zu", ( size_t ) 0, status ); - EXPECT_EQ( "%d", -1, a ); - } - - EXPECT_EQ( "%u", - bsplib_pid(bsplib) == 1 ? bsplib_nprocs(bsplib) : 0, - (unsigned) nMessages ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests bsplib_send with an empty message - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_null ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_null.cpp b/tests/functional/func_bsplib_send_null.cpp new file mode 100644 index 00000000..63723d5b --- /dev/null +++ b/tests/functional/func_bsplib_send_null.cpp @@ -0,0 +1,136 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t nmsg = -1, bytes = -1; + size_t status = -1; + size_t oldTagSize = 0; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + const int x = 0x12345678; + // const int y = 0x87654321; + const int z = 0x12344321; + + rc = bsplib_send(bsplib, 0, NULL, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_send(bsplib, 1, &z, NULL, 0); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ( + (size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) * sizeof(x) : 0), + bytes); + + int tag = -1; + size_t nMessages = 0; + while (rc = bsplib_get_tag(bsplib, &status, &tag), status != (size_t)-1) { + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + EXPECT_EQ(-1, tag); + EXPECT_NE((size_t)-1, status); + + int a = -1; + rc = bsplib_move(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + ++nMessages; + + // after the move the values returned by qsize decrease + bytes -= status; + size_t msgs2 = -1, bytes2 = -1; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, bsplib_nprocs(bsplib) - nMessages); + EXPECT_EQ((size_t)sizeof(x), status); + EXPECT_EQ(x, a); + } + + EXPECT_EQ(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0, + (unsigned)nMessages); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 1 ? bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ((size_t)0, bytes); + + tag = -1; + nMessages = 0; + while (rc = bsplib_get_tag(bsplib, &status, &tag), status != (size_t)-1) { + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(z, tag); + EXPECT_NE((size_t)-1, status); + + int a = -1; + rc = bsplib_move(bsplib, &a, sizeof(a)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + ++nMessages; + + // after the move the values returned by qsize decrease + bytes -= status; + size_t msgs2 = -1, bytes2 = -1; + rc = bsplib_qsize(bsplib, &msgs2, &bytes2); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ(bytes, bytes2); + EXPECT_EQ(msgs2, bsplib_nprocs(bsplib) - nMessages); + EXPECT_EQ((size_t)0, status); + EXPECT_EQ(-1, a); + } + + EXPECT_EQ(bsplib_pid(bsplib) == 1 ? bsplib_nprocs(bsplib) : 0, + (unsigned)nMessages); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests bsplib_send with an empty message + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_null) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_one.c b/tests/functional/func_bsplib_send_one.c deleted file mode 100644 index 43dee2fe..00000000 --- a/tests/functional/func_bsplib_send_one.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t nmsg = -1, bytes = -1; - size_t oldTagSize = 0; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - const int x = 0x12345678; - //const int y = 0x87654321; - - rc = bsplib_send(bsplib, 0, NULL, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == - 0 ? bsplib_nprocs(bsplib) * sizeof( x ) : 0 ), bytes ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests bsplib_send with just one message - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_one) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_one.cpp b/tests/functional/func_bsplib_send_one.cpp new file mode 100644 index 00000000..72db1e79 --- /dev/null +++ b/tests/functional/func_bsplib_send_one.cpp @@ -0,0 +1,69 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t nmsg = -1, bytes = -1; + size_t oldTagSize = 0; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + const int x = 0x12345678; + // const int y = 0x87654321; + + rc = bsplib_send(bsplib, 0, NULL, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ( + (size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) * sizeof(x) : 0), + bytes); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests bsplib_send with just one message + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_one) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_send_one_unsafemode.c b/tests/functional/func_bsplib_send_one_unsafemode.c deleted file mode 100644 index 61b35ac0..00000000 --- a/tests/functional/func_bsplib_send_one_unsafemode.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 0, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = sizeof( int ); - size_t nmsg = -1, bytes = -1; - size_t oldTagSize = 0; - - // set tag size which go in effect next super-step - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%zu", ( size_t ) 0, oldTagSize ); - - const int x = 0x12345678; - //const int y = 0x87654321; - - rc = bsplib_send(bsplib, 0, NULL, &x, sizeof( x ) ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - rc = bsplib_qsize(bsplib, &nmsg, &bytes ); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0 ), - nmsg ); - EXPECT_EQ( "%zu", ( size_t ) ( bsplib_pid(bsplib) == - 0 ? bsplib_nprocs(bsplib) * sizeof( x ) : 0 ), bytes ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests bsplib_send with just one message in unsafe mode - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_send_one_unsafemode) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_send_one_unsafemode.cpp b/tests/functional/func_bsplib_send_one_unsafemode.cpp new file mode 100644 index 00000000..ba221e4b --- /dev/null +++ b/tests/functional/func_bsplib_send_one_unsafemode.cpp @@ -0,0 +1,69 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 0, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = sizeof(int); + size_t nmsg = -1, bytes = -1; + size_t oldTagSize = 0; + + // set tag size which go in effect next super-step + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + const int x = 0x12345678; + // const int y = 0x87654321; + + rc = bsplib_send(bsplib, 0, NULL, &x, sizeof(x)); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + rc = bsplib_qsize(bsplib, &nmsg, &bytes); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + EXPECT_EQ((size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) : 0), + nmsg); + EXPECT_EQ( + (size_t)(bsplib_pid(bsplib) == 0 ? bsplib_nprocs(bsplib) * sizeof(x) : 0), + bytes); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests bsplib_send with just one message in unsafe mode + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_send_one_unsafemode) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_set_different_tag_size.c b/tests/functional/func_bsplib_set_different_tag_size.cpp similarity index 50% rename from tests/functional/func_bsplib_set_different_tag_size.c rename to tests/functional/func_bsplib_set_different_tag_size.cpp index 82cc9773..5c4b094d 100644 --- a/tests/functional/func_bsplib_set_different_tag_size.c +++ b/tests/functional/func_bsplib_set_different_tag_size.cpp @@ -15,39 +15,35 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" #include -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 0, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + bsplib_err_t rc = BSPLIB_SUCCESS; - size_t tagSize = bsplib_pid( bsplib ); - bsplib_set_tagsize( bsplib, tagSize ); - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_ERR_TAGSIZE_MISMATCH, rc ); + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 0, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + size_t tagSize = bsplib_pid(bsplib); + bsplib_set_tagsize(bsplib, tagSize); + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_TAGSIZE_MISMATCH, rc); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); } -/** +/** * \test Tests whether setting different tag sizes is detected * \pre P >= 2 * \return Exit code: 0 */ -TEST( func_bsplib_set_different_tag_size ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_bsplib_set_different_tag_size) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } - diff --git a/tests/functional/func_bsplib_set_tag_size.c b/tests/functional/func_bsplib_set_tag_size.c deleted file mode 100644 index e64957b8..00000000 --- a/tests/functional/func_bsplib_set_tag_size.c +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, (size_t) -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - size_t tagSize = 10, oldTagSize = -1; - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - - // test for the default tag size; - EXPECT_EQ( "%lu", (size_t) 0, oldTagSize ); - - // go back to the normal tag size - oldTagSize = bsplib_set_tagsize(bsplib, 0 ); - EXPECT_EQ( "%lu", (size_t) 0, oldTagSize ); - - tagSize = sizeof( int ); - oldTagSize = bsplib_set_tagsize(bsplib, tagSize ); - EXPECT_EQ( "%lu", (size_t) 0, oldTagSize ); - - rc = bsplib_sync(bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - oldTagSize = bsplib_set_tagsize(bsplib, 0 ); - EXPECT_EQ( "%lu", sizeof( int ), oldTagSize ); - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); -} - -/** - * \test Tests setting tag size - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_bsplib_set_tag_size ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_set_tag_size.cpp b/tests/functional/func_bsplib_set_tag_size.cpp new file mode 100644 index 00000000..5b70637e --- /dev/null +++ b/tests/functional/func_bsplib_set_tag_size.cpp @@ -0,0 +1,64 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, (size_t)-1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + size_t tagSize = 10, oldTagSize = -1; + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + + // test for the default tag size; + EXPECT_EQ((size_t)0, oldTagSize); + + // go back to the normal tag size + oldTagSize = bsplib_set_tagsize(bsplib, 0); + EXPECT_EQ((size_t)0, oldTagSize); + + tagSize = sizeof(int); + oldTagSize = bsplib_set_tagsize(bsplib, tagSize); + EXPECT_EQ((size_t)0, oldTagSize); + + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + oldTagSize = bsplib_set_tagsize(bsplib, 0); + EXPECT_EQ(sizeof(int), oldTagSize); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); +} + +/** + * \test Tests setting tag size + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_bsplib_set_tag_size) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_sync_except_p0.c b/tests/functional/func_bsplib_sync_except_p0.c deleted file mode 100644 index 2109d141..00000000 --- a/tests/functional/func_bsplib_sync_except_p0.c +++ /dev/null @@ -1,52 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 3, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); - - if (pid!=0) { - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_ERR_FATAL, rc ); - } - - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_ERR_FATAL, rc ); -} - -/** - * \test Test whether lpf_sync will detect sync mismatch when all except pid 0 sync - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_bsplib_sync_except_p0 ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_bsplib_sync_except_p0.cpp b/tests/functional/func_bsplib_sync_except_p0.cpp new file mode 100644 index 00000000..fa494eb5 --- /dev/null +++ b/tests/functional/func_bsplib_sync_except_p0.cpp @@ -0,0 +1,47 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + bsplib_err_t rc = BSPLIB_SUCCESS; + + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 3, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); + + if (pid != 0) { + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_FATAL, rc); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_ERR_FATAL, rc); +} + +/** + * \test Test whether lpf_sync will detect sync mismatch when all except pid 0 + * sync \pre P >= 2 \return Exit code: 0 + */ +TEST(API, func_bsplib_sync_except_p0) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_bsplib_sync_only_p0.c b/tests/functional/func_bsplib_sync_only_p0.cpp similarity index 53% rename from tests/functional/func_bsplib_sync_only_p0.c rename to tests/functional/func_bsplib_sync_only_p0.cpp index a66e3aa4..b3ad6490 100644 --- a/tests/functional/func_bsplib_sync_only_p0.c +++ b/tests/functional/func_bsplib_sync_only_p0.cpp @@ -15,38 +15,34 @@ * limitations under the License. */ -#include +#include "gtest/gtest.h" #include -#include "Test.h" +#include -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, (size_t) -1, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + bsplib_err_t rc = BSPLIB_SUCCESS; - if (pid==0) { - rc = bsplib_sync( bsplib ); - EXPECT_EQ( "%d", BSPLIB_ERR_FATAL, rc ); - } + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, (size_t)-1, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_ERR_FATAL, rc ); + if (pid == 0) { + rc = bsplib_sync(bsplib); + EXPECT_EQ(BSPLIB_ERR_FATAL, rc); + } + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_ERR_FATAL, rc); } -/** +/** * \test Test whether lpf_sync will detect sync mismatch when only pid 0 syncs * \pre P >= 2 * \return Exit code: 0 */ -TEST( func_bsplib_sync_only_p0 ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS , rc ); - return 0; +TEST(API, func_bsplib_sync_only_p0) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } - diff --git a/tests/functional/func_bsplib_time.c b/tests/functional/func_bsplib_time.cpp similarity index 51% rename from tests/functional/func_bsplib_time.c rename to tests/functional/func_bsplib_time.cpp index fa650d87..d4ae2d70 100644 --- a/tests/functional/func_bsplib_time.c +++ b/tests/functional/func_bsplib_time.cpp @@ -15,38 +15,34 @@ * limitations under the License. */ -#include +#include "gtest/gtest.h" #include -#include "Test.h" +#include -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec - bsplib_err_t rc = BSPLIB_SUCCESS; - - bsplib_t bsplib; - rc = bsplib_create( lpf, pid, nprocs, 1, 3, &bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + bsplib_err_t rc = BSPLIB_SUCCESS; - double t0 = bsplib_time( bsplib ); - EXPECT_LT( "%f", 0.0, t0); - double t1 = bsplib_time( bsplib ); - EXPECT_LT( "%f", t0, t1); + bsplib_t bsplib; + rc = bsplib_create(lpf, pid, nprocs, 1, 3, &bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); - rc = bsplib_destroy( bsplib); - EXPECT_EQ( "%d", BSPLIB_SUCCESS, rc ); + double t0 = bsplib_time(bsplib); + EXPECT_LT(0.0, t0); + double t1 = bsplib_time(bsplib); + EXPECT_LT(t0, t1); + + rc = bsplib_destroy(bsplib); + EXPECT_EQ(BSPLIB_SUCCESS, rc); } -/** +/** * \test Test lpf_time_ * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_bsplib_time ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_bsplib_time) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } - diff --git a/tests/functional/func_lpf_deregister_parallel_multiple.c b/tests/functional/func_lpf_deregister_parallel_multiple.c deleted file mode 100644 index c38b75c1..00000000 --- a/tests/functional/func_lpf_deregister_parallel_multiple.c +++ /dev/null @@ -1,89 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 8 , maxRegs = 4; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[8] = "abcd"; - lpf_memslot_t slots[4]; - - // register 4 entries - size_t i; - int j; - - for (j = 0; j < 1000; ++j) - { - for ( i = 0; i < maxRegs; ++i) - { - rc = lpf_register_global( lpf, &buffer[i*2], sizeof(buffer[0])*2, &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - EXPECT_STREQ( 4, "abcd", buffer ); - - for (i = 0; i < maxRegs; ++i) - { - rc = lpf_put( lpf, slots[i], 0u, - (pid+i)%nprocs, slots[i], 1u, sizeof(buffer[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - EXPECT_STREQ( 4, "aacc", buffer ); - - for ( i = 0 ; i < maxRegs; ++i) - { - rc = lpf_deregister( lpf, slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - // reset to previous state - buffer[1] = 'b'; - buffer[3] = 'd'; - } - -} - -/** - * \test Allocate some registers (globally), communicate, delete all registers, and start again. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_deregister_parallel_multiple ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_lpf_deregister_parallel_multiple.cpp b/tests/functional/func_lpf_deregister_parallel_multiple.cpp new file mode 100644 index 00000000..3831e1cb --- /dev/null +++ b/tests/functional/func_lpf_deregister_parallel_multiple.cpp @@ -0,0 +1,80 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 8, maxRegs = 4; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char buffer[8] = "abcd"; + lpf_memslot_t slots[4]; + + // register 4 entries + size_t i; + int j; + + for (j = 0; j < 1000; ++j) { + for (i = 0; i < maxRegs; ++i) { + rc = lpf_register_global(lpf, &buffer[i * 2], sizeof(buffer[0]) * 2, + &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + EXPECT_STREQ("abcd", buffer); + + for (i = 0; i < maxRegs; ++i) { + rc = lpf_put(lpf, slots[i], 0u, (pid + i) % nprocs, slots[i], 1u, + sizeof(buffer[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + EXPECT_STREQ("aacc", buffer); + + for (i = 0; i < maxRegs; ++i) { + rc = lpf_deregister(lpf, slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + // reset to previous state + buffer[1] = 'b'; + buffer[3] = 'd'; + } +} + +/** + * \test Allocate some registers (globally), communicate, delete all registers, + * and start again. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_deregister_parallel_multiple) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_deregister_parallel_single.c b/tests/functional/func_lpf_deregister_parallel_single.c deleted file mode 100644 index 80a0addc..00000000 --- a/tests/functional/func_lpf_deregister_parallel_single.c +++ /dev/null @@ -1,77 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 4 , maxRegs = 4; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - int x = 1, y = 2, z = 3; - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t zslot = LPF_INVALID_MEMSLOT; - - rc = lpf_register_local( lpf, &x, sizeof(x), &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, &y, sizeof(y), &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, &z, sizeof(z), &zslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( (pid | 0x1) < nprocs ) - { - rc = lpf_put( lpf, yslot, 0, pid ^ 0x1, zslot, 0, sizeof(y), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", (pid|0x1) < nprocs ? 2 : 3, z ); - - lpf_deregister( lpf, yslot ); - lpf_deregister( lpf, zslot ); -} - -/** - * \test Allocate some registers, deregister a local register, and communicate - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_deregister_parallel_single ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_deregister_parallel_single.cpp b/tests/functional/func_lpf_deregister_parallel_single.cpp new file mode 100644 index 00000000..82b635a0 --- /dev/null +++ b/tests/functional/func_lpf_deregister_parallel_single.cpp @@ -0,0 +1,74 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 4, maxRegs = 4; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + int x = 1, y = 2, z = 3; + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t zslot = LPF_INVALID_MEMSLOT; + + rc = lpf_register_local(lpf, &x, sizeof(x), &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, &y, sizeof(y), &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, &z, sizeof(z), &zslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if ((pid | 0x1) < nprocs) { + rc = + lpf_put(lpf, yslot, 0, pid ^ 0x1, zslot, 0, sizeof(y), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ((pid | 0x1) < nprocs ? 2 : 3, z); + + lpf_deregister(lpf, yslot); + lpf_deregister(lpf, zslot); +} + +/** + * \test Allocate some registers, deregister a local register, and communicate + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_deregister_parallel_single) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.c b/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.c deleted file mode 100644 index 569eed93..00000000 --- a/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.c +++ /dev/null @@ -1,121 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void function_1(void) {} -void function_2(int a, long b, double c, float d) -{ (void) a; (void) b; (void) c; (void) d; } - - -void spmd1( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_EQ( "%d", nprocs, 2 ); - - if (0 == pid) - { - EXPECT_EQ( "%zd", sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", sizeof(int), args.output_size ); - int n = (* (int *) args.input); - EXPECT_EQ( "%d", 4, n ); - * (int * ) args.output = 1 ; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } - EXPECT_EQ( "%zd", (size_t) 1 , args.f_size ); - EXPECT_EQ( "%p", (lpf_func_t) function_1, args.f_symbols[0] ); //note: function pointers cannot be formatted in ANSI C -} - -void spmd2( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_EQ( "%d", nprocs, 2 ); - - if (0 == pid) - { - EXPECT_EQ( "%zd", sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", sizeof(int), args.output_size ); - int n = (* (int *) args.input) ; - EXPECT_EQ( "%d", 3, n ); - * (int * ) args.output = 2; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } - EXPECT_EQ( "%zd", (size_t) 1 , args.f_size ); - EXPECT_EQ( "%p", (lpf_func_t) function_2, args.f_symbols[0] ); //note: function pointers cannot be formatted in ANSI C -} - - - - -/** - * \test Test two lpf_exec() calls with single argument on two processors - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_multiple_call_single_arg_dual_proc ) -{ - int input[2] = { 4, 3}; - int output[2] = { -1, -1 }; - lpf_func_t fps[2] = { (lpf_func_t) &function_1, (lpf_func_t) &function_2 }; - lpf_err_t rc = LPF_SUCCESS; - lpf_args_t args; - args.input = &input[0]; - args.input_size = sizeof(int); - args.output = &output[0]; - args.output_size = sizeof(int); - args.f_symbols = fps; - args.f_size = 1; - - rc = lpf_exec( LPF_ROOT, 2, &spmd1, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - args.input = &input[1]; - args.input_size = sizeof(int); - args.output = &output[1]; - args.output_size = sizeof(int); - args.f_symbols = fps + 1; - args.f_size = 1; - - rc = lpf_exec( LPF_ROOT, 2, &spmd2, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - int i; - for (i = 0; i < 2; ++i) - { - int m = input[i]; - EXPECT_EQ( "%d", 4-i, m ); - int n = output[i]; - EXPECT_EQ( "%d", i+1, n ); - } - return 0; -} diff --git a/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.cpp b/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.cpp new file mode 100644 index 00000000..587c7196 --- /dev/null +++ b/tests/functional/func_lpf_exec_multiple_call_single_arg_dual_proc.cpp @@ -0,0 +1,114 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void function_1(void) {} +void function_2(int a, long b, double c, float d) { + (void)a; + (void)b; + (void)c; + (void)d; +} + +void spmd1(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + + EXPECT_EQ(nprocs, 2); + + if (0 == pid) { + EXPECT_EQ(sizeof(int), args.input_size); + EXPECT_EQ(sizeof(int), args.output_size); + int n = (*(int *)args.input); + EXPECT_EQ(4, n); + *(int *)args.output = 1; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } + EXPECT_EQ((size_t)1, args.f_size); + EXPECT_EQ((lpf_func_t)function_1, + args.f_symbols[0]); // note: function pointers cannot be formatted + // in ANSI C +} + +void spmd2(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + + EXPECT_EQ(nprocs, 2); + + if (0 == pid) { + EXPECT_EQ(sizeof(int), args.input_size); + EXPECT_EQ(sizeof(int), args.output_size); + int n = (*(int *)args.input); + EXPECT_EQ(3, n); + *(int *)args.output = 2; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } + EXPECT_EQ((size_t)1, args.f_size); + EXPECT_EQ((lpf_func_t)function_2, + args.f_symbols[0]); // note: function pointers cannot be formatted + // in ANSI C +} + +/** + * \test Test two lpf_exec() calls with single argument on two processors + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_exec_multiple_call_single_arg_dual_proc) { + int input[2] = {4, 3}; + int output[2] = {-1, -1}; + lpf_func_t fps[2] = {(lpf_func_t)&function_1, (lpf_func_t)&function_2}; + lpf_err_t rc = LPF_SUCCESS; + lpf_args_t args; + args.input = &input[0]; + args.input_size = sizeof(int); + args.output = &output[0]; + args.output_size = sizeof(int); + args.f_symbols = fps; + args.f_size = 1; + + rc = lpf_exec(LPF_ROOT, 2, &spmd1, args); + EXPECT_EQ(LPF_SUCCESS, rc); + + args.input = &input[1]; + args.input_size = sizeof(int); + args.output = &output[1]; + args.output_size = sizeof(int); + args.f_symbols = fps + 1; + args.f_size = 1; + + rc = lpf_exec(LPF_ROOT, 2, &spmd2, args); + EXPECT_EQ(LPF_SUCCESS, rc); + + int i; + for (i = 0; i < 2; ++i) { + int m = input[i]; + EXPECT_EQ(4 - i, m); + int n = output[i]; + EXPECT_EQ(i + 1, n); + } +} diff --git a/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.c b/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.c deleted file mode 100644 index ac74b5fb..00000000 --- a/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.c +++ /dev/null @@ -1,127 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void function_1() {} -void function_2() {} -void function_3() {} - -void spmd2( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_LE( "%d", nprocs, 2); - - if ( 0 == pid ) - { - EXPECT_EQ( "%zd", sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", sizeof(int), args.output_size ); - - int n = * (int * ) args.input; - EXPECT_LE( "%d", 10, n ); - EXPECT_LT( "%d", n, 10 + 2); - - * (int * ) args.output = 9; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } - - EXPECT_EQ( "%zd", (size_t) 2, args.f_size ); - EXPECT_EQ( "%p", &function_2, args.f_symbols[0] ); - EXPECT_EQ( "%p", &function_3, args.f_symbols[1] ); -} - - - -void spmd1( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - EXPECT_LE( "%d", nprocs, 2); - - if ( 0 == pid ) - { - EXPECT_EQ( "%zd", sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", sizeof(int), args.output_size ); - - int n = * (int * ) args.input; - EXPECT_EQ( "%d", 3, n ); - EXPECT_EQ( "%d", -1, * (int *) args.output); - - * (int * ) args.output = 7; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } - - EXPECT_EQ( "%zd", (size_t) 3, args.f_size ); - EXPECT_EQ( "%p", &function_1, args.f_symbols[0] ); - EXPECT_EQ( "%p", &function_2, args.f_symbols[1] ); - EXPECT_EQ( "%p", &function_3, args.f_symbols[2] ); - - int x = 10 + pid; - lpf_args_t newArgs; - newArgs.input = &x; - newArgs.input_size = sizeof(x); - int number = -1; - newArgs.output = &number; - newArgs.output_size = sizeof(number); - newArgs.f_symbols = args.f_symbols + 1; - newArgs.f_size = args.f_size - 1; - - lpf_err_t rc = lpf_exec( lpf, 2, &spmd2, newArgs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 9, number ); -} - - - -/** - * \test Test nested lpf_exec() call with single argument on two processors. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_nested_call_single_arg_dual_proc ) -{ - lpf_err_t rc = LPF_SUCCESS; - int three = 3; - int number = -1; - void (*function_pointers[3])() = { &function_1, &function_2, &function_3 } ; - lpf_args_t args; - args.input = &three; - args.input_size = sizeof(three); - args.output = &number; - args.output_size = sizeof(number); - args.f_symbols = function_pointers; - args.f_size = sizeof(function_pointers)/sizeof(function_pointers[0]); - - rc = lpf_exec( LPF_ROOT, 2, &spmd1, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - EXPECT_EQ( "%d", number, 7 ); - return 0; -} diff --git a/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.cpp b/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.cpp new file mode 100644 index 00000000..0ce67642 --- /dev/null +++ b/tests/functional/func_lpf_exec_nested_call_single_arg_dual_proc.cpp @@ -0,0 +1,113 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void function_1() {} +void function_2() {} +void function_3() {} + +void spmd2(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + + EXPECT_LE(nprocs, 2); + + if (0 == pid) { + EXPECT_EQ(sizeof(int), args.input_size); + EXPECT_EQ(sizeof(int), args.output_size); + + int n = *(int *)args.input; + EXPECT_LE(10, n); + EXPECT_LT(n, 10 + 2); + + *(int *)args.output = 9; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } + + EXPECT_EQ((size_t)2, args.f_size); + EXPECT_EQ(&function_2, args.f_symbols[0]); + EXPECT_EQ(&function_3, args.f_symbols[1]); +} + +void spmd1(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + EXPECT_LE(nprocs, 2); + + if (0 == pid) { + EXPECT_EQ(sizeof(int), args.input_size); + EXPECT_EQ(sizeof(int), args.output_size); + + int n = *(int *)args.input; + EXPECT_EQ(3, n); + EXPECT_EQ(-1, *(int *)args.output); + + *(int *)args.output = 7; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } + + EXPECT_EQ((size_t)3, args.f_size); + EXPECT_EQ(&function_1, args.f_symbols[0]); + EXPECT_EQ(&function_2, args.f_symbols[1]); + EXPECT_EQ(&function_3, args.f_symbols[2]); + + int x = 10 + pid; + lpf_args_t newArgs; + newArgs.input = &x; + newArgs.input_size = sizeof(x); + int number = -1; + newArgs.output = &number; + newArgs.output_size = sizeof(number); + newArgs.f_symbols = args.f_symbols + 1; + newArgs.f_size = args.f_size - 1; + + lpf_err_t rc = lpf_exec(lpf, 2, &spmd2, newArgs); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(9, number); +} + +/** + * \test Test nested lpf_exec() call with single argument on two processors. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_exec_nested_call_single_arg_dual_proc) { + lpf_err_t rc = LPF_SUCCESS; + int three = 3; + int number = -1; + void (*function_pointers[3])() = {&function_1, &function_2, &function_3}; + lpf_args_t args; + args.input = &three; + args.input_size = sizeof(three); + args.output = &number; + args.output_size = sizeof(number); + args.f_symbols = function_pointers; + args.f_size = sizeof(function_pointers) / sizeof(function_pointers[0]); + + rc = lpf_exec(LPF_ROOT, 2, &spmd1, args); + EXPECT_EQ(LPF_SUCCESS, rc); + EXPECT_EQ(number, 7); +} diff --git a/tests/functional/func_lpf_exec_single_call_no_arg_max_proc.c b/tests/functional/func_lpf_exec_single_call_no_arg_max_proc.cpp similarity index 50% rename from tests/functional/func_lpf_exec_single_call_no_arg_max_proc.c rename to tests/functional/func_lpf_exec_single_call_no_arg_max_proc.cpp index 7b1ecf6d..84978761 100644 --- a/tests/functional/func_lpf_exec_single_call_no_arg_max_proc.c +++ b/tests/functional/func_lpf_exec_single_call_no_arg_max_proc.cpp @@ -15,34 +15,27 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_LE( "%u", (lpf_pid_t) 1, nprocs ); - EXPECT_LE( "%u", (lpf_pid_t) 0, pid ); - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); + EXPECT_LE((lpf_pid_t)1, nprocs); + EXPECT_LE((lpf_pid_t)0, pid); + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); } - -/** - * \test Test single lpf_exec() call without arguments on maximum number of processes - * \pre P >= 1 - * \return Exit code: 0 +/** + * \test Test single lpf_exec() call without arguments on maximum number of + * processes \pre P >= 1 \return Exit code: 0 */ -TEST( func_lpf_exec_single_call_no_arg_max_proc ) -{ - lpf_err_t rc = LPF_SUCCESS ; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_exec_single_call_no_arg_max_proc) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/func_lpf_exec_single_call_no_arg_single_proc.c b/tests/functional/func_lpf_exec_single_call_no_arg_single_proc.cpp similarity index 54% rename from tests/functional/func_lpf_exec_single_call_no_arg_single_proc.c rename to tests/functional/func_lpf_exec_single_call_no_arg_single_proc.cpp index d5b433a1..b880565e 100644 --- a/tests/functional/func_lpf_exec_single_call_no_arg_single_proc.c +++ b/tests/functional/func_lpf_exec_single_call_no_arg_single_proc.cpp @@ -15,33 +15,27 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include #include -#include "Test.h" - - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - EXPECT_LE( "%ud", (lpf_pid_t) 1, nprocs ); - EXPECT_LE( "%ud", (lpf_pid_t) 0, pid ); - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + EXPECT_LE((lpf_pid_t)1, nprocs); + EXPECT_LE((lpf_pid_t)0, pid); + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); } - -/** +/** * \test Test single lpf_exec() call without arguments on a single processor * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_lpf_exec_single_call_no_arg_single_proc ) -{ - lpf_err_t rc = LPF_SUCCESS ; - rc = lpf_exec( LPF_ROOT, 1, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; +TEST(API, func_lpf_exec_single_call_no_arg_single_proc) { + lpf_err_t rc = LPF_SUCCESS; + rc = lpf_exec(LPF_ROOT, 1, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.c b/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.c deleted file mode 100644 index ce0dc926..00000000 --- a/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.c +++ /dev/null @@ -1,66 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - - - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_EQ( "%d", 2, nprocs ); - if ( 0 == pid ) - { - EXPECT_EQ( "%d", 1, * (int *) args.input ); - *(int *) args.output = 1; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } -} - - -/** - * \test Test single lpf_exec() call with a single arg on two processors - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_single_call_single_arg_dual_proc ) -{ - lpf_err_t rc = LPF_SUCCESS; - int input = 1; - int output = 3; - lpf_args_t args; - args.input = &input; - args.input_size = sizeof(int); - args.output = &output; - args.output_size = sizeof(int); - args.f_size = 0; - args.f_symbols = NULL; - rc = lpf_exec( LPF_ROOT, 2, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 1, output ); - return 0; -} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.cpp b/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.cpp new file mode 100644 index 00000000..a7be0c53 --- /dev/null +++ b/tests/functional/func_lpf_exec_single_call_single_arg_dual_proc.cpp @@ -0,0 +1,57 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + + EXPECT_EQ(2, nprocs); + if (0 == pid) { + EXPECT_EQ(1, *(int *)args.input); + *(int *)args.output = 1; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } +} + +/** + * \test Test single lpf_exec() call with a single arg on two processors + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_exec_single_call_single_arg_dual_proc) { + lpf_err_t rc = LPF_SUCCESS; + int input = 1; + int output = 3; + lpf_args_t args; + args.input = &input; + args.input_size = sizeof(int); + args.output = &output; + args.output_size = sizeof(int); + args.f_size = 0; + args.f_symbols = NULL; + rc = lpf_exec(LPF_ROOT, 2, &spmd, args); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(1, output); +} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.c b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.c deleted file mode 100644 index 131297e9..00000000 --- a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.c +++ /dev/null @@ -1,107 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - - - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - lpf_err_t rc = LPF_SUCCESS; - int a[2] = { pid, -1 }; - lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; - - EXPECT_LE( "%d", 2, nprocs ); - - if ( 0 == pid ) - { - EXPECT_EQ( "%zd", (size_t) sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", (size_t) sizeof(int), args.output_size ); - EXPECT_EQ( "%d", 1, * (int *) args.input ); - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - } - - // perform a simple communication - rc = lpf_resize_message_queue( lpf, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf , LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, &a, sizeof(a), &aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf , LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_put( lpf, aSlot, 0, (pid+1) % nprocs, aSlot, sizeof(a[0]), sizeof(a[0]), LPF_MSG_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf , LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", a[0], (int) pid ); - EXPECT_EQ( "%d", a[1], (int) ((pid+nprocs-1) % nprocs) ); - - rc = lpf_deregister( lpf, aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // now, all other processes except 'one' perform an extra sync. - if ( 1 != pid ) - { - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_ERR_FATAL, rc ); - } - - // It is still possible to send output through the args - if ( 0 == pid ) - { - *(int *) args.output = 2; - } -} - - -/** - * \test Test single lpf_exec() call with a single arg on all processors. All processes other than process 1 perform an extra sync. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_single_call_single_arg_max_proc_early_exit_one ) -{ - lpf_err_t rc = LPF_SUCCESS; - int input = 1; - int output = 3; - lpf_args_t args; - args.input = &input; - args.input_size = sizeof(int); - args.output = &output; - args.output_size = sizeof(int); - args.f_size = 0; - args.f_symbols = NULL; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_ERR_FATAL , rc ); - - EXPECT_EQ( "%d", 2, output ); - return 0; -} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.cpp b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.cpp new file mode 100644 index 00000000..bf315820 --- /dev/null +++ b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_one.cpp @@ -0,0 +1,98 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + lpf_err_t rc = LPF_SUCCESS; + lpf_pid_t a[2] = {pid, LPF_MAX_P}; + lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; + + EXPECT_LE(2, nprocs); + EXPECT_LT(pid, LPF_MAX_P); + + if (0 == pid) { + EXPECT_EQ((size_t)sizeof(int), args.input_size); + EXPECT_EQ((size_t)sizeof(int), args.output_size); + EXPECT_EQ(1, *(int *)args.input); + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + } + + // perform a simple communication + rc = lpf_resize_message_queue(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, &a, sizeof(a), &aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_put(lpf, aSlot, 0, (pid + 1) % nprocs, aSlot, sizeof(a[0]), + sizeof(a[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(a[0], (int)pid); + EXPECT_EQ(a[1], (int)((pid + nprocs - 1) % nprocs)); + + rc = lpf_deregister(lpf, aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + // now, all other processes except 'one' perform an extra sync. + if (1 != pid) { + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_ERR_FATAL, rc); + } + + // It is still possible to send output through the args + if (0 == pid) { + *(int *)args.output = 2; + } +} + +/** + * \test Test single lpf_exec() call with a single arg on all processors. All + * processes other than process 1 perform an extra sync. \pre P >= 2 \return + * Exit code: 0 + */ +TEST(API, func_lpf_exec_single_call_single_arg_max_proc_early_exit_one) { + lpf_err_t rc = LPF_SUCCESS; + int input = 1; + int output = 3; + lpf_args_t args; + args.input = &input; + args.input_size = sizeof(int); + args.output = &output; + args.output_size = sizeof(int); + args.f_size = 0; + args.f_symbols = NULL; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args); + EXPECT_EQ(LPF_ERR_FATAL, rc); + + EXPECT_EQ(2, output); +} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.c b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.c deleted file mode 100644 index d84b77ad..00000000 --- a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - - - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - - EXPECT_LE( "%d", 2, nprocs ); - if ( 0 == pid ) - { - EXPECT_EQ( "%zd", (size_t) sizeof(int), args.input_size ); - EXPECT_EQ( "%zd", (size_t) sizeof(int), args.output_size ); - EXPECT_EQ( "%d", 1, * (int *) args.input ); - *(int *) args.output = 2; - } - else - { - EXPECT_EQ( "%zd", (size_t) 0, args.input_size ); - EXPECT_EQ( "%zd", (size_t) 0, args.output_size ); - EXPECT_EQ( "%p", (void *) NULL, args.input ); - EXPECT_EQ( "%p", (void *) NULL, args.output ); - - lpf_err_t rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_ERR_FATAL, rc ); - } -} - - -/** - * \test Test single lpf_exec() call with a single arg on all processors. Process 0 exits early while the other processes perform another sync. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero ) -{ - lpf_err_t rc = LPF_SUCCESS; - int input = 1; - int output = 3; - lpf_args_t args; - args.input = &input; - args.input_size = sizeof(int); - args.output = &output; - args.output_size = sizeof(int); - args.f_size = 0; - args.f_symbols = NULL; - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_ERR_FATAL, rc ); - - EXPECT_EQ( "%d", 2, output ); - return 0; -} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.cpp b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.cpp new file mode 100644 index 00000000..936dfaf9 --- /dev/null +++ b/tests/functional/func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero.cpp @@ -0,0 +1,62 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + + EXPECT_LE(2, nprocs); + if (0 == pid) { + EXPECT_EQ((size_t)sizeof(int), args.input_size); + EXPECT_EQ((size_t)sizeof(int), args.output_size); + EXPECT_EQ(1, *(int *)args.input); + *(int *)args.output = 2; + } else { + EXPECT_EQ((size_t)0, args.input_size); + EXPECT_EQ((size_t)0, args.output_size); + EXPECT_EQ((void *)NULL, args.input); + EXPECT_EQ((void *)NULL, args.output); + + lpf_err_t rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_ERR_FATAL, rc); + } +} + +/** + * \test Test single lpf_exec() call with a single arg on all processors. + * Process 0 exits early while the other processes perform another sync. \pre P + * >= 2 \return Exit code: 0 + */ +TEST(API, func_lpf_exec_single_call_single_arg_max_proc_early_exit_zero) { + lpf_err_t rc = LPF_SUCCESS; + int input = 1; + int output = 3; + lpf_args_t args; + args.input = &input; + args.input_size = sizeof(int); + args.output = &output; + args.output_size = sizeof(int); + args.f_size = 0; + args.f_symbols = NULL; + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args); + EXPECT_EQ(LPF_ERR_FATAL, rc); + + EXPECT_EQ(2, output); +} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.c b/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.c deleted file mode 100644 index 93493e9b..00000000 --- a/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.c +++ /dev/null @@ -1,63 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#define SAMPLE_INPUT_ARG "This is an input argument" -#define SAMPLE_INPUT_ARG_LENGTH 10 - -#define SAMPLE_OUTPUT_ARG "Some output" -#define SAMPLE_OUTPUT_ARG_LENGTH 9 - - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) lpf; // ignore lpf context variable - EXPECT_EQ( "%d", 1, (int) nprocs ); - EXPECT_EQ( "%d", 0, (int) pid); - - EXPECT_EQ( "%d", 0, memcmp( args.input, SAMPLE_INPUT_ARG, SAMPLE_INPUT_ARG_LENGTH ) ); - memcpy( args.output, SAMPLE_OUTPUT_ARG, SAMPLE_OUTPUT_ARG_LENGTH ); -} - - -/** - * \test Test single lpf_exec() call with a single arg on a single processor - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_exec_single_call_single_arg_single_proc ) -{ - lpf_err_t rc = LPF_SUCCESS; - char input_arg[] = SAMPLE_INPUT_ARG; - char output_arg[ SAMPLE_OUTPUT_ARG_LENGTH ]; - lpf_args_t args; - args.input = input_arg; - args.input_size = SAMPLE_INPUT_ARG_LENGTH; - args.output = output_arg; - args.output_size = SAMPLE_OUTPUT_ARG_LENGTH; - args.f_symbols = NULL; - args.f_size = 0; - - rc = lpf_exec( LPF_ROOT, 1, &spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - EXPECT_EQ( "%d", 0, memcmp( args.output, SAMPLE_OUTPUT_ARG, SAMPLE_OUTPUT_ARG_LENGTH ) ); - return 0; -} diff --git a/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.cpp b/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.cpp new file mode 100644 index 00000000..9f9feab3 --- /dev/null +++ b/tests/functional/func_lpf_exec_single_call_single_arg_single_proc.cpp @@ -0,0 +1,59 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +#define SAMPLE_INPUT_ARG "This is an input argument" +#define SAMPLE_INPUT_ARG_LENGTH 10 + +#define SAMPLE_OUTPUT_ARG "Some output" +#define SAMPLE_OUTPUT_ARG_LENGTH 9 + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)lpf; // ignore lpf context variable + EXPECT_EQ(1, (int)nprocs); + EXPECT_EQ(0, (int)pid); + + EXPECT_EQ(0, memcmp(args.input, SAMPLE_INPUT_ARG, SAMPLE_INPUT_ARG_LENGTH)); + memcpy(args.output, SAMPLE_OUTPUT_ARG, SAMPLE_OUTPUT_ARG_LENGTH); +} + +/** + * \test Test single lpf_exec() call with a single arg on a single processor + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_exec_single_call_single_arg_single_proc) { + lpf_err_t rc = LPF_SUCCESS; + char input_arg[] = SAMPLE_INPUT_ARG; + char output_arg[SAMPLE_OUTPUT_ARG_LENGTH]; + lpf_args_t args; + args.input = input_arg; + args.input_size = SAMPLE_INPUT_ARG_LENGTH; + args.output = output_arg; + args.output_size = SAMPLE_OUTPUT_ARG_LENGTH; + args.f_symbols = NULL; + args.f_size = 0; + + rc = lpf_exec(LPF_ROOT, 1, &spmd, args); + EXPECT_EQ(rc, LPF_SUCCESS); + + EXPECT_EQ(0, + memcmp(args.output, SAMPLE_OUTPUT_ARG, SAMPLE_OUTPUT_ARG_LENGTH)); +} diff --git a/tests/functional/func_lpf_get_parallel_alltoall.c b/tests/functional/func_lpf_get_parallel_alltoall.c deleted file mode 100644 index 4166a705..00000000 --- a/tests/functional/func_lpf_get_parallel_alltoall.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore 'args' parameter - - lpf_err_t rc = LPF_SUCCESS; - const int n = nprocs; - int i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, 2*nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", i, xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // Do an all-to-all which is like transposing a matrix - // ( i , xs[pid] ) -> ( pid, ys[ i ] ) - for ( i = 0; i < n; ++ i) - { - rc = lpf_get( lpf, i, xslot, sizeof(xs[0])*pid, - yslot, sizeof(ys[0])*i, sizeof(xs[0]), - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", i, xs[i] ); - EXPECT_EQ( "%d", (int) pid, ys[i] ); - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_get by doing an all-to-all - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_alltoall ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_alltoall.cpp b/tests/functional/func_lpf_get_parallel_alltoall.cpp new file mode 100644 index 00000000..e421ef06 --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_alltoall.cpp @@ -0,0 +1,89 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore 'args' parameter + + lpf_err_t rc = LPF_SUCCESS; + const int n = nprocs; + int i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, 2 * nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // Do an all-to-all which is like transposing a matrix + // ( i , xs[pid] ) -> ( pid, ys[ i ] ) + for (i = 0; i < n; ++i) { + rc = lpf_get(lpf, i, xslot, sizeof(xs[0]) * pid, yslot, sizeof(ys[0]) * i, + sizeof(xs[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + EXPECT_EQ((int)pid, ys[i]); + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get by doing an all-to-all + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_alltoall) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_get_parallel_huge.c b/tests/functional/func_lpf_get_parallel_huge.c deleted file mode 100644 index 3d42b3b4..00000000 --- a/tests/functional/func_lpf_get_parallel_huge.c +++ /dev/null @@ -1,105 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ("%d", 2, nprocs); - - size_t maxMsgs = 1 , maxRegs = 2; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - size_t huge = (size_t) 10 + INT_MAX; // if this overflows, it means that - // size_t fits in 'int' and so this - // test is pointless - int *x = calloc( huge , sizeof(int)); - int *y = calloc( huge, sizeof(int)); - - EXPECT_NE( "%p", (int *) NULL, x ); - EXPECT_NE( "%p", (int *) NULL, y ); - - size_t i; - for (i = 0; i = 2 - * \pre P <= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_huge ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_huge.cpp b/tests/functional/func_lpf_get_parallel_huge.cpp new file mode 100644 index 00000000..317949ac --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_huge.cpp @@ -0,0 +1,96 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "gtest/gtest.h" + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ(2, nprocs); + + size_t maxMsgs = 1, maxRegs = 2; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + size_t huge = (size_t)10 + INT_MAX; // if this overflows, it means that + // size_t fits in 'int' and so this + // test is pointless + int *x = (int *)calloc(huge, sizeof(int)); + int *y = (int *)calloc(huge, sizeof(int)); + + EXPECT_NE((int *)NULL, x); + EXPECT_NE((int *)NULL, y); + + size_t i; + for (i = 0; i < huge; ++i) { + x[i] = (int)(i % INT_MAX); + } + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, y, sizeof(int) * huge, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, x, sizeof(int) * huge, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid == 0) { + rc = lpf_get(lpf, 1, yslot, 0, xslot, 0, sizeof(int) * huge, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid == 0) { + for (i = 0; i < huge; ++i) { + EXPECT_EQ(x[i], y[i]); + } + } else { + for (i = 0; i < huge; ++i) { + EXPECT_EQ(0, y[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get by sending a message larger than INT_MAX + * \pre P >= 2 + * \pre P <= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_huge) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_complete.c b/tests/functional/func_lpf_get_parallel_overlapping_complete.c deleted file mode 100644 index bfda516b..00000000 --- a/tests/functional/func_lpf_get_parallel_overlapping_complete.c +++ /dev/null @@ -1,115 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore 'args' parameter passed through call to lpf_exec - - lpf_err_t rc = LPF_SUCCESS; - const int MTU = 2000; - const int n = nprocs*MTU; - int i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*n + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs + 1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) (i*n+pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // processor zero gets data from each processor. - if ( 0 == pid ) - { - for (i = 0; i < (int) nprocs; ++i) - { - rc = lpf_get( lpf, i, xslot, 0u, - yslot, 0u, sizeof(xs[0]) * n, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - // on processor 0 only one of the writes will occur. - int delta = ys[0] - xs[0]; - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", delta, ys[i] - xs[i] ); - } - } - else - { - // on the other processors nothing has been written - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_get when multiple processors write to the same memory area - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_overlapping_complete ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_complete.cpp b/tests/functional/func_lpf_get_parallel_overlapping_complete.cpp new file mode 100644 index 00000000..268d9fcf --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_overlapping_complete.cpp @@ -0,0 +1,101 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore 'args' parameter passed through call to lpf_exec + + lpf_err_t rc = LPF_SUCCESS; + const int MTU = 2000; + const int n = nprocs * MTU; + int i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * n + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // processor zero gets data from each processor. + if (0 == pid) { + for (i = 0; i < (int)nprocs; ++i) { + rc = lpf_get(lpf, i, xslot, 0u, yslot, 0u, sizeof(xs[0]) * n, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + // on processor 0 only one of the writes will occur. + int delta = ys[0] - xs[0]; + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(delta, ys[i] - xs[i]); + } + } else { + // on the other processors nothing has been written + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get when multiple processors write to the same memory area + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_overlapping_complete) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_pyramid.c b/tests/functional/func_lpf_get_parallel_overlapping_pyramid.c deleted file mode 100644 index 8b10b06b..00000000 --- a/tests/functional/func_lpf_get_parallel_overlapping_pyramid.c +++ /dev/null @@ -1,147 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - const size_t MTU=2000; - const size_t n = 2*nprocs*MTU; - size_t i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*n + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs+1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) (i*n+pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // processor zero gets the data from all other processors - if ( 0 == pid ) - { - for (i = 0; i < nprocs; ++i) - { - size_t start = i; - size_t end = 2*nprocs - i; - rc = lpf_get( lpf, i, xslot, start*MTU*sizeof(xs[0]), - yslot, start*MTU*sizeof(xs[0]), (end-start)*MTU*sizeof(xs[0]), - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - /** - * The array 'xs' is sent to processor 0 as a pyramid. Writes - * will overlap in the middle of the block. On those - * places a specific sequential ordering has to be inplace. - * - * proc 0: 0123456789 - * proc 1: abcdefgh - * proc 2: pqrstu - * proc 3: vwxy - * proc 4: z. - * - * -------------------- - * proc 0: 0apvz.yuh9 - * or p 1: 0123456789 - * or something in between - * - **/ - for (i = 0; i < n; i+=MTU) - { - // check the contents of a block - size_t pid1 = ys[i] - xs[i]; - size_t pid2 = ys[n-i-1] - xs[n-i-1]; - EXPECT_EQ( "%zu", pid1, pid2 ); - EXPECT_LE( "%zu", pid1, i ); - EXPECT_LE( "%zu", pid1, n-i-1 ); - - EXPECT_LE( "%d", (int) pid1, (int) nprocs); - - - // check that all values in the block are from the same processor - size_t j; - for (j = 0; j < MTU; ++j) - { - EXPECT_EQ( "%d", (int) pid1, ys[i+j] - xs[i+j]); - EXPECT_EQ( "%d", (int) pid1, ys[n-i-1-j] - xs[n-i-1-j] ); - } - } - } - else - { - // on the other processors nothing has changed - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_get writing to partial overlapping memory areas from multiple processors. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_overlapping_pyramid ) -{ - lpf_err_t rc =lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_pyramid.cpp b/tests/functional/func_lpf_get_parallel_overlapping_pyramid.cpp new file mode 100644 index 00000000..2d59fe63 --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_overlapping_pyramid.cpp @@ -0,0 +1,130 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + const size_t MTU = 2000; + const size_t n = 2 * nprocs * MTU; + size_t i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * n + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // processor zero gets the data from all other processors + if (0 == pid) { + for (i = 0; i < nprocs; ++i) { + size_t start = i; + size_t end = 2 * nprocs - i; + rc = lpf_get(lpf, i, xslot, start * MTU * sizeof(xs[0]), yslot, + start * MTU * sizeof(xs[0]), + (end - start) * MTU * sizeof(xs[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + /** + * The array 'xs' is sent to processor 0 as a pyramid. Writes + * will overlap in the middle of the block. On those + * places a specific sequential ordering has to be inplace. + * + * proc 0: 0123456789 + * proc 1: abcdefgh + * proc 2: pqrstu + * proc 3: vwxy + * proc 4: z. + * + * -------------------- + * proc 0: 0apvz.yuh9 + * or p 1: 0123456789 + * or something in between + * + **/ + for (i = 0; i < n; i += MTU) { + // check the contents of a block + size_t pid1 = ys[i] - xs[i]; + size_t pid2 = ys[n - i - 1] - xs[n - i - 1]; + EXPECT_EQ(pid1, pid2); + EXPECT_LE(pid1, i); + EXPECT_LE(pid1, n - i - 1); + + EXPECT_LE((int)pid1, (int)nprocs); + + // check that all values in the block are from the same processor + size_t j; + for (j = 0; j < MTU; ++j) { + EXPECT_EQ((int)pid1, ys[i + j] - xs[i + j]); + EXPECT_EQ((int)pid1, ys[n - i - 1 - j] - xs[n - i - 1 - j]); + } + } + } else { + // on the other processors nothing has changed + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get writing to partial overlapping memory areas from multiple + * processors. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_overlapping_pyramid) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.c b/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.c deleted file mode 100644 index 865854a7..00000000 --- a/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.c +++ /dev/null @@ -1,173 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - const size_t MTU = 2000; - const size_t n = 5*nprocs*MTU; - size_t i; - uint64_t * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*nprocs + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs+1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%" PRIu64, (uint64_t) (i*nprocs+pid), xs[i] ); - EXPECT_EQ( "%" PRIu64, (uint64_t) 0, ys[i] ); - } - - // Each processor copies his row to processor zero. - if ( 0 == pid ) - { - for (i = 0 ; i < nprocs; ++i ) - { - size_t start = 5*i; - size_t length = 5; - size_t offset = start - i; - rc = lpf_get( lpf, i, xslot, start*sizeof(xs[0])*MTU, - yslot, offset*sizeof(xs[0])*MTU, length*sizeof(xs[0])*MTU, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - /** - * The array 'xs' is sent to processor 0 as a rooftiling. Writes - * will overlap at the end and beginning of each tile. On those - * places a specific sequential ordering has to be inplace. - * - * proc0 proc1 proc2 proc3 - * 01234 56789 ..... ..... - * | / - * v | - * 01234 v - * 56789 - * ..... - * ..... - * - * Note that the arithmetic can get screwed up if the numbers grow - * too big. - **/ - - int offset = 0; - for (i = 0; i < nprocs; ++i) - { - int j; - size_t k; - for (j = 0; j < 5 ; ++j) - { - uint64_t fromPid = ys[(4*i+j) * MTU] - xs[(4*i + j + offset) * MTU]; - fromPid = (fromPid + nprocs*MTU)%nprocs; - for (k = 0; k < MTU; ++k) - { - uint64_t fromPid2 = ys[ (4*i+j) * MTU + k] - - xs[(4*i+j + offset) * MTU + k]; - fromPid2 = (fromPid2 + nprocs*MTU)%nprocs; - EXPECT_EQ( "%" PRIu64, fromPid, fromPid2 ); - - if (fromPid == i) - EXPECT_EQ( "%" PRIu64, (5*i+j)*nprocs*MTU + fromPid, ys[(4*i+j)*MTU] ); - } - - if (0 == j && i > 0) - { - EXPECT_EQ( "%d", 1, fromPid == i || fromPid == i-1 ); - } - else if (4 == j && i < nprocs-1) - { - EXPECT_EQ( "%d", 1, fromPid == i || fromPid == i+1 ); - } - else - { - EXPECT_EQ( "%" PRIu64, fromPid, (uint64_t) i ); - } - } - offset += 1; - } - EXPECT_EQ("%d", (int) nprocs, offset ); - // the rest of the ys array should be zero - for (i = 0; i < (nprocs - 1) * MTU; ++i) - { - EXPECT_EQ("%" PRIu64, (uint64_t) 0, ys[n-i-1]); - } - } - else - { - // on the other processors nothing has changed - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%" PRIu64, (uint64_t) ( i*nprocs + pid), xs[i] ); - EXPECT_EQ( "%" PRIu64, (uint64_t) 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_get writing to partial overlapping memory areas from multiple processors. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_overlapping_rooftiling ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.cpp b/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.cpp new file mode 100644 index 00000000..4384ed9a --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_overlapping_rooftiling.cpp @@ -0,0 +1,153 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + const size_t MTU = 2000; + const size_t n = 5 * nprocs * MTU; + size_t i; + uint64_t *xs, *ys; + ys = (uint64_t *)malloc(sizeof(ys[0]) * n); + xs = (uint64_t *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * nprocs + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((uint64_t)(i * nprocs + pid), xs[i]); + EXPECT_EQ((uint64_t)0, ys[i]); + } + + // Each processor copies his row to processor zero. + if (0 == pid) { + for (i = 0; i < nprocs; ++i) { + size_t start = 5 * i; + size_t length = 5; + size_t offset = start - i; + rc = lpf_get(lpf, i, xslot, start * sizeof(xs[0]) * MTU, yslot, + offset * sizeof(xs[0]) * MTU, length * sizeof(xs[0]) * MTU, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + /** + * The array 'xs' is sent to processor 0 as a rooftiling. Writes + * will overlap at the end and beginning of each tile. On those + * places a specific sequential ordering has to be inplace. + * + * proc0 proc1 proc2 proc3 + * 01234 56789 ..... ..... + * | / + * v | + * 01234 v + * 56789 + * ..... + * ..... + * + * Note that the arithmetic can get screwed up if the numbers grow + * too big. + **/ + + int offset = 0; + for (i = 0; i < nprocs; ++i) { + int j; + size_t k; + for (j = 0; j < 5; ++j) { + uint64_t fromPid = + ys[(4 * i + j) * MTU] - xs[(4 * i + j + offset) * MTU]; + fromPid = (fromPid + nprocs * MTU) % nprocs; + for (k = 0; k < MTU; ++k) { + uint64_t fromPid2 = + ys[(4 * i + j) * MTU + k] - xs[(4 * i + j + offset) * MTU + k]; + fromPid2 = (fromPid2 + nprocs * MTU) % nprocs; + EXPECT_EQ(fromPid, fromPid2); + + if (fromPid == i) { + EXPECT_EQ((5 * i + j) * nprocs * MTU + fromPid, + ys[(4 * i + j) * MTU]); + } + } + + if (0 == j && i > 0) { + EXPECT_EQ(1, fromPid == i || fromPid == i - 1); + } else if (4 == j && i < nprocs - 1) { + EXPECT_EQ(1, fromPid == i || fromPid == i + 1); + } else { + EXPECT_EQ(fromPid, (uint64_t)i); + } + } + offset += 1; + } + EXPECT_EQ((int)nprocs, offset); + // the rest of the ys array should be zero + for (i = 0; i < (nprocs - 1) * MTU; ++i) { + EXPECT_EQ((uint64_t)0, ys[n - i - 1]); + } + } else { + // on the other processors nothing has changed + for (i = 0; i < n; ++i) { + EXPECT_EQ((uint64_t)(i * nprocs + pid), xs[i]); + EXPECT_EQ((uint64_t)0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get writing to partial overlapping memory areas from multiple + * processors. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_overlapping_rooftiling) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_get_parallel_single.c b/tests/functional/func_lpf_get_parallel_single.c deleted file mode 100644 index 5ab4657c..00000000 --- a/tests/functional/func_lpf_get_parallel_single.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 2 , maxRegs = 2; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - int x = 5, y = 10; - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, &x, sizeof(x), &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_local( lpf, &y, sizeof(y), &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 10, y); - - rc = lpf_get( lpf, (pid+1)%nprocs, xslot, 0, yslot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 5, y); - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_get by sending a message following a ring. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_get_parallel_single ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_get_parallel_single.cpp b/tests/functional/func_lpf_get_parallel_single.cpp new file mode 100644 index 00000000..73d4dda4 --- /dev/null +++ b/tests/functional/func_lpf_get_parallel_single.cpp @@ -0,0 +1,71 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 2, maxRegs = 2; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + int x = 5, y = 10; + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, &x, sizeof(x), &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_local(lpf, &y, sizeof(y), &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(10, y); + + rc = lpf_get(lpf, (pid + 1) % nprocs, xslot, 0, yslot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(5, y); + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_get by sending a message following a ring. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_get_parallel_single) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_hook_simple.mpirma.c b/tests/functional/func_lpf_hook_simple.mpirma.c deleted file mode 100644 index 5dfa7104..00000000 --- a/tests/functional/func_lpf_hook_simple.mpirma.c +++ /dev/null @@ -1,94 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -void spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; - lpf_err_t rc = LPF_SUCCESS; - - rc = lpf_resize_message_queue( ctx, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - rc = lpf_sync(ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - int x = 5 - pid; - int y = pid; - - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - rc = lpf_register_global( ctx, &x, sizeof(x), &xSlot ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - rc = lpf_register_global( ctx, &y, sizeof(y), &ySlot ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_put( ctx, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - EXPECT_EQ( "%d", x, (int) (5 - pid) ); - EXPECT_EQ( "%d", y, (int) (5 - (pid + nprocs -1) % nprocs) ); -} - -// disable automatic initialization. -const int LPF_MPI_AUTO_INITIALIZE=0; - -/** - * \test Tests lpf_hook on mpi implementation - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_hook_simple_mpi ) -{ - lpf_err_t rc = LPF_SUCCESS; - MPI_Init(NULL, NULL); - - int pid = 0; - MPI_Comm_rank( MPI_COMM_WORLD, &pid); - - int nprocs = 0; - MPI_Comm_size( MPI_COMM_WORLD, &nprocs); - - lpf_init_t init; - rc = lpf_mpi_initialize_with_mpicomm( MPI_COMM_WORLD, &init); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_mpi_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - MPI_Finalize(); - return 0; -} - - diff --git a/tests/functional/func_lpf_hook_simple.mpirma.cpp b/tests/functional/func_lpf_hook_simple.mpirma.cpp new file mode 100644 index 00000000..83916dd1 --- /dev/null +++ b/tests/functional/func_lpf_hook_simple.mpirma.cpp @@ -0,0 +1,91 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +void spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; + lpf_err_t rc = LPF_SUCCESS; + + rc = lpf_resize_message_queue(ctx, 2); + EXPECT_EQ("%d", LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + int x = 5 - pid; + int y = pid; + + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + rc = lpf_register_global(ctx, &x, sizeof(x), &xSlot); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + rc = lpf_register_global(ctx, &y, sizeof(y), &ySlot); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_put(ctx, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + EXPECT_EQ("%d", x, (int)(5 - pid)); + EXPECT_EQ("%d", y, (int)(5 - (pid + nprocs - 1) % nprocs)); +} + +// disable automatic initialization. +const int LPF_MPI_AUTO_INITIALIZE = 0; + +/** + * \test Tests lpf_hook on mpi implementation + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(func_lpf_hook_simple_mpi) { + lpf_err_t rc = LPF_SUCCESS; + MPI_Init(NULL, NULL); + + int pid = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + int nprocs = 0; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + + lpf_init_t init; + rc = lpf_mpi_initialize_with_mpicomm(MPI_COMM_WORLD, &init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_hook(init, &spmd, LPF_NO_ARGS); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_mpi_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + MPI_Finalize(); + return 0; +} diff --git a/tests/functional/func_lpf_hook_simple.pthread.c b/tests/functional/func_lpf_hook_simple.pthread.c deleted file mode 100644 index 3b33bdc6..00000000 --- a/tests/functional/func_lpf_hook_simple.pthread.c +++ /dev/null @@ -1,120 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -pthread_key_t pid_key; - -/** Process information */ -struct thread_local_data { - /** Number of processes */ - long P; - - /** Process ID */ - long s; -}; - -void lpf_spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) ctx; - const struct thread_local_data * const data = pthread_getspecific( pid_key ); - - EXPECT_EQ( "%zd", (size_t)nprocs, (size_t)(data->P) ); - EXPECT_EQ( "%zd", (size_t)pid, (size_t)(data->s) ); - EXPECT_EQ( "%zd", (size_t)(args.input_size), (size_t)(sizeof( struct thread_local_data)) ); - EXPECT_EQ( "%zd", (size_t)(args.output_size), (size_t)0 ); - EXPECT_EQ( "%p", args.input, data ); - EXPECT_EQ( "%p", args.output, NULL ); -} - -void * pthread_spmd( void * _data ) { - EXPECT_NE( "%p", _data, NULL ); - - const struct thread_local_data data = * ((struct thread_local_data*) _data); - const int pts_rc = pthread_setspecific( pid_key, _data ); - lpf_args_t args; - args.input = _data; - args.input_size = sizeof(data); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - lpf_init_t init; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ( "%d", pts_rc, 0 ); - - rc = lpf_pthread_initialize( - (lpf_pid_t)data.s, - (lpf_pid_t)data.P, - &init - ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_hook( init, &lpf_spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_pthread_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - return NULL; -} - -/** - * \test Tests lpf_hook on pthread implementation - * \pre P <= 1 - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_hook_simple_pthread ) -{ - long k = 0; - const long P = sysconf( _SC_NPROCESSORS_ONLN ); - - const int ptc_rc = pthread_key_create( &pid_key, NULL ); - EXPECT_EQ( "%d", ptc_rc, 0 ); - - pthread_t * const threads = (pthread_t*) malloc( P * sizeof(pthread_t) ); - EXPECT_NE( "%p", threads, NULL ); - - struct thread_local_data * const data = (struct thread_local_data*) malloc( P * sizeof(struct thread_local_data) ); - EXPECT_NE( "%p", data, NULL ); - - for( k = 0; k < P; ++k ) { - data[ k ].P = P; - data[ k ].s = k; - const int rval = pthread_create( threads + k, NULL, &pthread_spmd, data + k ); - EXPECT_EQ( "%d", rval, 0 ); - } - - for( k = 0; k < P; ++k ) { - const int rval = pthread_join( threads[ k ], NULL ); - EXPECT_EQ( "%d", rval, 0 ); - } - - const int ptd_rc = pthread_key_delete( pid_key ); - EXPECT_EQ( "%d", ptd_rc, 0 ); - - return 0; -} - - diff --git a/tests/functional/func_lpf_hook_simple.pthread.cpp b/tests/functional/func_lpf_hook_simple.pthread.cpp new file mode 100644 index 00000000..d689be20 --- /dev/null +++ b/tests/functional/func_lpf_hook_simple.pthread.cpp @@ -0,0 +1,114 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +pthread_key_t pid_key; + +/** Process information */ +struct thread_local_data { + /** Number of processes */ + long P; + + /** Process ID */ + long s; +}; + +void lpf_spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)ctx; + const struct thread_local_data *const data = pthread_getspecific(pid_key); + + EXPECT_EQ("%zd", (size_t)nprocs, (size_t)(data->P)); + EXPECT_EQ("%zd", (size_t)pid, (size_t)(data->s)); + EXPECT_EQ("%zd", (size_t)(args.input_size), + (size_t)(sizeof(struct thread_local_data))); + EXPECT_EQ("%zd", (size_t)(args.output_size), (size_t)0); + EXPECT_EQ("%p", args.input, data); + EXPECT_EQ("%p", args.output, NULL); +} + +void *pthread_spmd(void *_data) { + EXPECT_NE("%p", _data, NULL); + + const struct thread_local_data data = *((struct thread_local_data *)_data); + const int pts_rc = pthread_setspecific(pid_key, _data); + lpf_args_t args; + args.input = _data; + args.input_size = sizeof(data); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + lpf_init_t init; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ("%d", pts_rc, 0); + + rc = lpf_pthread_initialize((lpf_pid_t)data.s, (lpf_pid_t)data.P, &init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_hook(init, &lpf_spmd, args); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_pthread_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + return NULL; +} + +/** + * \test Tests lpf_hook on pthread implementation + * \pre P <= 1 + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(func_lpf_hook_simple_pthread) { + long k = 0; + const long P = sysconf(_SC_NPROCESSORS_ONLN); + + const int ptc_rc = pthread_key_create(&pid_key, NULL); + EXPECT_EQ("%d", ptc_rc, 0); + + pthread_t *const threads = (pthread_t *)malloc(P * sizeof(pthread_t)); + EXPECT_NE("%p", threads, NULL); + + struct thread_local_data *const data = + (struct thread_local_data *)malloc(P * sizeof(struct thread_local_data)); + EXPECT_NE("%p", data, NULL); + + for (k = 0; k < P; ++k) { + data[k].P = P; + data[k].s = k; + const int rval = pthread_create(threads + k, NULL, &pthread_spmd, data + k); + EXPECT_EQ("%d", rval, 0); + } + + for (k = 0; k < P; ++k) { + const int rval = pthread_join(threads[k], NULL); + EXPECT_EQ("%d", rval, 0); + } + + const int ptd_rc = pthread_key_delete(pid_key); + EXPECT_EQ("%d", ptd_rc, 0); + + return 0; +} diff --git a/tests/functional/func_lpf_hook_subset.mpimsg.c b/tests/functional/func_lpf_hook_subset.mpimsg.c deleted file mode 100644 index f073e443..00000000 --- a/tests/functional/func_lpf_hook_subset.mpimsg.c +++ /dev/null @@ -1,75 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include - - -const int LPF_MPI_AUTO_INITIALIZE=0; - -void test_spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) ctx; - (void) pid; - (void) nprocs; - (void) args; - return; -} - -void subset_func(MPI_Comm comm) -{ - MPI_Barrier(comm); - - lpf_init_t init; - lpf_err_t rc = lpf_mpi_initialize_with_mpicomm(comm, &init); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_hook(init, test_spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test for lpf_hook on mpi implementation when only using a subset - * \pre P >= 3 - * \return Exit code: 0 - */ -TEST( func_lpf_hook_subset ) -{ - MPI_Init(NULL, NULL); - - int s; - MPI_Comm_rank(MPI_COMM_WORLD, &s); - - int subset = s < 2; // Processes are divided into 2 subsets {0,1} and {2,...,p-1} - - MPI_Comm subset_comm; - MPI_Comm_split(MPI_COMM_WORLD, subset, s, &subset_comm); - -// only the first subset enters that function - if (subset) - { - subset_func(subset_comm); - } - - MPI_Barrier(MPI_COMM_WORLD); // Paranoid barrier - - MPI_Finalize(); - return 0; -} diff --git a/tests/functional/func_lpf_hook_subset.mpimsg.cpp b/tests/functional/func_lpf_hook_subset.mpimsg.cpp new file mode 100644 index 00000000..8b41e531 --- /dev/null +++ b/tests/functional/func_lpf_hook_subset.mpimsg.cpp @@ -0,0 +1,71 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include + +const int LPF_MPI_AUTO_INITIALIZE = 0; + +void test_spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)ctx; + (void)pid; + (void)nprocs; + (void)args; + return; +} + +void subset_func(MPI_Comm comm) { + MPI_Barrier(comm); + + lpf_init_t init; + lpf_err_t rc = lpf_mpi_initialize_with_mpicomm(comm, &init); + EXPECT_EQ("%d", LPF_SUCCESS, rc); + + rc = lpf_hook(init, test_spmd, LPF_NO_ARGS); + EXPECT_EQ("%d", LPF_SUCCESS, rc); +} + +/** + * \test Test for lpf_hook on mpi implementation when only using a subset + * \pre P >= 3 + * \return Exit code: 0 + */ +TEST(func_lpf_hook_subset) { + MPI_Init(NULL, NULL); + + int s; + MPI_Comm_rank(MPI_COMM_WORLD, &s); + + int subset = + s < 2; // Processes are divided into 2 subsets {0,1} and {2,...,p-1} + + MPI_Comm subset_comm; + MPI_Comm_split(MPI_COMM_WORLD, subset, s, &subset_comm); + + // only the first subset enters that function + if (subset) { + subset_func(subset_comm); + } + + MPI_Barrier(MPI_COMM_WORLD); // Paranoid barrier + + MPI_Finalize(); + return 0; +} diff --git a/tests/functional/func_lpf_hook_tcp.mpirma.c b/tests/functional/func_lpf_hook_tcp.mpirma.c deleted file mode 100644 index 2921e6fc..00000000 --- a/tests/functional/func_lpf_hook_tcp.mpirma.c +++ /dev/null @@ -1,112 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -#include -#include - -void spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - lpf_err_t rc = LPF_SUCCESS; - - struct { int pid, nprocs; } params; - EXPECT_EQ( "%lu", sizeof(params), args.input_size ); - - memcpy( ¶ms, args.input, sizeof(params)); - EXPECT_EQ( "%u", (lpf_pid_t) params.pid, pid ); - EXPECT_EQ( "%u", (lpf_pid_t) params.nprocs, nprocs ); - - rc = lpf_resize_message_queue( ctx, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, 2); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - rc = lpf_sync(ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - int x = 5 - pid; - int y = pid; - - lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; - - rc = lpf_register_global( ctx, &x, sizeof(x), &xSlot ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - rc = lpf_register_global( ctx, &y, sizeof(y), &ySlot ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_put( ctx, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - EXPECT_EQ( "%d", x, (int) (5 - pid) ); - EXPECT_EQ( "%d", y, (int) (5 - (pid + nprocs -1) % nprocs) ); -} - -// disable automatic initialization. -const int LPF_MPI_AUTO_INITIALIZE=0; - -/** - * \test Tests lpf_hook on mpi implementation using TCP/IP to initialize. The pids and nprocs are checked for their correctness. - * \pre P >= 1 - * \return Exit code: 0 - * \note Independent processes: yes - */ -TEST( func_lpf_hook_tcp ) -{ - lpf_err_t rc = LPF_SUCCESS; - MPI_Init(&argc, &argv); - - struct { int pid, nprocs; } params = { 0, 0}; - EXPECT_GT("%d", argc, 2 ); - params.pid = atoi( argv[1] ); - params.nprocs = atoi( argv[2] ); - - lpf_init_t init; - rc = lpf_mpi_initialize_over_tcp( - "localhost", "9325", 240000, // time out should be high in order to - params.pid, params.nprocs, &init); // let e.g. Intel MPI try a few - // alternative fabrics - - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - lpf_args_t args; - args.input = ¶ms; - args.input_size = sizeof(params); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - - rc = lpf_hook( init, &spmd, args ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - rc = lpf_mpi_finalize( init ); - EXPECT_EQ( "%d", rc, LPF_SUCCESS ); - - MPI_Finalize(); - return 0; -} - - diff --git a/tests/functional/func_lpf_hook_tcp.mpirma.cpp b/tests/functional/func_lpf_hook_tcp.mpirma.cpp new file mode 100644 index 00000000..9df17e8d --- /dev/null +++ b/tests/functional/func_lpf_hook_tcp.mpirma.cpp @@ -0,0 +1,112 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Test.h" +#include +#include + +#include +#include + +void spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + lpf_err_t rc = LPF_SUCCESS; + + struct { + int pid, nprocs; + } params; + EXPECT_EQ("%lu", sizeof(params), args.input_size); + + memcpy(¶ms, args.input, sizeof(params)); + EXPECT_EQ("%u", (lpf_pid_t)params.pid, pid); + EXPECT_EQ("%u", (lpf_pid_t)params.nprocs, nprocs); + + rc = lpf_resize_message_queue(ctx, 2); + EXPECT_EQ("%d", LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, 2); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + int x = 5 - pid; + int y = pid; + + lpf_memslot_t xSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t ySlot = LPF_INVALID_MEMSLOT; + + rc = lpf_register_global(ctx, &x, sizeof(x), &xSlot); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + rc = lpf_register_global(ctx, &y, sizeof(y), &ySlot); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_put(ctx, xSlot, 0, (pid + 1) % nprocs, ySlot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + EXPECT_EQ("%d", x, (int)(5 - pid)); + EXPECT_EQ("%d", y, (int)(5 - (pid + nprocs - 1) % nprocs)); +} + +// disable automatic initialization. +const int LPF_MPI_AUTO_INITIALIZE = 0; + +/** + * \test Tests lpf_hook on mpi implementation using TCP/IP to initialize. The + * pids and nprocs are checked for their correctness. \pre P >= 1 \return Exit + * code: 0 \note Independent processes: yes + */ +TEST(func_lpf_hook_tcp) { + lpf_err_t rc = LPF_SUCCESS; + MPI_Init(&argc, &argv); + + struct { + int pid, nprocs; + } params = {0, 0}; + EXPECT_GT("%d", argc, 2); + params.pid = atoi(argv[1]); + params.nprocs = atoi(argv[2]); + + lpf_init_t init; + rc = lpf_mpi_initialize_over_tcp( + "localhost", "9325", 240000, // time out should be high in order to + params.pid, params.nprocs, &init); // let e.g. Intel MPI try a few + // alternative fabrics + + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + lpf_args_t args; + args.input = ¶ms; + args.input_size = sizeof(params); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + + rc = lpf_hook(init, &spmd, args); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + rc = lpf_mpi_finalize(init); + EXPECT_EQ("%d", rc, LPF_SUCCESS); + + MPI_Finalize(); + return 0; +} diff --git a/tests/functional/func_lpf_hook_tcp_timeout.mpirma.c b/tests/functional/func_lpf_hook_tcp_timeout.mpirma.cpp similarity index 59% rename from tests/functional/func_lpf_hook_tcp_timeout.mpirma.c rename to tests/functional/func_lpf_hook_tcp_timeout.mpirma.cpp index e8aba501..db77c17a 100644 --- a/tests/functional/func_lpf_hook_tcp_timeout.mpirma.c +++ b/tests/functional/func_lpf_hook_tcp_timeout.mpirma.cpp @@ -15,39 +15,34 @@ * limitations under the License. */ +#include "Test.h" #include #include -#include "Test.h" -#include #include +#include // Disable automatic initialization. -const int LPF_MPI_AUTO_INITIALIZE=0; +const int LPF_MPI_AUTO_INITIALIZE = 0; -/** - * \test Tests lpf_hook on mpi implementation using TCP/IP to initialize, while a timeout happens and _exit() is not called right away. - * \pre P >= 100 - * \pre P <= 100 - * \return Exit code: 1 +/** + * \test Tests lpf_hook on mpi implementation using TCP/IP to initialize, while + * a timeout happens and _exit() is not called right away. \pre P >= 100 \pre P + * <= 100 \return Exit code: 1 */ -TEST( func_lpf_hook_tcp_timeout_mpi ) -{ - MPI_Init(NULL, NULL); +TEST(func_lpf_hook_tcp_timeout_mpi) { + MPI_Init(NULL, NULL); - int pid, nprocs; - MPI_Comm_size(MPI_COMM_WORLD, &nprocs); - MPI_Comm_rank(MPI_COMM_WORLD, &pid); + int pid, nprocs; + MPI_Comm_size(MPI_COMM_WORLD, &nprocs); + MPI_Comm_rank(MPI_COMM_WORLD, &pid); - lpf_err_t rc = LPF_SUCCESS; - lpf_init_t init; - rc = lpf_mpi_initialize_over_tcp( - "localhost", "9325", 999, - pid, nprocs, &init); + lpf_err_t rc = LPF_SUCCESS; + lpf_init_t init; + rc = + lpf_mpi_initialize_over_tcp("localhost", "9325", 999, pid, nprocs, &init); - EXPECT_EQ( "%d", rc, LPF_ERR_FATAL ); + EXPECT_EQ("%d", rc, LPF_ERR_FATAL); - return 0; + return 0; } - - diff --git a/tests/functional/func_lpf_probe_parallel_full.c b/tests/functional/func_lpf_probe_parallel_full.c deleted file mode 100644 index 113aa0ca..00000000 --- a/tests/functional/func_lpf_probe_parallel_full.c +++ /dev/null @@ -1,86 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - lpf_machine_t subMachine = LPF_INVALID_MACHINE; - lpf_err_t rc = lpf_probe( lpf, &subMachine ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%u", nprocs, subMachine.p ); - EXPECT_EQ( "%u", 1u, subMachine.free_p ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(subMachine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(subMachine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(subMachine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(subMachine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - if ( 0 == pid ) - { - lpf_machine_t * machine = (lpf_machine_t * ) args.input; - EXPECT_EQ( "%zd", args.input_size, sizeof(lpf_machine_t) ); - - EXPECT_EQ( "%u", nprocs, machine->p ); - EXPECT_EQ( "%u", nprocs, machine->free_p ); - } -} - - -/** - * \test Test lpf_probe function on a parallel section where all processes are used immediately. - * \note Extra lpfrun parameters: -probe 1.0 - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_probe_parallel_full ) -{ - lpf_err_t rc = LPF_SUCCESS; - - lpf_machine_t machine = LPF_INVALID_MACHINE; - - rc = lpf_probe( LPF_ROOT, &machine ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_LE( "%u", 1u, machine.p ); - EXPECT_LE( "%u", 1u, machine.free_p ); - EXPECT_LE( "%u", machine.p, machine.free_p ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - lpf_args_t args; - args.input = &machine; - args.input_size = sizeof(machine); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - - rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - return 0; -} diff --git a/tests/functional/func_lpf_probe_parallel_full.cpp b/tests/functional/func_lpf_probe_parallel_full.cpp new file mode 100644 index 00000000..3e1dc7c4 --- /dev/null +++ b/tests/functional/func_lpf_probe_parallel_full.cpp @@ -0,0 +1,81 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + lpf_machine_t subMachine = LPF_INVALID_MACHINE; + lpf_err_t rc = lpf_probe(lpf, &subMachine); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(nprocs, subMachine.p); + EXPECT_EQ(1u, subMachine.free_p); + EXPECT_LT(0.0, (*(subMachine.g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.g))(subMachine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.l))(subMachine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, + (*(subMachine.g))(subMachine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, + (*(subMachine.l))(subMachine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + + if (0 == pid) { + lpf_machine_t *machine = (lpf_machine_t *)args.input; + EXPECT_EQ(args.input_size, sizeof(lpf_machine_t)); + + EXPECT_EQ(nprocs, machine->p); + EXPECT_EQ(nprocs, machine->free_p); + } +} + +/** + * \test Test lpf_probe function on a parallel section where all processes are + * used immediately. \note Extra lpfrun parameters: -probe 1.0 \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_probe_parallel_full) { + lpf_err_t rc = LPF_SUCCESS; + + lpf_machine_t machine = LPF_INVALID_MACHINE; + + rc = lpf_probe(LPF_ROOT, &machine); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_LE(1u, machine.p); + EXPECT_LE(1u, machine.free_p); + EXPECT_LE(machine.p, machine.free_p); + EXPECT_LT(0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + + lpf_args_t args; + args.input = &machine; + args.input_size = sizeof(machine); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + + rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, args); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_probe_parallel_nested.c b/tests/functional/func_lpf_probe_parallel_nested.c deleted file mode 100644 index bacafad8..00000000 --- a/tests/functional/func_lpf_probe_parallel_nested.c +++ /dev/null @@ -1,208 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd2( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - lpf_err_t rc = lpf_resize_message_queue( lpf, nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_machine_t machine[3] = { LPF_INVALID_MACHINE, LPF_INVALID_MACHINE, LPF_INVALID_MACHINE }; - lpf_memslot_t machineSlot = LPF_INVALID_MEMSLOT ; - rc = lpf_register_global( lpf, &machine[0], sizeof(machine), &machineSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - if ( 0 == pid ) - { - machine[0] = ((lpf_machine_t * ) args.input)[0]; - machine[1] = ((lpf_machine_t * ) args.input)[1]; - EXPECT_EQ( "%zd", args.input_size, 2*sizeof(lpf_machine_t) ); - } - else - { - // broadcast machine info - rc = lpf_get( lpf, 0, machineSlot, 0, machineSlot, 0, 2*sizeof(machine[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - rc = lpf_probe( lpf, &machine[2] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%u", machine[0].p, machine[1].p ); - EXPECT_EQ( "%u", machine[0].p, machine[2].p ); - EXPECT_EQ( "%u", 1u, machine[2].free_p ); - EXPECT_LT( "%g", 0.0, (*(machine[2].g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine[2].l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine[2].g))(machine[0].p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine[2].l))(machine[0].p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine[2].g))(machine[0].p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine[2].l))(machine[0].p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - rc = lpf_deregister( lpf, machineSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -void spmd1( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - - lpf_pid_t p = 0; - lpf_machine_t subMachine; - lpf_err_t rc = lpf_probe( lpf, &subMachine ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_resize_message_queue( lpf, nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_machine_t machine ; - lpf_memslot_t machineSlot = LPF_INVALID_MEMSLOT ; - rc = lpf_register_global( lpf, &machine, sizeof(machine), &machineSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - if ( 0 == pid ) - { - machine = * ( lpf_machine_t * ) args.input; - EXPECT_EQ( "%zd", args.input_size, sizeof(lpf_machine_t) ); - } - else - { - // broadcast machine info - rc = lpf_get( lpf, 0, machineSlot, 0, machineSlot, 0, sizeof(machine), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - rc = lpf_sync(lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_deregister( lpf, machineSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Do some checks - EXPECT_EQ( "%u", nprocs, subMachine.p / 2 ); - EXPECT_EQ( "%u", nprocs, machine.p / 2 ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(subMachine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - const int pthread = 1, mpirma = 1, mpimsg = 1, hybrid = 0, ibverbs=1; - (void) pthread; (void) mpirma; (void) mpimsg; (void) hybrid; (void) ibverbs; - if (LPF_CORE_IMPL_ID) // this part is disabled for the hybrid implementation, because - { // that one doesn't do generic nesting of lpf_exec's - EXPECT_EQ( "%d", 1, subMachine.free_p == 2 || subMachine.free_p == 3 ); - - // compute the sum of all 'free_p' values - lpf_pid_t * vec = malloc(sizeof(lpf_pid_t)*nprocs); - EXPECT_NE( "%p", NULL, vec ); - vec[ pid ] = subMachine.free_p; - - lpf_memslot_t vecSlot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, vec, sizeof(lpf_pid_t)*nprocs, &vecSlot); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - for (p = 0 ; p < nprocs; ++p) - { - if ( pid != p ) - { - rc = lpf_put( lpf, - vecSlot, pid*sizeof(vec[0]), - p, vecSlot, pid*sizeof(vec[0]), sizeof(vec[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_deregister( lpf, vecSlot ); - lpf_pid_t sum = 0; - for (p = 0; p < nprocs; ++p) - { - sum += vec[p]; - } - EXPECT_EQ( "%u", sum, machine.p ); - EXPECT_EQ( "%u", sum, subMachine.p ); - - free(vec); - } - - // When running this spmd1 section, only half of the processes was started - // This time we try to run spmd2 with a number of processes depending on the - // pid. Of course, only max free_p processes are started. - lpf_machine_t multiMachine[2] = { machine, subMachine }; - args.input = multiMachine; - args.input_size = sizeof(multiMachine); - rc = lpf_exec( lpf, pid + 3, &spmd2, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - - -/** - * \test Test lpf_probe function on a parallel section where all processes are used immediately. - * \note Extra lpfrun parameters: -probe 1.0 - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_probe_parallel_nested ) -{ - lpf_err_t rc = LPF_SUCCESS; - - lpf_machine_t machine; - - rc = lpf_probe( LPF_ROOT, &machine ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_LE( "%u", 1u, machine.p ); - EXPECT_LE( "%u", 1u, machine.free_p ); - EXPECT_LE( "%u", machine.p, machine.free_p ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - lpf_args_t args; - args.input = &machine; - args.input_size = sizeof(machine); - args.output = NULL; - args.output_size = 0; - args.f_symbols = NULL; - args.f_size = 0; - - rc = lpf_exec( LPF_ROOT, machine.p / 2, &spmd1, args ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - return 0; -} diff --git a/tests/functional/func_lpf_probe_parallel_nested.cpp b/tests/functional/func_lpf_probe_parallel_nested.cpp new file mode 100644 index 00000000..759e14f2 --- /dev/null +++ b/tests/functional/func_lpf_probe_parallel_nested.cpp @@ -0,0 +1,199 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd2(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + lpf_err_t rc = lpf_resize_message_queue(lpf, nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_machine_t machine[3] = {LPF_INVALID_MACHINE, LPF_INVALID_MACHINE, + LPF_INVALID_MACHINE}; + lpf_memslot_t machineSlot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, &machine[0], sizeof(machine), &machineSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + if (0 == pid) { + machine[0] = ((lpf_machine_t *)args.input)[0]; + machine[1] = ((lpf_machine_t *)args.input)[1]; + EXPECT_EQ(args.input_size, 2 * sizeof(lpf_machine_t)); + } else { + // broadcast machine info + rc = lpf_get(lpf, 0, machineSlot, 0, machineSlot, 0, 2 * sizeof(machine[0]), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_probe(lpf, &machine[2]); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(machine[0].p, machine[1].p); + EXPECT_EQ(machine[0].p, machine[2].p); + EXPECT_EQ(1u, machine[2].free_p); + EXPECT_LT(0.0, (*(machine[2].g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine[2].l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine[2].g))(machine[0].p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine[2].l))(machine[0].p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, + (*(machine[2].g))(machine[0].p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, + (*(machine[2].l))(machine[0].p, (size_t)(-1), LPF_SYNC_DEFAULT)); + + rc = lpf_deregister(lpf, machineSlot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +void spmd1(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + + lpf_pid_t p = 0; + lpf_machine_t subMachine; + lpf_err_t rc = lpf_probe(lpf, &subMachine); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_resize_message_queue(lpf, nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_machine_t machine; + lpf_memslot_t machineSlot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, &machine, sizeof(machine), &machineSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + if (0 == pid) { + machine = *(lpf_machine_t *)args.input; + EXPECT_EQ(args.input_size, sizeof(lpf_machine_t)); + } else { + // broadcast machine info + rc = lpf_get(lpf, 0, machineSlot, 0, machineSlot, 0, sizeof(machine), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, machineSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Do some checks + EXPECT_EQ(nprocs, subMachine.p / 2); + EXPECT_EQ(nprocs, machine.p / 2); + EXPECT_LT(0.0, (*(subMachine.g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.g))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.l))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(subMachine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + + const int pthread = 1, mpirma = 1, mpimsg = 1, hybrid = 0, ibverbs = 1; + (void)pthread; + (void)mpirma; + (void)mpimsg; + (void)hybrid; + (void)ibverbs; + if (LPF_CORE_IMPL_ID) // this part is disabled for the hybrid implementation, + // because + { // that one doesn't do generic nesting of lpf_exec's + EXPECT_EQ(1, subMachine.free_p == 2 || subMachine.free_p == 3); + + // compute the sum of all 'free_p' values + lpf_pid_t *vec = (lpf_pid_t *)malloc(sizeof(lpf_pid_t) * nprocs); + EXPECT_NE(nullptr, vec); + vec[pid] = subMachine.free_p; + + lpf_memslot_t vecSlot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, vec, sizeof(lpf_pid_t) * nprocs, &vecSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + for (p = 0; p < nprocs; ++p) { + if (pid != p) { + rc = lpf_put(lpf, vecSlot, pid * sizeof(vec[0]), p, vecSlot, + pid * sizeof(vec[0]), sizeof(vec[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, vecSlot); + lpf_pid_t sum = 0; + for (p = 0; p < nprocs; ++p) { + sum += vec[p]; + } + EXPECT_EQ(sum, machine.p); + EXPECT_EQ(sum, subMachine.p); + + free(vec); + } + + // When running this spmd1 section, only half of the processes was started + // This time we try to run spmd2 with a number of processes depending on the + // pid. Of course, only max free_p processes are started. + lpf_machine_t multiMachine[2] = {machine, subMachine}; + args.input = multiMachine; + args.input_size = sizeof(multiMachine); + rc = lpf_exec(lpf, pid + 3, &spmd2, args); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_probe function on a parallel section where all processes are + * used immediately. \note Extra lpfrun parameters: -probe 1.0 \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_probe_parallel_nested) { + lpf_err_t rc = LPF_SUCCESS; + + lpf_machine_t machine; + + rc = lpf_probe(LPF_ROOT, &machine); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_LE(1u, machine.p); + EXPECT_LE(1u, machine.free_p); + EXPECT_LE(machine.p, machine.free_p); + EXPECT_LT(0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + + lpf_args_t args; + args.input = &machine; + args.input_size = sizeof(machine); + args.output = NULL; + args.output_size = 0; + args.f_symbols = NULL; + args.f_size = 0; + + rc = lpf_exec(LPF_ROOT, machine.p / 2, &spmd1, args); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_probe_root.c b/tests/functional/func_lpf_probe_root.c deleted file mode 100644 index 5a655678..00000000 --- a/tests/functional/func_lpf_probe_root.c +++ /dev/null @@ -1,46 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -/** - * \test Test lpf_probe function on LPF_ROOT - * \note Extra lpfrun parameters: -probe 1.0 - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_probe_root ) -{ - lpf_err_t rc = LPF_SUCCESS; - - lpf_machine_t machine = LPF_INVALID_MACHINE; - - rc = lpf_probe( LPF_ROOT, &machine ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_LE( "%u", 1u, machine.p ); - EXPECT_LE( "%u", 1u, machine.free_p ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - EXPECT_LT( "%g", 0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT) ); - - return 0; -} diff --git a/tests/functional/func_lpf_probe_root.cpp b/tests/functional/func_lpf_probe_root.cpp new file mode 100644 index 00000000..fab3fcae --- /dev/null +++ b/tests/functional/func_lpf_probe_root.cpp @@ -0,0 +1,43 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +/** + * \test Test lpf_probe function on LPF_ROOT + * \note Extra lpfrun parameters: -probe 1.0 + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_probe_root) { + lpf_err_t rc = LPF_SUCCESS; + + lpf_machine_t machine = LPF_INVALID_MACHINE; + + rc = lpf_probe(LPF_ROOT, &machine); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_LE(1u, machine.p); + EXPECT_LE(1u, machine.free_p); + EXPECT_LT(0.0, (*(machine.g))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(1, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, 0, LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.g))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); + EXPECT_LT(0.0, (*(machine.l))(machine.p, (size_t)(-1), LPF_SYNC_DEFAULT)); +} diff --git a/tests/functional/func_lpf_put_and_get_overlapping.c b/tests/functional/func_lpf_put_and_get_overlapping.c deleted file mode 100644 index ffd1b4bb..00000000 --- a/tests/functional/func_lpf_put_and_get_overlapping.c +++ /dev/null @@ -1,106 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - const int MTU = 2000; - const int n = nprocs*MTU; - int i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*n + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, 4*nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_global( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) (i*n+pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // get the block from all processors and also put data to all processors - // it must appear that the put and gets were performed in some sequential - // order - for (i = 0; i < (int) nprocs; ++i) - { - rc = lpf_get( lpf, i, xslot, 0u, - yslot, 0u, sizeof(xs[0]) * n, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_put( lpf, xslot, 0u, - i, yslot, 0u, sizeof(xs[0]) * n, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // on all processors the writes have occurred in some sequential order - int delta = ys[0] - xs[0]; - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", delta, ys[i] - xs[i] ); - } - - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test destination of lpf_put and lpf_get overlap. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_and_get_overlapping ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_and_get_overlapping.cpp b/tests/functional/func_lpf_put_and_get_overlapping.cpp new file mode 100644 index 00000000..c746ca4a --- /dev/null +++ b/tests/functional/func_lpf_put_and_get_overlapping.cpp @@ -0,0 +1,95 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + const int MTU = 2000; + const int n = nprocs * MTU; + int i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * n + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, 4 * nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_global(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // get the block from all processors and also put data to all processors + // it must appear that the put and gets were performed in some sequential + // order + for (i = 0; i < (int)nprocs; ++i) { + rc = lpf_get(lpf, i, xslot, 0u, yslot, 0u, sizeof(xs[0]) * n, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_put(lpf, xslot, 0u, i, yslot, 0u, sizeof(xs[0]) * n, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // on all processors the writes have occurred in some sequential order + int delta = ys[0] - xs[0]; + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(delta, ys[i] - xs[i]); + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test destination of lpf_put and lpf_get overlap. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_and_get_overlapping) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_alltoall.c b/tests/functional/func_lpf_put_parallel_alltoall.c deleted file mode 100644 index 3dafc19a..00000000 --- a/tests/functional/func_lpf_put_parallel_alltoall.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - - lpf_err_t rc = LPF_SUCCESS; - const int n = nprocs; - int i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, 2*nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", i, xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // Do an all-to-all which is like transposing a matrix - // ( pid, xs[i] ) -> ( i, ys[ pid ] ) - for ( i = 0; i < n; ++ i) - { - rc = lpf_put( lpf, xslot, sizeof(xs[0])*i, - i, yslot, sizeof(ys[0])*pid, sizeof(xs[0]), - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", i, xs[i] ); - EXPECT_EQ( "%d", (int) pid, ys[i] ); - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_put by doing an all-to-all - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_alltoall ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_alltoall.cpp b/tests/functional/func_lpf_put_parallel_alltoall.cpp new file mode 100644 index 00000000..e3b8f8f5 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_alltoall.cpp @@ -0,0 +1,89 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + + lpf_err_t rc = LPF_SUCCESS; + const int n = nprocs; + int i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, 2 * nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // Do an all-to-all which is like transposing a matrix + // ( pid, xs[i] ) -> ( i, ys[ pid ] ) + for (i = 0; i < n; ++i) { + rc = lpf_put(lpf, xslot, sizeof(xs[0]) * i, i, yslot, sizeof(ys[0]) * pid, + sizeof(xs[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + EXPECT_EQ((int)pid, ys[i]); + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put by doing an all-to-all + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_alltoall) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_bad_pattern.c b/tests/functional/func_lpf_put_parallel_bad_pattern.c deleted file mode 100644 index 08756644..00000000 --- a/tests/functional/func_lpf_put_parallel_bad_pattern.c +++ /dev/null @@ -1,101 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - - lpf_err_t rc = LPF_SUCCESS; - const unsigned n = sqrt(nprocs); - unsigned i; - unsigned * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, n); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%u", i, xs[i] ); - EXPECT_EQ( "%u", 0u, ys[i] ); - } - - if ( pid < n ) - { - for ( i = 0; i < n; ++ i) - { - EXPECT_LT("%u", i*n, nprocs); - rc = lpf_put( lpf, xslot, sizeof(xs[0])*i, - i*n, yslot, sizeof(ys[0])*pid, sizeof(xs[0]), - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%u", i, xs[i] ); - if ( pid % n == 0 && pid < n*n) - EXPECT_EQ( "%u", pid / n, ys[i] ); - else - EXPECT_EQ( "%d", 0, ys[i] ); - } - -} - -/** - * \test Test lpf_put by doing a pattern which bad for a sparse all-to-all - * \pre P >= 1024 - * \pre P <= 1024 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_bad_pattern ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_bad_pattern.cpp b/tests/functional/func_lpf_put_parallel_bad_pattern.cpp new file mode 100644 index 00000000..281e7102 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_bad_pattern.cpp @@ -0,0 +1,90 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "gtest/gtest.h" + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + + lpf_err_t rc = LPF_SUCCESS; + const unsigned n = sqrt(nprocs); + unsigned i; + unsigned *xs, *ys; + ys = (unsigned *)malloc(sizeof(ys[0]) * n); + xs = (unsigned *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, n); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + EXPECT_EQ(0u, ys[i]); + } + + if (pid < n) { + for (i = 0; i < n; ++i) { + EXPECT_LT(i * n, nprocs); + rc = lpf_put(lpf, xslot, sizeof(xs[0]) * i, i * n, yslot, + sizeof(ys[0]) * pid, sizeof(xs[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (i = 0; i < n; ++i) { + EXPECT_EQ(i, xs[i]); + if (pid % n == 0 && pid < n * n) + EXPECT_EQ(pid / n, ys[i]); + else + EXPECT_EQ(0, ys[i]); + } +} + +/** + * \test Test lpf_put by doing a pattern which bad for a sparse all-to-all + * \pre P >= 5 + * \pre P <= 5 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_bad_pattern) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_big.c b/tests/functional/func_lpf_put_parallel_big.c deleted file mode 100644 index af4b3e77..00000000 --- a/tests/functional/func_lpf_put_parallel_big.c +++ /dev/null @@ -1,84 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include - -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t arg ) -{ - (void) arg; - - lpf_resize_message_queue( lpf, 2*nprocs-2 ); - lpf_resize_memory_register( lpf, 2); - - lpf_sync( lpf, LPF_SYNC_DEFAULT ); - - const size_t blocksize = 99999; - const size_t bufsize = nprocs * blocksize; - char * srcbuf = calloc( bufsize, 1 ); - char * dstbuf = calloc( bufsize, 1 ); - - lpf_memslot_t srcslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t dstslot = LPF_INVALID_MEMSLOT; - - lpf_register_global( lpf, srcbuf, bufsize, &srcslot); - lpf_register_global( lpf, dstbuf, bufsize, &dstslot); - - int try = 0; - for (try = 0; try < 3; ++try ) { - lpf_err_t rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ) ; - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - size_t dstoffset = 0; - size_t srcoffset = 0; - unsigned p; - for ( p = 0; p < nprocs; ++p ) { - dstoffset = p * blocksize; - if (pid != p) lpf_put( lpf, srcslot, srcoffset, p, dstslot, dstoffset, blocksize, LPF_MSG_DEFAULT); - srcoffset += blocksize; - } - } - - lpf_err_t rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ) ; - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_deregister( lpf, srcslot ); - lpf_deregister( lpf, dstslot ); -} - - -/** - * \test Test lpf_put by sending messages larger than max MPI message size - * \pre P >= 2 - * \note Extra lpfrun parameters: -max-mpi-msg-size 500 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_big ) -{ - (void) argc; - (void) argv; - - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_big.cpp b/tests/functional/func_lpf_put_parallel_big.cpp new file mode 100644 index 00000000..e2bb7d6f --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_big.cpp @@ -0,0 +1,78 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t arg) { + (void)arg; + + lpf_resize_message_queue(lpf, 2 * nprocs - 2); + lpf_resize_memory_register(lpf, 2); + + lpf_sync(lpf, LPF_SYNC_DEFAULT); + + const size_t blocksize = 99999; + const size_t bufsize = nprocs * blocksize; + char *srcbuf = (char *)calloc(bufsize, 1); + char *dstbuf = (char *)calloc(bufsize, 1); + + lpf_memslot_t srcslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t dstslot = LPF_INVALID_MEMSLOT; + + lpf_register_global(lpf, srcbuf, bufsize, &srcslot); + lpf_register_global(lpf, dstbuf, bufsize, &dstslot); + + int i = 0; + for (i = 0; i < 3; ++i) { + lpf_err_t rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + size_t dstoffset = 0; + size_t srcoffset = 0; + unsigned p; + for (p = 0; p < nprocs; ++p) { + dstoffset = p * blocksize; + if (pid != p) + lpf_put(lpf, srcslot, srcoffset, p, dstslot, dstoffset, blocksize, + LPF_MSG_DEFAULT); + srcoffset += blocksize; + } + } + + lpf_err_t rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_deregister(lpf, srcslot); + lpf_deregister(lpf, dstslot); +} + +/** + * \test Test lpf_put by sending messages larger than max MPI message size + * \pre P >= 2 + * \note Extra lpfrun parameters: -max-mpi-msg-size 500 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_big) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_huge.c b/tests/functional/func_lpf_put_parallel_huge.c deleted file mode 100644 index b26d0802..00000000 --- a/tests/functional/func_lpf_put_parallel_huge.c +++ /dev/null @@ -1,105 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_EQ("%d", 2, nprocs); - - size_t maxMsgs = 1 , maxRegs = 2; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - size_t huge = (size_t) 10 + INT_MAX; // if this overflows, it means that - // size_t fits in 'int' and so this - // test is pointless - int *x = calloc( huge , sizeof(int)); - int *y = calloc( huge, sizeof(int)); - - EXPECT_NE( "%p", (int *) NULL, x ); - EXPECT_NE( "%p", (int *) NULL, y ); - - size_t i; - for (i = 0; i = 2 - * \pre P <= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_huge ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_huge.cpp b/tests/functional/func_lpf_put_parallel_huge.cpp new file mode 100644 index 00000000..5541c6b3 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_huge.cpp @@ -0,0 +1,95 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "gtest/gtest.h" + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_EQ(2, nprocs); + + size_t maxMsgs = 1, maxRegs = 2; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + size_t huge = (size_t)10 + INT_MAX; // if this overflows, it means that + // size_t fits in 'int' and so this + // test is pointless + int *x = (int *)calloc(huge, sizeof(int)); + int *y = (int *)calloc(huge, sizeof(int)); + + EXPECT_NE((int *)NULL, x); + EXPECT_NE((int *)NULL, y); + + size_t i; + for (i = 0; i < huge; ++i) { + x[i] = (int)(i % INT_MAX); + } + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, x, sizeof(int) * huge, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, y, sizeof(int) * huge, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid == 1) { + rc = lpf_put(lpf, xslot, 0, 0, yslot, 0, sizeof(int) * huge, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (pid == 0) { + for (i = 0; i < huge; ++i) { + EXPECT_EQ(x[i], y[i]); + } + } else { + for (i = 0; i < huge; ++i) { + EXPECT_EQ(0, y[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put by sending a message larger than INT_MAX + * \pre P >= 2 + * \pre P <= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_huge) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_complete.c b/tests/functional/func_lpf_put_parallel_overlapping_complete.c deleted file mode 100644 index 32ff4679..00000000 --- a/tests/functional/func_lpf_put_parallel_overlapping_complete.c +++ /dev/null @@ -1,108 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - const int MTU=2000; - const int n = MTU*nprocs; - int i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*n + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs+1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", i*n + (int) pid, xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // Each processor copies his row to processor zero. - rc = lpf_put( lpf, xslot, 0u, - 0, yslot, 0u, sizeof(xs[0]) * n, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - // on processor 0 only one of the writes will occur. - int delta = ys[0] - xs[0]; - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", delta, ys[i] - xs[i] ); - } - } - else - { - // on the other processors nothing has been written - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_put when multiple processors write to the same memory area - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_overlapping_complete ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_complete.cpp b/tests/functional/func_lpf_put_parallel_overlapping_complete.cpp new file mode 100644 index 00000000..04afa828 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_overlapping_complete.cpp @@ -0,0 +1,95 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + const int MTU = 2000; + const int n = MTU * nprocs; + int i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * n + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ(i * n + (int)pid, xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // Each processor copies his row to processor zero. + rc = + lpf_put(lpf, xslot, 0u, 0, yslot, 0u, sizeof(xs[0]) * n, LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + // on processor 0 only one of the writes will occur. + int delta = ys[0] - xs[0]; + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(delta, ys[i] - xs[i]); + } + } else { + // on the other processors nothing has been written + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put when multiple processors write to the same memory area + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_overlapping_complete) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_pyramid.c b/tests/functional/func_lpf_put_parallel_overlapping_pyramid.c deleted file mode 100644 index 690ebaf5..00000000 --- a/tests/functional/func_lpf_put_parallel_overlapping_pyramid.c +++ /dev/null @@ -1,141 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args ; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - const size_t MTU=2000; - const size_t n = 2*nprocs*MTU; - size_t i; - int * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*n + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs + 1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) (i*n+pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - - // Each processor copies his row to processor zero. - size_t start = pid; - size_t end = 2*nprocs - pid; - rc = lpf_put( lpf, xslot, start*MTU*sizeof(xs[0]), - 0, yslot, start*MTU*sizeof(xs[0]), (end-start)*MTU*sizeof(xs[0]), - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - /** - * The array 'xs' is sent to processor 0 as a pyramid. Writes - * will overlap in the middle of the block. On those - * places a specific sequential ordering has to be inplace. - * - * proc 0: 0123456789 - * proc 1: abcdefgh - * proc 2: pqrstu - * proc 3: vwxy - * proc 4: z. - * - * -------------------- - * proc 0: 0apvz.yuh9 - * or p 1: 0123456789 - * or something in between - * - **/ - for (i = 0; i < n; i+=MTU) - { - // check the contents of a block - int pid1 = ys[i] - xs[i]; - int pid2 = ys[n-i-1] - xs[n-i-1]; - EXPECT_EQ( "%d", pid1, pid2 ); - EXPECT_LE( "%d", pid1, (int) i ); - EXPECT_LE( "%d", pid1, (int) (n-i-1) ); - - EXPECT_LE( "%d", pid1, (int) nprocs); - - - // check that all values in the block are from the same processor - size_t j; - for (j = 0; j < MTU; ++j) - { - EXPECT_EQ( "%d", pid1, ys[i+j] - xs[i+j]); - EXPECT_EQ( "%d", pid1, ys[n-i-1-j] - xs[n-i-1-j] ); - } - } - } - else - { - // on the other processors nothing has changed - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%d", (int) ( i*n + pid), xs[i] ); - EXPECT_EQ( "%d", 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_put writing to partial overlapping memory areas from multiple processors. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_overlapping_pyramid ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_pyramid.cpp b/tests/functional/func_lpf_put_parallel_overlapping_pyramid.cpp new file mode 100644 index 00000000..a016c11b --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_overlapping_pyramid.cpp @@ -0,0 +1,126 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + const size_t MTU = 2000; + const size_t n = 2 * nprocs * MTU; + size_t i; + int *xs, *ys; + ys = (int *)malloc(sizeof(ys[0]) * n); + xs = (int *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * n + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + + // Each processor copies his row to processor zero. + size_t start = pid; + size_t end = 2 * nprocs - pid; + rc = lpf_put(lpf, xslot, start * MTU * sizeof(xs[0]), 0, yslot, + start * MTU * sizeof(xs[0]), (end - start) * MTU * sizeof(xs[0]), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + /** + * The array 'xs' is sent to processor 0 as a pyramid. Writes + * will overlap in the middle of the block. On those + * places a specific sequential ordering has to be inplace. + * + * proc 0: 0123456789 + * proc 1: abcdefgh + * proc 2: pqrstu + * proc 3: vwxy + * proc 4: z. + * + * -------------------- + * proc 0: 0apvz.yuh9 + * or p 1: 0123456789 + * or something in between + * + **/ + for (i = 0; i < n; i += MTU) { + // check the contents of a block + int pid1 = ys[i] - xs[i]; + int pid2 = ys[n - i - 1] - xs[n - i - 1]; + EXPECT_EQ(pid1, pid2); + EXPECT_LE(pid1, (int)i); + EXPECT_LE(pid1, (int)(n - i - 1)); + + EXPECT_LE(pid1, (int)nprocs); + + // check that all values in the block are from the same processor + size_t j; + for (j = 0; j < MTU; ++j) { + EXPECT_EQ(pid1, ys[i + j] - xs[i + j]); + EXPECT_EQ(pid1, ys[n - i - 1 - j] - xs[n - i - 1 - j]); + } + } + } else { + // on the other processors nothing has changed + for (i = 0; i < n; ++i) { + EXPECT_EQ((int)(i * n + pid), xs[i]); + EXPECT_EQ(0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put writing to partial overlapping memory areas from multiple + * processors. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_overlapping_pyramid) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.c b/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.c deleted file mode 100644 index 4e08b8eb..00000000 --- a/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.c +++ /dev/null @@ -1,170 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -#include -#include - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - - lpf_err_t rc = LPF_SUCCESS; - const size_t MTU = 2048; - const size_t n = 5*nprocs*MTU; - size_t i; - uint64_t * xs, *ys; - ys = malloc( sizeof(ys[0]) * n); - xs = malloc( sizeof(xs[0]) * n); - for (i = 0; i < n; ++i) - { - xs[i] = i*nprocs + pid; - ys[i] = 0; - } - - rc = lpf_resize_message_queue( lpf, nprocs+1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, xs, sizeof(xs[0]) * n, &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, ys, sizeof(ys[0]) * n, &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - // Check that data is OK. - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%" PRIu64, (uint64_t) (i*nprocs+pid), xs[i] ); - EXPECT_EQ( "%" PRIu64, (uint64_t) 0, ys[i] ); - } - - // Each processor copies his row to processor zero. - { - size_t start = 5*pid; - size_t length = 5; - size_t offset = start - pid; - rc = lpf_put( lpf, xslot, start*sizeof(xs[0])*MTU, - 0, yslot, offset*sizeof(xs[0])*MTU, length*sizeof(xs[0])*MTU, - LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - if ( 0 == pid ) - { - /** - * The array 'xs' is sent to processor 0 as a rooftiling. Writes - * will overlap at the end and beginning of each tile. On those - * places a specific sequential ordering has to be inplace. - * - * proc0 proc1 proc2 proc3 - * 01234 56789 ..... ..... - * | / - * v | - * 01234 v - * 56789 - * ..... - * ..... - * - * Note that the arithmetic can get screwed up if the numbers grow - * too big. - **/ - - unsigned int offset = 0; - for (i = 0; i < nprocs; ++i) - { - int j; - size_t k; - for (j = 0; j < 5 ; ++j) - { - uint64_t fromPid = ys[(4*i+j) * MTU] - xs[(4*i + j + offset) * MTU]; - fromPid = (fromPid + nprocs*MTU)%nprocs; - for (k = 0; k < MTU; ++k) - { - uint64_t fromPid2 = ys[ (4*i+j) * MTU + k] - - xs[(4*i+j + offset) * MTU + k]; - fromPid2 = (fromPid2 + nprocs*MTU)%nprocs; - EXPECT_EQ( "%" PRIu64, fromPid, fromPid2 ); - - if (fromPid == i) - EXPECT_EQ( "%" PRIu64, (5*i+j)*nprocs*MTU + fromPid, ys[(4*i+j)*MTU] ); - } - - if (0 == j && i > 0) - { - EXPECT_EQ( "%d", 1, fromPid == i || fromPid == i-1 ); - } - else if (4 == j && i < nprocs-1) - { - EXPECT_EQ( "%d", 1, fromPid == i || fromPid == i+1 ); - } - else - { - EXPECT_EQ( "%" PRIu64, fromPid, (uint64_t) i ); - } - } - offset += 1; - } - EXPECT_EQ("%u", (unsigned) nprocs, offset ); - // the rest of the ys array should be zero - for (i = 0; i < (nprocs-1) * MTU ; ++i) - { - EXPECT_EQ("%" PRIu64, (uint64_t) 0, ys[n-i-1]); - } - } - else - { - // on the other processors nothing has changed - for (i = 0; i < n; ++i) - { - EXPECT_EQ( "%" PRIu64, (uint64_t) ( i*nprocs + pid), xs[i] ); - EXPECT_EQ( "%" PRIu64, (uint64_t) 0, ys[i] ); - } - } - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_put writing to partial overlapping memory areas from multiple processors. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_overlapping_rooftiling ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.cpp b/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.cpp new file mode 100644 index 00000000..8b21c583 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_overlapping_rooftiling.cpp @@ -0,0 +1,152 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + + lpf_err_t rc = LPF_SUCCESS; + const size_t MTU = 2048; + const size_t n = 5 * nprocs * MTU; + size_t i; + uint64_t *xs, *ys; + ys = (uint64_t *)malloc(sizeof(ys[0]) * n); + xs = (uint64_t *)malloc(sizeof(xs[0]) * n); + for (i = 0; i < n; ++i) { + xs[i] = i * nprocs + pid; + ys[i] = 0; + } + + rc = lpf_resize_message_queue(lpf, nprocs + 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, xs, sizeof(xs[0]) * n, &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, ys, sizeof(ys[0]) * n, &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // Check that data is OK. + for (i = 0; i < n; ++i) { + EXPECT_EQ((uint64_t)(i * nprocs + pid), xs[i]); + EXPECT_EQ((uint64_t)0, ys[i]); + } + + // Each processor copies his row to processor zero. + { + size_t start = 5 * pid; + size_t length = 5; + size_t offset = start - pid; + rc = lpf_put(lpf, xslot, start * sizeof(xs[0]) * MTU, 0, yslot, + offset * sizeof(xs[0]) * MTU, length * sizeof(xs[0]) * MTU, + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + if (0 == pid) { + /** + * The array 'xs' is sent to processor 0 as a rooftiling. Writes + * will overlap at the end and beginning of each tile. On those + * places a specific sequential ordering has to be inplace. + * + * proc0 proc1 proc2 proc3 + * 01234 56789 ..... ..... + * | / + * v | + * 01234 v + * 56789 + * ..... + * ..... + * + * Note that the arithmetic can get screwed up if the numbers grow + * too big. + **/ + + unsigned int offset = 0; + for (i = 0; i < nprocs; ++i) { + int j; + size_t k; + for (j = 0; j < 5; ++j) { + uint64_t fromPid = + ys[(4 * i + j) * MTU] - xs[(4 * i + j + offset) * MTU]; + fromPid = (fromPid + nprocs * MTU) % nprocs; + for (k = 0; k < MTU; ++k) { + uint64_t fromPid2 = + ys[(4 * i + j) * MTU + k] - xs[(4 * i + j + offset) * MTU + k]; + fromPid2 = (fromPid2 + nprocs * MTU) % nprocs; + EXPECT_EQ(fromPid, fromPid2); + + if (fromPid == i) { + EXPECT_EQ((5 * i + j) * nprocs * MTU + fromPid, + ys[(4 * i + j) * MTU]); + } + } + + if (0 == j && i > 0) { + EXPECT_EQ(1, fromPid == i || fromPid == i - 1); + } else if (4 == j && i < nprocs - 1) { + EXPECT_EQ(1, fromPid == i || fromPid == i + 1); + } else { + EXPECT_EQ(fromPid, (uint64_t)i); + } + } + offset += 1; + } + EXPECT_EQ((unsigned)nprocs, offset); + // the rest of the ys array should be zero + for (i = 0; i < (nprocs - 1) * MTU; ++i) { + EXPECT_EQ((uint64_t)0, ys[n - i - 1]); + } + } else { + // on the other processors nothing has changed + for (i = 0; i < n; ++i) { + EXPECT_EQ((uint64_t)(i * nprocs + pid), xs[i]); + EXPECT_EQ((uint64_t)0, ys[i]); + } + } + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put writing to partial overlapping memory areas from multiple + * processors. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_overlapping_rooftiling) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_put_parallel_single.c b/tests/functional/func_lpf_put_parallel_single.c deleted file mode 100644 index 9fa85d84..00000000 --- a/tests/functional/func_lpf_put_parallel_single.c +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 2 , maxRegs = 2; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - int x = 5, y = 10; - lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; - lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; - rc = lpf_register_local( lpf, &x, sizeof(x), &xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_register_global( lpf, &y, sizeof(y), &yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 10, y); - - rc = lpf_put( lpf, xslot, 0, (pid+1)%nprocs, yslot, 0, sizeof(x), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%d", 5, y); - - rc = lpf_deregister( lpf, xslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_deregister( lpf, yslot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Test lpf_put by sending a message following a ring. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_put_parallel_single ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ("%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_put_parallel_single.cpp b/tests/functional/func_lpf_put_parallel_single.cpp new file mode 100644 index 00000000..66488c24 --- /dev/null +++ b/tests/functional/func_lpf_put_parallel_single.cpp @@ -0,0 +1,70 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 2, maxRegs = 2; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + int x = 5, y = 10; + lpf_memslot_t xslot = LPF_INVALID_MEMSLOT; + lpf_memslot_t yslot = LPF_INVALID_MEMSLOT; + rc = lpf_register_local(lpf, &x, sizeof(x), &xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_register_global(lpf, &y, sizeof(y), &yslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(10, y); + + rc = lpf_put(lpf, xslot, 0, (pid + 1) % nprocs, yslot, 0, sizeof(x), + LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(5, y); + + rc = lpf_deregister(lpf, xslot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_deregister(lpf, yslot); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Test lpf_put by sending a message following a ring. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_put_parallel_single) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_and_deregister_irregularly.c b/tests/functional/func_lpf_register_and_deregister_irregularly.c deleted file mode 100644 index 0047bfcd..00000000 --- a/tests/functional/func_lpf_register_and_deregister_irregularly.c +++ /dev/null @@ -1,88 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - (void) pid; - (void) nprocs; - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 0 , maxRegs = 16; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[16] = "abcdefghijklmnop"; - lpf_memslot_t slots[16]; - - // register 3 entries - int i; - for ( i = 0; i < 16; ++i) - { - rc = lpf_register_global( lpf, &buffer[i], sizeof(buffer[i]), &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // deregister all but the last - for ( i = 0; i < 15; ++i) - { - rc = lpf_deregister( lpf, slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // and resize to 2 - maxRegs = 2; - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // and deregister the last one - rc = lpf_deregister( lpf, slots[15] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Register a few global registers and deregister them again in a funny way. This broke a previous memory registration implementation. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_and_deregister_irregularly ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_lpf_register_and_deregister_irregularly.cpp b/tests/functional/func_lpf_register_and_deregister_irregularly.cpp new file mode 100644 index 00000000..e7d747bb --- /dev/null +++ b/tests/functional/func_lpf_register_and_deregister_irregularly.cpp @@ -0,0 +1,82 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + (void)pid; + (void)nprocs; + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 0, maxRegs = 16; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + std::string buffer = "abcdefghijklmnop"; + lpf_memslot_t slots[16]; + + // register 3 entries + int i; + for (i = 0; i < 16; ++i) { + rc = lpf_register_global(lpf, &buffer[i], sizeof(buffer[i]), &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // deregister all but the last + for (i = 0; i < 15; ++i) { + rc = lpf_deregister(lpf, slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // and resize to 2 + maxRegs = 2; + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // and deregister the last one + rc = lpf_deregister(lpf, slots[15]); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Register a few global registers and deregister them again in a funny + * way. This broke a previous memory registration implementation. \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_and_deregister_irregularly) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_and_deregister_many_global.c b/tests/functional/func_lpf_register_and_deregister_many_global.c deleted file mode 100644 index 851c25e7..00000000 --- a/tests/functional/func_lpf_register_and_deregister_many_global.c +++ /dev/null @@ -1,74 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - (void) pid; - (void) nprocs; - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 4 , maxRegs = 4; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[8] = "abcd"; - lpf_memslot_t slots[4]; - - // register 4 entries - size_t i; - int j; - - for (j = 0; j < 1000; ++j) - { - for ( i = 0; i < maxRegs; ++i) - { - rc = lpf_register_global( lpf, &buffer[i*2], sizeof(buffer[0])*2, &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - for ( i = 0 ; i < maxRegs; ++i) - { - rc = lpf_deregister( lpf, slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Allocate and deallocate many times the same register (globally) in the same superstep. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_and_deregister_many_global ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_lpf_register_and_deregister_many_global.cpp b/tests/functional/func_lpf_register_and_deregister_many_global.cpp new file mode 100644 index 00000000..0ff7b65e --- /dev/null +++ b/tests/functional/func_lpf_register_and_deregister_many_global.cpp @@ -0,0 +1,67 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + (void)pid; + (void)nprocs; + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 4, maxRegs = 4; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char buffer[8] = "abcd"; + lpf_memslot_t slots[4]; + + // register 4 entries + size_t i; + int j; + + for (j = 0; j < 1000; ++j) { + for (i = 0; i < maxRegs; ++i) { + rc = lpf_register_global(lpf, &buffer[i * 2], sizeof(buffer[0]) * 2, + &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + for (i = 0; i < maxRegs; ++i) { + rc = lpf_deregister(lpf, slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Allocate and deallocate many times the same register (globally) in the + * same superstep. \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_register_and_deregister_many_global) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_global_parallel_grow.c b/tests/functional/func_lpf_register_global_parallel_grow.c deleted file mode 100644 index 1c5821fd..00000000 --- a/tests/functional/func_lpf_register_global_parallel_grow.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 20 , maxRegs = 7; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[21] = "Ditiseentestmettandr"; - lpf_memslot_t slots[10]; - - int i; - for ( i = 0; i < 5; ++i) - { - rc = lpf_register_global( lpf, &buffer[i*2], sizeof(buffer[0])*2, &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_resize_memory_register( lpf, maxRegs + 3 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for ( i = 0; i < 5; ++i) - { - rc = lpf_register_global( lpf, &buffer[(i+5)*2], sizeof(buffer[0])*2, &slots[i+5] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - EXPECT_STREQ( 20, "Ditiseentestmettandr", buffer ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - for (i = 0; i < 10; ++i) - { - lpf_put( lpf, slots[i], 0u, - (pid+i)%nprocs, slots[i], 1u, sizeof(buffer[0]), LPF_MSG_DEFAULT ); - } - - lpf_sync( lpf, LPF_SYNC_DEFAULT ); - - EXPECT_STREQ( 20, "DDttsseettssmmttaadd", buffer ); - - for (i = 0; i < 10; ++i) - lpf_deregister( lpf, slots[i] ); -} - -/** - * \test Allocate some registers, use some, and allocate some more. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_global_parallel_grow ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_register_global_parallel_grow.cpp b/tests/functional/func_lpf_register_global_parallel_grow.cpp new file mode 100644 index 00000000..36b36eb3 --- /dev/null +++ b/tests/functional/func_lpf_register_global_parallel_grow.cpp @@ -0,0 +1,81 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 20, maxRegs = 7; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char buffer[21] = "Ditiseentestmettandr"; + lpf_memslot_t slots[10]; + + int i; + for (i = 0; i < 5; ++i) { + rc = lpf_register_global(lpf, &buffer[i * 2], sizeof(buffer[0]) * 2, + &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_resize_memory_register(lpf, maxRegs + 3); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (i = 0; i < 5; ++i) { + rc = lpf_register_global(lpf, &buffer[(i + 5) * 2], sizeof(buffer[0]) * 2, + &slots[i + 5]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + EXPECT_STREQ("Ditiseentestmettandr", buffer); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + for (i = 0; i < 10; ++i) { + lpf_put(lpf, slots[i], 0u, (pid + i) % nprocs, slots[i], 1u, + sizeof(buffer[0]), LPF_MSG_DEFAULT); + } + + lpf_sync(lpf, LPF_SYNC_DEFAULT); + + EXPECT_STREQ("DDttsseettssmmttaadd", buffer); + + for (i = 0; i < 10; ++i) + lpf_deregister(lpf, slots[i]); +} + +/** + * \test Allocate some registers, use some, and allocate some more. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_global_parallel_grow) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_global_parallel_multiple.c b/tests/functional/func_lpf_register_global_parallel_multiple.c deleted file mode 100644 index 515f1f87..00000000 --- a/tests/functional/func_lpf_register_global_parallel_multiple.c +++ /dev/null @@ -1,112 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; // ignore args parameter - EXPECT_LT( "%d", (int) pid, (int) nprocs ); - char a[1] = { 'i' }; - char b[2] = { 'p', 'q' }; - char c[3] = { 'a', 'b', 'c'}; - char d[6] = "hallo"; - - lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t dSlot = LPF_INVALID_MEMSLOT; - lpf_err_t rc = LPF_SUCCESS; - - rc = lpf_resize_message_queue( lpf, 1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 4); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &a, sizeof(a), &aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &c, sizeof(c), &cSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &d, sizeof(d), &dSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'c', c[2]); - EXPECT_EQ( "%c", 'h', d[0]); - EXPECT_EQ( "%c", 'a', d[1]); - EXPECT_EQ( "%c", 'l', d[2]); - EXPECT_EQ( "%c", 'l', d[3]); - EXPECT_EQ( "%c", 'o', d[4]); - EXPECT_EQ( "%c", '\0', d[5]); - - if ( 0 == pid ) - { - rc = lpf_register_local( lpf, &b, sizeof(b), &bSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, bSlot, 1u * sizeof(b[0]), - 1u, dSlot, 2u*sizeof(d[0]), sizeof(b[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'c', c[2]); - EXPECT_EQ( "%c", 'h', d[0]); - EXPECT_EQ( "%c", 'a', d[1]); - EXPECT_EQ( "%c", pid == 1 ? 'q' : 'l', d[2]); - EXPECT_EQ( "%c", 'l', d[3]); - EXPECT_EQ( "%c", 'o', d[4]); - EXPECT_EQ( "%c", '\0', d[5]); - - - lpf_deregister( lpf, dSlot ); - lpf_deregister( lpf, cSlot ); - if (pid == 0) lpf_deregister( lpf, bSlot ); - lpf_deregister( lpf, aSlot ); -} - -/** - * \test Test registering global variables in the context of a parallel program. - * \pre P >= 2 - * \return Exit code: 0 - */ -TEST( func_lpf_register_global_parallel_multiple ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc); - return 0; -} diff --git a/tests/functional/func_lpf_register_global_parallel_multiple.cpp b/tests/functional/func_lpf_register_global_parallel_multiple.cpp new file mode 100644 index 00000000..19a53e4a --- /dev/null +++ b/tests/functional/func_lpf_register_global_parallel_multiple.cpp @@ -0,0 +1,108 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + EXPECT_LT((int)pid, (int)nprocs); + char a[1] = {'i'}; + char b[2] = {'p', 'q'}; + char c[3] = {'a', 'b', 'c'}; + char d[6] = "hallo"; + + lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t dSlot = LPF_INVALID_MEMSLOT; + lpf_err_t rc = LPF_SUCCESS; + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 4); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &a, sizeof(a), &aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &c, sizeof(c), &cSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &d, sizeof(d), &dSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('c', c[2]); + EXPECT_EQ('h', d[0]); + EXPECT_EQ('a', d[1]); + EXPECT_EQ('l', d[2]); + EXPECT_EQ('l', d[3]); + EXPECT_EQ('o', d[4]); + EXPECT_EQ('\0', d[5]); + + if (0 == pid) { + rc = lpf_register_local(lpf, &b, sizeof(b), &bSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, bSlot, 1u * sizeof(b[0]), 1u, dSlot, 2u * sizeof(d[0]), + sizeof(b[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('c', c[2]); + EXPECT_EQ('h', d[0]); + EXPECT_EQ('a', d[1]); + EXPECT_EQ(pid == 1 ? 'q' : 'l', d[2]); + EXPECT_EQ('l', d[3]); + EXPECT_EQ('o', d[4]); + EXPECT_EQ('\0', d[5]); + + lpf_deregister(lpf, dSlot); + lpf_deregister(lpf, cSlot); + if (pid == 0) + lpf_deregister(lpf, bSlot); + lpf_deregister(lpf, aSlot); +} + +/** + * \test Test registering global variables in the context of a parallel program. + * \pre P >= 2 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_global_parallel_multiple) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_global_parallel_shrink.c b/tests/functional/func_lpf_register_global_parallel_shrink.c deleted file mode 100644 index ec1ac62a..00000000 --- a/tests/functional/func_lpf_register_global_parallel_shrink.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore args parameter - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 20 , maxRegs = 10; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[21] = "Ditiseentestmettandr"; - lpf_memslot_t slots[10]; - - // register 10 entries - int i; - for ( i = 0; i < 10; ++i) - { - rc = lpf_register_global( lpf, &buffer[i*2], sizeof(buffer[0])*2, &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - // deregister 4 in an atypical order - int nDelRegs = 4; - size_t delRegs[] = { 8, 0, 5, 9}; - size_t otherRegs[] = { 1, 2, 3, 4, 6, 7 }; - for (i = 0; i < nDelRegs; ++i) - { - rc = lpf_deregister( lpf, slots[ delRegs[i] ]); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - // reduce by 4 which gets accepted - rc = lpf_resize_memory_register( lpf, maxRegs - 4); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_STREQ( 20, "Ditiseentestmettandr", buffer ); - - // test that the remaining registrations still work - size_t k; - for (k = 0; k < 10; ++k) - { - int j; - for ( j = 0; j < nDelRegs; ++j) - { - if ( delRegs[j] == k ) - break; - } - // if slot wasn't deregistered, then send something - if ( j == nDelRegs) - { - lpf_put( lpf, slots[k], 0u, - (pid+k)%nprocs, slots[k], 1u, sizeof(buffer[0]), LPF_MSG_DEFAULT ); - } - } - - lpf_sync( lpf, LPF_SYNC_DEFAULT ); - - EXPECT_STREQ( 20, "Dittsseettstmmttandr", buffer ); - - for (i = 0; i < 6; ++i) - lpf_deregister( lpf, slots[ otherRegs[i] ]); -} - -/** - * \test Allocate some registers, use some and then delete a few. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_global_parallel_shrink ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} diff --git a/tests/functional/func_lpf_register_global_parallel_shrink.cpp b/tests/functional/func_lpf_register_global_parallel_shrink.cpp new file mode 100644 index 00000000..d88f56a8 --- /dev/null +++ b/tests/functional/func_lpf_register_global_parallel_shrink.cpp @@ -0,0 +1,92 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 20, maxRegs = 10; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + char buffer[21] = "Ditiseentestmettandr"; + lpf_memslot_t slots[10]; + + // register 10 entries + int i; + for (i = 0; i < 10; ++i) { + rc = lpf_register_global(lpf, &buffer[i * 2], sizeof(buffer[0]) * 2, + &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + // deregister 4 in an atypical order + int nDelRegs = 4; + size_t delRegs[] = {8, 0, 5, 9}; + size_t otherRegs[] = {1, 2, 3, 4, 6, 7}; + for (i = 0; i < nDelRegs; ++i) { + rc = lpf_deregister(lpf, slots[delRegs[i]]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + // reduce by 4 which gets accepted + rc = lpf_resize_memory_register(lpf, maxRegs - 4); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_STREQ("Ditiseentestmettandr", buffer); + + // test that the remaining registrations still work + size_t k; + for (k = 0; k < 10; ++k) { + int j; + for (j = 0; j < nDelRegs; ++j) { + if (delRegs[j] == k) + break; + } + // if slot wasn't deregistered, then send something + if (j == nDelRegs) { + lpf_put(lpf, slots[k], 0u, (pid + k) % nprocs, slots[k], 1u, + sizeof(buffer[0]), LPF_MSG_DEFAULT); + } + } + + lpf_sync(lpf, LPF_SYNC_DEFAULT); + + EXPECT_STREQ("Dittsseettstmmttandr", buffer); + + for (i = 0; i < 6; ++i) + lpf_deregister(lpf, slots[otherRegs[i]]); +} + +/** + * \test Allocate some registers, use some and then delete a few. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_global_parallel_shrink) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_register_global_root_multiple.c b/tests/functional/func_lpf_register_global_root_multiple.c deleted file mode 100644 index 04c69846..00000000 --- a/tests/functional/func_lpf_register_global_root_multiple.c +++ /dev/null @@ -1,79 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -/** - * \test Test registering two times a global variable. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_global_root_multiple ) -{ - char a[1] = { 'i' }; - char b[2] = { 'p', 'q' }; - char c[3] = { 'a', 'b', 'c'}; - - lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; - lpf_err_t rc = LPF_SUCCESS; - - rc = lpf_resize_message_queue( LPF_ROOT, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, 3); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( LPF_ROOT, &a, sizeof(a), &aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( LPF_ROOT, &b, sizeof(b), &bSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( LPF_ROOT, &c, sizeof(c), &cSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'c', c[2]); - - rc = lpf_put( LPF_ROOT, bSlot, 1u * sizeof(b[0]), - 0u, cSlot, 2u*sizeof(c[0]), sizeof(b[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'q', c[2]); - - return 0; -} diff --git a/tests/functional/func_lpf_register_global_root_multiple.cpp b/tests/functional/func_lpf_register_global_root_multiple.cpp new file mode 100644 index 00000000..98e494ac --- /dev/null +++ b/tests/functional/func_lpf_register_global_root_multiple.cpp @@ -0,0 +1,76 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +/** + * \test Test registering two times a global variable. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_global_root_multiple) { + char a[1] = {'i'}; + char b[2] = {'p', 'q'}; + char c[3] = {'a', 'b', 'c'}; + + lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; + lpf_err_t rc = LPF_SUCCESS; + + rc = lpf_resize_message_queue(LPF_ROOT, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(LPF_ROOT, 3); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(LPF_ROOT, &a, sizeof(a), &aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(LPF_ROOT, &b, sizeof(b), &bSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(LPF_ROOT, &c, sizeof(c), &cSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('c', c[2]); + + rc = lpf_put(LPF_ROOT, bSlot, 1u * sizeof(b[0]), 0u, cSlot, 2u * sizeof(c[0]), + sizeof(b[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('q', c[2]); +} diff --git a/tests/functional/func_lpf_register_global_root_single.c b/tests/functional/func_lpf_register_global_root_single.c deleted file mode 100644 index 87514734..00000000 --- a/tests/functional/func_lpf_register_global_root_single.c +++ /dev/null @@ -1,67 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -/** - * \test Test registering one global variable. - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_register_global_root_single ) -{ - char a[1] = { 'j' }; - char b[2] = { 'a', 'b' }; - lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; - lpf_err_t rc = LPF_SUCCESS; - - rc = lpf_resize_message_queue( LPF_ROOT, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, 2); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( LPF_ROOT, &a, sizeof(a), &aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_local( LPF_ROOT, &b, sizeof(b), &bSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'j', a[0]); - EXPECT_EQ( "%c", 'a', b[0]); - EXPECT_EQ( "%c", 'b', b[1]); - - rc = lpf_put( LPF_ROOT, bSlot, 1u * sizeof(b[0]), - 0u, aSlot, 0u*sizeof(a[0]), sizeof(a[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'b', a[0]); - EXPECT_EQ( "%c", 'a', b[0]); - EXPECT_EQ( "%c", 'b', b[1]); - - return 0; -} diff --git a/tests/functional/func_lpf_register_global_root_single.cpp b/tests/functional/func_lpf_register_global_root_single.cpp new file mode 100644 index 00000000..933cf13f --- /dev/null +++ b/tests/functional/func_lpf_register_global_root_single.cpp @@ -0,0 +1,64 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +/** + * \test Test registering one global variable. + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_global_root_single) { + char a[1] = {'j'}; + char b[2] = {'a', 'b'}; + lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t bSlot = LPF_INVALID_MEMSLOT; + lpf_err_t rc = LPF_SUCCESS; + + rc = lpf_resize_message_queue(LPF_ROOT, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(LPF_ROOT, 2); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(LPF_ROOT, &a, sizeof(a), &aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_local(LPF_ROOT, &b, sizeof(b), &bSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('j', a[0]); + EXPECT_EQ('a', b[0]); + EXPECT_EQ('b', b[1]); + + rc = lpf_put(LPF_ROOT, bSlot, 1u * sizeof(b[0]), 0u, aSlot, 0u * sizeof(a[0]), + sizeof(a[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('b', a[0]); + EXPECT_EQ('a', b[0]); + EXPECT_EQ('b', b[1]); +} diff --git a/tests/functional/func_lpf_register_local_parallel_multiple.c b/tests/functional/func_lpf_register_local_parallel_multiple.c deleted file mode 100644 index 368fbe17..00000000 --- a/tests/functional/func_lpf_register_local_parallel_multiple.c +++ /dev/null @@ -1,101 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - (void) args; // ignore args parameter passed by lpf_exec - - char a[1] = { 'i' }; - char b[2] = { 'p', 'q' }; - char c[3] = { 'a', 'b', 'c'}; - - lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; - lpf_memslot_t xSlot[10]; - lpf_err_t rc = LPF_SUCCESS; - - EXPECT_LT( "%u", pid, nprocs ); - - rc = lpf_resize_message_queue( lpf, 1); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, 2 + nprocs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_pid_t i; - for (i = 0; i < pid; ++i) - { - int x = 0; - rc = lpf_register_local( lpf, &x, sizeof(x)+pid, &xSlot[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_register_global( lpf, &a, sizeof(a), &aSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'c', c[2]); - - if ( 1 == pid ) - { - rc = lpf_register_local( lpf, &c, sizeof(c), &cSlot ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_put( lpf, cSlot, 1u * sizeof(c[0]), - 0u, aSlot, 0u*sizeof(a[0]), sizeof(a[0]), LPF_MSG_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - EXPECT_EQ( "%c", 0 == pid ? 'b' : 'i', a[0]); - EXPECT_EQ( "%c", 'p', b[0]); - EXPECT_EQ( "%c", 'q', b[1]); - EXPECT_EQ( "%c", 'a', c[0]); - EXPECT_EQ( "%c", 'b', c[1]); - EXPECT_EQ( "%c", 'c', c[2]); - - if ( 1 == pid) lpf_deregister( lpf, cSlot ); - lpf_deregister( lpf, aSlot ); - for ( i = 0; i < pid; ++i) - lpf_deregister( lpf, xSlot[i] ); -} - -/** - * \test Test registering a different number of local variables on each pid - * \pre P >= 2 - * \pre P <= 10 - * \return Exit code: 0 - */ -TEST( func_lpf_register_local_parallel_multiple ) -{ - lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - return 0; -} diff --git a/tests/functional/func_lpf_register_local_parallel_multiple.cpp b/tests/functional/func_lpf_register_local_parallel_multiple.cpp new file mode 100644 index 00000000..725bc55b --- /dev/null +++ b/tests/functional/func_lpf_register_local_parallel_multiple.cpp @@ -0,0 +1,97 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore args parameter passed by lpf_exec + + char a[1] = {'i'}; + char b[2] = {'p', 'q'}; + char c[3] = {'a', 'b', 'c'}; + + lpf_memslot_t aSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t cSlot = LPF_INVALID_MEMSLOT; + lpf_memslot_t xSlot[10]; + lpf_err_t rc = LPF_SUCCESS; + + EXPECT_LT(pid, nprocs); + + rc = lpf_resize_message_queue(lpf, 1); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, 2 + nprocs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_pid_t i; + for (i = 0; i < pid; ++i) { + int x = 0; + rc = lpf_register_local(lpf, &x, sizeof(x) + pid, &xSlot[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_register_global(lpf, &a, sizeof(a), &aSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ('i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('c', c[2]); + + if (1 == pid) { + rc = lpf_register_local(lpf, &c, sizeof(c), &cSlot); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_put(lpf, cSlot, 1u * sizeof(c[0]), 0u, aSlot, 0u * sizeof(a[0]), + sizeof(a[0]), LPF_MSG_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_EQ(0 == pid ? 'b' : 'i', a[0]); + EXPECT_EQ('p', b[0]); + EXPECT_EQ('q', b[1]); + EXPECT_EQ('a', c[0]); + EXPECT_EQ('b', c[1]); + EXPECT_EQ('c', c[2]); + + if (1 == pid) + lpf_deregister(lpf, cSlot); + lpf_deregister(lpf, aSlot); + for (i = 0; i < pid; ++i) + lpf_deregister(lpf, xSlot[i]); +} + +/** + * \test Test registering a different number of local variables on each pid + * \pre P >= 2 + * \pre P <= 10 + * \return Exit code: 0 + */ +TEST(API, func_lpf_register_local_parallel_multiple) { + lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); +} diff --git a/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.c b/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.c deleted file mode 100644 index 1ff9ff99..00000000 --- a/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.c +++ /dev/null @@ -1,79 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - (void) pid; - (void) nprocs; - - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 0 , maxRegs = 16; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buffer[16] = "abcdefghijklmnop"; - lpf_memslot_t slots[16]; - - // register 16 entries - int i; - for ( i = 0; i < 16; ++i) - { - rc = lpf_register_global( lpf, &buffer[i], sizeof(buffer[i]), &slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // resize to 0 again. - maxRegs = 0; - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // deregister all - for ( i = 0; i < 16; ++i) - { - rc = lpf_deregister( lpf, slots[i] ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - } - - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); -} - -/** - * \test Tests whether the memory registration tables are indeed shrunk in a delayed * manner - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_resize_delayed_shrinking_memory_registers ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.cpp b/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.cpp new file mode 100644 index 00000000..7b9a5553 --- /dev/null +++ b/tests/functional/func_lpf_resize_delayed_shrinking_memory_registers.cpp @@ -0,0 +1,71 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + (void)pid; + (void)nprocs; + + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = 0, maxRegs = 16; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + std::string buffer = "abcdefghijklmnop"; + lpf_memslot_t slots[16]; + + // register 16 entries + int i; + for (i = 0; i < 16; ++i) { + rc = lpf_register_global(lpf, &buffer[i], sizeof(buffer[i]), &slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // resize to 0 again. + maxRegs = 0; + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + + // deregister all + for (i = 0; i < 16; ++i) { + rc = lpf_deregister(lpf, slots[i]); + EXPECT_EQ(LPF_SUCCESS, rc); + } + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); +} + +/** + * \test Tests whether the memory registration tables are indeed shrunk in a + * delayed * manner \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_resize_delayed_shrinking_memory_registers) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.c b/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.c deleted file mode 100644 index 94e2f3e1..00000000 --- a/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - -void spmd( lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) -{ - (void) args; // ignore any arguments passed through call to lpf_exec - (void) pid; - (void) nprocs; - - lpf_err_t rc = LPF_SUCCESS; - - // reserve space for 16 messages - size_t maxMsgs = 32 , maxRegs = 2; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( lpf, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - char buf1[16] = "abcdefghijklmnop"; - char buf2[16] = "ABCDEFGHIJKLMNOP"; - lpf_memslot_t slot1, slot2; - - rc = lpf_register_global( lpf, &buf1[0], sizeof(buf1), &slot1 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_register_global( lpf, &buf2[0], sizeof(buf2), &slot2 ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - // resize to 0 messages again. - maxMsgs = 0; - rc = lpf_resize_message_queue( lpf, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - unsigned i; - for ( i = 0; i < 16; ++i ) - lpf_put( lpf, slot1, i, (pid + 1 ) % nprocs, slot2, i, 1, LPF_MSG_DEFAULT); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - - EXPECT_STREQ( 16, buf2, "abcdefghijklmnop"); - - rc = lpf_sync( lpf, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - lpf_deregister( lpf, slot1 ); - lpf_deregister( lpf, slot2 ); -} - -/** - * \test Tests whether the message queues are indeed shrunk in a delayed manner - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_resize_delayed_shrinking_message_queues ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - return 0; -} - diff --git a/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.cpp b/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.cpp new file mode 100644 index 00000000..c01871fc --- /dev/null +++ b/tests/functional/func_lpf_resize_delayed_shrinking_message_queues.cpp @@ -0,0 +1,80 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +void spmd(lpf_t lpf, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + (void)args; // ignore any arguments passed through call to lpf_exec + (void)pid; + (void)nprocs; + + lpf_err_t rc = LPF_SUCCESS; + + // reserve space for 16 messages + size_t maxMsgs = 32, maxRegs = 2; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(lpf, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + std::string buf1 = "abcdefghijklmnop"; + std::string buf2 = "ABCDEFGHIJKLMNOP"; + lpf_memslot_t slot1, slot2; + + rc = lpf_register_global(lpf, &buf1[0], sizeof(buf1), &slot1); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_register_global(lpf, &buf2[0], sizeof(buf2), &slot2); + EXPECT_EQ(LPF_SUCCESS, rc); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + // resize to 0 messages again. + maxMsgs = 0; + rc = lpf_resize_message_queue(lpf, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + + unsigned i; + for (i = 0; i < 16; ++i) + lpf_put(lpf, slot1, i, (pid + 1) % nprocs, slot2, i, 1, LPF_MSG_DEFAULT); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + EXPECT_STREQ(buf2.c_str(), "abcdefghijklmnop"); + + rc = lpf_sync(lpf, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); + + lpf_deregister(lpf, slot1); + lpf_deregister(lpf, slot2); +} + +/** + * \test Tests whether the message queues are indeed shrunk in a delayed manner + * \pre P >= 1 + * \return Exit code: 0 + */ +TEST(API, func_lpf_resize_delayed_shrinking_message_queues) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); +} diff --git a/tests/functional/func_lpf_resize_parallel_five.c b/tests/functional/func_lpf_resize_parallel_five.cpp similarity index 51% rename from tests/functional/func_lpf_resize_parallel_five.c rename to tests/functional/func_lpf_resize_parallel_five.cpp index c0937c51..436593be 100644 --- a/tests/functional/func_lpf_resize_parallel_five.c +++ b/tests/functional/func_lpf_resize_parallel_five.cpp @@ -15,38 +15,33 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" -void spmd( lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args ) -{ - // ignore the following parameters: - (void) pid; - (void) nprocs; - (void) args; +void spmd(lpf_t ctx, lpf_pid_t pid, lpf_pid_t nprocs, lpf_args_t args) { + // ignore the following parameters: + (void)pid; + (void)nprocs; + (void)args; - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 5 , maxRegs = 7; - rc = lpf_resize_message_queue( ctx, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( ctx, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); + lpf_err_t rc = LPF_SUCCESS; - rc = lpf_sync( ctx, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); + size_t maxMsgs = 5, maxRegs = 7; + rc = lpf_resize_message_queue(ctx, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(ctx, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_sync(ctx, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); } - -/** +/** * \test Test lpf_resize function in parallel and set maxMsgs to five * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_lpf_resize_parallel_five ) -{ - lpf_err_t rc = lpf_exec( LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); - EXPECT_EQ( "%d", LPF_SUCCESS, rc); - return 0; +TEST(API, func_lpf_resize_parallel_five) { + lpf_err_t rc = lpf_exec(LPF_ROOT, LPF_MAX_P, &spmd, LPF_NO_ARGS); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/func_lpf_resize_root_five.c b/tests/functional/func_lpf_resize_root_five.cpp similarity index 63% rename from tests/functional/func_lpf_resize_root_five.c rename to tests/functional/func_lpf_resize_root_five.cpp index bbaea650..fca4c3ee 100644 --- a/tests/functional/func_lpf_resize_root_five.c +++ b/tests/functional/func_lpf_resize_root_five.cpp @@ -15,26 +15,23 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" -/** +/** * \test Test lpf_resize function on LPF_ROOT and set maxMsgs to five * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_lpf_resize_root_five ) -{ - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = 5 , maxRegs = 7; - rc = lpf_resize_message_queue( LPF_ROOT, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +TEST(API, func_lpf_resize_root_five) { + lpf_err_t rc = LPF_SUCCESS; - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); + size_t maxMsgs = 5, maxRegs = 7; + rc = lpf_resize_message_queue(LPF_ROOT, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(LPF_ROOT, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); - return 0; + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/func_lpf_resize_root_outofmem.c b/tests/functional/func_lpf_resize_root_outofmem.c deleted file mode 100644 index 7c15ccc3..00000000 --- a/tests/functional/func_lpf_resize_root_outofmem.c +++ /dev/null @@ -1,49 +0,0 @@ - -/* - * Copyright 2021 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Test.h" - - - -/** - * \test Test lpf_resize function on LPF_ROOT when requested resources take too much memory - * \pre P >= 1 - * \return Exit code: 0 - */ -TEST( func_lpf_resize_root_outofmem ) -{ - lpf_err_t rc = LPF_SUCCESS; - - size_t maxMsgs = ((size_t) -1)/10 ; - size_t maxRegs = ((size_t) -1)/10; - rc = lpf_resize_message_queue( LPF_ROOT, maxMsgs); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, maxRegs ); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - - - - maxMsgs = -1; - maxRegs = -1; - rc = lpf_resize_message_queue( LPF_ROOT, maxMsgs); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, maxRegs ); - EXPECT_EQ( "%d", LPF_ERR_OUT_OF_MEMORY, rc ); - - return 0; -} diff --git a/tests/functional/func_lpf_resize_root_outofmem.cpp b/tests/functional/func_lpf_resize_root_outofmem.cpp new file mode 100644 index 00000000..0d064189 --- /dev/null +++ b/tests/functional/func_lpf_resize_root_outofmem.cpp @@ -0,0 +1,41 @@ + +/* + * Copyright 2021 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include + +/** + * \test Test lpf_resize function on LPF_ROOT when requested resources take too + * much memory \pre P >= 1 \return Exit code: 0 + */ +TEST(API, func_lpf_resize_root_outofmem) { + lpf_err_t rc = LPF_SUCCESS; + + size_t maxMsgs = ((size_t)-1) / 10; + size_t maxRegs = ((size_t)-1) / 10; + rc = lpf_resize_message_queue(LPF_ROOT, maxMsgs); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); + rc = lpf_resize_memory_register(LPF_ROOT, maxRegs); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); + + maxMsgs = -1; + maxRegs = -1; + rc = lpf_resize_message_queue(LPF_ROOT, maxMsgs); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); + rc = lpf_resize_memory_register(LPF_ROOT, maxRegs); + EXPECT_EQ(LPF_ERR_OUT_OF_MEMORY, rc); +} diff --git a/tests/functional/func_lpf_resize_root_zero.c b/tests/functional/func_lpf_resize_root_zero.cpp similarity index 63% rename from tests/functional/func_lpf_resize_root_zero.c rename to tests/functional/func_lpf_resize_root_zero.cpp index 55585084..ee8f96fb 100644 --- a/tests/functional/func_lpf_resize_root_zero.c +++ b/tests/functional/func_lpf_resize_root_zero.cpp @@ -15,25 +15,22 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" -/** +/** * \test Test lpf_resize function on LPF_ROOT allocating nothing * \pre P >= 1 * \return Exit code: 0 */ -TEST( func_lpf_resize_root_zero ) -{ - lpf_err_t rc = LPF_SUCCESS; - size_t maxMsgs = 0 , maxRegs = 0; - rc = lpf_resize_message_queue( LPF_ROOT, maxMsgs); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - rc = lpf_resize_memory_register( LPF_ROOT, maxRegs ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); +TEST(API, func_lpf_resize_root_zero) { + lpf_err_t rc = LPF_SUCCESS; + size_t maxMsgs = 0, maxRegs = 0; + rc = lpf_resize_message_queue(LPF_ROOT, maxMsgs); + EXPECT_EQ(LPF_SUCCESS, rc); + rc = lpf_resize_memory_register(LPF_ROOT, maxRegs); + EXPECT_EQ(LPF_SUCCESS, rc); - rc = lpf_sync( LPF_ROOT, LPF_SYNC_DEFAULT ); - EXPECT_EQ( "%d", LPF_SUCCESS, rc ); - - return 0; + rc = lpf_sync(LPF_ROOT, LPF_SYNC_DEFAULT); + EXPECT_EQ(LPF_SUCCESS, rc); } diff --git a/tests/functional/macro_LPF_VERSION.c b/tests/functional/macro_LPF_VERSION.cpp similarity index 72% rename from tests/functional/macro_LPF_VERSION.c rename to tests/functional/macro_LPF_VERSION.cpp index 4527d24d..8cda3b8c 100644 --- a/tests/functional/macro_LPF_VERSION.c +++ b/tests/functional/macro_LPF_VERSION.cpp @@ -15,26 +15,22 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" #ifdef _LPF_VERSION - #if _LPF_VERSION == 202000L - // everything is OK - #else - #error Macro _LPF_VERSION has not been defined as 202000L - #endif +#if _LPF_VERSION == 202000L +// everything is OK #else - #error Macro _LPF_VERSION has not been defined +#error Macro _LPF_VERSION has not been defined as 202000L +#endif +#else +#error Macro _LPF_VERSION has not been defined #endif -/** +/** * \test Test the existence and value of the preprocessor macro _LPF_VERSION * \pre P >= 1 * \return Exit code: 0 */ -TEST( macro_LPF_VERSION ) -{ - EXPECT_EQ( "%ld", 202000L, _LPF_VERSION ); - return 0; -} +TEST(API, macro_LPF_VERSION) { EXPECT_EQ(202000L, _LPF_VERSION); } diff --git a/tests/functional/type_lpf_spmd_t.c b/tests/functional/type_lpf_spmd_t.cpp similarity index 57% rename from tests/functional/type_lpf_spmd_t.c rename to tests/functional/type_lpf_spmd_t.cpp index adb8e0c5..bc6c6820 100644 --- a/tests/functional/type_lpf_spmd_t.c +++ b/tests/functional/type_lpf_spmd_t.cpp @@ -15,41 +15,39 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" -void test_spmd( const lpf_t lpf, const lpf_pid_t pid, const lpf_pid_t nprocs, const lpf_args_t args) -{ - // ignore all parameters - (void) lpf; - (void) pid; - (void) nprocs; - (void) args; +void test_spmd(const lpf_t lpf, const lpf_pid_t pid, const lpf_pid_t nprocs, + const lpf_args_t args) { + // ignore all parameters + (void)lpf; + (void)pid; + (void)nprocs; + (void)args; - /* empty */ + /* empty */ } extern lpf_spmd_t var_a; static lpf_spmd_t var_b = NULL; -lpf_spmd_t var_c = & test_spmd; +lpf_spmd_t var_c = &test_spmd; /** \test Test whether the lpf_spmd_t typedef is defined appropriately * \pre P >= 1 * \return Exit code: 0 */ -TEST( type_lpf_spmd_t ) -{ - lpf_spmd_t var_d = NULL; - lpf_spmd_t var_e = & test_spmd; - - lpf_t a = NULL; - lpf_pid_t b = 0; - lpf_pid_t c = 0; - lpf_args_t e; - (*var_e)(a, b, c, e); - - EXPECT_EQ( "%p", (lpf_spmd_t) NULL, var_b ); - EXPECT_EQ( "%p", &test_spmd, var_e ); - EXPECT_EQ( "%p", (lpf_spmd_t) NULL, var_d ); - return 0; +TEST(API, type_lpf_spmd_t) { + lpf_spmd_t var_d = NULL; + lpf_spmd_t var_e = &test_spmd; + + lpf_t a = NULL; + lpf_pid_t b = 0; + lpf_pid_t c = 0; + lpf_args_t e; + (*var_e)(a, b, c, e); + + EXPECT_EQ((lpf_spmd_t)NULL, var_b); + EXPECT_EQ(&test_spmd, var_e); + EXPECT_EQ((lpf_spmd_t)NULL, var_d); } diff --git a/tests/functional/type_lpf_t.c b/tests/functional/type_lpf_t.cpp similarity index 73% rename from tests/functional/type_lpf_t.c rename to tests/functional/type_lpf_t.cpp index 91353605..66bdada6 100644 --- a/tests/functional/type_lpf_t.c +++ b/tests/functional/type_lpf_t.cpp @@ -15,27 +15,24 @@ * limitations under the License. */ +#include "gtest/gtest.h" #include -#include "Test.h" - -/** +/** * \test Test the existence of typedef lpf_t and its equivalence to (void *) * \pre P >= 1 * \return Exit code: 0 */ -TEST( type_lpf_t ) -{ - lpf_t var_d = NULL; +TEST(API, type_lpf_t) { + lpf_t var_d = NULL; - int x = 5; - void * y = & x; + int x = 5; + void *y = &x; - lpf_t var_e = y; - y = var_d; + lpf_t var_e = y; + y = var_d; - EXPECT_EQ( "%ld", sizeof(lpf_t), sizeof(void *)); - EXPECT_EQ( "%p", NULL, y ); - EXPECT_EQ( "%p", (lpf_t) &x, var_e ); - return 0; + EXPECT_EQ(sizeof(lpf_t), sizeof(void *)); + EXPECT_EQ(NULL, y); + EXPECT_EQ((lpf_t)&x, var_e); }