X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fpb-config%2Fstorage-test.c;h=48cb238bd383bcaabb1efc2e571d3033d1c749d4;hp=ba4e952d94ac0f64b4b26091feb646d6540544c4;hb=fafa0c268844aa3921f9df0ef72a1cb7c860793f;hpb=32fe8024f5af5cd8de23c638ddad8ada67a46cd5 diff --git a/lib/pb-config/storage-test.c b/lib/pb-config/storage-test.c index ba4e952..48cb238 100644 --- a/lib/pb-config/storage-test.c +++ b/lib/pb-config/storage-test.c @@ -4,15 +4,17 @@ #include #include +#include + #include "pb-config.h" #include "storage.h" -struct network_config net1 = { +struct interface_config net1 = { .hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }, .method = CONFIG_METHOD_DHCP, }; -struct network_config net2 = { +struct interface_config net2 = { .hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x56 }, .method = CONFIG_METHOD_STATIC, .static_config = { @@ -21,36 +23,51 @@ struct network_config net2 = { }, }; -struct network_config *network_configs[] = { &net1, &net2 }; - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +struct interface_config *interface_configs[] = { &net1, &net2 }; +const char *dns_servers[] = { "192.168.1.1", "192.168.1.2" }; struct config test_config = { .autoboot_enabled = true, - .network_configs = network_configs, - .n_network_configs = ARRAY_SIZE(network_configs), + .network = { + .interfaces = interface_configs, + .n_interfaces = ARRAY_SIZE(interface_configs), + .dns_servers = dns_servers, + .n_dns_servers = ARRAY_SIZE(dns_servers), + } }; struct test_storage { struct config_storage storage; struct param *params; int n_params; + struct config *config; }; -static int load(struct config_storage *st __attribute__((unused)), - struct config *config) +#define to_test_storage(st) container_of(st, struct test_storage, storage) + +static int load(struct config_storage *st, struct config *config) +{ + struct test_storage *ts = to_test_storage(st); + memcpy(config, ts->config, sizeof(test_config)); + return 0; +} + +static int save(struct config_storage *st, struct config *newconfig) { - memcpy(config, &test_config, sizeof(test_config)); + struct test_storage *ts = to_test_storage(st); + ts->config = newconfig; return 0; } static struct test_storage st = { .storage = { .load = load, + .save = save, }, }; struct config_storage *create_test_storage(void *ctx __attribute__((unused))) { + st.config = &test_config; return &st.storage; }