From 685cc4f6f5a378ebe8cfdafa47eecf4e0c892b5c Mon Sep 17 00:00:00 2001 From: Maneesh Gupta Date: Thu, 4 Aug 2022 09:32:12 +0530 Subject: [PATCH] Fix win:setenv/unsetenv tests build failure [ROCm/hip commit: 08d24c55d9ec6fcf4d837af84b515446bc14c9d0] --- .../device/hipDeviceGetP2PAttribute_exe.cc | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/projects/hip/tests/catch/unit/device/hipDeviceGetP2PAttribute_exe.cc b/projects/hip/tests/catch/unit/device/hipDeviceGetP2PAttribute_exe.cc index 44e98495ca..92b1c577f5 100644 --- a/projects/hip/tests/catch/unit/device/hipDeviceGetP2PAttribute_exe.cc +++ b/projects/hip/tests/catch/unit/device/hipDeviceGetP2PAttribute_exe.cc @@ -20,23 +20,43 @@ THE SOFTWARE. #include #include "hip/hip_runtime_api.h" #include +#include +bool UNSETENV(std::string var) { + int result = -1; + #ifdef __unix__ + result = unsetenv(var.c_str()); + #else + result = _putenv((var + '=').c_str()); + #endif + return (result == 0) ? true: false; +} + +bool SETENV(std::string var, std::string value, int overwrite) { + int result = -1; + #ifdef __unix__ + result = setenv(var.c_str(), value.c_str(), overwrite); + #else + result = _putenv((var + '=' + value).c_str()); + #endif + return (result == 0) ? true: false; +} void inline hideDevices(const char* devices) { #if HT_NVIDIA - setenv("CUDA_VISIBLE_DEVICES", devices, 1); + SETENV("CUDA_VISIBLE_DEVICES", devices, 1); #else - setenv("HIP_VISIBLE_DEVICES", devices, 1); - setenv("ROCR_VISIBLE_DEVICES", devices, 1); + SETENV("HIP_VISIBLE_DEVICES", devices, 1); + SETENV("ROCR_VISIBLE_DEVICES", devices, 1); #endif } void inline unhideAllDevices() { #if HT_NVIDIA - unsetenv("CUDA_VISIBLE_DEVICES"); + UNSETENV("CUDA_VISIBLE_DEVICES"); #else - unsetenv("HIP_VISIBLE_DEVICES"); - unsetenv("ROCR_VISIBLE_DEVICES"); + UNSETENV("HIP_VISIBLE_DEVICES"); + UNSETENV("ROCR_VISIBLE_DEVICES"); #endif } @@ -63,4 +83,4 @@ int main(int argc, char** argv) { } return error; -} \ No newline at end of file +}