summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.test-framework/gen_directive_tests
blob: 6aa63ad6f6920bdbe377b6694d00079819446fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
#! /bin/bash

########################################################################
#
# File:    generate_framework_tests
# Author:  Janis Johnson
# Date:    2004/11/02
#
# Generate tests of GCC's test framework.  Each test has encoded in
# its name the dg commands that are used in the test and the expected
# result of the test, *-1.c.  Each test is followed by a test ending
# in *-2.c that is expected to pass.
#
# This script has evolved and could be rewritten to be more compact.
#
#
# Copyright (c) 2004, 2005, 2007 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.
#
########################################################################

cd $1

GOOD0='*-*-*'
GOOD1="yes"
GOOD2='empty-*-* *-*-empty *-*-*'
BAD0='empty-empty-empty'
BAD1="no"
BAD2='empty-*-* *-empty-* *-*-empty'

# Programs used in the tests: good compile and run, bad compile, and
# bad run.
GOOD_PROG="int main () { return 0; }"
BADC_PROG="int missing_body () }"
BADR_PROG="extern void abort (void); int main () { abort (); }"

# dg-do commands with a target list.
DOT_S0="{ dg-do compile { target ${GOOD0} } }"
DOT_S1="{ dg-do compile { target ${GOOD1} } }"
DOT_N0="{ dg-do compile { target ${BAD0} } }"
DOT_N1="{ dg-do compile { target ${BAD1} } }"

# dg-do commands with an xfail list; the xfail list is ignored for
# everything but "run".
DOX_P0="{ dg-do run { xfail ${BAD0} } }"
DOX_P1="{ dg-do run { xfail ${BAD1} } }"
DOX_F0="{ dg-do run { xfail ${GOOD0} } }"
DOX_F1="{ dg-do run { xfail ${GOOD1} } }"

# dg-xfail-if commands.
XIF_P0="{ dg-xfail-if \"target not matched\" { ${BAD0} } { \"-DY1\" } { \"-DY2\" } }"
XIF_P1="{ dg-xfail-if \"target not matched\" { ${BAD0} } { \"-DY1\" } { \"-DN\" } }"
XIF_P2="{ dg-xfail-if \"target not matched\" { ${BAD0} } { \"-DN\" } { \"-DY1\" } }"
XIF_P3="{ dg-xfail-if \"target not matched\" { ${BAD0} } { \"-DN1\" } { \"-DN2\" } }"
XIF_P4="{ dg-xfail-if \"exclude option matched\" { ${GOOD0} } { \"-DY1\" } { \"-DY2\" } }"
XIF_P5="{ dg-xfail-if \"include option not matched\" { ${GOOD0} } { \"-DN\" } { \"-DY1\" } }"
XIF_P6="{ dg-xfail-if \"include option not matched\" { ${GOOD0} } { \"-DN1\" } { \"-DN2\" } }"
XIF_F0="{ dg-xfail-if \"all matches succeed\" { ${GOOD0} } { \"-DY1\" } { \"-DN\" } }"
XIF_F1="{ dg-xfail-if \"all matches succeed\" { ${GOOD0} } { \"*\" } { \"-DN\" } }"
XIF_F2="{ dg-xfail-if \"all matches succeed\" { ${GOOD0} } { \"-DY1\" } { \"\" } }"
XIF_F3="{ dg-xfail-if \"all matches succeed\" { ${GOOD0} } { \"*\" } { \"\" } }"

XIF_P7="{ dg-xfail-if \"target not matched\" { ${BAD1} } { \"-DY1\" } { \"-DY2\" } }"
XIF_P8="{ dg-xfail-if \"target not matched\" { ${BAD1} } { \"-DY1\" } { \"-DN\" } }"
XIF_P9="{ dg-xfail-if \"target not matched\" { ${BAD1} } { \"-DN\" } { \"-DY1\" } }"
XIF_P10="{ dg-xfail-if \"target not matched\" { ${BAD1} } { \"-DN1\" } { \"-DN2\" } }"
XIF_P11="{ dg-xfail-if \"exclude option matched\" { ${GOOD1} } { \"-DY1\" } { \"-DY2\" } }"
XIF_P12="{ dg-xfail-if \"include option not matched\" { ${GOOD1} } { \"-DN\" } { \"-DY1\" } }"
XIF_P13="{ dg-xfail-if \"include option not matched\" { ${GOOD1} } { \"-DN1\" } { \"-DN2\" } }"
XIF_F4="{ dg-xfail-if \"all matches succeed\" { ${GOOD1} } { \"-DY1\" } { \"-DN\" } }"
XIF_F5="{ dg-xfail-if \"all matches succeed\" { ${GOOD1} } { \"*\" } { \"-DN\" } }"
XIF_F6="{ dg-xfail-if \"all matches succeed\" { ${GOOD1} } { \"-DY1\" } { \"\" } }"
XIF_F7="{ dg-xfail-if \"all matches succeed\" { ${GOOD1} } { \"*\" } { \"\" } }"


