aboutsummaryrefslogtreecommitdiffstats
path: root/prog/hints_test.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-05-05 12:14:52 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-05 14:01:52 +0200
commite42fa3fd020db0a54d0e3ecd8300a77e57fc08fd (patch)
treeb02e4e95e80c7a4a16c9bdcfab5c829e2be31a00 /prog/hints_test.go
parent1905d7c090a13a8b94e5d19a5388104f2d7693fd (diff)
prog: refactor hints tests
The way the tests fabricate types dynamically creates problems during any non-trivial changes to prog package. Use existing types from descriptions instead.
Diffstat (limited to 'prog/hints_test.go')
-rw-r--r--prog/hints_test.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/prog/hints_test.go b/prog/hints_test.go
index 54b6569a2..c868855a8 100644
--- a/prog/hints_test.go
+++ b/prog/hints_test.go
@@ -31,7 +31,7 @@ type DataArgTest struct {
// Tests checkConstArg(). Is not intended to check correctness of any mutations.
// Mutation are checked in their own tests.
func TestHintsCheckConstArg(t *testing.T) {
- t.Parallel()
+ target := initTargetTest(t, "test", "64")
var tests = []ConstArgTest{
{
name: "one-replacer-test",
@@ -150,13 +150,16 @@ func TestHintsCheckConstArg(t *testing.T) {
res: []uint64{0xab, 0xabcd, 0xdeadbeef, 0xdeadbeefdeadbeef},
},
}
-
+ meta := target.SyscallMap["test$hint_int"]
+ structType := meta.Args[0].Type.(*PtrType).Elem.(*StructType)
+ types := make(map[string]Type)
+ for _, field := range structType.Fields {
+ types[field.Name] = field.Type
+ }
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
var res []uint64
- typ := &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{
- TypeSize: test.size},
- BitfieldLen: test.bitsize}}
+ typ := types[fmt.Sprintf("int%v_%v", test.size, test.bitsize)]
constArg := MakeConstArg(typ, DirIn, test.in)
checkConstArg(constArg, test.comps, func() {
res = append(res, constArg.Val)
@@ -171,7 +174,7 @@ func TestHintsCheckConstArg(t *testing.T) {
// Tests checkDataArg(). Is not intended to check correctness of any mutations.
// Mutation are checked in their own tests.
func TestHintsCheckDataArg(t *testing.T) {
- t.Parallel()
+ target := initTargetTest(t, "test", "64")
// All inputs are in Little-Endian.
var tests = []DataArgTest{
{
@@ -290,12 +293,11 @@ func TestHintsCheckDataArg(t *testing.T) {
},
},
}
+ meta := target.SyscallMap["test$hint_data"]
+ typ := meta.Args[0].Type.(*PtrType).Elem // array[int8]
for _, test := range tests {
t.Run(fmt.Sprintf("%v", test.name), func(t *testing.T) {
res := make(map[string]bool)
- // Whatever type here. It's just needed to pass the
- // dataArg.Type().Dir() == DirIn check.
- typ := &ArrayType{TypeCommon{"", 0, false, true}, nil, 0, 0, 0}
dataArg := MakeDataArg(typ, DirIn, []byte(test.in))
checkDataArg(dataArg, test.comps, func() {
res[string(dataArg.Data())] = true