]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.c
discover: Separate temporary and permanent device data
[petitboot] / test / parser / 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 <types/types.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 struct device *discover_context_device(struct discover_context *ctx)
21 {
22         return ctx->device->device;
23 }
24
25 void discover_context_add_boot_option(struct discover_context *ctx,
26                 struct boot_option *boot_option)
27 {
28         fprintf(testf, "%s: %s\n", __func__, ctx->device->device->id);
29         fprintf(testf, " id     '%s'\n", boot_option->id);
30         fprintf(testf, " name   '%s'\n", boot_option->name);
31         fprintf(testf, " descr  '%s'\n", boot_option->description);
32         fprintf(testf, " icon   '%s'\n", boot_option->icon_file);
33         fprintf(testf, " image  '%s'\n", boot_option->boot_image_file);
34         fprintf(testf, " initrd '%s'\n", boot_option->initrd_file);
35         fprintf(testf, " args   '%s'\n", boot_option->boot_args);
36         fflush(testf);
37 }
38
39 const char *generic_icon_file(
40         enum generic_icon_type __attribute__((unused)) type)
41 {
42         return "tester.png";
43 }
44
45 enum generic_icon_type guess_device_type(
46         struct discover_context __attribute__((unused)) *ctx)
47 {
48         return ICON_TYPE_UNKNOWN;
49 }
50
51 int main(int argc, char **argv)
52 {
53         struct discover_context *ctx;
54
55         if (argc != 3) {
56                 fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
57                 return EXIT_FAILURE;
58         }
59
60         /* Default to test on stdout, pb_log on stderr. */
61
62         testf = stdout;
63
64         pb_log_set_stream(stderr);
65         pb_log_always_flush(1);
66         pb_log("--- parser-test ---\n");
67
68         ctx = talloc_zero(NULL, struct discover_context);
69
70         ctx->device = talloc_zero(ctx, struct discover_device);
71         ctx->device->device = talloc_zero(ctx->device, struct device);
72         ctx->device->device_path = talloc_asprintf(ctx, "%s/%s",
73                                                         argv[1], argv[2]);
74         ctx->device->device->id = talloc_strdup(ctx->device->device, argv[2]);
75
76         iterate_parsers(ctx);
77
78         pb_log("--- end ---\n");
79
80         return EXIT_SUCCESS;
81 }