lib/process: Add add_stderr flag to process module
[petitboot] / lib / pb-config / storage-test.c
1
2 #include <string.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6
7 #include <util/util.h>
8
9 #include "pb-config.h"
10 #include "storage.h"
11
12 struct interface_config net1 = {
13         .hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
14         .method = CONFIG_METHOD_DHCP,
15 };
16
17 struct interface_config net2 = {
18         .hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x56 },
19         .method = CONFIG_METHOD_STATIC,
20         .static_config = {
21                 .address = "192.168.0.2/24",
22                 .gateway = "192.168.0.1",
23         },
24 };
25
26 struct interface_config *interface_configs[] = { &net1, &net2 };
27 const char *dns_servers[] = { "192.168.1.1", "192.168.1.2" };
28
29 struct config test_config = {
30         .autoboot_enabled = true,
31         .network = {
32                 .interfaces = interface_configs,
33                 .n_interfaces = ARRAY_SIZE(interface_configs),
34                 .dns_servers = dns_servers,
35                 .n_dns_servers = ARRAY_SIZE(dns_servers),
36         }
37 };
38
39 struct test_storage {
40         struct config_storage   storage;
41         struct param            *params;
42         int                     n_params;
43         struct config           *config;
44 };
45
46 #define to_test_storage(st) container_of(st, struct test_storage, storage)
47
48 static int load(struct config_storage *st, struct config *config)
49 {
50         struct test_storage *ts = to_test_storage(st);
51         memcpy(config, ts->config, sizeof(test_config));
52         return 0;
53 }
54
55 static int save(struct config_storage *st, struct config *newconfig)
56 {
57         struct test_storage *ts = to_test_storage(st);
58         ts->config = newconfig;
59         return 0;
60 }
61
62 static struct test_storage st = {
63         .storage = {
64                 .load  = load,
65                 .save = save,
66         },
67 };
68
69 struct config_storage *create_test_storage(void *ctx __attribute__((unused)))
70 {
71         st.config = &test_config;
72         return &st.storage;
73 }