Skip to content

Commit

Permalink
prog_test: compare BTF program tags instead of raw insns
Browse files Browse the repository at this point in the history
To prepare for Instruction no longer being comparable, remove the only test
that directly compares Instructions. Comparing instruction streams should be
done using Instructions.Tag().

Re-introduce a map load as in 9c06a48, as it
was removed to avoid having to overwrite the map fd with an id in xlated insns.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed Feb 23, 2022
1 parent 07fff6e commit ba2072b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions prog_test.go
Expand Up @@ -687,12 +687,16 @@ func TestProgramBindMap(t *testing.T) {
}

func TestProgramInstructions(t *testing.T) {
arr := createArray(t)
defer arr.Close()

name := "test_prog"
spec := &ProgramSpec{
Type: SocketFilter,
Name: name,
Instructions: asm.Instructions{
asm.LoadImm(asm.R0, -1, asm.DWord).Sym(name),
asm.LoadMapPtr(asm.R1, arr.FD()),
asm.Mov.Imm32(asm.R0, 0),
asm.Return(),
},
Expand All @@ -716,8 +720,18 @@ func TestProgramInstructions(t *testing.T) {
t.Fatal(err)
}

if diff := cmp.Diff(insns, spec.Instructions); diff != "" {
t.Fatal(diff)
tag, err := spec.Tag()
if err != nil {
t.Fatal(err)
}

tagXlated, err := insns.Tag(internal.NativeEndian)
if err != nil {
t.Fatal(err)
}

if tag != tagXlated {
t.Fatalf("tag %s differs from xlated instructions tag %s", tag, tagXlated)
}
}

Expand Down

0 comments on commit ba2072b

Please sign in to comment.