]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/config_jump_table.c
tests: enforce all methods for config items
[mirror_lxc.git] / src / tests / config_jump_table.c
CommitLineData
c04f651e
CB
1/* liblxcapi
2 *
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2017 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include <lxc/lxccontainer.h>
20
21#include <unistd.h>
22#include <signal.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/types.h>
27#include <sys/wait.h>
28#include <stdlib.h>
29#include <errno.h>
30#include <string.h>
31
32#include "confile.h"
33#include "lxc/state.h"
34#include "lxctest.h"
35
36int main(int argc, char *argv[])
37{
38 int fulllen = 0, inlen = 0, ret = EXIT_FAILURE;
39 char *key, *keys, *saveptr = NULL;
40
41 fulllen = lxc_listconfigs(NULL, inlen);
42
43 keys = malloc(sizeof(char) * fulllen + 1);
44 if (!keys) {
45 lxc_error("%s\n", "failed to allocate memory");
46 exit(ret);
47 }
48
49 if (lxc_listconfigs(keys, fulllen) != fulllen) {
50 lxc_error("%s\n", "failed to retrieve configuration keys");
51 goto on_error;
52 }
53
54 for (key = strtok_r(keys, "\n", &saveptr); key != NULL;
55 key = strtok_r(NULL, "\n", &saveptr)) {
56 struct lxc_config_t *config;
57 config = lxc_getconfig(key);
58 if (!config) {
59 lxc_error("configuration key \"%s\" not implemented in "
60 "jump table",
61 key);
62 goto on_error;
63 }
64
65 if (!config->set) {
66 lxc_error("configuration key \"%s\" has no set method "
67 "in jump table",
68 key);
69 goto on_error;
70 }
71
72 if (!config->get) {
73 lxc_error("configuration key \"%s\" has no get method "
74 "in jump table",
75 key);
76 goto on_error;
77 }
78
79 if (!config->clr) {
80 lxc_error("configuration key \"%s\" has no clr (clear) "
81 "method in jump table",
82 key);
83 goto on_error;
84 }
85 }
86
87 ret = EXIT_SUCCESS;
88
89on_error:
90 free(keys);
91
92 exit(ret);
93
94}