FreeBSD regtest: remove test for version 13+ syscalls
[valgrind.git] / memcheck / tests / freebsd / get_set_context.c
blobe0b7db63b1b07a33b16b0c57c7d7af79c68da4b9
1 /*
2 * Tests for various context functions
4 * getcontext
5 * setcontext
6 * swapcontext
7 */
9 #include <ucontext.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <assert.h>
14 #include <unistd.h>
15 #include <assert.h>
16 #include "../../memcheck.h"
18 int main(void)
20 ucontext_t uc;
21 volatile int flag = 0;
22 if (-1 == getcontext(&uc)) {
23 perror("getcontext failed: ");
26 flag++;
28 if (flag == 1) {
29 if (-1 == setcontext(&uc)) {
30 perror("setcontext failed: ");
34 flag++;
36 if (flag == 3) {
37 ucontext_t uc2;
38 if (-1 == swapcontext(&uc2, &uc)) {
39 perror("swapcontext failed: ");
43 assert(flag == 5);
45 // error section
46 ucontext_t* ucp = malloc(sizeof(*ucp));
47 ucontext_t* ucp2 = malloc(sizeof(*ucp2));
48 (void)VALGRIND_MAKE_MEM_NOACCESS(ucp, sizeof(*ucp));
49 (void)VALGRIND_MAKE_MEM_NOACCESS(ucp2, sizeof(*ucp2));
50 flag = 0;
51 if (-1 == getcontext(ucp)) {
52 perror("getcontext failed: ");
55 flag++;
57 if (flag == 1) {
58 (void)VALGRIND_MAKE_MEM_NOACCESS(ucp, sizeof(*ucp));
59 if (-1 == setcontext(ucp)) {
60 perror("setcontext failed: ");
62 fprintf(stderr, "should never see setcontext return\n");
65 flag++;
67 if (flag == 3) {
68 (void)VALGRIND_MAKE_MEM_NOACCESS(ucp, sizeof(*ucp));
69 if (-1 == swapcontext(ucp2, ucp)) {
70 perror("swapcontext failed: ");
72 fprintf(stderr, "should never see swapcontest return\n");
75 assert(flag == 5);
76 free(ucp);
77 free(ucp2);