qapi: Move conditional code from QAPISchemaVariants to its subtypes
[qemu/kevin.git] / tests / tcg / hexagon / hex_sigsegv.c
blobf43e0308f9131c007bfae4b3adfa3e23709a9850
1 /*
2 * Copyright(c) 2021-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * Test the VLIW semantics of two stores in a packet
21 * When a packet has 2 stores, either both commit or neither commit.
22 * We test this with a packet that does stores to both NULL and a global
23 * variable, "should_not_change". After the SIGSEGV is caught, we check
24 * that the "should_not_change" value is the same.
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <setjmp.h>
35 #include <signal.h>
37 int err;
39 #include "hex_test.h"
41 bool segv_caught;
43 #define SHOULD_NOT_CHANGE_VAL 5
44 int32_t should_not_change = SHOULD_NOT_CHANGE_VAL;
46 #define BUF_SIZE 300
47 uint8_t buf[BUF_SIZE];
48 jmp_buf jmp_env;
50 static void sig_segv(int sig, siginfo_t *info, void *puc)
52 check32(sig, SIGSEGV);
53 segv_caught = true;
54 longjmp(jmp_env, 1);
57 int main()
59 struct sigaction act;
61 /* SIGSEGV test */
62 act.sa_sigaction = sig_segv;
63 sigemptyset(&act.sa_mask);
64 act.sa_flags = SA_SIGINFO;
65 chk_error(sigaction(SIGSEGV, &act, NULL));
66 if (setjmp(jmp_env) == 0) {
67 asm volatile("r18 = ##should_not_change\n\t"
68 "r19 = #0\n\t"
69 "{\n\t"
70 " memw(r18) = #7\n\t"
71 " memw(r19) = #0\n\t"
72 "}\n\t"
73 : : : "r18", "r19", "memory");
76 act.sa_handler = SIG_DFL;
77 sigemptyset(&act.sa_mask);
78 act.sa_flags = 0;
79 chk_error(sigaction(SIGSEGV, &act, NULL));
81 check32(segv_caught, true);
82 check32(should_not_change, SHOULD_NOT_CHANGE_VAL);
84 puts(err ? "FAIL" : "PASS");
85 return err ? EXIT_FAILURE : EXIT_SUCCESS;