Add a unit test for v1_shares_to_v2(). [----------] 5 tests from CgroupV1SharesToV2 [ RUN ] CgroupV1SharesToV2.NullSharesVal [ OK ] CgroupV1SharesToV2.NullSharesVal (0 ms) [ RUN ] CgroupV1SharesToV2.EmptySharesVal [ OK ] CgroupV1SharesToV2.EmptySharesVal (0 ms) [ RUN ] CgroupV1SharesToV2.ValidShares1 [ OK ] CgroupV1SharesToV2.ValidShares1 (0 ms) [ RUN ] CgroupV1SharesToV2.ValidShares2 [ OK ] CgroupV1SharesToV2.ValidShares2 (0 ms) [ RUN ] CgroupV1SharesToV2.ValidShares3 [ OK ] CgroupV1SharesToV2.ValidShares3 (0 ms) [----------] 5 tests from CgroupV1SharesToV2 (0 ms total)
Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com> --- gunit/016-v1_shares_to_v2.cpp | 91 +++++++++++++++++++++++++++++++++++ gunit/Makefile.am | 3 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 gunit/016-v1_shares_to_v2.cpp diff --git a/gunit/016-v1_shares_to_v2.cpp b/gunit/016-v1_shares_to_v2.cpp new file mode 100644 index 000000000000..be3cedef19f0 --- /dev/null +++ b/gunit/016-v1_shares_to_v2.cpp @@ -0,0 +1,91 @@ +/** + * libcgroup googletest for v1_shares_to_v2() + * + * Copyright (c) 2021 Oracle and/or its affiliates. + * Author: Tom Hromatka <tom.hroma...@oracle.com> + */ + +/* + * This library is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License as + * published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, see <http://www.gnu.org/licenses>. + */ + +#include "gtest/gtest.h" +#include "abstraction-common.h" +#include "libcgroup-internal.h" + +class CgroupV1SharesToV2: public ::testing::Test { +}; + +TEST_F(CgroupV1SharesToV2, NullSharesVal) +{ + struct cgroup_controller cgc = {0}; + char *shares_val = NULL; + int ret; + + ret = v1_shares_to_v2(&cgc, shares_val); + ASSERT_EQ(ret, ECGINVAL); + ASSERT_EQ(shares_val, nullptr); + ASSERT_EQ(cgc.index, 0); +} + +TEST_F(CgroupV1SharesToV2, EmptySharesVal) +{ + struct cgroup_controller cgc = {0}; + char *shares_val = ""; + int ret; + + ret = v1_shares_to_v2(&cgc, shares_val); + ASSERT_EQ(ret, 0); + ASSERT_EQ(cgc.index, 1); + ASSERT_STREQ(cgc.values[0]->name, "cpu.weight"); + ASSERT_STREQ(cgc.values[0]->value, ""); +} + +TEST_F(CgroupV1SharesToV2, ValidShares1) +{ + struct cgroup_controller cgc = {0}; + char *shares_val = "1024"; + int ret; + + ret = v1_shares_to_v2(&cgc, shares_val); + ASSERT_EQ(ret, 0); + ASSERT_EQ(cgc.index, 1); + ASSERT_STREQ(cgc.values[0]->name, "cpu.weight"); + ASSERT_STREQ(cgc.values[0]->value, "100\n"); +} + +TEST_F(CgroupV1SharesToV2, ValidShares2) +{ + struct cgroup_controller cgc = {0}; + char *shares_val = "2048"; + int ret; + + ret = v1_shares_to_v2(&cgc, shares_val); + ASSERT_EQ(ret, 0); + ASSERT_EQ(cgc.index, 1); + ASSERT_STREQ(cgc.values[0]->name, "cpu.weight"); + ASSERT_STREQ(cgc.values[0]->value, "200\n"); +} + +TEST_F(CgroupV1SharesToV2, ValidShares3) +{ + struct cgroup_controller cgc = {0}; + char *shares_val = "256"; + int ret; + + ret = v1_shares_to_v2(&cgc, shares_val); + ASSERT_EQ(ret, 0); + ASSERT_EQ(cgc.index, 1); + ASSERT_STREQ(cgc.values[0]->name, "cpu.weight"); + ASSERT_STREQ(cgc.values[0]->value, "25\n"); +} diff --git a/gunit/Makefile.am b/gunit/Makefile.am index 6eb8ffce6d1e..11a96f5f8c6a 100644 --- a/gunit/Makefile.am +++ b/gunit/Makefile.am @@ -52,6 +52,7 @@ gtest_SOURCES = gtest.cpp \ 012-cgroup_create_cgroup.cpp \ 013-cgroup_build_tasks_procs_path.cpp \ 014-cgroupv2_get_subtree_control.cpp \ - 015-cgroupv2_controller_enabled.cpp + 015-cgroupv2_controller_enabled.cpp \ + 016-v1_shares_to_v2.cpp gtest_LDFLAGS = -L$(top_builddir)/googletest/googletest -l:libgtest.so \ -rpath $(abs_top_builddir)/googletest/googletest -- 2.26.2 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel