1# Copyright (C) 2012-2016 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 this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
16
17# Test for error messages when a bad register name, an out of range operand, or
18# invalid syntax is used.  Adapted from Ben Elliston's load-hazard testcase.
19
20# Run GAS and check that it emits the desired error for the test case.
21# Arguments:
22#   file -- name of the test case to assemble.
23#   testname -- a string describing the test.
24#   warnpattern -- a regular expression, suitable for use by the Tcl
25#     regexp command, to decide if the warning string was emitted by
26#     the assembler to stderr.
27
28proc mrisc1_error_test { file testname {warnpattern ""} } {
29    global comp_output
30
31    gas_run $file "" ">/dev/null"
32    verbose "output was $comp_output" 2
33
34    if {$warnpattern == ""} {
35	if {$comp_output == ""} { pass $testname } else { fail $testname }
36	return
37    }
38
39    if {[regexp "Error: $warnpattern" $comp_output]} {
40	pass $testname
41    } else {
42	fail $testname
43    }
44}
45
46if [istarget mt-*-*] {
47    foreach file [lsort [glob -nocomplain -- $srcdir/$subdir/bad*.s]] {
48	set file [file tail $file]
49	switch -- $file {
50	    "badreg.s" {
51		set warnpattern "unrecognized keyword/register name *"
52	    }
53	    "badorder.s" {
54		set warnpattern "unrecognized form of instruction*"
55	    }
56	    "badsyntax.s" {
57		set warnpattern "unrecognized keyword/register name *"
58	    }
59	    "badsyntax1.s" {
60		set warnpattern "unrecognized form of instruction*"
61	    }
62	    "badoffsethigh.s" {
63		set warnpattern "Operand out of range. Must be between -32768 and 32767.*"
64	    }
65	    "badoffsetlow.s" {
66		set warnpattern "Operand out of range. Must be between -32768 and 32767.*"
67	    }
68	    "badunsignedimmhigh.s" {
69		set warnpattern "operand out of range (65536 not between 0 and 65535)*"
70	    }
71	    "badunsignedimmlow.s" {
72		set warnpattern "operand out of range (65536 not between 0 and 65535)*"
73	    }
74	    "badsignedimmhigh.s" {
75		set warnpattern "operand out of range.*"
76	    }
77	    "badsignedimmlow.s" {
78		set warnpattern "operand out of range.*"
79	    }
80	    "badinsn.s" {
81		set warnpattern "unrecognized instruction *"
82	    }
83	    "badinsn1.s" {
84		set warnpattern "junk at end of line *"
85	    }
86            default {
87                error "no expected result specified for $file"
88                return
89
90	    }
91	}
92	mrisc1_error_test $file "assembler emits error for $file" $warnpattern
93    }
94
95}
96