]> git.ozlabs.org Git - petitboot/blob - test/parser/parser-test.c
test/url: Add uncommitted data files
[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 struct discover_boot_option *discover_boot_option_create(
26                 struct discover_context *ctx,
27                 struct discover_device *dev)
28 {
29         struct discover_boot_option *opt;
30
31         opt = talloc_zero(ctx, struct discover_boot_option);
32         opt->option = talloc(opt, struct boot_option);
33         opt->device = dev;
34
35         return opt;
36 }
37
38 struct discover_device *device_lookup_by_name(
39                 struct device_handler *handler __attribute__((unused)),
40                 const char *name __attribute__((unused)))
41 {
42         return NULL;
43 }
44
45 struct discover_device *device_lookup_by_label(
46                 struct device_handler *handler __attribute__((unused)),
47                 const char *label __attribute__((unused)))
48 {
49         return NULL;
50 }
51
52 struct discover_device *device_lookup_by_uuid(
53                 struct device_handler *handler __attribute__((unused)),
54                 const char *uuid __attribute__((unused)))
55 {
56         return NULL;
57 }
58
59
60 void discover_context_add_boot_option(struct discover_context *ctx,
61                 struct discover_boot_option *boot_option)
62 {
63         struct boot_option *opt = boot_option->option;
64
65         fprintf(testf, "%s: %s\n", __func__, ctx->device->device->id);
66         fprintf(testf, " id     '%s'\n", opt->id);
67         fprintf(testf, " name   '%s'\n", opt->name);
68         fprintf(testf, " descr  '%s'\n", opt->description);
69         fprintf(testf, " icon   '%s'\n", opt->icon_file);
70         fprintf(testf, " image  '%s'\n", opt->boot_image_file);
71         fprintf(testf, " initrd '%s'\n", opt->initrd_file);
72         fprintf(testf, " args   '%s'\n", opt->boot_args);
73         fflush(testf);
74 }
75
76 const char *generic_icon_file(
77         enum generic_icon_type __attribute__((unused)) type)
78 {
79         return "tester.png";
80 }
81
82 enum generic_icon_type guess_device_type(
83         struct discover_context __attribute__((unused)) *ctx)
84 {
85         return ICON_TYPE_UNKNOWN;
86 }
87
88 int main(int argc, char **argv)
89 {
90         struct discover_context *ctx;
91
92         if (argc != 3) {
93                 fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
94                 return EXIT_FAILURE;
95         }
96
97         /* Default to test on stdout, pb_log on stderr. */
98
99         testf = stdout;
100
101         pb_log_set_stream(stderr);
102         pb_log_always_flush(1);
103         pb_log("--- parser-test ---\n");
104
105         ctx = talloc_zero(NULL, struct discover_context);
106
107         ctx->device = talloc_zero(ctx, struct discover_device);
108         ctx->device->device = talloc_zero(ctx->device, struct device);
109         ctx->device->mount_path = talloc_asprintf(ctx, "%s/%s",
110                                                         argv[1], argv[2]);
111         ctx->device->device->id = talloc_strdup(ctx->device->device, argv[2]);
112
113         iterate_parsers(ctx, CONF_METHOD_LOCAL_FILE);
114
115         pb_log("--- end ---\n");
116
117         return EXIT_SUCCESS;
118 }