summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-16 09:56:29 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:58:59 +0200
commit39154d61478a7440b1527f02afeff5b6ffb541ce (patch)
tree3a2b58edba80a96a1de75c693898832bcb877250 /src/test
parentc3d60196c5b20e6209fcc649a63c6d7c1692d798 (diff)
Move config_parse_join_controllers to shared, add test
config_parse_join_controllers would free the destination argument on failure, which is contrary to our normal style, where failed parsing has no effect. Moving it to shared also allows a test to be added.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-conf-parser.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c
index 62dd558f0..fc6847954 100644
--- a/src/test/test-conf-parser.c
+++ b/src/test/test-conf-parser.c
@@ -242,6 +242,43 @@ static void test_config_parse_iec_uint64(void) {
}
#endif // 0
+static void test_config_parse_join_controllers(void) {
+ int r;
+ _cleanup_(strv_free_freep) char ***c = NULL;
+ char ***c2;
+
+ /* Test normal operation */
+ r = config_parse_join_controllers(NULL, "example.conf", 11, "Section", 10, "JoinControllers", 0, "cpu,cpuacct net_cls,netprio", &c, NULL);
+ assert_se(r == 0);
+ assert_se(c);
+ assert_se(strv_length(c[0]) == 2);
+ assert_se(strv_equal(c[0], STRV_MAKE("cpu", "cpuacct")));
+ assert_se(strv_length(c[1]) == 2);
+ assert_se(strv_equal(c[1], STRV_MAKE("net_cls", "netprio")));
+ assert_se(c[2] == NULL);
+
+ /* Test special case of no mounted controllers */
+ r = config_parse_join_controllers(NULL, "example.conf", 12, "Section", 10, "JoinControllers", 0, "", &c, NULL);
+ assert_se(r == 0);
+ assert_se(c == NULL);
+
+ /* Test merging of overlapping lists */
+ r = config_parse_join_controllers(NULL, "example.conf", 13, "Section", 10, "JoinControllers", 0, "a,b b,c", &c, NULL);
+ assert_se(r == 0);
+ assert_se(c);
+ assert_se(strv_length(c[0]) == 3);
+ assert_se(strv_contains(c[0], "a"));
+ assert_se(strv_contains(c[0], "b"));
+ assert_se(strv_contains(c[0], "c"));
+ assert_se(c[1] == NULL);
+
+ /* Test ignoring of bad lines */
+ c2 = c;
+ r = config_parse_join_controllers(NULL, "example.conf", 14, "Section", 10, "JoinControllers", 0, "a,\"b ", &c, NULL);
+ assert_se(r < 0);
+ assert_se(c == c2);
+}
+
#define x10(x) x x x x x x x x x x
#define x100(x) x10(x10(x))
#define x1000(x) x10(x100(x))
@@ -387,6 +424,7 @@ int main(int argc, char **argv) {
test_config_parse_nsec();
test_config_parse_iec_uint64();
#endif // 0
+ test_config_parse_join_controllers();
for (i = 0; i < ELEMENTSOF(config_file); i++)
test_config_parse(i, config_file[i]);