From d603e4b761d41d9f16693fcf6d12e035168f50a0 Mon Sep 17 00:00:00 2001 From: agunashe <86270081+agunashe@users.noreply.github.com> Date: Wed, 15 Dec 2021 20:41:02 -0800 Subject: [PATCH 1/3] SWDEV-273235 - catch2 packaging for jenkins build (#2430) Change-Id: I9686b3e26d4e8a24ce97ac1e1f31a4293678d577 --- tests/catch/CMakeLists.txt | 4 +--- tests/catch/external/Catch2/cmake/Catch2/Catch.cmake | 11 +++++++---- .../external/Catch2/cmake/Catch2/CatchAddTests.cmake | 7 ++++--- tests/catch/unit/CMakeLists.txt | 4 +++- tests/catch/unit/graph/hipGraph.cc | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/catch/CMakeLists.txt b/tests/catch/CMakeLists.txt index a10d61a678..0ef45a4f2e 100644 --- a/tests/catch/CMakeLists.txt +++ b/tests/catch/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.16.8) -project(hiptests) # Check if platform and compiler are set if(HIP_PLATFORM STREQUAL "amd") @@ -34,11 +33,10 @@ else() cmake_path(SET CMAKE_C_COMPILER "${HIP_PATH}/bin/hipcc.bat") endif() - if(NOT UNIX) # In linux this reruns the cmake and fails with incorrect vars. # so the project command is used only for windows - project(build_tests) + project(hiptests) endif() if(NOT DEFINED CATCH2_PATH) diff --git a/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake b/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake index 38da2b8097..7b1a783e45 100644 --- a/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake +++ b/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake @@ -169,9 +169,12 @@ function(catch_discover_tests TARGET) VERBATIM ) + file(RELATIVE_PATH ctestincludepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_include_file}) + file(RELATIVE_PATH ctestfilepath ${CMAKE_CURRENT_BINARY_DIR} ${ctest_tests_file}) + file(WRITE "${ctest_include_file}" - "if(EXISTS \"${ctest_tests_file}\")\n" - " include(\"${ctest_tests_file}\")\n" + "if(EXISTS \"${ctestfilepath}\")\n" + " include(\"${ctestfilepath}\")\n" "else()\n" " message(WARNING \"Test ${TARGET} not built yet.\")\n" "endif()\n" @@ -180,14 +183,14 @@ function(catch_discover_tests TARGET) if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0") # Add discovered tests to directory TEST_INCLUDE_FILES set_property(DIRECTORY - APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}" + APPEND PROPERTY TEST_INCLUDE_FILES "${ctestincludepath}" ) else() # Add discovered tests as directory TEST_INCLUDE_FILE if possible get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET) if (NOT ${test_include_file_set}) set_property(DIRECTORY - PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}" + PROPERTY TEST_INCLUDE_FILE "${ctestincludepath}" ) else() message(FATAL_ERROR diff --git a/tests/catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake b/tests/catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake index 184e506e5d..3a69718a5a 100644 --- a/tests/catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake +++ b/tests/catch/external/Catch2/cmake/Catch2/CatchAddTests.cmake @@ -107,12 +107,14 @@ foreach(line ${output}) string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name}) set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}") endif() - + + file(RELATIVE_PATH exe_path ${CMAKE_CURRENT_BINARY_DIR} ${TEST_EXECUTABLE}) + # ...and add to script add_command(add_test "${prefix}${test}${suffix}" ${TEST_EXECUTOR} - "${TEST_EXECUTABLE}" + "${exe_path}" "${test_name}" ${extra_args} "${reporter_arg}" @@ -121,7 +123,6 @@ foreach(line ${output}) add_command(set_tests_properties "${prefix}${test}${suffix}" PROPERTIES - WORKING_DIRECTORY "${TEST_WORKING_DIR}" ${properties} ) list(APPEND tests "${prefix}${test}${suffix}") diff --git a/tests/catch/unit/CMakeLists.txt b/tests/catch/unit/CMakeLists.txt index b81a588d00..167a984c30 100644 --- a/tests/catch/unit/CMakeLists.txt +++ b/tests/catch/unit/CMakeLists.txt @@ -28,4 +28,6 @@ add_subdirectory(rtc) add_subdirectory(printf) add_subdirectory(printfExe) add_subdirectory(texture) -add_subdirectory(graph) +if(UNIX) + add_subdirectory(graph) +endif() diff --git a/tests/catch/unit/graph/hipGraph.cc b/tests/catch/unit/graph/hipGraph.cc index d7c07149ff..e653f8abd8 100644 --- a/tests/catch/unit/graph/hipGraph.cc +++ b/tests/catch/unit/graph/hipGraph.cc @@ -61,7 +61,7 @@ static __global__ void reduceFinal(double* d_in, double* d_out) { static void init_input(float* a, size_t size) { unsigned int seed = time(nullptr); for (size_t i = 0; i < size; i++) { - a[i] = (rand_r(&seed) & 0xFF) / static_cast(RAND_MAX); + a[i] = (HipTest::RAND_R(&seed) & 0xFF) / static_cast(RAND_MAX); } } From eeaadda46eddf1556f6cc2417e76e92bcba9e5d5 Mon Sep 17 00:00:00 2001 From: agunashe <86270081+agunashe@users.noreply.github.com> Date: Wed, 15 Dec 2021 20:41:13 -0800 Subject: [PATCH 2/3] SWDEV-273235 - enabling catch2 config file and graph tests (#2437) Change-Id: Ia9ce9e4b32aaca0986b86a237ff01a030e8da4d5 --- tests/catch/CMakeLists.txt | 2 + tests/catch/README.md | 9 +- .../config/config_amd_windows.json | 28 +++++++ tests/catch/hipTestMain/hip_test_context.cc | 82 +++++++++++++++++-- tests/catch/include/hip_test_context.hh | 9 +- tests/catch/unit/graph/CMakeLists.txt | 8 +- 6 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 tests/catch/hipTestMain/config/config_amd_windows.json diff --git a/tests/catch/CMakeLists.txt b/tests/catch/CMakeLists.txt index 0ef45a4f2e..56de9a6e63 100644 --- a/tests/catch/CMakeLists.txt +++ b/tests/catch/CMakeLists.txt @@ -74,6 +74,8 @@ include_directories( ${JSON_PARSER} ) +file(COPY ./hipTestMain/config DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hipTestMain) + if(HIP_PLATFORM MATCHES "amd" AND HIP_COMPILER MATCHES "clang") add_compile_options(-Wall -Wextra -pedantic -Werror) endif() diff --git a/tests/catch/README.md b/tests/catch/README.md index b366ff990a..ade70de8e9 100644 --- a/tests/catch/README.md +++ b/tests/catch/README.md @@ -35,7 +35,14 @@ Some useful functions are: This information can be accessed in any test via using: `TestContext::get().isAmd()`. ## Config file schema -Some tests can be skipped using a config file placed in same directory as the exe. +Some tests can be skipped using a config file placed in hipTestMain/config folder. Multiple config files can be defined for different configurations. +The naming convention for the file needs to be "config_platform_os_archname.json" +Platform and os are mandatory, "all" for os if the tests needs to be skipped for all OS. +Arch name is optional and takes precedence while loading the json file. + +example: +config_amd_windows.json +config_nvidia_windows.json The schema of the json file is as follows: ```json diff --git a/tests/catch/hipTestMain/config/config_amd_windows.json b/tests/catch/hipTestMain/config/config_amd_windows.json new file mode 100644 index 0000000000..bd74895f03 --- /dev/null +++ b/tests/catch/hipTestMain/config/config_amd_windows.json @@ -0,0 +1,28 @@ +{ + "DisabledTests": + [ + "Unit_hipMemcpy3D_Basic - int", + "Unit_hipMemcpy3D_Basic - unsigned int", + "Unit_hipMemcpy3D_Basic - float", + "Unit_hipMemcpy3DAsync_Basic - int", + "Unit_hipMemcpy3DAsync_Basic - unsigned int", + "Unit_hipMemcpy3DAsync_Basic - float", + "Unit_hipMemcpy3DAsync_multiDevice-Negative", + "Unit_hipMemcpy3DAsync_multiDevice-DiffStream", + "Unit_hipPointerGetAttributes_ClusterAlloc", + "Unit_hipMallocManaged_MultiChunkMultiDevice", + "Unit_hipMallocManaged_TwoPointers - int", + "Unit_hipMallocManaged_TwoPointers - float", + "Unit_hipMallocManaged_TwoPointers - double", + "Unit_hipMallocManaged_DeviceContextChange - unsigned char", + "Unit_hipMallocManaged_DeviceContextChange - int", + "Unit_hipMallocManaged_DeviceContextChange - float", + "Unit_hipMallocManaged_DeviceContextChange - double", + "Unit_hipHostMalloc_CoherentTst", + "Unit_hipMallocManaged_CoherentTst", + "Unit_hipMallocManaged_CoherentTstWthAdvise", + "Unit_hipMalloc_CoherentTst", + "Unit_hipExtMallocWithFlags_CoherentTst" + ] + +} diff --git a/tests/catch/hipTestMain/hip_test_context.cc b/tests/catch/hipTestMain/hip_test_context.cc index dd440ce153..ec55e2395e 100644 --- a/tests/catch/hipTestMain/hip_test_context.cc +++ b/tests/catch/hipTestMain/hip_test_context.cc @@ -21,7 +21,79 @@ void TestContext::detectPlatform() { #endif } +std::string TestContext::substringFound(std::vector list, std::string filename) { + std::string match = ""; + for(unsigned int i = 0; i < list.size() ; i++) { + if (filename.find(list.at(i)) != std::string::npos) { + match = list.at(i); + break; + } + } + return match; +} + + +std::string TestContext::getMatchingConfigFile(std::string config_dir) { + std::string configFileToUse; + for(auto& p: fs::recursive_directory_iterator(config_dir)) { + fs::path filename = p.path(); + std::string cur_arch = "TODO"; + std::string arch = substringFound(amd_arch_list_,filename.filename().string()); + std::string platform = substringFound(platform_list_,filename.filename().string()); + std::string os = substringFound(os_list_,filename.filename().string()); + // if arch found then use that exit from loop + if(arch == cur_arch) { + configFileToUse = filename.string(); + break; + // match the platform/os and continue to look + } else if((platform == config_.platform) && + (os == config_.os || os == "all")) { + configFileToUse = filename.string(); + } + } + return configFileToUse; +} + + +std::string& TestContext::getJsonFile() { + fs::path config_dir = exe_path; + config_dir = config_dir.parent_path(); + int levels = 0; + bool configFolderFound = false; + std::vector configList; + std::string configFile; + // check a max of 5 levels down the executable path + while(levels < 5) { + fs::path temp_path = config_dir; + temp_path /= "hipTestMain"; + temp_path /= "config"; + if (fs::exists(temp_path)) { + config_dir = fs::absolute(temp_path); + configFolderFound = true; + break; + } else { + config_dir = config_dir.parent_path(); + levels++; + } + } + + // get config.json files if config folder. + if (configFolderFound) { + json_file_ = getMatchingConfigFile(config_dir.string()); + } + return json_file_; +} + + void TestContext::fillConfig() { + config_.platform = (amd ? "amd" : (nvidia ? "nvidia" : "unknown")); + config_.os = (p_windows ? "windows" : (p_linux ? "linux" : "unknown")); + + if (config_.os == "unknown" || config_.platform == "unknown") { + LogPrintf("%s", "Either Config or Os is unknown, this wont end well"); + abort(); + } + const char* env_config = std::getenv("HT_CONFIG_FILE"); LogPrintf("Env Config file: %s", (env_config != nullptr) ? env_config : "Not found, using default config"); @@ -41,17 +113,9 @@ void TestContext::fillConfig() { } else if (config_path.has_parent_path()) { config_.json_file = config_path.string() + def_config_json; } else { - config_.json_file = exe_path + def_config_json; + config_.json_file = getJsonFile(); } LogPrintf("Config file path: %s", config_.json_file.c_str()); - - config_.platform = (amd ? "amd" : (nvidia ? "nvidia" : "unknown")); - config_.os = (p_windows ? "windows" : (p_linux ? "linux" : "unknown")); - - if (config_.os == "unknown" || config_.platform == "unknown") { - LogPrintf("%s", "Either Config or Os is unknown, this wont end well"); - abort(); - } } TestContext::TestContext(int argc, char** argv) { diff --git a/tests/catch/include/hip_test_context.hh b/tests/catch/include/hip_test_context.hh index d00342f55d..e6429454ae 100644 --- a/tests/catch/include/hip_test_context.hh +++ b/tests/catch/include/hip_test_context.hh @@ -68,15 +68,22 @@ class TestContext { std::string exe_path; std::string current_test; std::set skip_test; + std::string json_file_; + std::vector platform_list_ = {"amd" , "nvidia"}; + std::vector os_list_ = {"windows", "linux", "all"}; + std::vector amd_arch_list_ = {}; Config config_; - + std::string& getJsonFile(); + std::string substringFound( std::vector list, + std::string filename); void detectOS(); void detectPlatform(); void fillConfig(); void setExePath(int, char**); void parseOptions(int, char**); bool parseJsonFile(); + std::string getMatchingConfigFile(std::string config_dir); const Config& getConfig() const { return config_; } TestContext(int argc, char** argv); diff --git a/tests/catch/unit/graph/CMakeLists.txt b/tests/catch/unit/graph/CMakeLists.txt index 80fb448618..557ddeca06 100644 --- a/tests/catch/unit/graph/CMakeLists.txt +++ b/tests/catch/unit/graph/CMakeLists.txt @@ -27,8 +27,6 @@ set(TEST_SRC hipGraphAddMemcpyNode.cc ) -# Create shared lib of all tests -add_library(GraphsTest SHARED EXCLUDE_FROM_ALL ${TEST_SRC}) - -# Add dependency on build_tests to build it on this custom target -add_dependencies(build_tests GraphsTest) +hip_add_exe_to_target(NAME GraphsTest + TEST_SRC ${TEST_SRC} + TEST_TARGET_NAME build_tests) From 2734e9429388a8aeae8cb3854a73f5f441cc420a Mon Sep 17 00:00:00 2001 From: sumanthtg <90063301+sumanthtg@users.noreply.github.com> Date: Mon, 20 Dec 2021 14:04:38 +0530 Subject: [PATCH 3/3] SWDEV-309676 - Fix for build failure due to new compiler flag -Wbitwise-instead-of-logical (#2443) Change-Id: I55d230dbb409b93d17dcff2bd29b27100b586e17 --- tests/catch/unit/memory/hipMallocConcurrency.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/catch/unit/memory/hipMallocConcurrency.cc b/tests/catch/unit/memory/hipMallocConcurrency.cc index 5083ea1c25..98bc2ab014 100644 --- a/tests/catch/unit/memory/hipMallocConcurrency.cc +++ b/tests/catch/unit/memory/hipMallocConcurrency.cc @@ -285,8 +285,8 @@ static bool regressAllocInLoopMthread(int gpu) { * Thread func to regress alloc and check data consistency */ static void threadFunc(int gpu) { - g_thTestPassed = regressAllocInLoopMthread(gpu); - g_thTestPassed = g_thTestPassed & validateMemoryOnGpuMThread(gpu); + g_thTestPassed = regressAllocInLoopMthread(gpu) + && validateMemoryOnGpuMThread(gpu); UNSCOPED_INFO("thread execution status on gpu" << gpu << ":" << g_thTestPassed.load());