The following tests are in this commit:
RulesOptions_Ignore() - The valid option "ignore" is tested
RulesOptions_IgnoreWithComma() - The valid (but syntactically
strange) option "ignore," is tested
RulesOptions_InvalidOption() - An invalid option is tested
RulesOptions_InvalidOption2() - An invalid option along with
a valid option is tested
RulesOptions_EmptyOptions() - An empty string is tested
RulesOptions_NullOptions() - A null-pointer option string is
tested
The results from googletest are reported below:
[----------] 6 tests from ParseRulesOptionsTest
[ RUN ] ParseRulesOptionsTest.RulesOptions_Ignore
[ OK ] ParseRulesOptionsTest.RulesOptions_Ignore (0 ms)
[ RUN ] ParseRulesOptionsTest.RulesOptions_IgnoreWithComma
[ OK ] ParseRulesOptionsTest.RulesOptions_IgnoreWithComma (0 ms)
[ RUN ] ParseRulesOptionsTest.RulesOptions_InvalidOption
[ OK ] ParseRulesOptionsTest.RulesOptions_InvalidOption (0 ms)
[ RUN ] ParseRulesOptionsTest.RulesOptions_InvalidOption2
[ OK ] ParseRulesOptionsTest.RulesOptions_InvalidOption2 (0 ms)
[ RUN ] ParseRulesOptionsTest.RulesOptions_EmptyOptions
[ OK ] ParseRulesOptionsTest.RulesOptions_EmptyOptions (0 ms)
[ RUN ] ParseRulesOptionsTest.RulesOptions_NullOptions
[ OK ] ParseRulesOptionsTest.RulesOptions_NullOptions (0 ms)
[----------] 6 tests from ParseRulesOptionsTest (0 ms total)
Signed-off-by: Tom Hromatka <[email protected]>
---
src/api.c | 2 +-
src/libcgroup-internal.h | 3 +
tests/gunit/002-cgroup_parse_rules_options.cpp | 105 +++++++++++++++++++++++++
tests/gunit/Makefile.am | 3 +-
4 files changed, 111 insertions(+), 2 deletions(-)
create mode 100644 tests/gunit/002-cgroup_parse_rules_options.cpp
diff --git a/src/api.c b/src/api.c
index c418223bd6a6..907475f8d6cf 100644
--- a/src/api.c
+++ b/src/api.c
@@ -473,7 +473,7 @@ static char *cg_skip_unused_charactors_in_rule(char *rule)
* TODO: Make this function thread safe!
*
*/
-static int cgroup_parse_rules_options(char *options,
+STATIC int cgroup_parse_rules_options(char *options,
struct cgroup_rule * const rule)
{
char *stok_buff = NULL;
diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h
index b8c3324646e6..b52c82c3f042 100644
--- a/src/libcgroup-internal.h
+++ b/src/libcgroup-internal.h
@@ -294,6 +294,9 @@ int cg_chmod_path(const char *path, mode_t mode, int
owner_is_umask);
*/
#ifdef UNIT_TEST
+int cgroup_parse_rules_options(char *options,
+ struct cgroup_rule * const rule);
+
#endif /* UNIT_TEST */
__END_DECLS
diff --git a/tests/gunit/002-cgroup_parse_rules_options.cpp
b/tests/gunit/002-cgroup_parse_rules_options.cpp
new file mode 100644
index 000000000000..b9ec477b6a36
--- /dev/null
+++ b/tests/gunit/002-cgroup_parse_rules_options.cpp
@@ -0,0 +1,105 @@
+/**
+ * libcgroup googletest for cgroup_parse_rules_options()
+ *
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ * Author: Tom Hromatka <[email protected]>
+ */
+
+/*
+ * 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 "libcgroup-internal.h"
+
+class ParseRulesOptionsTest : public ::testing::Test {
+};
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_Ignore)
+{
+ struct cgroup_rule rule;
+ char options[] = "ignore";
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(rule.is_ignore, true);
+}
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_IgnoreWithComma)
+{
+ struct cgroup_rule rule;
+ char options[] = "ignore,";
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(rule.is_ignore, true);
+}
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_InvalidOption)
+{
+ struct cgroup_rule rule;
+ char options[] = "ignoretypo";
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, -EINVAL);
+ ASSERT_EQ(rule.is_ignore, false);
+}
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_InvalidOption2)
+{
+ struct cgroup_rule rule;
+ char options[] = "ignore,foobar";
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, -EINVAL);
+ ASSERT_EQ(rule.is_ignore, true);
+}
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_EmptyOptions)
+{
+ struct cgroup_rule rule;
+ char options[] = "";
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, -EINVAL);
+ ASSERT_EQ(rule.is_ignore, false);
+}
+
+TEST_F(ParseRulesOptionsTest, RulesOptions_NullOptions)
+{
+ struct cgroup_rule rule;
+ char *options = NULL;
+ int ret;
+
+ rule.is_ignore = false;
+
+ ret = cgroup_parse_rules_options(options, &rule);
+ ASSERT_EQ(ret, -EINVAL);
+ ASSERT_EQ(rule.is_ignore, false);
+}
diff --git a/tests/gunit/Makefile.am b/tests/gunit/Makefile.am
index 79f9f7ee08b9..f3fe400b3218 100644
--- a/tests/gunit/Makefile.am
+++ b/tests/gunit/Makefile.am
@@ -39,4 +39,5 @@ check_PROGRAMS = gtest
TESTS = gtest
gtest_SOURCES = gtest.cpp \
- 001-path.cpp
+ 001-path.cpp \
+ 002-cgroup_parse_rules_options.cpp
--
1.8.3.1
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel