From 0b1ab4fa0aa26f9848e321dcc429f5b5bbeebf0f Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 31 Mar 2021 16:58:48 +0000 Subject: [PATCH] gtest: Add unit test for cgset's parse_r_flag() Add a unit test for parse_r_flag() in cgset.c. [----------] 1 test from CgsetParseRFlagTest [ RUN ] CgsetParseRFlagTest.EqualCharInValue [ OK ] CgsetParseRFlagTest.EqualCharInValue (0 ms) [----------] 1 test from CgsetParseRFlagTest (0 ms total) Signed-off-by: Tom Hromatka --- gunit/016-cgset_parse_r_flag.cpp | 52 ++++++++++++++++++++++++++++++++ gunit/Makefile.am | 7 +++-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 gunit/016-cgset_parse_r_flag.cpp diff --git a/gunit/016-cgset_parse_r_flag.cpp b/gunit/016-cgset_parse_r_flag.cpp new file mode 100644 index 00000000..713535fa --- /dev/null +++ b/gunit/016-cgset_parse_r_flag.cpp @@ -0,0 +1,52 @@ +/** + * libcgroup googletest for parse_r_flag() in cgset + * + * Copyright (c) 2021 Oracle and/or its affiliates. + * Author: Tom Hromatka + */ + +/* + * 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 . + */ + +#include + +#include "gtest/gtest.h" + +#include "libcgroup-internal.h" +#include "tools-common.h" + +static const char * const PARENT_DIR = "test016cgset/"; + +static const char * const NAME = "io.max"; +static const char * const VALUE = "\"8:16 wbps=1024\""; + +class CgsetParseRFlagTest : public ::testing::Test { +}; + +TEST_F(CgsetParseRFlagTest, EqualCharInValue) +{ + struct control_value name_value; + char name_value_str[4092]; + int ret; + + ret = snprintf(name_value_str, sizeof(name_value_str) -1, + "%s=%s", NAME, VALUE); + ASSERT_GT(ret, 0); + + ret = parse_r_flag("cgset", name_value_str, &name_value); + ASSERT_EQ(ret, 0); + + ASSERT_STREQ(name_value.name, NAME); + ASSERT_STREQ(name_value.value, VALUE); +} diff --git a/gunit/Makefile.am b/gunit/Makefile.am index 6eb8ffce..654002cd 100644 --- a/gunit/Makefile.am +++ b/gunit/Makefile.am @@ -21,13 +21,15 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \ -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/tools \ -I$(top_builddir)/googletest/googletest/include \ -I$(top_builddir)/googletest/googletest \ -std=c++11 \ -Wno-write-strings \ -DSTATIC= \ -DUNIT_TEST -LDADD = $(top_builddir)/src/.libs/libcgroupfortesting.la +LDADD = $(top_builddir)/src/.libs/libcgroupfortesting.la \ + $(top_builddir)/src/tools/.libs/libcgset.la EXTRA_DIST = $(top_srcdir)/googletest/googletest/libgtest.so \ $(top_srcdir)/googletest/googletest/libgtest_main.so \ @@ -52,6 +54,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-cgset_parse_r_flag.cpp gtest_LDFLAGS = -L$(top_builddir)/googletest/googletest -l:libgtest.so \ -rpath $(abs_top_builddir)/googletest/googletest -- 2.47.2