Xen Test Framework
main.c
Go to the documentation of this file.
1 
12 #include <xtf.h>
13 
14 const char test_title[] = "Live Patch Privilege Check";
15 
17 
18 static 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 
38 static void test_upload(void)
39 {
40  static uint8_t payload[PAGE_SIZE];
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 
63 static 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 
86 static 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 
106 static 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 
128 void 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 
142  xtf_success(NULL);
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  */
#define XEN_SYSCTL_LIVEPATCH_UPLOAD
Definition: sysctl.h:85
uint32_t cmd
Definition: sysctl.h:191
static void test_list(void)
Definition: main.c:63
#define TEST_NAME
Definition: main.c:36
#define XEN_SYSCTL_LIVEPATCH_LIST
Definition: sysctl.h:138
#define LIVEPATCH_ACTION_APPLY
Definition: sysctl.h:169
void printk(const char *fmt,...)
Definition: console.c:134
#define ENOSYS
Definition: errno.h:43
#define NULL
Definition: stddef.h:12
#define LIVEPATCH_ACTION_REVERT
Definition: sysctl.h:168
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
static void test_get(void)
Definition: main.c:86
#define XEN_SYSCTL_LIVEPATCH_GET
Definition: sysctl.h:101
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:137
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
static void check_ret(const char *test, int rc)
Definition: main.c:18
int xtf_probe_sysctl_interface_version(void)
Probe for the SYSCTL_INTERFACE_VERSION in use by the hypervisor.
Definition: lib.c:32
void xtf_skip(const char *fmt,...)
Report a test skip.
Definition: report.c:66
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
#define EPERM
Definition: errno.h:15
const char test_title[]
The title of the test.
Definition: main.c:14
static void test_action(uint32_t action)
Definition: main.c:106
static long hypercall_sysctl(xen_sysctl_t *arg)
Definition: hypercall.h:182
#define LIVEPATCH_ACTION_UNLOAD
Definition: sysctl.h:167
#define XEN_LIVEPATCH_NAME_SIZE
Definition: sysctl.h:61
Definition: main.c:38
#define XEN_SYSCTL_LIVEPATCH_ACTION
Definition: sysctl.h:164
#define PAGE_SIZE
Definition: page.h:11
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
#define XEN_SYSCTL_livepatch_op
Definition: sysctl.h:192
static int sysctl_interface_version
Definition: main.c:16
static void test_upload(void)
Definition: main.c:38
#define NR_PAYLOADS
Definition: main.c:61
static char payload[XENSTORE_PAYLOAD_MAX+1]
Definition: xenbus.c:10
#define LIVEPATCH_ACTION_REPLACE
Definition: sysctl.h:170
__UINT8_TYPE__ uint8_t
Definition: stdint.h:14