aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-09-14 18:03:44 +0200
committerAleksandr Nogikh <nogikh@google.com>2023-10-04 09:27:33 +0000
commitc4dc646bee41c7e983a13750652f1035ae27b737 (patch)
tree41628c9297a3fe6937dc0b1d2204b7b7d6eee4de /pkg/compiler
parent12dde47641ed4c314decd0728d9d54ba6cd0aa02 (diff)
pkg/compiler: add ExistsAny() to ConstFile
The new method checks whether the value is defined for at least one of the known arches. Refactor ConstFile tests.
Diffstat (limited to 'pkg/compiler')
-rw-r--r--pkg/compiler/const_file.go4
-rw-r--r--pkg/compiler/const_file_test.go16
2 files changed, 10 insertions, 10 deletions
diff --git a/pkg/compiler/const_file.go b/pkg/compiler/const_file.go
index 0df0bb0ca..1968092a4 100644
--- a/pkg/compiler/const_file.go
+++ b/pkg/compiler/const_file.go
@@ -82,6 +82,10 @@ func (cf *ConstFile) Arch(arch string) map[string]uint64 {
return m
}
+func (cf *ConstFile) ExistsAny(constName string) bool {
+ return len(cf.m[constName].vals) > 0
+}
+
func (cf *ConstFile) Serialize() []byte {
if len(cf.arches) == 0 {
return nil
diff --git a/pkg/compiler/const_file_test.go b/pkg/compiler/const_file_test.go
index ccfce4c95..957cb6421 100644
--- a/pkg/compiler/const_file_test.go
+++ b/pkg/compiler/const_file_test.go
@@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"
- "github.com/google/go-cmp/cmp"
+ "github.com/stretchr/testify/assert"
)
func TestConstFile(t *testing.T) {
@@ -86,9 +86,9 @@ CONST5_SOME_UNDEFINED2 = 100, arch3:???
cf.AddArch(name, arch.consts, arch.undefined)
}
data := cf.Serialize()
- if diff := cmp.Diff(serialized, string(data)); diff != "" {
- t.Fatal(diff)
- }
+ assert.Equal(t, serialized, string(data))
+ assert.True(t, cf.ExistsAny("CONST3_SOME_UNDEFINED"))
+ assert.False(t, cf.ExistsAny("CONST4_ALL_UNDEFINED"))
{
file, err := os.CreateTemp("", "syz-const")
if err != nil {
@@ -102,9 +102,7 @@ CONST5_SOME_UNDEFINED2 = 100, arch3:???
file.Close()
cf1 := DeserializeConstFile(file.Name(), nil)
for name, arch := range arches {
- if diff := cmp.Diff(arch.consts, cf1.Arch(name)); diff != "" {
- t.Errorf("%v: %v", name, diff)
- }
+ assert.Equal(t, cf1.Arch(name), arch.consts)
}
}
{
@@ -117,9 +115,7 @@ CONST5_SOME_UNDEFINED2 = 100, arch3:???
}
cf1 := DeserializeConstFile(filepath.Join(dir, "*"), nil)
for name, arch := range arches {
- if diff := cmp.Diff(arch.consts, cf1.Arch(name)); diff != "" {
- t.Errorf("%v: %v", name, diff)
- }
+ assert.Equal(t, cf1.Arch(name), arch.consts)
}
}
}