SWDEV-466829 - Disable ROCP when in GTest

Change-Id: I3b218fe256717c1dc9187d5f17476dfc990656c2
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>


[ROCm/rdc commit: c40a6308c5]
This commit is contained in:
Galantsev, Dmitrii
2024-09-26 16:57:32 -05:00
parent 59ea16496e
commit 999cae5e2c
4 changed files with 37 additions and 2 deletions
+1
View File
@@ -79,6 +79,7 @@ typedef enum {
//!< but none was found
RDC_ST_PERM_ERROR, //!< Insufficient permission to complete
//!< operation
RDC_ST_DISABLED_MODULE, //!< Attempted loading disabled module
RDC_ST_UNKNOWN_ERROR = 0xFFFFFFFF //!< Unknown error
} rdc_status_t;
+7 -2
View File
@@ -62,8 +62,13 @@ RdcRocpLib::RdcRocpLib()
status = rdc_module_init_(0);
if (status != RDC_ST_OK) {
RDC_LOG(RDC_ERROR, "Fail to init librdc_rocp.so:" << rdc_status_string(status)
<< ". ROCP related function will not work.");
if (status == RDC_ST_DISABLED_MODULE) {
RDC_LOG(RDC_INFO, "Module: librdc_rocp.so is intentionally disabled!");
} else {
RDC_LOG(RDC_ERROR,
"Fail to init librdc_rocp.so:" << rdc_status_string(status)
<< ". ROCP related function will not work.");
}
return;
}
@@ -38,7 +38,32 @@ THE SOFTWARE.
std::unique_ptr<amd::rdc::RdcRocpBase> rocp_p;
bool is_rocp_disabled() {
const char* value = std::getenv("RDC_DISABLE_ROCP");
if (value == nullptr) return false;
std::string value_str = value;
std::transform(value_str.begin(), value_str.end(), value_str.begin(),
[](unsigned char c) { return std::tolower(c); });
const std::vector<const char*> positive_list = {"yes", "true", "1", "on", "y", "t"};
return std::any_of(positive_list.begin(), positive_list.end(),
[&value_str](const char* val) { return value_str == val; });
}
rdc_status_t rdc_module_init(uint64_t flags) {
if (is_rocp_disabled()) {
// rocprofiler does NOT work in gtest.
// GTest starts up multiple instances of the progam under test,
// however HSA does not allow for multiple instances. Since hsa_init() is called at the very
// top of RdcRocpBase constructor - easiest to disable it alltogether when RDC_DISABLE_ROCP is
// set.
//
// We cannot rely on GTEST_DECLARE_bool_ variable because RDC is compiled
// before the tests are. Utilize an env var instead.
return RDC_ST_DISABLED_MODULE;
}
rocp_p = std::unique_ptr<amd::rdc::RdcRocpBase>(new amd::rdc::RdcRocpBase);
return RDC_ST_OK;
}
+4
View File
@@ -23,6 +23,7 @@ THE SOFTWARE.
#include <dirent.h>
#include <gtest/gtest.h>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <memory>
@@ -190,6 +191,9 @@ static int startRDCD(std::string* rdcd_path, char* envp[]) {
}
int main(int argc, char** argv, char* envp[]) {
::testing::InitGoogleTest(&argc, argv);
// disable ROCProfiler because its RDC plugin implementation does not work
// with GTest
setenv("RDC_DISABLE_ROCP", "yes", 0);
RDCTstGlobals settings;
int ret;