# dg-skip-if commands.
SIF_S0="{ dg-skip-if \"target not matched\" { ${BAD0} } { \"-DY1\" } { \"-DY2\" } }"
SIF_S1="{ dg-skip-if \"target not matched\" { ${BAD0} } { \"-DY1\" } { \"-DN\" } }"
SIF_S2="{ dg-skip-if \"target not matched\" { ${BAD0} } { \"-DN\" } { \"-DY1\" } }"
SIF_S3="{ dg-skip-if \"target not matched\" { ${BAD0} } { \"-DN1\" } { \"-DN2\" } }"
SIF_S4="{ dg-skip-if \"exclude option matched\" { ${GOOD0} } { \"-DY1\" } { \"-DY2\" } }"
SIF_S5="{ dg-skip-if \"include option not matched\" { ${GOOD0} } { \"-DN\" } { \"-DY1\" } }"
SIF_S6="{ dg-skip-if \"include option not matched\" { ${GOOD0} } { \"-DN1\" } { \"-DN2\" } }"
SIF_N0="{ dg-skip-if \"all matches succeed\" { ${GOOD0} } { \"-DY1\" } { \"-DN\" } }"
SIF_N1="{ dg-skip-if \"all matches succeed\" { ${GOOD0} } { \"*\" } { \"-DN\" } }"
SIF_N2="{ dg-skip-if \"all matches succeed\" { ${GOOD0} } { \"-DY1\" } { \"\" } }"
SIF_N3="{ dg-skip-if \"all matches succeed\" { ${GOOD0} } { \"*\" } { \"\" } }"
SIF_S7="{ dg-skip-if \"target not matched\" { ${BAD1} } { \"-DY1\" } { \"-DY2\" } }"
SIF_S8="{ dg-skip-if \"target not matched\" { ${BAD1} } { \"-DY1\" } { \"-DN\" } }"
SIF_S9="{ dg-skip-if \"target not matched\" { ${BAD1} } { \"-DN\" } { \"-DY1\" } }"
SIF_S10="{ dg-skip-if \"target not matched\" { ${BAD1} } { \"-DN1\" } { \"-DN2\" } }"
SIF_S11="{ dg-skip-if \"exclude option matched\" { ${GOOD1} } { \"-DY1\" } { \"-DY2\" } }"
SIF_S12="{ dg-skip-if \"include option not matched\" { ${GOOD1} } { \"-DN\" } { \"-DY1\" } }"
SIF_S13="{ dg-skip-if \"include option not matched\" { ${GOOD1} } { \"-DN1\" } { \"-DN2\" } }"
SIF_N4="{ dg-skip-if \"all matches succeed\" { ${GOOD1} } { \"-DY1\" } { \"-DN\" } }"
SIF_N5="{ dg-skip-if \"all matches succeed\" { ${GOOD1} } { \"*\" } { \"-DN\" } }"
SIF_N6="{ dg-skip-if \"all matches succeed\" { ${GOOD1} } { \"-DY1\" } { \"\" } }"
SIF_N7="{ dg-skip-if \"all matches succeed\" { ${GOOD1} } { \"*\" } { \"\" } }"

# dg-require-* commands, using procedures defined for this set of tests.
REQ_S0="{ dg-require-true \"\" }"    # do not skip the test
REQ_N0="{ dg-require-false \"\" }"   # skip the test

# scan-assembler-not, which is hoped to be representative of commands
# used with dg-final, with a target list.
SAT_N0="{ dg-final { scan-assembler-not \"unexpected gargage\" { target ${BAD0} } } }"
SAT_N1="{ dg-final { scan-assembler-not \"unexpected gargage\" { target ${BAD1} } } }"
SAT_S0="{ dg-final { scan-assembler-not \"unexpected gargage\" { target ${GOOD0} } } }"
SAT_S1="{ dg-final { scan-assembler-not \"unexpected gargage\" { target ${GOOD1} } } }"

# scan-assembler-not, which is hoped to be representative of commands
# used with dg-final, with an xfail list.
SAX_P0="{ dg-final { scan-assembler-not \"unexpected gargage\" { xfail ${BAD0} } } }"
SAX_P1="{ dg-final { scan-assembler-not \"unexpected gargage\" { xfail ${BAD1} } } }"
SAX_F0="{ dg-final { scan-assembler-not \"unexpected gargage\" { xfail ${GOOD0} } } }"
SAX_F1="{ dg-final { scan-assembler-not \"unexpected gargage\" { xfail ${GOOD1} } } }"

KIND_LIST=""

