Xen Test Framework
main.c
Go to the documentation of this file.
1
12#include <xtf.h>
13
14const char test_title[] = "Live Patch Privilege Check";
15
17
18static void check_ret(const char *test, int rc)
19{
20 switch ( rc )
21 {
22 case -EPERM:
23 printk("%s: Xen correctly denied Live Patch calls\n", test);
24 break;
25
26 case -ENOSYS:
27 xtf_skip("%s: Live Patch support not detected\n", test);
28 break;
29
30 default:
31 xtf_failure("Fail: %s: Unexpected return code %d\n", test, rc);
32 break;
33 }
34}
35
36#define TEST_NAME "foo"
37
38static void test_upload(void)
39{
41 xen_sysctl_t op =
42 {
44 .interface_version = sysctl_interface_version,
45 .u.livepatch = {
47 .u.upload = {
48 .name = {
49 .name = {{ TEST_NAME }},
50 .size = sizeof(TEST_NAME),
51 },
52 .size = PAGE_SIZE,
53 .payload = {{ payload }},
54 },
55 },
56 };
57
58 check_ret(__func__, hypercall_sysctl(&op));
59}
60
61#define NR_PAYLOADS 8
62
63static void test_list(void)
64{
66 uint32_t lengths[NR_PAYLOADS];
67
68 xen_sysctl_t op =
69 {
71 .interface_version = sysctl_interface_version,
72 .u.livepatch = {
74 .u.list = {
75 .idx = 0,
76 .nr = NR_PAYLOADS,
77 .name = {{ names }},
78 .len = {{ lengths }},
79 },
80 },
81 };
82
83 check_ret(__func__, hypercall_sysctl(&op));
84}
85
86static void test_get(void)
87{
88 xen_sysctl_t op =
89 {
91 .interface_version = sysctl_interface_version,
92 .u.livepatch = {
94 .u.get = {
95 .name = {
96 .name = {{ TEST_NAME }},
97 .size = sizeof(TEST_NAME),
98 },
99 },
100 },
101 };
102
103 check_ret(__func__, hypercall_sysctl(&op));
104}
105
106static void test_action(uint32_t action)
107{
108 xen_sysctl_t op =
109 {
111 .interface_version = sysctl_interface_version,
112 .u.livepatch = {
114 .u.action = {
115 .name = {
116 .name = {{ TEST_NAME }},
117 .size = sizeof(TEST_NAME),
118 },
119 .cmd = action,
120 .timeout = 0,
121 },
122 },
123 };
124
125 check_ret(__func__, hypercall_sysctl(&op));
126}
127
128void test_main(void)
129{
131 if ( sysctl_interface_version < 0 )
132 return xtf_error("Failed to find sysctl interface version\n");
133
134 test_upload();
135 test_list();
136 test_get();
141
143}
144
145/*
146 * Local variables:
147 * mode: C
148 * c-file-style: "BSD"
149 * c-basic-offset: 4
150 * tab-width: 4
151 * indent-tabs-mode: nil
152 * End:
153 */
void printk(const char *fmt,...)
Definition: console.c:134
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:110
const char test_title[]
The title of the test.
Definition: main.c:24
#define ENOSYS
Definition: errno.h:43
#define EPERM
Definition: errno.h:15
static long hypercall_sysctl(xen_sysctl_t *arg)
Definition: hypercall.h:182
int xtf_probe_sysctl_interface_version(void)
Probe for the SYSCTL_INTERFACE_VERSION in use by the hypervisor.
Definition: lib.c:32
static void check_ret(const char *test, int rc)
Definition: main.c:18
#define NR_PAYLOADS
Definition: main.c:61
static void test_upload(void)
Definition: main.c:38
#define TEST_NAME
Definition: main.c:36
static void test_list(void)
Definition: main.c:63
static void test_get(void)
Definition: main.c:86
static int sysctl_interface_version
Definition: main.c:16
static void test_action(uint32_t action)
Definition: main.c:106
#define PAGE_SIZE
Definition: page.h:11
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
void xtf_skip(const char *fmt,...)
Report a test skip.
Definition: report.c:66
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
#define NULL
Definition: stddef.h:12
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
__UINT8_TYPE__ uint8_t
Definition: stdint.h:14
Definition: main.c:39
uint32_t cmd
Definition: sysctl.h:191
#define XEN_SYSCTL_LIVEPATCH_ACTION
Definition: sysctl.h:164
#define LIVEPATCH_ACTION_REVERT
Definition: sysctl.h:168
#define XEN_SYSCTL_LIVEPATCH_LIST
Definition: sysctl.h:138
#define XEN_SYSCTL_livepatch_op
Definition: sysctl.h:192
#define LIVEPATCH_ACTION_REPLACE
Definition: sysctl.h:170
#define XEN_LIVEPATCH_NAME_SIZE
Definition: sysctl.h:61
#define XEN_SYSCTL_LIVEPATCH_UPLOAD
Definition: sysctl.h:85
#define XEN_SYSCTL_LIVEPATCH_GET
Definition: sysctl.h:101
#define LIVEPATCH_ACTION_APPLY
Definition: sysctl.h:169
#define LIVEPATCH_ACTION_UNLOAD
Definition: sysctl.h:167
static char payload[XENSTORE_PAYLOAD_MAX+1]
Definition: xenbus.c:10