blob: ef1fd33ec7a7b0f803c9f1d465f4fa9b8f2af6dd [file] [log] [blame]
armvixlb0c8ae22014-03-21 14:03:59 +00001#!/usr/bin/env python2.7
2
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
65// test-simulator-a64.
66//
67// If you update input lists in test-simulator-inputs-a64.h, or add a new test
68// to test-simulator-a64.cc, please run tools/generate_simulator_traces.py on a
69// reference platform to regenerate this file and trace files.
70//
71
Pierre Langlois88c46b82016-06-02 18:15:32 +010072#ifndef VIXL_TEST_A64_SIMULATOR_TRACES_A64_H_
73#define VIXL_TEST_A64_SIMULATOR_TRACES_A64_H_
armvixl5289c592015-03-02 13:52:04 +000074
75#include <stdint.h>
76
77// To add a new simulator test to test-simulator-a64.cc, add dummy array(s)
78// below to build test-simulator-a64 for reference platform. Then, run
79// tools/generate_simulator_traces.py on a reference platform to regenerate this
80// file and traces files.
81
82// ---------------------------------------------------------------------
83// ADD DUMMY ARRAYS FOR NEW SIMULATOR TEST HERE.
84// ---------------------------------------------------------------------
85const uint64_t kExpected_dummy_64[] = { 0 };
86const size_t kExpectedCount_dummy_64 = 0;
87
88const uint32_t kExpected_dummy_32[] = { 0 };
89const size_t kExpectedCount_dummy_32 = 0;
90
91// ---------------------------------------------------------------------
92// Simulator test trace output files.
93// ---------------------------------------------------------------------
94"""
95master_trace_footer = """
Pierre Langlois88c46b82016-06-02 18:15:32 +010096#endif // VIXL_TEST_A64_SIMULATOR_TRACES_A64_H_
armvixl5289c592015-03-02 13:52:04 +000097"""
98
99trace_header = """
100// ---------------------------------------------------------------------
101// This file is auto generated using tools/generate_simulator_traces.py.
102//
103// PLEASE DO NOT EDIT.
104// ---------------------------------------------------------------------
105"""
106
armvixlb0c8ae22014-03-21 14:03:59 +0000107def BuildOptions(root):
108 result = argparse.ArgumentParser(description = 'Simulator test generator.')
armvixl0f35e362016-05-10 13:57:58 +0100109 result.add_argument('--runner', action='store',
110 default=os.path.join(root, 'obj/latest/test/test-runner'),
armvixl330dc712014-11-25 10:38:32 +0000111 help='The test executable to run.')
Pierre Langlois88c46b82016-06-02 18:15:32 +0100112 result.add_argument('--aarch32-only', action='store_true')
113 result.add_argument('--aarch64-only', action='store_true')
armvixlb0c8ae22014-03-21 14:03:59 +0000114 result.add_argument('--out', action='store',
Pierre Langlois88c46b82016-06-02 18:15:32 +0100115 default='test/a64/test-simulator-traces-a64.h')
armvixlb0c8ae22014-03-21 14:03:59 +0000116 return result.parse_args()
117
Pierre Langlois88c46b82016-06-02 18:15:32 +0100118def ShouldGenerateAArch32(args):
119 return (not args.aarch32_only and not args.aarch64_only) or args.aarch32_only
120
121def ShouldGenerateAArch64(args):
122 return (not args.aarch32_only and not args.aarch64_only) or args.aarch64_only
armvixlb0c8ae22014-03-21 14:03:59 +0000123
124if __name__ == '__main__':
125 # $ROOT/tools/generate_simulator_traces.py
126 root_dir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
127 os.chdir(root_dir)
128
129 args = BuildOptions(root_dir)
130
Pierre Langlois88c46b82016-06-02 18:15:32 +0100131 # List all tests.
132 status, test_list = util.getstatusoutput(args.runner + ' --list')
armvixlb0c8ae22014-03-21 14:03:59 +0000133 if status != 0: util.abort('Failed to list all tests')
armvixlb0c8ae22014-03-21 14:03:59 +0000134
Pierre Langlois88c46b82016-06-02 18:15:32 +0100135 if ShouldGenerateAArch64(args):
136 # Run each simulator test (AARCH64_SIM_*) with the --generate_test_trace
137 # option, and use the output to create the traces header (from --out). In
138 # addition, the test-simulator-traces-a64.h file, the master trace file,
139 # which includes all other trace files is generated.
armvixlb0c8ae22014-03-21 14:03:59 +0000140
Pierre Langlois88c46b82016-06-02 18:15:32 +0100141 # Create master trace file.
142 master_trace_f = open(args.out, 'w')
143 master_trace_f.write(copyright_header)
144 master_trace_f.write(master_trace_header)
145 master_trace_f.write('\n\n')
armvixlb0c8ae22014-03-21 14:03:59 +0000146
Pierre Langlois88c46b82016-06-02 18:15:32 +0100147 # Find the AArch64 simulator tests.
148 tests = sorted(filter(lambda t: 'AARCH64_SIM_' in t, test_list.split()))
armvixl5289c592015-03-02 13:52:04 +0000149
Pierre Langlois88c46b82016-06-02 18:15:32 +0100150 for test in tests:
151 # Run each test.
152 print 'Generating trace for ' + test;
153 # Strip out 'AARCH64_' to get the name of the test.
154 test_name = test[len('AARCH64_'):]
155 cmd = ' '.join([args.runner, '--generate_test_trace', test])
156 status, output = util.getstatusoutput(cmd)
157 if status != 0: util.abort('Failed to run ' + cmd + '.')
158
159 # Create a new trace header file.
160 trace_filename = test_name.lower().replace('_', '-') + "-trace-a64.h"
161 trace_f = open("test/a64/traces/" + trace_filename, 'w')
162 trace_f.write(copyright_header)
163 trace_f.write(trace_header)
164 trace_f.write('\n')
165 trace_f.write("#ifndef VIXL_" + test_name.upper() + "_TRACE_A64_H_\n")
166 trace_f.write("#define VIXL_" + test_name.upper() + "_TRACE_A64_H_\n")
167 trace_f.write('\n')
168 trace_f.write(output)
169 trace_f.write('\n')
170 trace_f.write('\n' + "#endif // VIXL_"
171 + test_name.upper() + "_TRACE_A64_H_" + '\n')
172 trace_f.close()
173
174 # Update master trace file.
175 master_trace_f.write('#include \"a64/traces/' + trace_filename + '\"\n')
176
177 # Close master trace file.
178 master_trace_f.write(master_trace_footer)
179 master_trace_f.close()
180
181 if ShouldGenerateAArch32(args):
182 # Run each test (AARCH32_{SIMULATOR,ASSEMBLER}_*) with the
183 # --generate_test_trace option.
184
185 # Find the AArch32 tests.
186 tests = sorted(filter(
187 lambda t: 'AARCH32_SIMULATOR_' in t or 'AARCH32_ASSEMBLER_' in t,
188 test_list.split()))
189
190 for test in tests:
191 # Run each test.
192 print 'Generating trace for ' + test;
193 # Strip out 'AARCH32_' to get the name of the test.
194 test_name = test[len('AARCH32_'):]
195 cmd = ' '.join([args.runner, '--generate_test_trace', test])
196 status, output = util.getstatusoutput(cmd)
197 if status != 0: util.abort('Failed to run ' + cmd + '.')
198
199 # Create a new trace header file.
200 trace_filename = test_name.lower().replace('_', '-') + ".h"
201 trace_f = open("test/a32/traces/" + trace_filename, 'w')
202 trace_f.write(copyright_header)
203 trace_f.write(trace_header)
204 trace_f.write('\n')
205 trace_f.write("#ifndef VIXL_" + test_name.upper() + "_H_\n")
206 trace_f.write("#define VIXL_" + test_name.upper() + "_H_\n")
207 trace_f.write('\n')
208 trace_f.write(output)
209 trace_f.write('\n')
210 trace_f.write('\n' + "#endif // VIXL_" + test_name.upper() + "_H_" + '\n')
211 trace_f.close()
212
armvixl5289c592015-03-02 13:52:04 +0000213 print 'Trace generation COMPLETE'