# Expected result of the *-1.c test, encoded into the file name.
EXP_PASS="exp-P"
EXP_XPASS="exp-XP"
EXP_SKIP="exp-U"
EXP_FAIL="exp-F"
EXP_XFAIL="exp-XF"

get_list() {
    KIND=$1
    case $KIND in
      "dots") KIND_LIST="dots0 dots1";;
      "dotn") KIND_LIST="dotn0 dotn1";;
      "doxp") KIND_LIST="doxp0 doxp1";;
      "doxf") KIND_LIST="doxf0 doxf1";;
      "sifs") KIND_LIST="sifs0 sifs1 sifs2 sifs3 sifs4 sifs5 sifs6 sifs7 sifs8 sifs9 sifs10 sifs11 sifs12 sifs13";;
      "sifn") KIND_LIST="sifn0 sifn1 sifn2 sifn3 sifn4 sifn5 sifn6 sifn7";;
      "xifp") KIND_LIST="xifp0 xifp1 xifp2 xifp3 xifp4 xifp5 xifp6 xifp7 xifp8 xifp9 xifp10 xifp11 xifp12 xifp13";;
      "xiff") KIND_LIST="xiff0 xiff1 xiff2 xiff3 xiff4 xiff5 xiff6 xiff7";;
      "sats") KIND_LIST="sats0 sats1";;
      "satn") KIND_LIST="satn0 satn1";;
      "saxp") KIND_LIST="saxp0 saxp1";;
      "saxf") KIND_LIST="saxf0 saxf1";;
      "reqs") KIND_LIST="reqs0";;
      "reqn") KIND_LIST="reqn0";;
      *) echo "oops: $KIND"; exit 1;;
    esac
}

