Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/os-tests/tests/getcontext_extd.c
+++ new/usr/src/test/os-tests/tests/getcontext_extd.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2023 Oxide Computer Company
14 14 */
15 15
16 16 /*
17 17 * Basic test for getcontext_extd() variant. We have two cases that we need to
18 18 * consider. A ucontext_t that is allocated and initialized from the stack and
19 19 * then one that comes from a ucontext_alloc(). We test both that setcontext()
20 20 * and makecontext() work with these.
21 21 */
22 22
23 23 #include <ucontext.h>
24 24 #include <unistd.h>
25 25 #include <stdlib.h>
26 26 #include <err.h>
27 27 #include <string.h>
28 28 #include <errno.h>
29 29 #include <upanic.h>
30 30
31 31 #define STACK_MAGIC 42
32 32 #define EXIT_MAGIC 23
33 33 static volatile uint32_t count = 0;
34 34 static volatile uint32_t stack_count = 0;
35 35
36 36 static void
37 37 successful_exit(uint32_t test)
38 38 {
39 39 if (test != EXIT_MAGIC) {
40 40 errx(EXIT_FAILURE, "TEST FAILED: makecontext had wrong "
41 41 "argument, found 0x%x, expected 0x%x", test, EXIT_MAGIC);
42 42 }
43 43
44 44 printf("TEST PASSED: makecontext called with right argument\n");
45 45 exit(0);
46 46 }
47 47
48 48 static void
49 49 getcontext_stack(uint32_t test)
50 50 {
51 51 ucontext_t ctx;
52 52
53 53 if (test != STACK_MAGIC) {
54 54 errx(EXIT_FAILURE, "TEST FAILED: makecontext had wrong "
55 55 "argument, found 0x%x, expected 0x%x", test, STACK_MAGIC);
56 56 }
57 57
58 58 (void) memset(&ctx, 0, sizeof (ctx));
59 59
60 60 if (getcontext_extd(&ctx, 0) != 0) {
61 61 err(EXIT_FAILURE, "failed to get extended context from stack");
62 62 }
63 63
64 64 count++;
65 65 if (count < 5) {
66 66 const char *msg = "stack setcontext returned, sorry";
67 67 (void) setcontext(&ctx);
68 68 upanic(msg, strlen(msg) + 1);
69 69 }
70 70
71 71 (void) printf("TEST PASSED: stack ucontext_t / getcontext_extd() / "
72 72 "setcontext() combo worked\n");
73 73 makecontext(&ctx, successful_exit, 1, EXIT_MAGIC);
74 74 (void) setcontext(&ctx);
75 75
76 76 err(EXIT_FAILURE, "TEST FAILED: stack ucontext_t / makecontext() "
77 77 "returned from setcontext()");
78 78 }
79 79
80 80 int
81 81 main(void)
82 82 {
83 83 ucontext_t *ctx = ucontext_alloc(0);
84 84 if (ctx == NULL) {
85 85 err(EXIT_FAILURE, "failed to get allocate ucontext_t");
86 86 }
87 87
88 88 if (getcontext_extd(ctx, 23) == 0) {
89 89 errx(EXIT_FAILURE, "TEST FAILED: getcontext_extd worked with "
90 90 "bad flags");
91 91 }
92 92
93 93 if (errno != EINVAL) {
94 94 errx(EXIT_FAILURE, "TEST FAILED: getcontext_extd returned "
95 95 "wrong errno for bad flags: 0x%x", errno);
96 96 }
97 97
98 98 if (getcontext_extd(ctx, 0) != 0) {
99 99 err(EXIT_FAILURE, "failed to get extended context");
100 100 }
101 101
102 102 count++;
103 103 if (count < 5) {
104 104 const char *msg = "setcontext returned, sorry";
105 105 (void) setcontext(ctx);
106 106 upanic(msg, strlen(msg) + 1);
107 107 }
108 108
109 109 (void) printf("TEST PASSED: ucontext_alloc() / getcontext_extd() / "
110 110 "setcontext() combo worked\n");
111 111 makecontext(ctx, getcontext_stack, 1, STACK_MAGIC);
112 112 (void) setcontext(ctx);
113 113
114 114 warn("TEST FAILED: failed to setcontext() to makecontext() from "
115 115 "ucontext_alloc() / getcontext_extd()");
116 116 return (EXIT_FAILURE);
117 117 }
|
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX