]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tests: add a function for negative netdev tests
authorFelix Abecassis <fabecassis@nvidia.com>
Wed, 29 Nov 2017 04:27:34 +0000 (20:27 -0800)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Dec 2017 11:42:30 +0000 (12:42 +0100)
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
src/tests/parse_config_file.c

index db61dd0446451e573dde7afd4d4c05e182480051..7479793ac01cfe3583cd4c25e923483d78f37ddc 100644 (file)
@@ -155,6 +155,23 @@ static int set_and_clear_complete_netdev(struct lxc_container *c)
        return 0;
 }
 
+static int set_invalid_netdev(struct lxc_container *c) {
+       if (c->set_config_item(c, "lxc.net.0.asdf", "veth")) {
+               lxc_error("%s\n", "lxc.net.0.asdf should be invalid");
+               return -1;
+       }
+
+       if (c->set_config_item(c, "lxc.net.2147483647.type", "veth")) {
+               lxc_error("%s\n", "lxc.net.2147483647.type should be invalid");
+               return -1;
+       }
+
+       c->clear_config(c);
+       c->lxc_conf = NULL;
+
+       return 0;
+}
+
 int test_idmap_parser(void)
 {
        size_t i;
@@ -970,12 +987,6 @@ int main(int argc, char *argv[])
                goto non_test_error;
        }
 
-       if (!set_get_compare_clear_save_load(c, "lxc.net.0.asdf", "veth",
-                                           tmpf, true)) {
-               lxc_error("%s\n", "lxc.net.0.asdf");
-               goto non_test_error;
-       }
-
        if (set_get_compare_clear_save_load_network(
                c, "lxc.net.0.macvlan.mode", "private", tmpf, true,
                "macvlan")) {
@@ -1070,6 +1081,11 @@ int main(int argc, char *argv[])
                goto non_test_error;
        }
 
+       if (set_invalid_netdev(c) < 0) {
+               lxc_error("%s\n", "failed to reject invalid configuration");
+               goto non_test_error;
+       }
+
        ret = EXIT_SUCCESS;
 non_test_error:
        (void)unlink(tmpf);