cmd() {
    KIND=$1
    FILE=$2

    case $KIND in
      "dots") echo '/*' "${DOT_S0}" '*/' >> $FILE;;
      "dots0") echo '/*' "${DOT_S0}" '*/' >> $FILE;;
      "dots1") echo '/*' "${DOT_S1}" '*/' >> $FILE;;
      "dots2") echo '/*' "${DOT_S2}" '*/' >> $FILE;;
      "dots3") echo '/*' "${DOT_S3}" '*/' >> $FILE;;
      "dots4") echo '/*' "${DOT_S4}" '*/' >> $FILE;;
      "dotn") echo '/*' "${DOT_N0}" '*/' >> $FILE;;
      "dotn0") echo '/*' "${DOT_N0}" '*/' >> $FILE;;
      "dotn1") echo '/*' "${DOT_N1}" '*/' >> $FILE;;
      "dotn2") echo '/*' "${DOT_N2}" '*/' >> $FILE;;
      "dotn3") echo '/*' "${DOT_N3}" '*/' >> $FILE;;
      "dotn4") echo '/*' "${DOT_N4}" '*/' >> $FILE;;
      "doxp") echo '/*' "${DOX_P0}" '*/' >> $FILE;;
      "doxp0") echo '/*' "${DOX_P0}" '*/' >> $FILE;;
      "doxp1") echo '/*' "${DOX_P1}" '*/' >> $FILE;;
      "doxp2") echo '/*' "${DOX_P2}" '*/' >> $FILE;;
      "doxp3") echo '/*' "${DOX_P3}" '*/' >> $FILE;;
      "doxp4") echo '/*' "${DOX_P4}" '*/' >> $FILE;;
      "doxf") echo '/*' "${DOX_F0}" '*/' >> $FILE;;
      "doxf0") echo '/*' "${DOX_F0}" '*/' >> $FILE;;
      "doxf1") echo '/*' "${DOX_F1}" '*/' >> $FILE;;
      "doxf2") echo '/*' "${DOX_F2}" '*/' >> $FILE;;
      "doxf3") echo '/*' "${DOX_F3}" '*/' >> $FILE;;
      "doxf4") echo '/*' "${DOX_F4}" '*/' >> $FILE;;
      "sifs") echo '/*' "${SIF_S0}" '*/' >> $FILE;;
      "sifs0") echo '/*' "${SIF_S0}" '*/' >> $FILE;;
      "sifs1") echo '/*' "${SIF_S1}" '*/' >> $FILE;;
      "sifs2") echo '/*' "${SIF_S2}" '*/' >> $FILE;;
      "sifs3") echo '/*' "${SIF_S3}" '*/' >> $FILE;;
      "sifs4") echo '/*' "${SIF_S4}" '*/' >> $FILE;;
      "sifs5") echo '/*' "${SIF_S5}" '*/' >> $FILE;;
      "sifs6") echo '/*' "${SIF_S6}" '*/' >> $FILE;;
      "sifs7") echo '/*' "${SIF_S7}" '*/' >> $FILE;;
      "sifs8") echo '/*' "${SIF_S8}" '*/' >> $FILE;;
      "sifs9") echo '/*' "${SIF_S9}" '*/' >> $FILE;;
      "sifs10") echo '/*' "${SIF_S10}" '*/' >> $FILE;;
      "sifs11") echo '/*' "${SIF_S11}" '*/' >> $FILE;;
      "sifs12") echo '/*' "${SIF_S12}" '*/' >> $FILE;;
      "sifs13") echo '/*' "${SIF_S13}" '*/' >> $FILE;;
      "sifn") echo '/*' "${SIF_N0}" '*/' >> $FILE;;
      "sifn0") echo '/*' "${SIF_N0}" '*/' >> $FILE;;
      "sifn1") echo '/*' "${SIF_N1}" '*/' >> $FILE;;
      "sifn2") echo '/*' "${SIF_N2}" '*/' >> $FILE;;
      "sifn3") echo '/*' "${SIF_N3}" '*/' >> $FILE;;
      "sifn4") echo '/*' "${SIF_N4}" '*/' >> $FILE;;
      "sifn5") echo '/*' "${SIF_N5}" '*/' >> $FILE;;
      "sifn6") echo '/*' "${SIF_N6}" '*/' >> $FILE;;
      "sifn7") echo '/*' "${SIF_N7}" '*/' >> $FILE;;
      "xifp") echo '/*' "${XIF_P0}" '*/' >> $FILE;;
      "xifp0") echo '/*' "${XIF_P0}" '*/' >> $FILE;;
      "xifp1") echo '/*' "${XIF_P1}" '*/' >> $FILE;;
      "xifp2") echo '/*' "${XIF_P2}" '*/' >> $FILE;;
      "xifp3") echo '/*' "${XIF_P3}" '*/' >> $FILE;;
      "xifp4") echo '/*' "${XIF_P4}" '*/' >> $FILE;;
      "xifp5") echo '/*' "${XIF_P5}" '*/' >> $FILE;;
      "xifp6") echo '/*' "${XIF_P6}" '*/' >> $FILE;;
      "xifp7") echo '/*' "${XIF_P7}" '*/' >> $FILE;;
      "xifp8") echo '/*' "${XIF_P8}" '*/' >> $FILE;;
      "xifp9") echo '/*' "${XIF_P9}" '*/' >> $FILE;;
      "xifp10") echo '/*' "${XIF_P10}" '*/' >> $FILE;;
      "xifp11") echo '/*' "${XIF_P11}" '*/' >> $FILE;;
      "xifp12") echo '/*' "${XIF_P12}" '*/' >> $FILE;;
      "xifp13") echo '/*' "${XIF_P13}" '*/' >> $FILE;;
      "xiff") echo '/*' "${XIF_F0}" '*/' >> $FILE;;
      "xiff0") echo '/*' "${XIF_F0}" '*/' >> $FILE;;
      "xiff1") echo '/*' "${XIF_F1}" '*/' >> $FILE;;
      "xiff2") echo '/*' "${XIF_F2}" '*/' >> $FILE;;
      "xiff3") echo '/*' "${XIF_F3}" '*/' >> $FILE;;
      "xiff4") echo '/*' "${XIF_F4}" '*/' >> $FILE;;
      "xiff5") echo '/*' "${XIF_F5}" '*/' >> $FILE;;
      "xiff6") echo '/*' "${XIF_F6}" '*/' >> $FILE;;
      "xiff7") echo '/*' "${XIF_F7}" '*/' >> $FILE;;
      "satn") echo '/*' "${SAT_N0}" '*/' >> $FILE;;
      "satn0") echo '/*' "${SAT_N0}" '*/' >> $FILE;;
      "satn1") echo '/*' "${SAT_N1}" '*/' >> $FILE;;
      "satn2") echo '/*' "${SAT_N2}" '*/' >> $FILE;;
      "satn3") echo '/*' "${SAT_N3}" '*/' >> $FILE;;
      "satn4") echo '/*' "${SAT_N4}" '*/' >> $FILE;;
      "sats") echo '/*' "${SAT_S0}" '*/' >> $FILE;;
      "sats0") echo '/*' "${SAT_S0}" '*/' >> $FILE;;
      "sats1") echo '/*' "${SAT_S1}" '*/' >> $FILE;;
      "sats2") echo '/*' "${SAT_S2}" '*/' >> $FILE;;
      "sats3") echo '/*' "${SAT_S3}" '*/' >> $FILE;;
      "sats4") echo '/*' "${SAT_S4}" '*/' >> $FILE;;
      "saxp") echo '/*' "${SAX_P0}" '*/' >> $FILE;;
      "saxp0") echo '/*' "${SAX_P0}" '*/' >> $FILE;;
      "saxp1") echo '/*' "${SAX_P1}" '*/' >> $FILE;;
      "saxp2") echo '/*' "${SAX_P2}" '*/' >> $FILE;;
      "saxp3") echo '/*' "${SAX_P3}" '*/' >> $FILE;;
      "saxp4") echo '/*' "${SAX_P4}" '*/' >> $FILE;;
      "saxf") echo '/*' "${SAX_F0}" '*/' >> $FILE;;
      "saxf0") echo '/*' "${SAX_F0}" '*/' >> $FILE;;
      "saxf1") echo '/*' "${SAX_F1}" '*/' >> $FILE;;
      "saxf2") echo '/*' "${SAX_F2}" '*/' >> $FILE;;
      "saxf3") echo '/*' "${SAX_F3}" '*/' >> $FILE;;
      "saxf4") echo '/*' "${SAX_F4}" '*/' >> $FILE;;
      "reqs") echo '/*' "${REQ_S0}" '*/' >> $FILE;;
      "reqs0") echo '/*' "${REQ_S0}" '*/' >> $FILE;;
      "reqn") echo '/*' "${REQ_N0}" '*/' >> $FILE;;
      "reqn0") echo '/*' "${REQ_N0}" '*/' >> $FILE;;
      *) echo "oops: $KIND"; exit 1;;
    esac
}

