Skip to content

Commit

Permalink
Add test for omrsysinfo_get_cgroup_subsystem_list
Browse files Browse the repository at this point in the history
  • Loading branch information
EricYangIBM committed May 30, 2022
1 parent c9e5c0f commit 3fe8478
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion fvtest/porttest/si.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,7 @@ class CgroupTest : public ::testing::Test {
static bool isV2Available;
static std::string memCgroup;
static std::string cpuCgroup;
static std::string cpusetCgroup;
const static std::map<std::string, uint64_t> supportedSubsystems;
constexpr static char CGROUP_MOUNT_POINT[] = "/sys/fs/cgroup";
static uint64_t available;
Expand All @@ -2403,6 +2404,7 @@ class CgroupTest : public ::testing::Test {

portTestEnv->log(LEVEL_ERROR, "/proc/self/cgroup line:\n %s\n", line.c_str());
ASSERT_TRUE(std::regex_match(line, sm, v1Regex));
ASSERT_EQ(sm[2].str().at(0), '/');
if (0 != sm[1].length()) {
std::stringstream ss(sm[1].str());
std::vector<std::string> subsystems;
Expand All @@ -2423,6 +2425,11 @@ class CgroupTest : public ::testing::Test {
case OMR_CGROUP_SUBSYSTEM_MEMORY:
memCgroup = sm[2].str();
break;
case OMR_CGROUP_SUBSYSTEM_CPUSET:
cpusetCgroup = sm[2].str();
break;
default:
FAIL() << "Unsupported subsystem";
}
}
}
Expand All @@ -2438,6 +2445,7 @@ class CgroupTest : public ::testing::Test {

cpuCgroup = sm[1].str();
memCgroup = cpuCgroup;
cpusetCgroup = cpuCgroup;
ASSERT_EQ(cpuCgroup.at(0), '/');
std::ifstream controllerFile(CGROUP_MOUNT_POINT + cpuCgroup + "/cgroup.controllers");
std::string s;
Expand Down Expand Up @@ -2496,6 +2504,7 @@ bool CgroupTest::isV1Available = false;
bool CgroupTest::isV2Available = false;
std::string CgroupTest::memCgroup;
std::string CgroupTest::cpuCgroup;
std::string CgroupTest::cpusetCgroup;
const std::map<std::string, uint64_t> CgroupTest::supportedSubsystems = {
{"cpu", OMR_CGROUP_SUBSYSTEM_CPU},
{"memory", OMR_CGROUP_SUBSYSTEM_MEMORY},
Expand Down Expand Up @@ -2588,7 +2597,7 @@ TEST_F(CgroupTest, sysinfo_cgroup_are_subsystems_available)
CgroupTest::available & (OMR_CGROUP_SUBSYSTEM_ALL));
#else /* defined(LINUX) */
if (0 != omrsysinfo_cgroup_are_subsystems_available(OMR_CGROUP_SUBSYSTEM_ALL)) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "omrsysinfo_cgroup_are_subsystems_available returned nonzero on nonlinux\n");
outputErrorMessage(PORTTEST_ERROR_ARGS, "omrsysinfo_cgroup_are_subsystems_available returned nonzero on non-Linux\n");
}
#endif /* defined(LINUX) */

Expand Down Expand Up @@ -2701,6 +2710,54 @@ TEST(PortSysinfoTest, sysinfo_cgroup_get_memlimit)
return;
}

/**
* Test omrsysinfo_get_cgroup_subsystem_list.
*/
TEST_F(CgroupTest, sysinfo_get_cgroup_subsystem_list)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
const char *testName = "omrsysinfo_get_cgroup_subsystem_list";

reportTestEntry(OMRPORTLIB, testName);

#if defined(LINUX)
OMRCgroupEntry *entries = omrsysinfo_get_cgroup_subsystem_list();
OMRCgroupEntry *temp = entries;

if (NULL == temp) {
EXPECT_EQ(CgroupTest::available, (uint64_t)0);
} else {
do {
EXPECT_EQ(CgroupTest::available & temp->flag, temp->flag);
switch(temp->flag) {
case OMR_CGROUP_SUBSYSTEM_CPU:
EXPECT_EQ(temp->cgroup, cpuCgroup);
EXPECT_STREQ(temp->subsystem, "cpu");
break;
case OMR_CGROUP_SUBSYSTEM_MEMORY:
EXPECT_EQ(temp->cgroup, memCgroup);
EXPECT_STREQ(temp->subsystem, "memory");
break;
case OMR_CGROUP_SUBSYSTEM_CPUSET:
EXPECT_EQ(temp->cgroup, cpusetCgroup);
EXPECT_STREQ(temp->subsystem, "cpuset");
break;
default:
FAIL() << "Unsupported subsystem";
}
temp = temp->next;
} while (temp != entries);
}
#else /* defined(LINUX) */
if (NULL != omrsysinfo_get_cgroup_subsystem_list()) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "omrsysinfo_get_cgroup_subsystem_list returned not null on non-Linux\n");
}
#endif /* defined(LINUX) */

reportTestExit(OMRPORTLIB, testName);
return;
}

/**
* Test GetProcessorDescription.
*/
Expand Down

0 comments on commit 3fe8478

Please sign in to comment.