1#   Copyright (C) 2018-2021 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with GCC; see the file COPYING3.  If not see
15# <http://www.gnu.org/licenses/>.
16
17# Tests that test dejagnu extensions used in gcc testing
18
19load_lib "scantree.exp"
20load_lib "scanrtl.exp"
21load_lib "scanipa.exp"
22load_lib "scanlang.exp"
23load_lib "lto.exp"
24load_lib "scanasm.exp"
25load_lib "scanwpaipa.exp"
26load_lib "scanltranstree.exp"
27load_lib "scanoffloadtree.exp"
28load_lib "scanoffloadrtl.exp"
29load_lib "gcc-dg.exp"
30
31proc verify_call_1 { args } {
32    set call_name [lindex $args 0]
33    set call_args [lindex $args 1]
34    set expected_error [lindex $args 2]
35    set testid [lindex $args 3]
36
37    set errMsg ""
38    catch {
39	eval $call_name $call_args
40    } errMsg
41
42    if { "$errMsg" != "$expected_error" } {
43	send_log "For call $call_name $call_args\n"
44	send_log "expected: $expected_error\n"
45	send_log "but got: $errMsg\n"
46	fail "$testid"
47	return
48    } else {
49	pass "$testid"
50    }
51}
52
53proc verify_call { args } {
54    set call_name [lindex $args 0]
55    set call_args [lindex $args 1]
56    set expected_error [lindex $args 2]
57    verify_call_1 $call_name $call_args "$call_name: $expected_error" \
58	"$call_name: $expected_error"
59}
60
61proc verify_call_np { args } {
62    set call_name [lindex $args 0]
63    set call_args [lindex $args 1]
64    set expected_error [lindex $args 2]
65    verify_call_1 $call_name $call_args "$expected_error" \
66	"$call_name: $expected_error"
67}
68
69proc dg_final_directive_check_num_args {} {
70    proc verify_args { args } {
71	set proc_name [lindex $args 0]
72	set min [lindex $args 1]
73	set max [lindex $args 2]
74	set too_many [list]
75	set too_few [list]
76	for {set i 0} {$i < $min - 1}  {incr i} {
77	    lappend too_few $i
78	}
79	for {set i 0} {$i < $max + 1}  {incr i} {
80	    lappend too_many $i
81	}
82	verify_call $proc_name $too_many "too many arguments"
83	verify_call $proc_name $too_few "too few arguments"
84    }
85
86    foreach kind [list "tree" "rtl" "ipa" "ltrans-tree" "wpa-ipa" \
87		      "offload-tree" "offload-rtl"] {
88	verify_args scan-$kind-dump 2 3
89	verify_args scan-$kind-dump-times 3 4
90	verify_args scan-$kind-dump-not 2 3
91	verify_args scan-$kind-dump-dem 2 3
92	verify_args scan-$kind-dump-dem-not 2 3
93    }
94
95    verify_args scan-lang-dump 2 3
96
97    verify_args object-readelf 2 3
98
99    verify_args scan-assembler-times 2 3
100    verify_args scan-assembler-dem 1 2
101    verify_args scan-assembler-dem-not 1 2
102
103    verify_args object-size 3 4
104
105    global testname_with_flags
106    set testname_with_flags "test.c"
107    verify_args scan-assembler 1 2
108    verify_args scan-assembler-not 1 2
109    verify_args scan-hidden 1 2
110    verify_args scan-not-hidden 1 2
111    verify_args scan-file 2 3
112    verify_args scan-file-not 2 3
113    verify_args scan-stack-usage 1 2
114    verify_args scan-stack-usage-not 1 2
115    verify_args scan-ada-spec 1 2
116    verify_args scan-ada-spec-not 1 2
117    verify_args scan-lto-assembler 1 2
118    unset testname_with_flags
119}
120
121proc dg_final_directive_check_utils {} {
122    verify_call_np get-absolute-line [list "" bla] \
123	"dg-line var bla used, but not defined"
124    verify_call_np get-absolute-line [list 1 bla] \
125	"dg-line var bla used at line 1, but not defined"
126}
127
128if ![gcc_parallel_test_run_p dg-final] {
129    return
130}
131gcc_parallel_test_enable 0
132dg_final_directive_check_num_args
133dg_final_directive_check_utils
134gcc_parallel_test_enable 1
135