From d475659793841a31d631c211a43a9bf0b7e8d8ca Mon Sep 17 00:00:00 2001 From: Timo Beckers Date: Wed, 23 Feb 2022 14:01:00 +0100 Subject: [PATCH] prog_test: compare BTF program tags instead of raw insns 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 9c06a484cfd5e6f184a2945f8196c0ad27e9c87d, as it was removed to avoid having to overwrite the map fd with an id in xlated insns. Signed-off-by: Timo Beckers --- prog_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/prog_test.go b/prog_test.go index 2f846ca75..f48b3b4cf 100644 --- a/prog_test.go +++ b/prog_test.go @@ -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(), }, @@ -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) } }