# Generate a test using a single dg- command.  If requested, generate a
# second version that will fail.
one() {
    KIND=$1
    EXP=$2
    FAIL_VERSION=$3

    NAME=${KIND}-${EXP}
    FILE1=${NAME}-1.c
    FILE2=${NAME}-2.c
    rm -f $FILE1
    touch $FILE1
    cmd $KIND $FILE1
    echo "${GOOD_PROG}" >> $FILE1
    echo "${GOOD_PROG}" > $FILE2

    if [ "${FAIL_VERSION}" == "yes" ]; then
	if [ "${EXP}" == "${EXP_PASS}" ]; then
	    NAME=${KIND}-${EXP_FAIL}
	else
	    NAME=${KIND}-${EXP_XFAIL}
	fi

	FILE1=${NAME}-1.c
	FILE2=${NAME}-2.c
	rm -f $FILE1
	touch $FILE1
	cmd $KIND $FILE1
	case $KIND in
	dox*)	echo "${BADR_PROG}" >> $FILE1;;
	*)	echo "${BADC_PROG}" >> $FILE1;;
	esac
	echo "${GOOD_PROG}" > $FILE2
    fi
}

# Generate a test using two dg- commands.  If requested, generate a
# second version that will fail.
two() {
    KIND1=$1
    KIND2=$2
    EXP=$3
    FAIL_VERSION=$4

    NAME=${KIND1}-${KIND2}-${EXP}
    FILE1=${NAME}-1.c
    FILE2=${NAME}-2.c

    rm -f $FILE1
    touch $FILE1
    cmd $KIND1 $FILE1
    cmd $KIND2 $FILE1
    echo "${GOOD_PROG}" >> $FILE1
    echo "${GOOD_PROG}" > $FILE2

    if [ "${FAIL_VERSION}" == "yes" ]; then
	if [ "${EXP}" == "${EXP_PASS}" ]; then
	    NAME=${KIND1}-${KIND2}-${EXP_FAIL}
	else
	    NAME=${KIND1}-${KIND2}-${EXP_XFAIL}
	fi

	FILE1=${NAME}-1.c
	FILE2=${NAME}-2.c
	rm -f $FILE1
	touch $FILE1
	cmd $KIND1 $FILE1
	cmd $KIND2 $FILE1
	# dg-do with an xfail list is only used as the first command.
	case $KIND1 in
	dox*)	echo "${BADR_PROG}" >> $FILE1;;
	*)	echo "${BADC_PROG}" >> $FILE1;;
	esac
	echo "${GOOD_PROG}" > $FILE2
    fi
}

# Generate a test using three dg- commands.  If requested generate a
# second version that will fail.
three() {
    KIND1=$1
    KIND2=$2
    KIND3=$3
    EXP=$4
    FAIL_VERSION=$5

    NAME=${KIND1}-${KIND2}-${KIND3}-${EXP}
    FILE1=${NAME}-1.c
    FILE2=${NAME}-2.c
    rm -f $FILE1
    touch $FILE1
    cmd $KIND1 $FILE1
    cmd $KIND2 $FILE1
    cmd $KIND3 $FILE1
    echo "${GOOD_PROG}" >> $FILE1
    echo "${GOOD_PROG}" > $FILE2

    if [ "${FAIL_VERSION}" == "${yes}" ]; then
	if [ "${EXP}" == "${EXP_PASS}" ]; then
	    NAME=${KIND1}-${KIND2}-${KIND3}-${EXP_FAIL}
	else
	    NAME=${KIND1}-${KIND2}-${KIND3}-${EXP_XFAIL}
	fi

	FILE1=${NAME}-1.c
	FILE2=${NAME}-2.c
	rm -f $FILE1
	touch $FILE1
	cmd $KIND1 $FILE1
	cmd $KIND2 $FILE1
	cmd $KIND3 $FILE1
	# dg-do with an xfail list is only used as the first command.
	case $KIND1 in
	dox*)	echo "${BADR_PROG}" >> $FILE1;;
	*)	echo "${BADC_PROG}" >> $FILE1;;
	esac
	echo "${GOOD_PROG}" > $FILE2
    fi
}

