]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/criu_check_feature.c
tests: include config.h
[mirror_lxc.git] / src / tests / criu_check_feature.c
1 /* liblxcapi
2 *
3 * Copyright © 2017 Adrian Reber <areber@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include "config.h"
20
21 #include <string.h>
22 #include <limits.h>
23
24 #include "lxc/lxccontainer.h"
25 #include "lxctest.h"
26
27 int main(int argc, char *argv[])
28 {
29 struct lxc_container *c;
30 struct migrate_opts m_opts;
31 int ret = EXIT_FAILURE;
32
33 /* Test the feature check interface,
34 * we actually do not need a container. */
35 c = lxc_container_new("check_feature", NULL);
36 if (!c) {
37 lxc_error("%s", "Failed to create container \"check_feature\"");
38 exit(ret);
39 }
40
41 if (c->is_defined(c)) {
42 lxc_error("%s\n", "Container \"check_feature\" is defined");
43 goto on_error_put;
44 }
45
46 /* check the migrate API call with wrong 'cmd' */
47 if (!c->migrate(c, UINT_MAX, &m_opts, sizeof(struct migrate_opts))) {
48 /* This should failed */
49 lxc_error("%s\n", "Migrate API calls with command UINT_MAX did not fail");
50 goto on_error_put;
51 }
52
53 /* do the actual feature check for memory tracking */
54 m_opts.features_to_check = FEATURE_MEM_TRACK;
55 if (c->migrate(c, MIGRATE_FEATURE_CHECK, &m_opts, sizeof(struct migrate_opts))) {
56 lxc_debug("%s\n", "System does not support \"FEATURE_MEM_TRACK\".");
57 }
58
59 /* check for lazy pages */
60 m_opts.features_to_check = FEATURE_LAZY_PAGES;
61 if (c->migrate(c, MIGRATE_FEATURE_CHECK, &m_opts, sizeof(struct migrate_opts))) {
62 lxc_debug("%s\n", "System does not support \"FEATURE_LAZY_PAGES\".");
63 }
64
65 /* check for lazy pages and memory tracking */
66 m_opts.features_to_check = FEATURE_LAZY_PAGES | FEATURE_MEM_TRACK;
67 if (c->migrate(c, MIGRATE_FEATURE_CHECK, &m_opts, sizeof(struct migrate_opts))) {
68 if (m_opts.features_to_check == FEATURE_LAZY_PAGES)
69 lxc_debug("%s\n", "System does not support \"FEATURE_MEM_TRACK\"");
70 else if (m_opts.features_to_check == FEATURE_MEM_TRACK)
71 lxc_debug("%s\n", "System does not support \"FEATURE_LAZY_PAGES\"");
72 else
73 lxc_debug("%s\n", "System does not support \"FEATURE_MEM_TRACK\" "
74 "and \"FEATURE_LAZY_PAGES\"");
75 }
76
77 /* test for unknown feature; once there are 64 features to test
78 * this will be valid... */
79 m_opts.features_to_check = -1ULL;
80 if (!c->migrate(c, MIGRATE_FEATURE_CHECK, &m_opts, sizeof(struct migrate_opts))) {
81 lxc_error("%s\n", "Unsupported feature supported, which is strange.");
82 goto on_error_put;
83 }
84
85 ret = EXIT_SUCCESS;
86
87 on_error_put:
88 lxc_container_put(c);
89 if (ret == EXIT_SUCCESS)
90 lxc_debug("%s\n", "All criu feature check tests passed");
91
92 exit(ret);
93 }