Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/os-tests/tests/xsave/swapcontext_extd.c
+++ new/usr/src/test/os-tests/tests/xsave/swapcontext_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 * This test exercises the swapcontext_extd(2) functionality and verifies that
18 18 * we can swap contexts tht have both extended and non-extended ucontext_t's and
19 19 * that we can get at that state in both cases. This test relies on extended
20 20 * states as we try to validate and ensure that they exist.
21 21 */
22 22
23 23 #include <err.h>
24 24 #include <stdlib.h>
25 25 #include <ucontext.h>
26 26 #include <limits.h>
27 27 #include <errno.h>
28 28
29 29 #include "xsave_util.h"
30 30
31 31 static xsu_fpu_t mk_fpu, orig_fpu, found;
32 32 static ucontext_t *mk_ctx, *orig_ctx;
33 33 static volatile int estatus = EXIT_SUCCESS;
34 34
35 35 static void
36 36 mkctx_target(uint32_t hwsup)
37 37 {
38 38 xsu_getfpu(&found, hwsup);
39 39 if (!xsu_same(&mk_fpu, &found, hwsup)) {
40 40 estatus = EXIT_FAILURE;
41 41 warnx("TEST FAILED: initial swap had bad FPU");
42 42 } else {
43 43 (void) printf("TEST PASSED: initial swap had correct FPU\n");
44 44 }
45 45
46 46 (void) swapcontext_extd(mk_ctx, 0, orig_ctx);
47 47 err(EXIT_FAILURE, "swapcontext_extd() back failed");
48 48 }
49 49
50 50 static void
51 51 mkctx_failure(void)
52 52 {
53 53 errx(EXIT_FAILURE, "swapcontext_extd() called failure func");
54 54 }
55 55
56 56 int
57 57 main(void)
58 58 {
59 59 uint32_t hwsup = xsu_hwsupport();
60 60 uint32_t start = arc4random();
61 61
62 62 xsu_fill(&mk_fpu, hwsup, start);
63 63 xsu_fill(&orig_fpu, hwsup, start + INT_MAX);
64 64
65 65 mk_ctx = ucontext_alloc(0);
66 66 if (mk_ctx == NULL)
67 67 err(EXIT_FAILURE, "failed to allocate extended ucontext_t");
68 68 orig_ctx = ucontext_alloc(0);
69 69 if (orig_ctx == NULL)
70 70 err(EXIT_FAILURE, "failed to allocate extended ucontext_t");
71 71
72 72 /*
73 73 * Set the FPU and snag our initial context. We'll use makecontext to
74 74 * call this and then change our FPU, swap and start checking and then
75 75 * swap back.
76 76 */
77 77 xsu_setfpu(&mk_fpu, hwsup);
78 78 if (getcontext_extd(mk_ctx, 0) != 0) {
79 79 errx(EXIT_FAILURE, "failed to get initial extended context for "
80 80 "makecontext");
81 81 }
82 82
83 83 makecontext(mk_ctx, mkctx_target, 1, hwsup);
84 84 xsu_setfpu(&orig_fpu, hwsup);
85 85 if (swapcontext_extd(orig_ctx, 0, mk_ctx) != 0) {
86 86 err(EXIT_FAILURE, "failed to swap contexts");
87 87 }
88 88 xsu_getfpu(&found, hwsup);
89 89 if (!xsu_same(&orig_fpu, &found, hwsup)) {
90 90 estatus = EXIT_FAILURE;
91 91 warnx("TEST FAILED: swap back did not have the right FPU");
92 92 } else {
93 93 (void) printf("TEST PASSED: swap back had the correct FPU\n");
94 94 }
95 95
96 96 makecontext(mk_ctx, mkctx_failure, 0);
97 97 if (swapcontext_extd(orig_ctx, 23, mk_ctx) != -1) {
98 98 errx(EXIT_FAILURE, "somehow got back from error test "
99 99 "swapcontext_extd() with bad func");
100 100 }
101 101 if (errno != EINVAL) {
102 102 estatus = EXIT_FAILURE;
103 103 warnx("TEST FAILED: swapcontext_extd() with bad flags had "
104 104 "errno %d expected EINVAL", errno);
105 105 } else {
106 106 (void) printf("TEST PASSED: swapcontext_extd() with bad flags "
107 107 "has correct errno (EINVAL)\n");
108 108 }
109 109
110 110 return (estatus);
111 111 }
|
↓ open down ↓ |
111 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX