From 3d889cc189a9e592ea3079a7e4364a2bd299e2ca Mon Sep 17 00:00:00 2001 From: "Kapil S. Pawar" Date: Wed, 27 Aug 2025 09:30:37 -0500 Subject: [PATCH] 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 [ROCm/rccl commit: c9becd89cd200a6c989c7641a0a1832cbae47178] --- projects/rccl/test/CMakeLists.txt | 1 + projects/rccl/test/ParamTests.cpp | 41 +++++++++++++++++++++++ projects/rccl/test/ParamTestsConfFile.txt | 3 ++ 3 files changed, 45 insertions(+) create mode 100644 projects/rccl/test/ParamTests.cpp create mode 100644 projects/rccl/test/ParamTestsConfFile.txt diff --git a/projects/rccl/test/CMakeLists.txt b/projects/rccl/test/CMakeLists.txt index 37fea0ca88..c950e418cb 100644 --- a/projects/rccl/test/CMakeLists.txt +++ b/projects/rccl/test/CMakeLists.txt @@ -140,6 +140,7 @@ if(BUILD_TESTS) set(TEST_FIXTURE_SOURCE_FILES AltRsmiTests.cpp AllocTests.cpp + ParamTests.cpp ArgCheckTests.cpp BitOpsTests.cpp CollRegTests.cpp diff --git a/projects/rccl/test/ParamTests.cpp b/projects/rccl/test/ParamTests.cpp new file mode 100644 index 0000000000..201d0db9b3 --- /dev/null +++ b/projects/rccl/test/ParamTests.cpp @@ -0,0 +1,41 @@ +#include "param.h" +#include +#include + +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 \ No newline at end of file diff --git a/projects/rccl/test/ParamTestsConfFile.txt b/projects/rccl/test/ParamTestsConfFile.txt new file mode 100644 index 0000000000..50ff731ae1 --- /dev/null +++ b/projects/rccl/test/ParamTestsConfFile.txt @@ -0,0 +1,3 @@ +# Comment: This file is required to run unit tests for param.cc +TEST_VAR_WITH_NO_VALUE +TEST_VAR=12345 \ No newline at end of file