]> git.ozlabs.org Git - petitboot/blob - test/parser-test.c
Fix build error in parser-test
[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
50         if (argc != 3) {
51                 fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
52                 return EXIT_FAILURE;
53         }
54
55         /* Default to test on stdout, pb_log on stderr. */
56
57         testf = stdout;
58
59         pb_log_set_stream(stderr);
60         pb_log_always_flush(1);
61         pb_log("--- parser-test ---\n");
62
63         ctx = talloc_zero(NULL, struct discover_context);
64
65         ctx->device_path = talloc_asprintf(ctx, "%s/%s", argv[1], argv[2]);
66         ctx->device = talloc_zero(ctx, struct device);
67         ctx->device->id = talloc_strdup(ctx->device, argv[2]);
68
69         iterate_parsers(ctx);
70
71         pb_log("--- end ---\n");
72
73         return EXIT_SUCCESS;
74 }