golang.org/x/arch@v0.17.0/riscv64/riscv64asm/objdump_test.go (about) 1 // Copyright 2024 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 riscv64asm 6 7 import ( 8 "strings" 9 "testing" 10 ) 11 12 func TestObjdumpRISCV64TestDecodeGNUSyntaxdata(t *testing.T) { 13 testObjdumpRISCV64(t, testdataCases(t, "gnu")) 14 } 15 func TestObjdumpRISCV64TestDecodeGoSyntaxdata(t *testing.T) { 16 testObjdumpRISCV64(t, testdataCases(t, "plan9")) 17 } 18 19 func TestObjdumpRISCV64Manual(t *testing.T) { 20 testObjdumpRISCV64(t, hexCases(t, objdumpManualTests)) 21 } 22 23 // objdumpManualTests holds test cases that will be run by TestObjdumpRISCV64Manual. 24 // If you are debugging a few cases that turned up in a longer run, it can be useful 25 // to list them here and then use -run=Manual, particularly with tracing enabled. 26 // Note that these are byte sequences, so they must be reversed from the usual 27 // word presentation. 28 var objdumpManualTests = ` 29 93020300 30 13000000 31 9b020300 32 afb5b50e 33 73b012c0 34 73f01fc0 35 73a012c0 36 73e01fc0 37 f3223000 38 f3221000 39 f3222000 40 f3123300 41 f3121300 42 f3122300 43 739012c0 44 73d01fc0 45 53a01022 46 53a01020 47 53801022 48 53801020 49 53901022 50 53901020 51 67800000 52 67800200 53 b3026040 54 bb026040 55 9342f3ff 56 f32200c0 57 f32200c8 58 f32220c0 59 f32220c8 60 f32210c0 61 f32210c8 62 ` 63 64 // allowedMismatchObjdump reports whether the mismatch between text and dec 65 // should be allowed by the test. 66 func allowedMismatchObjdump(text string, inst *Inst, dec ExtInst) bool { 67 // Allow the mismatch of Branch/Jump instruction's offset. 68 decsp := strings.Split(dec.text, ",") 69 70 switch inst.Op { 71 case BEQ, BGE, BGEU, BLT, BLTU, BNE: 72 if inst.Args[2].(Simm).String() != decsp[len(decsp)-1] { 73 return true 74 } 75 case JAL: 76 if inst.Args[1].(Simm).String() != decsp[len(decsp)-1] { 77 return true 78 } 79 case JALR: 80 if inst.Args[1].(RegOffset).Ofs.String() != decsp[len(decsp)-1] { 81 return true 82 } 83 } 84 85 return false 86 }