1 /* $NetBSD: t_ucontext.c,v 1.5 2018/02/27 12:20:35 kamil Exp $ */ 2 3 /* 4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __COPYRIGHT("@(#) Copyright (c) 2008\ 31 The NetBSD Foundation, inc. All rights reserved."); 32 __RCSID("$NetBSD: t_ucontext.c,v 1.5 2018/02/27 12:20:35 kamil Exp $"); 33 34 #include <atf-c.h> 35 #include <stdio.h> 36 #include <ucontext.h> 37 #include <inttypes.h> 38 39 ATF_TC(ucontext_basic); 40 ATF_TC_HEAD(ucontext_basic, tc) 41 { 42 atf_tc_set_md_var(tc, "descr", "Checks {get,set}context(2)"); 43 } 44 45 ATF_TC_BODY(ucontext_basic, tc) 46 { 47 ucontext_t u, v, w; 48 volatile int x, y; 49 50 x = 0; 51 y = 0; 52 53 printf("Start\n"); 54 55 getcontext(&u); 56 y++; 57 58 printf("x == %d\n", x); 59 60 getcontext(&v); 61 62 if ( x < 20 ) { 63 x++; 64 getcontext(&w); 65 setcontext(&u); 66 } 67 68 printf("End, y = %d\n", y); 69 ATF_REQUIRE_EQ(y, 21); 70 } 71 72 ATF_TC(ucontext_sp); 73 ATF_TC_HEAD(ucontext_sp, tc) 74 { 75 atf_tc_set_md_var(tc, "descr", "Retrieve _UC_MACHINE_SP()"); 76 } 77 78 ATF_TC_BODY(ucontext_sp, tc) 79 { 80 ucontext_t u; 81 82 getcontext(&u); 83 84 printf("_UC_MACHINE_SP(u)=%" PRIxREGISTER "\n", (register_t)_UC_MACHINE_SP(&u)); 85 } 86 87 ATF_TC(ucontext_fp); 88 ATF_TC_HEAD(ucontext_fp, tc) 89 { 90 atf_tc_set_md_var(tc, "descr", "Retrieve _UC_MACHINE_FP()"); 91 } 92 93 ATF_TC_BODY(ucontext_fp, tc) 94 { 95 ucontext_t u; 96 97 getcontext(&u); 98 99 printf("_UC_MACHINE_FP(u)=%" PRIxREGISTER "\n", (register_t)_UC_MACHINE_FP(&u)); 100 } 101 102 ATF_TC(ucontext_pc); 103 ATF_TC_HEAD(ucontext_pc, tc) 104 { 105 atf_tc_set_md_var(tc, "descr", "Retrieve _UC_MACHINE_PC()"); 106 } 107 108 ATF_TC_BODY(ucontext_pc, tc) 109 { 110 ucontext_t u; 111 112 getcontext(&u); 113 114 printf("_UC_MACHINE_PC(u)=%" PRIxREGISTER "\n", (register_t)_UC_MACHINE_PC(&u)); 115 } 116 117 ATF_TC(ucontext_intrv); 118 ATF_TC_HEAD(ucontext_intrv, tc) 119 { 120 atf_tc_set_md_var(tc, "descr", "Retrieve _UC_MACHINE_INTRV()"); 121 } 122 123 ATF_TC_BODY(ucontext_intrv, tc) 124 { 125 ucontext_t u; 126 127 getcontext(&u); 128 129 printf("_UC_MACHINE_INTRV(u)=%" PRIxREGISTER "\n", (register_t)_UC_MACHINE_INTRV(&u)); 130 } 131 132 ATF_TP_ADD_TCS(tp) 133 { 134 ATF_TP_ADD_TC(tp, ucontext_basic); 135 ATF_TP_ADD_TC(tp, ucontext_sp); 136 ATF_TP_ADD_TC(tp, ucontext_fp); 137 ATF_TP_ADD_TC(tp, ucontext_pc); 138 ATF_TP_ADD_TC(tp, ucontext_intrv); 139 140 return atf_no_error(); 141 } 142