]> git.ozlabs.org Git - petitboot/blob - test/parser-test.c
Minor include path fix
[petitboot] / test / parser-test.c
1 #define _GNU_SOURCE
2
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8
9 #include <log/log.h>
10 #include "pb-protocol/pb-protocol.h"
11 #include <talloc/talloc.h>
12
13 #include "discover/device-handler.h"
14 #include "discover/parser.h"
15 #include "discover/parser-utils.h"
16 #include "discover/paths.h"
17
18 static FILE *testf;
19
20 void device_add_boot_option(struct device *device,
21                 struct boot_option *boot_option)
22 {
23         fprintf(testf, "%s: %s\n", __func__, device->id);
24         fprintf(testf, " id     '%s'\n", boot_option->id);
25         fprintf(testf, " name   '%s'\n", boot_option->name);
26         fprintf(testf, " descr  '%s'\n", boot_option->description);
27         fprintf(testf, " icon   '%s'\n", boot_option->icon_file);
28         fprintf(testf, " image  '%s'\n", boot_option->boot_image_file);
29         fprintf(testf, " initrd '%s'\n", boot_option->initrd_file);
30         fprintf(testf, " args   '%s'\n", boot_option->boot_args);
31         fflush(testf);
32 }
33
34 const char *generic_icon_file(
35         enum generic_icon_type __attribute__((unused)) type)
36 {
37         return "tester.png";
38 }
39
40 enum generic_icon_type guess_device_type(
41         struct discover_context __attribute__((unused)) *ctx)
42 {
43         return ICON_TYPE_UNKNOWN;
44 }
45
46 int main(int argc, char **argv)
47 {
48         struct discover_context *ctx;
49         int rc;
50
51         if (argc != 3) {
52                 fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
53                 return EXIT_FAILURE;
54         }
55
56         /* Default to test on stdout, pb_log on stderr. */
57
58         testf = stdout;
59
60         pb_log_set_stream(stderr);
61         pb_log_always_flush(1);
62         pb_log("--- parser-test ---\n");
63
64         ctx = talloc_zero(NULL, struct discover_context);
65
66         ctx->device_path = talloc_asprintf(ctx, "%s/%s", argv[1], argv[2]);
67         ctx->device = talloc_zero(ctx, struct device);
68         ctx->device->id = talloc_strdup(ctx->device, argv[2]);
69
70         rc = iterate_parsers(ctx);
71
72         pb_log("--- end ---\n");
73
74         return EXIT_SUCCESS;
75 }