# Generate tests using one dg- command.  Generate a test for each variant
# of KIND.
one_all() {
    KIND=$1
    EXP=$2
    FAIL_VERSION=$3

    get_list $KIND
    for k in $KIND_LIST; do
	one $k $EXP $FAIL_VERSION
    done
}

# Generate tests using two dg- commands.  For each KIND, generate
# a test for each of its variants.
two_all() {
    KIND1=$1
    KIND2=$2
    EXP=$3
    FAIL_VERSION=$4

    get_list $KIND1
    KIND_LIST1="$KIND_LIST"
    get_list $KIND2
    KIND_LIST2="$KIND_LIST"
    for k1 in $KIND_LIST1; do
	for k2 in $KIND_LIST2; do
	    two $k1 $k2 $EXP $FAIL_VERSION
	done
    done
}

# Generate tests using three dg- commands.  For each KIND, generate
# a test for each of its variants.
three_all() {
    KIND1=$1
    KIND2=$2
    KIND3=$3
    EXP=$4
    FAIL_VERSION=$5

    get_list $KIND1
    KIND_LIST1="$KIND_LIST"
    get_list $KIND2
    KIND_LIST2="$KIND_LIST"
    get_list $KIND3
    KIND_LIST3="$KIND_LIST"
    for k1 in $KIND_LIST1; do
	for k2 in $KIND_LIST2; do
	    for k3 in $KIND_LIST3; do
		three $k1 $k2 $k3 $EXP $FAIL_VERSION
	    done
	done
    done
}

# Generate a test that uses a dg-do directive with a selector expression.
dgdo_progs() {
    WHAT=$1
    KIND=$2
    PROG="$3"
    NAME="$4"
    XPR="$5"
    
    FILE1=${NAME}-1.c
    FILE2=${NAME}-2.c
    rm -f $FILE1
    touch $FILE1
    echo '/* { dg-do' $WHAT '{' $KIND "$XPR" '} } */' >> $FILE1
    echo "${PROG}" >> $FILE1
    echo "${GOOD_PROG}" > $FILE2
}

# Use various selector-expressions that evaluate to TRUE in dg-do directives.
selector_good() {
    NUM=101
    for xpr in \
        "$GOOD0" \
        "$GOOD1" \
        "$GOOD2" \
        "{ ! $BAD0 }" \
        "{ ! $BAD1 }" \
	"{ ! { $BAD2 } }" \
	"{ ! \"${BAD2}\" }" \
        "{ $GOOD1 || $GOOD0 }"  \
        "{ $BAD1 || $GOOD0 }" \
        "{ $GOOD0 && $GOOD1 }"  \
        "{ $BAD1 || { \"${GOOD2}\" && $GOOD1 } }" \
        "{ { $BAD0 || $GOOD0 } && $GOOD0 }" \
        "{ $GOOD1 && { \"${GOOD2}\" || $BAD1 } }" \
        "{ \"${GOOD2}\" && { $GOOD1 || $BAD1 } }"
    do
        dgdo_progs compile target "$GOOD_PROG" "dots${NUM}-exp-P" "$xpr"
        dgdo_progs compile target "$BADC_PROG" "dots${NUM}-exp-F" "$xpr"
        dgdo_progs run xfail "$GOOD_PROG" "doxf${NUM}-exp-XP" "$xpr"
        dgdo_progs run xfail "$BADR_PROG" "doxf${NUM}-exp-XF" "$xpr"
        let NUM=NUM+1
    done
}

# Use various selector-expressions that evaluate to FALSE in dg-do directives.
selector_bad() {
    NUM=101
    for xpr in \
        "$BAD0" \
        "$BAD1" \
        "$BAD2" \
        "{ ! $GOOD0 }" \
        "{ ! $GOOD1 }" \
	"{ ! { $GOOD2 } }" \
	"{ ! \"${GOOD2}\" }" \
        "{ $BAD1 || $BAD0 }" \
        "{ $BAD0 && $GOOD1 }" \
        "{ $GOOD1 && $BAD0 }" \
        "{ $BAD1 || { $GOOD1 && $BAD0 } }" \
        "{ { $GOOD1 || $BAD1 } && $BAD0 }" \
        "{ $BAD1 || { \"${BAD2}\" && $GOOD1 } }" \
        "{ \"${BAD2}\" && { $GOOD1 || $BAD1 } }"
    do
        dgdo_progs compile target "$GOOD_PROG" "dotn${NUM}-exp-U" "$xpr"
        dgdo_progs run xfail "$GOOD_PROG" "doxp${NUM}-exp-P" "$xpr"
        dgdo_progs run xfail "$BADR_PROG" "doxp${NUM}-exp-F" "$xpr"
        let NUM=NUM+1
    done
}

