SWDEV-345188 - Windows: fix warnings while building catch (#3071)

fixes deprecated warning for 'getenv' on Windows

Change-Id: I5ecdaca451a936e843691c4611910ee338b22e46
This commit is contained in:
ROCm CI Service Account
2022-11-28 20:17:09 +05:30
committed by GitHub
parent 955f1e4979
commit 0e06303fe2
3 changed files with 41 additions and 17 deletions
+4 -3
View File
@@ -4,6 +4,7 @@
#include <fstream>
#include <sstream>
#include <regex>
#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);
}
+33 -10
View File
@@ -32,6 +32,7 @@ THE SOFTWARE.
#include <set>
#include <unordered_map>
// 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<std::string> 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'); \
} \
}
@@ -37,7 +37,7 @@ TEST_CASE("Unit_hipExtStreamGetCUMask_verifyDefaultAndCustomMask") {
std::vector<uint32_t> cuMask(maxNum);
hipDeviceProp_t props;
std::stringstream ss;
char* gCUMask{nullptr};
std::string gCUMask;
std::string globalCUMask("");
std::vector<uint32_t> 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]