Commit | Line | Data |
---|---|---|
f6bb7db3 YQ |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
88b9d363 | 3 | Copyright 2015-2022 Free Software Foundation, Inc. |
f6bb7db3 YQ |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
9c027c2f TV |
18 | #include <stdlib.h> |
19 | #include <stdio.h> | |
20 | ||
8b00c176 | 21 | typedef void (*testcase_ftype) (void); |
f6bb7db3 | 22 | |
8b00c176 LM |
23 | /* The arch-specific files need to implement both the initialize function |
24 | and define the testcases array. */ | |
f6bb7db3 | 25 | |
8b00c176 LM |
26 | #if (defined __aarch64__) |
27 | #include "insn-reverse-aarch64.c" | |
9fde51ed | 28 | #elif (defined __arm__) |
8b00c176 | 29 | #include "insn-reverse-arm.c" |
20b477a7 LM |
30 | #elif (defined __x86_64__) || (defined __i386__) |
31 | #include "insn-reverse-x86.c" | |
8b00c176 LM |
32 | #else |
33 | /* We get here if the current architecture being tested doesn't have any | |
34 | record/replay instruction decoding tests implemented. */ | |
35 | static testcase_ftype testcases[] = {}; | |
9fde51ed | 36 | |
8b00c176 LM |
37 | /* Dummy implementation in case this target doesn't have any record/replay |
38 | instruction decoding tests implemented. */ | |
9fde51ed YQ |
39 | |
40 | static void | |
8b00c176 | 41 | initialize (void) |
9fde51ed | 42 | { |
9fde51ed | 43 | } |
3263bceb YQ |
44 | #endif |
45 | ||
8b00c176 LM |
46 | /* GDB will read n_testcases to know how many functions to test. The |
47 | functions are implemented in arch-specific files and the testcases | |
48 | array is defined together with them. */ | |
3263bceb | 49 | static int n_testcases = (sizeof (testcases) / sizeof (testcase_ftype)); |
f6bb7db3 | 50 | |
9c027c2f TV |
51 | static void |
52 | usage (void) | |
53 | { | |
54 | printf ("usage: insn-reverse <0-%d>\n", n_testcases - 1); | |
55 | } | |
56 | ||
57 | static int test_nr; | |
58 | ||
59 | static void | |
60 | parse_args (int argc, char **argv) | |
61 | { | |
62 | if (argc != 2) | |
63 | { | |
64 | usage (); | |
65 | exit (1); | |
66 | } | |
67 | ||
68 | char *tail; | |
69 | test_nr = strtol (argv[1], &tail, 10); | |
70 | if (*tail != '\0') | |
71 | { | |
72 | usage (); | |
73 | exit (1); | |
74 | } | |
75 | ||
76 | int in_range_p = 0 <= test_nr && test_nr < n_testcases; | |
77 | if (!in_range_p) | |
78 | { | |
79 | usage (); | |
80 | exit (1); | |
81 | } | |
82 | } | |
83 | ||
f6bb7db3 | 84 | int |
9c027c2f | 85 | main (int argc, char **argv) |
f6bb7db3 | 86 | { |
9c027c2f | 87 | parse_args (argc, argv); |
3263bceb | 88 | |
8b00c176 LM |
89 | /* Initialize any required arch-specific bits. */ |
90 | initialize (); | |
91 | ||
9c027c2f | 92 | testcases[test_nr] (); |
3263bceb | 93 | |
f6bb7db3 YQ |
94 | return 0; |
95 | } |