# Write a test whose directive is too long and messy to do as one string.
deep_progs() {
    PROG="$1"
    NAME=$2
    CMD1="$3"
    CMD2="$4"
    CMD3="$5"

    FILE1=${NAME}-1.c
    FILE2=${NAME}-2.c
    rm -f $FILE1
    touch $FILE1
    echo "$CMD1" "$CMD2" "$CMD3" > $FILE1
    echo "$PROG" >> $FILE1
    echo "$GOOD_PROG" > $FILE2
}

# Use nested expressions in various test directives.
selector_deep() {
    GOODXPR="{ \"${GOOD2}\" && { ! { $BAD0 || $BAD1 } } }"
    BADXPR="{ ! { \"${GOOD2}\" || { $GOOD1 && $BAD1 } } }"
    NUM=100
    dgdo_progs compile target "$GOOD_PROG" "dots${NUM}-exp-P" "$GOODXPR"
    dgdo_progs compile target "$GOOD_PROG" "dotn${NUM}-exp-U" "$BADXPR"

    deep_progs "$BADC_PROG" "xiff-100-exp-XF" \
      '/* { dg-xfail-if "match" { ' "{ $GOODXPR }" ' } { "*" } { "" } } */'
    deep_progs "$GOOD_PROG" "xifp-100-exp-P" \
      '/* { dg-xfail-if "no match" { ' "{ $BADXPR }" ' } { "*" } { "" } } */'
    deep_progs "$BADC_PROG" "xifn-100-exp-U" \
      '/* { dg-skip-if "match" { ' "{ $GOODXPR }" ' } { "*" } { "" } } */'
    deep_progs "$GOOD_PROG" "xifs-100-exp-P" \
      '/* { dg-skip-if "match" { ' "{ $BADXPR }" ' } { "*" } { "" } } */'
    deep_progs "$GOOD_PROG" "satn-100-exp-P" \
      '/* { dg-final { scan-assembler-not "unexpected garbage" { target ' \
      "$GOODXPR" ' } } } */'
    deep_progs "$GOOD_PROG" "satn-100-exp-U" \
      '/* { dg-final { scan-assembler-not "unexpected garbage" { target ' \
      "$BADXPR" ' } } } */'
    deep_progs "$GOOD_PROG" "satf-100-exp-XP" \
      '/* { dg-final { scan-assembler-not "unexpected garbage" { xfail ' \
      "$GOODXPR" ' } } } */'
    deep_progs "$GOOD_PROG" "satp-100-exp-P" \
      '/* { dg-final { scan-assembler-not "unexpected garbage" { xfail ' \
      "$BADXPR" ' } } } */'
}

selector_good
selector_bad
selector_deep

one_all saxp $EXP_PASS no
one_all saxf $EXP_XPASS no
one_all sats $EXP_PASS no
one_all satn $EXP_SKIP no
one_all dots $EXP_PASS yes
one_all dotn $EXP_SKIP no
one_all doxp $EXP_PASS yes
one_all doxf $EXP_XPASS yes
one_all sifs $EXP_PASS yes
one_all sifn $EXP_SKIP no
one_all xifp $EXP_PASS yes
one_all xiff $EXP_XPASS yes
one_all reqs $EXP_PASS yes
one_all reqn $EXP_SKIP no

two_all dots xifp $EXP_PASS yes
two_all dots xiff $EXP_XPASS yes
two_all dots sifs $EXP_PASS yes
two_all dots sifn $EXP_SKIP no
two_all dotn xifp $EXP_SKIP no
two_all dotn sifs $EXP_SKIP no
two_all dotn sifn $EXP_SKIP no
two_all dotn xiff $EXP_SKIP no
two_all dots reqs $EXP_PASS yes
two_all dots reqn $EXP_SKIP no
two_all dotn reqs $EXP_SKIP no
two_all dotn reqn $EXP_SKIP no

two_all doxp xifp $EXP_PASS yes
two_all doxp xiff $EXP_PASS yes   # dg-xfail-if applies to compile, not run
two_all doxp sifs $EXP_PASS yes
two_all doxp sifn $EXP_SKIP no
two_all doxf xifp $EXP_XPASS yes
two_all doxf xiff $EXP_XPASS yes
two_all doxf sifs $EXP_XPASS yes
two_all doxf sifn $EXP_SKIP no

