blob: 4261331d4361c409b42355c4301518343827b9ea [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001# Copyright (c) 2017 ARM Limited.
2#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22import SCons
23import os.path
24
25Import('env')
26Import('vars')
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010028SConscript('./framework/SConscript', duplicate=0)
29
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030# vars is imported from arm_compute:
31variables = [
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032 BoolVariable("validation_tests", "Build validation test programs", True),
Pablo Telloea1c9502017-11-09 11:49:18 +000033 BoolVariable("benchmark_tests", "Build benchmark test programs", True),
Anthony Barbier6db0ff52018-01-05 10:59:12 +000034 BoolVariable("benchmark_examples", "Build benchmark examples programs", True),
Pablo Telloea1c9502017-11-09 11:49:18 +000035 ("test_filter", "Pattern to specify the tests' filenames to be compiled", "*.cpp")
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036]
37
38# We need a separate set of Variables for the Help message (Otherwise the global variables will get displayed twice)
39new_options = Variables('scons')
40
41for v in variables:
42 new_options.Add(v)
43 vars.Add(v)
44
Gian Marco Iodicef2399532017-09-13 14:16:41 +010045# Disable floating-point expression contraction (e.g. fused multiply-add operations)
46env.Append(CXXFLAGS = ['-ffp-contract=off'])
47
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048# Clone the environment to make sure we're not polluting the arm_compute one:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010049test_env = env.Clone()
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010050vars.Update(test_env)
51
52Help(new_options.GenerateHelpText(test_env))
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010053
Anthony Barbier6db0ff52018-01-05 10:59:12 +000054Import("arm_compute_test_framework")
55test_env.Append(LIBS = arm_compute_test_framework)
56
Georgios Pinitas9873ea32017-12-05 15:28:55 +000057if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010058 Import("arm_compute_a")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010059 Import("arm_compute_core_a")
60 test_env.Append(LIBS = [arm_compute_a, arm_compute_core_a])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010061 arm_compute_lib = arm_compute_a
62else:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010063 Import("arm_compute_so")
Anthony Barbierb2881fc2017-09-29 17:12:12 +010064 test_env.Append(LIBS = ["arm_compute", "arm_compute_core"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010065 arm_compute_lib = arm_compute_so
66
67#FIXME Delete before release
Anthony Barbiera4e5e1e2017-10-05 14:55:34 +010068if env['internal_only']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010069 test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010070
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010071test_env.Append(CPPPATH = ["#3rdparty/include"])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010072test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
73test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010074test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010075
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010076common_files = Glob('*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010077common_objects = [test_env.StaticObject(f) for f in common_files]
78
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010079files_benchmark = Glob('benchmark/*.cpp')
80files_validation = Glob('validation/*.cpp')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010081
82# Always compile reference for validation
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000083files_validation += Glob('validation/reference/*.cpp')
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010084
Abe Mbise925ca0f2017-10-02 19:16:33 +010085# Add unit tests
86files_validation += Glob('validation/UNIT/*/*.cpp')
87files_validation += Glob('validation/UNIT/*.cpp')
88
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000089# Add CPP tests
90filter_pattern = test_env['test_filter']
91files_validation += Glob('validation/CPP/' + filter_pattern)
92
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010093if env['opencl']:
94 Import('opencl')
Pablo Telloea1c9502017-11-09 11:49:18 +000095 filter_pattern = test_env['test_filter']
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010096
Moritz Pflanzerc7d15032017-07-18 16:21:16 +010097 test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
98 test_env.Append(LIBS = ["OpenCL"])
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010099
Pablo Telloea1c9502017-11-09 11:49:18 +0000100 files_benchmark += Glob('benchmark/CL/*/' + filter_pattern)
101 files_benchmark += Glob('benchmark/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100102
Pablo Telloea1c9502017-11-09 11:49:18 +0000103 files_validation += Glob('validation/CL/*/' + filter_pattern)
104 files_validation += Glob('validation/CL/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100105
106if env['neon']:
Pablo Telloea1c9502017-11-09 11:49:18 +0000107 filter_pattern = test_env['test_filter']
108 files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern)
109 files_benchmark += Glob('benchmark/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110
Pablo Telloea1c9502017-11-09 11:49:18 +0000111 files_validation += Glob('validation/NEON/*/' + filter_pattern)
112 files_validation += Glob('validation/NEON/' + filter_pattern)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100113
Anthony Barbier7068f992017-10-26 15:23:08 +0100114if env['gles_compute']:
115 if env['os'] != 'android':
116 Import('egl')
117 Import('glesv2')
118
Anthony Barbier7068f992017-10-26 15:23:08 +0100119 test_env.Append(LIBS = ["EGL", "GLESv2"])
120 else:
121 if env['arch'] != 'armv7a':
122 test_env.Append(LIBS = ["EGL", "GLESv3"])
123 else:
124 test_env.Append(LIBS = ["EGL", "GLESv2"])
125
126 test_env.Append(CPPDEFINES=['ARM_COMPUTE_GC'])
127
128 files_benchmark += Glob('benchmark/GLES_COMPUTE/*/*.cpp')
129 files_benchmark += Glob('benchmark/GLES_COMPUTE/*.cpp')
130
131 files_validation += Glob('validation/GLES_COMPUTE/*/*.cpp')
132 files_validation += Glob('validation/GLES_COMPUTE/*.cpp')
133
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100134if env['os'] == 'android':
135 test_env.Append(LIBS = ["log"])
136else:
137 test_env.Append(LIBS = ["rt"])
138
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100139if test_env['benchmark_tests']:
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100140 arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100141 Depends(arm_compute_benchmark, arm_compute_test_framework)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142 Depends(arm_compute_benchmark, arm_compute_lib)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100143
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100144 if env['opencl']:
145 Depends(arm_compute_benchmark, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100146 if env['gles_compute'] and env['os'] != 'android':
147 Depends(arm_compute_benchmark, egl)
148 Depends(arm_compute_benchmark, glesv2)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100149
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150 Default(arm_compute_benchmark)
151 Export('arm_compute_benchmark')
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100152
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100153if test_env['validation_tests']:
154 arm_compute_validation = test_env.Program('arm_compute_validation', files_validation + common_objects)
155 Depends(arm_compute_validation, arm_compute_test_framework)
156 Depends(arm_compute_validation, arm_compute_lib)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100157
158 if env['opencl']:
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100159 Depends(arm_compute_validation, opencl)
Anthony Barbier7068f992017-10-26 15:23:08 +0100160 if env['gles_compute'] and env['os'] != 'android':
161 Depends(arm_compute_validation, egl)
162 Depends(arm_compute_validation, glesv2)
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100163
Moritz Pflanzera09de0c2017-09-01 20:41:12 +0100164 Default(arm_compute_validation)
165 Export('arm_compute_validation')
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000166
167if test_env['benchmark_examples']:
168 files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp')
169 arm_compute_benchmark_examples = []
170 if test_env['neon']:
171 for file in Glob("../examples/neon_*.cpp"):
172 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
173 arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ]
174 if test_env['opencl']:
175 cl_examples = []
176 files = Glob("../examples/cl_*.cpp")
177 if test_env['neon']:
178 files += Glob("../examples/neoncl_*.cpp")
179 for file in files:
180 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
181 cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = test_env["LIBS"] + ["OpenCL"]) ]
182 Depends(cl_examples, opencl)
183 arm_compute_benchmark_examples += cl_examples
184 if test_env['opencl'] and test_env['neon']:
185 if env['os'] == 'android':
186 Import('arm_compute_graph_a')
187 graph_dependency = arm_compute_graph_a
188 else:
189 Import('arm_compute_graph_so')
190 graph_dependency = arm_compute_graph_so
191
192 graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils")
193 for file in Glob("../examples/graph_*.cpp"):
194 example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0])
195 if env['os'] == 'android':
196 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["OpenCL"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',graph_dependency,'-Wl,--no-whole-archive'])
197 Depends(prog, [graph_dependency, opencl])
198 arm_compute_benchmark_examples += [ prog ]
199 else:
200 #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies
201 prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] )
202 Depends(prog, graph_dependency)
203 arm_compute_benchmark_examples += [ prog ]
204 Depends(arm_compute_benchmark_examples, arm_compute_test_framework)
205 Depends(arm_compute_benchmark_examples, arm_compute_lib)
206 Default(arm_compute_benchmark_examples)
207 Export('arm_compute_benchmark_examples')
208