blob: 66c49c3a876fd2024c273f273daf4f335b362796 [file] [log] [blame]
snickolls-arm2decd2c2024-01-17 11:24:49 +00001#!/usr/bin/env python3
armvixlb0c8ae22014-03-21 14:03:59 +00002
Alexandre Ramesb78f1392016-07-01 14:22:22 +01003# Copyright 2015, VIXL authors
armvixlb0c8ae22014-03-21 14:03:59 +00004# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# * Redistributions of source code must retain the above copyright notice,
10# this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright notice,
12# this list of conditions and the following disclaimer in the documentation
13# and/or other materials provided with the distribution.
14# * Neither the name of ARM Limited nor the names of its contributors may be
15# used to endorse or promote products derived from this software without
16# specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29import os
30import sys
31import argparse
32import re
33import util
34
Alexandre Ramesb78f1392016-07-01 14:22:22 +010035copyright_header = """// Copyright 2015, VIXL authors
armvixl5289c592015-03-02 13:52:04 +000036// All rights reserved.
37//
38// Redistribution and use in source and binary forms, with or without
39// modification, are permitted provided that the following conditions are met:
40//
41// * Redistributions of source code must retain the above copyright notice,
42// this list of conditions and the following disclaimer.
43// * Redistributions in binary form must reproduce the above copyright notice,
44// this list of conditions and the following disclaimer in the documentation
45// and/or other materials provided with the distribution.
46// * Neither the name of ARM Limited nor the names of its contributors may be
47// used to endorse or promote products derived from this software without
48// specific prior written permission.
49//
50// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
51// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
52// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
54// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
56// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
57// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60
61"""
62
63master_trace_header = """
64// This file holds the expected results for the instructions tested by
Alexandre Ramesd3832962016-07-04 15:03:43 +010065// test-simulator-aarch64.
armvixl5289c592015-03-02 13:52:04 +000066//
Alexandre Ramesd3832962016-07-04 15:03:43 +010067// If you update input lists in test-simulator-inputs-aarch64.h, or add a new
68// test to test-simulator-aarch64.cc, please run
69// tools/generate_simulator_traces.py on a reference platform to regenerate
70// this file and trace files.
armvixl5289c592015-03-02 13:52:04 +000071//
72
Alexandre Ramesd3832962016-07-04 15:03:43 +010073#ifndef VIXL_TEST_AARCH64_SIMULATOR_TRACES_AARCH64_H_
74#define VIXL_TEST_AARCH64_SIMULATOR_TRACES_AARCH64_H_
armvixl5289c592015-03-02 13:52:04 +000075
Pierre Langlois78973f22016-08-10 14:35:56 +010076extern "C" {
armvixl5289c592015-03-02 13:52:04 +000077#include <stdint.h>
Pierre Langlois78973f22016-08-10 14:35:56 +010078}
armvixl5289c592015-03-02 13:52:04 +000079
Martyn Capewellacdea502020-11-10 16:12:34 +000080// To add a new simulator test to test-simulator-aarch64.cc, add placeholder array(s)
Alexandre Ramesd3832962016-07-04 15:03:43 +010081// below to build test-simulator-aarch64 for reference platform. Then, run
armvixl5289c592015-03-02 13:52:04 +000082// tools/generate_simulator_traces.py on a reference platform to regenerate this
83// file and traces files.
84
85// ---------------------------------------------------------------------
86// ADD DUMMY ARRAYS FOR NEW SIMULATOR TEST HERE.
87// ---------------------------------------------------------------------
Martyn Capewellacdea502020-11-10 16:12:34 +000088const uint64_t kExpected_placeholder_64[] = {0};
89const size_t kExpectedCount_placeholder_64 = 0;
armvixl5289c592015-03-02 13:52:04 +000090
Martyn Capewellacdea502020-11-10 16:12:34 +000091const uint32_t kExpected_placeholder_32[] = {0};
92const size_t kExpectedCount_placeholder_32 = 0;
armvixl5289c592015-03-02 13:52:04 +000093
94// ---------------------------------------------------------------------
95// Simulator test trace output files.
96// ---------------------------------------------------------------------
97"""
98master_trace_footer = """
Alexandre Ramesd3832962016-07-04 15:03:43 +010099#endif // VIXL_TEST_AARCH64_SIMULATOR_TRACES_AARCH64_H_
armvixl5289c592015-03-02 13:52:04 +0000100"""
101
102trace_header = """
103// ---------------------------------------------------------------------
104// This file is auto generated using tools/generate_simulator_traces.py.
105//
106// PLEASE DO NOT EDIT.
107// ---------------------------------------------------------------------
108"""
109
armvixlb0c8ae22014-03-21 14:03:59 +0000110def BuildOptions(root):
111 result = argparse.ArgumentParser(description = 'Simulator test generator.')
armvixl0f35e362016-05-10 13:57:58 +0100112 result.add_argument('--runner', action='store',
113 default=os.path.join(root, 'obj/latest/test/test-runner'),
armvixl330dc712014-11-25 10:38:32 +0000114 help='The test executable to run.')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100115 result.add_argument('--aarch32-only', action='store_true')
116 result.add_argument('--aarch64-only', action='store_true')
armvixlb0c8ae22014-03-21 14:03:59 +0000117 result.add_argument('--out', action='store',
Alexandre Ramesd3832962016-07-04 15:03:43 +0100118 default='test/aarch64/test-simulator-traces-aarch64.h')
Alexander Gilday69203a52018-05-22 10:51:09 +0100119 result.add_argument('--filter', action='store', help='Test regexp filter.')
armvixlb0c8ae22014-03-21 14:03:59 +0000120 return result.parse_args()
121
Pierre Langlois88c46b82016-06-02 18:15:32 +0100122def ShouldGenerateAArch32(args):
123 return (not args.aarch32_only and not args.aarch64_only) or args.aarch32_only
124
125def ShouldGenerateAArch64(args):
126 return (not args.aarch32_only and not args.aarch64_only) or args.aarch64_only
armvixlb0c8ae22014-03-21 14:03:59 +0000127
Alexander Gilday69203a52018-05-22 10:51:09 +0100128def GetAArch32Filename(test):
129 return test.lower().replace('_', '-') + '.h'
130
131def GetAArch64Filename(test):
132 return test.lower().replace('_', '-') + '-trace-aarch64.h'
133
armvixlb0c8ae22014-03-21 14:03:59 +0000134if __name__ == '__main__':
135 # $ROOT/tools/generate_simulator_traces.py
136 root_dir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
137 os.chdir(root_dir)
138
139 args = BuildOptions(root_dir)
140
Pierre Langlois88c46b82016-06-02 18:15:32 +0100141 # List all tests.
142 status, test_list = util.getstatusoutput(args.runner + ' --list')
armvixlb0c8ae22014-03-21 14:03:59 +0000143 if status != 0: util.abort('Failed to list all tests')
armvixlb0c8ae22014-03-21 14:03:59 +0000144
Pierre Langlois88c46b82016-06-02 18:15:32 +0100145 if ShouldGenerateAArch64(args):
146 # Run each simulator test (AARCH64_SIM_*) with the --generate_test_trace
147 # option, and use the output to create the traces header (from --out). In
Alexandre Ramesd3832962016-07-04 15:03:43 +0100148 # addition, the test-simulator-traces-aarch64.h file, the master trace file,
Pierre Langlois88c46b82016-06-02 18:15:32 +0100149 # which includes all other trace files is generated.
armvixlb0c8ae22014-03-21 14:03:59 +0000150
Pierre Langlois88c46b82016-06-02 18:15:32 +0100151 # Create master trace file.
152 master_trace_f = open(args.out, 'w')
153 master_trace_f.write(copyright_header)
154 master_trace_f.write(master_trace_header)
155 master_trace_f.write('\n\n')
armvixlb0c8ae22014-03-21 14:03:59 +0000156
Pierre Langlois88c46b82016-06-02 18:15:32 +0100157 # Find the AArch64 simulator tests.
snickolls-arm2decd2c2024-01-17 11:24:49 +0000158 tests = sorted([t for t in test_list.split() if 'AARCH64_SIM_' in t],
Alexander Gilday69203a52018-05-22 10:51:09 +0100159 key=lambda t: GetAArch64Filename(t))
armvixl5289c592015-03-02 13:52:04 +0000160
Pierre Langlois88c46b82016-06-02 18:15:32 +0100161 for test in tests:
Pierre Langlois88c46b82016-06-02 18:15:32 +0100162 # Strip out 'AARCH64_' to get the name of the test.
163 test_name = test[len('AARCH64_'):]
Alexander Gilday69203a52018-05-22 10:51:09 +0100164 trace_filename = GetAArch64Filename(test_name)
165 if not args.filter or re.compile(args.filter).search(test):
166 # Run each test.
snickolls-arm2decd2c2024-01-17 11:24:49 +0000167 print('Generating trace for ' + test);
Alexander Gilday69203a52018-05-22 10:51:09 +0100168 cmd = ' '.join([args.runner, '--generate_test_trace', test])
169 status, output = util.getstatusoutput(cmd)
170 if status != 0: util.abort('Failed to run ' + cmd + '.')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100171
Alexander Gilday69203a52018-05-22 10:51:09 +0100172 # Create a new trace header file.
173 trace_f = open("test/aarch64/traces/" + trace_filename, 'w')
174 trace_f.write(copyright_header)
175 trace_f.write(trace_header)
176 trace_f.write('\n')
177 trace_f.write("#ifndef VIXL_" + test_name.upper() + "_TRACE_AARCH64_H_\n")
178 trace_f.write("#define VIXL_" + test_name.upper() + "_TRACE_AARCH64_H_\n")
179 trace_f.write('\n')
180 trace_f.write(output)
181 trace_f.write('\n')
182 trace_f.write('\n' + "#endif // VIXL_"
183 + test_name.upper() + "_TRACE_AARCH64_H_" + '\n')
184 trace_f.close()
Pierre Langlois88c46b82016-06-02 18:15:32 +0100185
186 # Update master trace file.
Alexandre Ramesd3832962016-07-04 15:03:43 +0100187 master_trace_f.write(
188 '#include \"aarch64/traces/' + trace_filename + '\"\n')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100189
190 # Close master trace file.
191 master_trace_f.write(master_trace_footer)
192 master_trace_f.close()
193
194 if ShouldGenerateAArch32(args):
195 # Run each test (AARCH32_{SIMULATOR,ASSEMBLER}_*) with the
196 # --generate_test_trace option.
197
198 # Find the AArch32 tests.
Alexander Gilday69203a52018-05-22 10:51:09 +0100199 tests = sorted(
200 filter(
201 lambda t: 'AARCH32_SIMULATOR_' in t or ('AARCH32_ASSEMBLER_' in t
202 and not 'AARCH32_ASSEMBLER_NEGATIVE_' in t),
203 test_list.split()),
204 key=lambda t: GetAArch32Filename(t))
205 if args.filter:
206 tests = filter(re.compile(args.filter).search, tests)
Pierre Langlois88c46b82016-06-02 18:15:32 +0100207
208 for test in tests:
209 # Run each test.
snickolls-arm2decd2c2024-01-17 11:24:49 +0000210 print('Generating trace for ' + test);
Pierre Langlois88c46b82016-06-02 18:15:32 +0100211 # Strip out 'AARCH32_' to get the name of the test.
212 test_name = test[len('AARCH32_'):]
Pierre Langlois5b0cbc82016-09-26 14:00:30 +0100213
214 # An "and" instruction will be called "and_" since we cannot clash with
215 # the C++ operator. Rename "and_" to "and" to keep sane filenames.
216 test_name = test_name.replace('and_', 'and')
217
Pierre Langlois88c46b82016-06-02 18:15:32 +0100218 cmd = ' '.join([args.runner, '--generate_test_trace', test])
219 status, output = util.getstatusoutput(cmd)
220 if status != 0: util.abort('Failed to run ' + cmd + '.')
221
222 # Create a new trace header file.
Alexander Gilday69203a52018-05-22 10:51:09 +0100223 trace_filename = GetAArch32Filename(test_name)
Alexandre Ramesd3832962016-07-04 15:03:43 +0100224 trace_f = open("test/aarch32/traces/" + trace_filename, 'w')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100225 trace_f.write(copyright_header)
226 trace_f.write(trace_header)
227 trace_f.write('\n')
228 trace_f.write("#ifndef VIXL_" + test_name.upper() + "_H_\n")
229 trace_f.write("#define VIXL_" + test_name.upper() + "_H_\n")
230 trace_f.write('\n')
231 trace_f.write(output)
232 trace_f.write('\n')
Alexandre Ramesd3832962016-07-04 15:03:43 +0100233 trace_f.write(
234 '\n' + "#endif // VIXL_" + test_name.upper() + "_H_" + '\n')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100235 trace_f.close()
236
snickolls-arm2decd2c2024-01-17 11:24:49 +0000237 print('Trace generation COMPLETE')