]> git.ozlabs.org Git - petitboot/commitdiff
test/parser: Add check_args helper
authorJeremy Kerr <jk@ozlabs.org>
Mon, 6 May 2013 03:10:36 +0000 (11:10 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 16 May 2013 03:53:34 +0000 (11:53 +0800)
Add a small helper to check boot option arguments.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/parser/parser-test.h
test/parser/utils.c

index 744c9140341e2e1bf54e435a4e3fb2c5430a6d05..ac4af40077663af2a335f573943221206174807f 100644 (file)
@@ -55,5 +55,12 @@ extern const size_t __embedded_config_size;
        __check_boot_option_count(ctx, count, __FILE__, __LINE__)
 void __check_boot_option_count(struct discover_context *ctx, int count,
                const char *file, int line);
+/*
+ * Check that a boot option @opt has args @args
+ */
+void __check_args(struct discover_boot_option *opt, const char *args,
+               const char *file, int line);
+#define check_args(opt, args) \
+       __check_args(opt, args, __FILE__, __LINE__)
 
 #endif /* PARSER_TEST_H */
index 019ba633e23b8de944dca06d906b8e3d4423aa31..0b4c89f5faec63fe239716684c69ba968d1eecc6 100644 (file)
@@ -179,3 +179,24 @@ void __check_boot_option_count(struct discover_context *ctx, int count,
 
        exit(EXIT_FAILURE);
 }
+
+void __check_args(struct discover_boot_option *opt, const char *args,
+               const char *file, int line)
+{
+       int rc;
+
+       if (!opt->option->boot_args) {
+               fprintf(stderr, "%s%d: arg check failed\n", file, line);
+               fprintf(stderr, "  no arguments parsed\n");
+               fprintf(stderr, "  expected '%s'\n", args);
+               exit(EXIT_FAILURE);
+       }
+
+       rc = strcmp(opt->option->boot_args, args);
+       if (rc) {
+               fprintf(stderr, "%s%d: arg check failed\n", file, line);
+               fprintf(stderr, "  got      '%s'\n", opt->option->boot_args);
+               fprintf(stderr, "  expected '%s'\n", args);
+               exit(EXIT_FAILURE);
+       }
+}