diff --git a/catch/hipTestMain/hip_test_context.cc b/catch/hipTestMain/hip_test_context.cc index 27419e4e88..bc38b32f94 100644 --- a/catch/hipTestMain/hip_test_context.cc +++ b/catch/hipTestMain/hip_test_context.cc @@ -4,6 +4,7 @@ #include #include #include +#include "hip_test_context.hh" #include "hip_test_filesystem.hh" void TestContext::detectOS() { @@ -98,11 +99,11 @@ void TestContext::getConfigFiles() { abort(); } - const char* env_config = std::getenv("HIP_CATCH_EXCLUDE_FILE"); + std::string env_config = TestContext::getEnvVar("HIP_CATCH_EXCLUDE_FILE"); LogPrintf("Env Config file: %s", - (env_config != nullptr) ? env_config : "Not found, using common config"); + (!env_config.empty()) ? env_config.c_str() : "Not found, using common config"); // HIP_CATCH_EXCLUDE_FILE is set for custom file path - if (env_config != nullptr) { + if (!env_config.empty()) { if(fs::exists(env_config)) { config_.json_files.push_back(env_config); } diff --git a/catch/include/hip_test_context.hh b/catch/include/hip_test_context.hh index 2ee221330e..931593cc4d 100644 --- a/catch/include/hip_test_context.hh +++ b/catch/include/hip_test_context.hh @@ -32,6 +32,7 @@ THE SOFTWARE. #include #include +// OS Check #if defined(_WIN32) #define HT_WIN 1 #define HT_LINUX 0 @@ -42,6 +43,7 @@ THE SOFTWARE. #error "OS not recognized" #endif +// Platform check #if defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__) #define HT_AMD 1 #define HT_NVIDIA 0 @@ -52,16 +54,6 @@ THE SOFTWARE. #error "Platform not recognized" #endif -static int _log_enable = (std::getenv("HT_LOG_ENABLE") ? 1 : 0); - -#define LogPrintf(format, ...) \ - { \ - if (_log_enable) { \ - printf(format, __VA_ARGS__); \ - printf("%c", '\n'); \ - } \ - } - typedef struct Config_ { std::vector json_files; // Json files std::string platform; // amd/nvidia @@ -124,6 +116,26 @@ class TestContext { return instance; } + static std::string getEnvVar(std::string var) { + #if defined(_WIN32) + rsize_t MAX_LEN = 4096; + char dstBuf[MAX_LEN]; + size_t dstSize; + if (!::getenv_s(&dstSize, dstBuf, MAX_LEN, var.c_str())) { + return std::string(dstBuf); + } + #elif defined(__linux__) + char* val = std::getenv(var.c_str()); + if (val != NULL) { + return std::string(val); + } + #else + #error "OS not recognized" + #endif + return std::string(""); + } + + bool isWindows() const; bool isLinux() const; bool isNvidia() const; @@ -171,3 +183,14 @@ class TestContext { ~TestContext(); }; + +static bool _log_enable = (!TestContext::getEnvVar("HT_LOG_ENABLE").empty() ? true : false); + +// printing logs +#define LogPrintf(format, ...) \ +{ \ + if(_log_enable) { \ + printf(format, __VA_ARGS__); \ + printf("%c", '\n'); \ + } \ +} \ No newline at end of file diff --git a/catch/unit/stream/hipStreamGetCUMask.cc b/catch/unit/stream/hipStreamGetCUMask.cc index f63acc212a..d7d10dd807 100644 --- a/catch/unit/stream/hipStreamGetCUMask.cc +++ b/catch/unit/stream/hipStreamGetCUMask.cc @@ -37,7 +37,7 @@ TEST_CASE("Unit_hipExtStreamGetCUMask_verifyDefaultAndCustomMask") { std::vector cuMask(maxNum); hipDeviceProp_t props; std::stringstream ss; - char* gCUMask{nullptr}; + std::string gCUMask; std::string globalCUMask(""); std::vector defaultCUMask; @@ -54,8 +54,8 @@ TEST_CASE("Unit_hipExtStreamGetCUMask_verifyDefaultAndCustomMask") { props.name << " with " << props.multiProcessorCount << " CUs"); // Get global CU Mask if exists - gCUMask = getenv("ROC_GLOBAL_CU_MASK"); - if (gCUMask != nullptr && gCUMask[0] != '\0') { + gCUMask = TestContext::getEnvVar("ROC_GLOBAL_CU_MASK"); + if (!gCUMask.empty()) { globalCUMask.assign(gCUMask); for_each(globalCUMask.begin(), globalCUMask.end(), [](char & c) { @@ -155,7 +155,7 @@ TEST_CASE("Unit_hipExtStreamGetCUMask_verifyDefaultAndCustomMask") { INFO("info: reading back CU mask 0x" << ss.str() << " for stream " << stream); - if (!gCUMask) { + if (!gCUMask.empty()) { for (size_t i = 0; i < customMask.size(); i++) { if (customMask[i] != cuMask[i]) { INFO("Error! expected CU mask:" << customMask[i]