two_all doxp reqs $EXP_PASS yes
two_all doxp reqn $EXP_SKIP no
two_all doxf reqs $EXP_XPASS yes
two_all doxf reqn $EXP_SKIP no

two_all reqs xifp $EXP_PASS yes
two_all reqs xiff $EXP_XPASS yes
two_all reqs sifs $EXP_PASS yes
two_all reqs sifn $EXP_SKIP no
two_all reqn xifp $EXP_SKIP no
two_all reqn xiff $EXP_SKIP no
two_all reqn sifs $EXP_SKIP no
two_all reqn sifn $EXP_SKIP no

two_all xifp reqs $EXP_PASS yes
two_all xiff reqs $EXP_XPASS yes
two_all sifs reqs $EXP_PASS yes
two_all sifn reqs $EXP_SKIP no
two_all xifp reqn $EXP_SKIP no
two_all xiff reqn $EXP_SKIP no
two_all sifs reqn $EXP_SKIP no
two_all sifn reqn $EXP_SKIP no

three_all dots reqs xifp $EXP_PASS yes
three_all dots reqs xiff $EXP_XPASS yes
three_all dots reqs sifs $EXP_PASS yes
three_all dots reqs sifn $EXP_SKIP no
three_all dots reqn xifp $EXP_SKIP no
three_all dots reqn xiff $EXP_SKIP no
three_all dots reqn sifs $EXP_SKIP no
three_all dots reqn sifn $EXP_SKIP no
three_all dotn reqs xifp $EXP_SKIP no
three_all dotn reqs xiff $EXP_SKIP no
three_all dotn reqs sifs $EXP_SKIP no
three_all dotn reqs sifn $EXP_SKIP no
three_all dotn reqn xifp $EXP_SKIP no
three_all dotn reqn xiff $EXP_SKIP no
three_all dotn reqn sifs $EXP_SKIP no
three_all dotn reqn sifn $EXP_SKIP no
#
three_all dots xifp reqs $EXP_PASS yes
three_all dots xiff reqs $EXP_XPASS yes
three_all dots sifs reqs $EXP_PASS yes
three_all dots sifn reqs $EXP_SKIP no
three_all dots xifp reqn $EXP_SKIP no
three_all dots xiff reqn $EXP_SKIP no
three_all dots sifs reqn $EXP_SKIP no
three_all dots sifn reqn $EXP_SKIP no
three_all dotn xifp reqs $EXP_SKIP no
three_all dotn xiff reqs $EXP_SKIP no
three_all dotn sifs reqs $EXP_SKIP no
three_all dotn sifn reqs $EXP_SKIP no
three_all dotn xifp reqn $EXP_SKIP no
three_all dotn xiff reqn $EXP_SKIP no
three_all dotn sifs reqn $EXP_SKIP no
three_all dotn sifn reqn $EXP_SKIP no

three_all doxp reqs xifp $EXP_PASS yes
three_all doxp reqs xiff $EXP_PASS yes # dg-xfail-if applies to compile, not run
three_all doxp reqs sifs $EXP_PASS yes
three_all doxp reqs sifn $EXP_SKIP no
three_all doxp reqn xifp $EXP_SKIP no
three_all doxp reqn xiff $EXP_SKIP no
three_all doxp reqn sifs $EXP_SKIP no
three_all doxp reqn sifn $EXP_SKIP no
three_all doxf reqs xifp $EXP_XPASS yes
three_all doxf reqs xiff $EXP_XPASS yes
three_all doxf reqs sifs $EXP_XPASS yes
three_all doxf reqs sifn $EXP_SKIP no
three_all doxf reqn xifp $EXP_SKIP no
three_all doxf reqn xiff $EXP_SKIP no
three_all doxf reqn sifs $EXP_SKIP no
three_all doxf reqn sifn $EXP_SKIP no

three_all doxp xifp reqs $EXP_PASS yes
three_all doxp xiff reqs $EXP_PASS yes # dg-xfail-if applies to compile, not run
three_all doxp sifs reqs $EXP_PASS yes
three_all doxp sifn reqs $EXP_SKIP no
three_all doxp xifp reqn $EXP_SKIP no
three_all doxp xiff reqn $EXP_SKIP no
three_all doxp sifs reqn $EXP_SKIP no
three_all doxp sifn reqn $EXP_SKIP no
three_all doxf xifp reqs $EXP_XPASS yes
three_all doxf xiff reqs $EXP_XPASS yes
three_all doxf sifs reqs $EXP_XPASS yes
three_all doxf sifn reqs $EXP_SKIP no
three_all doxf xifp reqn $EXP_SKIP no
three_all doxf xiff reqn $EXP_SKIP no
three_all doxf sifs reqn $EXP_SKIP no
three_all doxf sifn reqn $EXP_SKIP no