1 # Test procedures in lib/specs.exp -*- Tcl -*-
3 # Copyright (C) 2021 Free Software Foundation, Inc.
5 # This file is part of DejaGnu.
7 # DejaGnu is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # DejaGnu is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with DejaGnu; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 source $srcdir/$subdir/default_procs.tcl
23 proc load_lib { lib } {
25 source $srcdir/../lib/$lib
28 foreach lib { targetdb specs } {
29 source $srcdir/../lib/${lib}.exp
33 # Create a false board config array
35 set board_info(baz,name) "baz"
36 set board_info(baz,ldscript) "-Tbaz.ld"
37 set board_info(quux,name) "quux"
38 set board_info(quux,ldscript) "-specs quux.specs"
39 set board_info(quux,other) "-mquux"
41 ::dejagnu::specs::load_specs test_specs {
48 base_test {%{two} %{one} %{three}}
49 esc_test_1 {%{two} %% %{three}}
50 esc_test_2 {%{one} %{percent} %{three}}
53 mapped/asc {%{one} %{two} %{three}}
54 mapped/desc {%{three} %{two} %{one}}
56 mapped/ {%{mapped/asc}}
59 map_test {%{mapped/%{mapped_order}}}
64 call_test_1 {%[test_proc_1]}
65 call_test_2 {%[test_proc_2 %{args}]}
71 board_test {%{board_info(%{board}):%{key}}}
80 # test procedures for %[...] tests
81 proc test_proc_1 {} { return "test-1" }
82 proc test_proc_2 { args } { return "[llength $args]: $args" }
84 # simple wrapper to bring global spec database into current scope
85 proc eval_specs { database_name goal options } {
87 ::dejagnu::specs::eval_specs $database_name $goal $options
91 { "#" simple substitutions }
92 { lib_ret_test eval_specs {test_specs base_test {}}
94 "evaluate simple spec substitutions" }
95 { lib_ret_test eval_specs {test_specs base_test {one 5}}
97 "evaluate simple spec substitutions with option as override" }
98 { lib_ret_test eval_specs {test_specs esc_test_1 {}}
100 "evaluate simple spec substitutions with literal %" }
101 { lib_ret_test eval_specs {test_specs esc_test_2 {}}
103 "evaluate simple spec substitutions with literal % substituted" }
105 { "#" layer search path }
106 { lib_ret_test eval_specs {test_specs base_test {_layers {foo}}}
109 { lib_ret_test eval_specs {test_specs base_test {_layers {bar}}}
112 { lib_ret_test eval_specs {test_specs base_test {_layers {foo bar}}}
114 "use layers 'foo' and 'bar'" }
115 { lib_ret_test eval_specs {test_specs base_test {_layers {bar foo}}}
117 "use layers 'bar' and 'foo'" }
119 { "#" value-map substitutions }
120 { lib_ret_test eval_specs {test_specs map_test {}}
122 "mapped-value substitution as default" }
123 { lib_ret_test eval_specs {test_specs map_test {mapped_order desc}}
125 "mapped-value substitution with option as override" }
126 { lib_ret_test eval_specs {test_specs map_test {mapped_order ""}}
128 "mapped-value substitution with empty selector" }
129 { lib_errpat_test eval_specs {test_specs map_test {mapped_order bogus}}
131 "error if mapped value refers to non-existent spec string" }
133 { "#" procedure-call substitutions }
134 { lib_ret_test eval_specs {test_specs call_test_1 {}}
136 "substitute arity 0 procedure call result" }
137 { lib_ret_test eval_specs {test_specs call_test_2 {}}
139 "substitute procedure call result with no arguments" }
140 { lib_ret_test eval_specs {test_specs call_test_2 {args {%{base_test}}}}
142 "substitute procedure call result with substituted arguments" }
143 { lib_ret_test eval_specs {test_specs call_test_2 {args {%%{one}}}}
145 "substitutions not evaluated in procedure call result" }
147 { "#" board_info substitutions }
148 { lib_ret_test eval_specs {test_specs board_test {board baz key other}}
150 "empty result for non-existent key" }
151 { lib_ret_test eval_specs {test_specs board_test {board baz}}
153 "find 'ldscript' key for board 'baz'" }
154 { lib_ret_test eval_specs {test_specs board_test {board quux}}
156 "find 'ldscript' key for board 'quux'" }
157 { lib_ret_test eval_specs {test_specs board_test {board quux key other}}
159 "find 'other' key for board 'quux'" }
162 puts "END specs.test"