github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/inline/inlheur/tserial_test.go (about) 1 // Copyright 2023 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 inlheur 6 7 import "testing" 8 9 func fpeq(fp1, fp2 FuncProps) bool { 10 if fp1.Flags != fp2.Flags { 11 return false 12 } 13 if len(fp1.ParamFlags) != len(fp2.ParamFlags) { 14 return false 15 } 16 for i := range fp1.ParamFlags { 17 if fp1.ParamFlags[i] != fp2.ParamFlags[i] { 18 return false 19 } 20 } 21 if len(fp1.ResultFlags) != len(fp2.ResultFlags) { 22 return false 23 } 24 for i := range fp1.ResultFlags { 25 if fp1.ResultFlags[i] != fp2.ResultFlags[i] { 26 return false 27 } 28 } 29 return true 30 } 31 32 func TestSerDeser(t *testing.T) { 33 testcases := []FuncProps{ 34 {}, 35 { 36 Flags: 0xfffff, 37 }, 38 { 39 Flags: 1, 40 ResultFlags: []ResultPropBits{ResultAlwaysSameConstant}, 41 }, 42 { 43 Flags: 1, 44 ParamFlags: []ParamPropBits{0x99, 0xaa, 0xfffff}, 45 ResultFlags: []ResultPropBits{0xfeedface}, 46 }, 47 } 48 49 for k, tc := range testcases { 50 s := tc.SerializeToString() 51 fp := DeserializeFromString(s) 52 got := fp.String() 53 want := tc.String() 54 if !fpeq(*fp, tc) { 55 t.Errorf("eq check failed for test %d: got:\n%s\nwant:\n%s\n", k, got, want) 56 } 57 } 58 59 var nilt *FuncProps 60 ns := nilt.SerializeToString() 61 nfp := DeserializeFromString(ns) 62 if len(ns) != 0 || nfp != nil { 63 t.Errorf("nil serialize/deserialize failed") 64 } 65 }