Skip to content

Commit

Permalink
collection: copy CollectionSpec.BTF in Copy()
Browse files Browse the repository at this point in the history
Without this, loading a copied CollectionSpec fails with:

loading collection: map test: BTF doesn't match collection

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed Feb 23, 2022
1 parent 279bd96 commit 9fda6d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions collection.go
Expand Up @@ -45,6 +45,7 @@ func (cs *CollectionSpec) Copy() *CollectionSpec {
Maps: make(map[string]*MapSpec, len(cs.Maps)),
Programs: make(map[string]*ProgramSpec, len(cs.Programs)),
ByteOrder: cs.ByteOrder,
BTF: cs.BTF.Copy(),
}

for name, spec := range cs.Maps {
Expand Down
6 changes: 6 additions & 0 deletions collection_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/cilium/ebpf/asm"
"github.com/cilium/ebpf/internal/btf"
"github.com/cilium/ebpf/internal/testutils"
)

Expand Down Expand Up @@ -66,6 +67,7 @@ func TestCollectionSpecCopy(t *testing.T) {
License: "MIT",
},
},
BTF: &btf.Spec{},
}
cpy := cs.Copy()

Expand All @@ -80,6 +82,10 @@ func TestCollectionSpecCopy(t *testing.T) {
if cpy.Programs["test"] == cs.Programs["test"] {
t.Error("Copy returned same Programs")
}

if cpy.BTF == cs.BTF {
t.Error("Copy returned same BTF")
}
}

func TestCollectionSpecRewriteMaps(t *testing.T) {
Expand Down

0 comments on commit 9fda6d0

Please sign in to comment.