Code coverage tests for param.cc (#1872)
* Added code coverage unit tests for param.cc
* Updated ParamTests.cpp and removed ParamTestsConfFile.txt
* Updated ParamTests.cpp
* Removed NCCL_LOG_INFO and added sample cofig file
---------
Co-authored-by: Pawar <kpawar@ctr2-alola-ctrl-01.amd.com>
[ROCm/rccl commit: c9becd89cd]
This commit is contained in:
@@ -140,6 +140,7 @@ if(BUILD_TESTS)
|
||||
set(TEST_FIXTURE_SOURCE_FILES
|
||||
AltRsmiTests.cpp
|
||||
AllocTests.cpp
|
||||
ParamTests.cpp
|
||||
ArgCheckTests.cpp
|
||||
BitOpsTests.cpp
|
||||
CollRegTests.cpp
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "param.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <rccl/rccl.h>
|
||||
|
||||
namespace RcclUnitTesting {
|
||||
TEST(ParamTests, initEnv_ParseValidConfFile) {
|
||||
// Skip the test if NCCL_CONF_FILE is not set
|
||||
const char *value = getenv("NCCL_CONF_FILE");
|
||||
|
||||
if (!value) {
|
||||
GTEST_SKIP() << "SKIPPING TEST. Set environment variable NCCL_CONF_FILE.\n"
|
||||
<< "A sample config file has been provided at: "
|
||||
"rccl/test/ParamTestsConfFile.txt\n"
|
||||
<< "Set NCCL_CONF_FILE to the absolute path of this file to "
|
||||
"run the test.\n";
|
||||
}
|
||||
// This function call reads and opens the conf file from the path
|
||||
// which is set using env. variable NCCL_CONF_FILE
|
||||
initEnv();
|
||||
|
||||
EXPECT_EQ(getenv("TEST_VAR_WITH_NO_VALUE"), nullptr);
|
||||
EXPECT_STREQ(getenv("TEST_VAR"), "12345");
|
||||
|
||||
// Clean up
|
||||
unsetenv("TEST_VAR_WITH_NO_VALUE");
|
||||
unsetenv("TEST_VAR");
|
||||
}
|
||||
|
||||
TEST(ParamTests, ncclLoadParam_InvalidParam) {
|
||||
int64_t cache = -1;
|
||||
const int64_t defaultVal = 12345; // Dummy input value
|
||||
|
||||
// Force overflow: value exceeds int64_t max (9223372036854775807)
|
||||
setenv("TEST_INVALID_PARAM", "99999999999999999999",
|
||||
1); // Dummy variable and value
|
||||
ncclLoadParam("TEST_INVALID_PARAM", defaultVal, -1, &cache);
|
||||
unsetenv("TEST_INVALID_PARAM");
|
||||
|
||||
EXPECT_EQ(cache, defaultVal); // Cache should be set to default value
|
||||
}
|
||||
} // namespace RcclUnitTesting
|
||||
@@ -0,0 +1,3 @@
|
||||
# Comment: This file is required to run unit tests for param.cc
|
||||
TEST_VAR_WITH_NO_VALUE
|
||||
TEST_VAR=12345
|
||||
Fai riferimento in un nuovo problema
Block a user