Source file src/cmd/asm/internal/asm/line_test.go

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package asm
     6  
     7  import (
     8  	"cmd/asm/internal/lex"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  type badInstTest struct {
    14  	input, error string
    15  }
    16  
    17  func TestAMD64BadInstParser(t *testing.T) {
    18  	testBadInstParser(t, "amd64", []badInstTest{
    19  		// Test AVX512 suffixes.
    20  		{"VADDPD.A X0, X1, X2", `unknown suffix "A"`},
    21  		{"VADDPD.A.A X0, X1, X2", `unknown suffix "A"; duplicate suffix "A"`},
    22  		{"VADDPD.A.A.A X0, X1, X2", `unknown suffix "A"; duplicate suffix "A"`},
    23  		{"VADDPD.A.B X0, X1, X2", `unknown suffix "A"; unknown suffix "B"`},
    24  		{"VADDPD.Z.A X0, X1, X2", `Z suffix should be the last; unknown suffix "A"`},
    25  		{"VADDPD.Z.Z X0, X1, X2", `Z suffix should be the last; duplicate suffix "Z"`},
    26  		{"VADDPD.SAE.BCST X0, X1, X2", `can't combine rounding/SAE and broadcast`},
    27  		{"VADDPD.BCST.SAE X0, X1, X2", `can't combine rounding/SAE and broadcast`},
    28  		{"VADDPD.BCST.Z.SAE X0, X1, X2", `Z suffix should be the last; can't combine rounding/SAE and broadcast`},
    29  		{"VADDPD.SAE.SAE X0, X1, X2", `duplicate suffix "SAE"`},
    30  		{"VADDPD.RZ_SAE.SAE X0, X1, X2", `bad suffix combination`},
    31  
    32  		// BSWAP on 16-bit registers is undefined. See #29167,
    33  		{"BSWAPW DX", `unrecognized instruction`},
    34  		{"BSWAPW R11", `unrecognized instruction`},
    35  	})
    36  }
    37  
    38  func testBadInstParser(t *testing.T, goarch string, tests []badInstTest) {
    39  	for i, test := range tests {
    40  		arch, ctxt := setArch(goarch)
    41  		tokenizer := lex.NewTokenizer("", strings.NewReader(test.input+"\n"), nil)
    42  		parser := NewParser(ctxt, arch, tokenizer)
    43  
    44  		err := tryParse(t, func() {
    45  			parser.Parse()
    46  		})
    47  
    48  		switch {
    49  		case err == nil:
    50  			t.Errorf("#%d: %q: want error %q; have none", i, test.input, test.error)
    51  		case !strings.Contains(err.Error(), test.error):
    52  			t.Errorf("#%d: %q: want error %q; have %q", i, test.input, test.error, err)
    53  		}
    54  	}
    55  }
    56  

View as plain text