1#
2# SPDX-License-Identifier: BSD-3-Clause
3#
4# Copyright © 2020 Keith Packard
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above
14#    copyright notice, this list of conditions and the following
15#    disclaimer in the documentation and/or other materials provided
16#    with the distribution.
17#
18# 3. Neither the name of the copyright holder nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33# OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35
36semihost_tests = [
37  'semihost-argv',
38  'semihost-exit',
39  'semihost-exit-extended',
40  'semihost-clock',
41  'semihost-errno',
42  'semihost-flen',
43  'semihost-get-cmdline',
44  'semihost-gettimeofday',
45  'semihost-istty',
46  'semihost-open',
47  'semihost-read',
48  'semihost-remove',
49  'semihost-rename',
50  'semihost-seek',
51  'semihost-system',
52  'semihost-time',
53  'semihost-times',
54  'semihost-writec',
55  'semihost-write0',
56]
57
58# These tests should pass, but are currently broken under qemu
59semihost_broken = [
60  'semihost-elapsed',
61  'semihost-heapinfo',
62  'semihost-readc',
63  'semihost-tickfreq',
64  'semihost-tmpnam',
65  ]
66
67semihost_fail_tests = [
68  'semihost-exit-failure',
69  'semihost-exit-extended-failure',
70  'semihost-system-failure',
71]
72
73semihost_no_args_tests = [
74  'semihost-no-argv',
75]
76
77test_args = ['hello', 'world']
78
79foreach target : targets
80  value = get_variable('target_' + target)
81
82  _libs = [get_variable('lib_c' + target)]
83  _libs += [get_variable('lib_semihost' + target)]
84  if is_variable('crt0_semihost' + target)
85    _objs = [get_variable('crt0_semihost'+ target)]
86  elif is_variable('crt0_hosted' + target)
87    _objs = [get_variable('crt0_hosted'+ target)]
88  else
89    _objs = []
90  endif
91
92  _c_args = value[1] + get_variable('test_c_args_' + target, test_c_args)
93  _link_args = value[1] + get_variable('test_link_args_' + target, test_link_args)
94  _link_depends = get_variable('test_link_depends_' + target, test_link_depends)
95
96  foreach semihost_test : semihost_tests
97    semihost_test_src = semihost_test + '.c'
98    if target == ''
99      semihost_test_name = semihost_test
100    else
101      semihost_test_name = semihost_test + '_' + target
102    endif
103
104    _cmd_arg = ['-DCOMMAND_LINE="' + 'program-name' + ' ' + ' '.join(test_args) + '"']
105
106    test(semihost_test_name,
107	 executable(semihost_test_name, [semihost_test_src],
108		    c_args: _c_args + _cmd_arg,
109		    link_args: double_printf_link_args + _link_args,
110		    objects: _objs,
111		    link_with: _libs,
112		    link_depends:  _link_depends,
113		    include_directories: inc),
114	 args: test_args,
115         depends: bios_bin,
116         suite: 'semihost',
117	 env: test_env)
118  endforeach
119
120  foreach semihost_fail_test : semihost_fail_tests
121    semihost_fail_test_src = semihost_fail_test + '.c'
122    if target == ''
123      semihost_fail_test_name = semihost_fail_test
124    else
125      semihost_fail_test_name = semihost_fail_test + '_' + target
126    endif
127
128    test(semihost_fail_test_name,
129	 executable(semihost_fail_test_name, [semihost_fail_test_src],
130		    c_args: _c_args + _cmd_arg,
131		    link_args: _link_args,
132		    objects: _objs,
133		    link_with: _libs,
134		    link_depends:  _link_depends,
135		    include_directories: inc),
136	 args: test_args,
137         depends: bios_bin,
138         suite: 'semihost',
139	 env: test_env,
140	 should_fail: true)
141  endforeach
142
143  if has_semihost_args
144    foreach semihost_test : semihost_no_args_tests
145      semihost_test_src = semihost_test + '.c'
146      if target == ''
147	semihost_test_name = semihost_test
148      else
149	semihost_test_name = semihost_test + '_' + target
150      endif
151
152      test(semihost_test_name,
153	   executable(semihost_test_name, [semihost_test_src],
154		      c_args: _c_args + _cmd_arg,
155		      link_args: double_printf_link_args + _link_args,
156		      objects: _objs,
157		      link_with: _libs,
158		      link_depends:  test_link_depends,
159		      include_directories: inc),
160           depends: bios_bin,
161           suite: 'semihost',
162	   env: test_env)
163    endforeach
164  endif
165
166endforeach
167