diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00b76e420..27fffb3c2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,6 +129,9 @@ jobs: - name: Test run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $CI_MAX_KERNEL_VERSION -short -count 1 -json ./... + - name: Benchmark + run: go test -exec sudo -short -run '^$' -bench . -benchtime=1x ./... + - name: Upload Test Results if: always() uses: actions/upload-artifact@v3 diff --git a/btf/core_test.go b/btf/core_test.go index 1acd9295d..3308efb51 100644 --- a/btf/core_test.go +++ b/btf/core_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/go-cmp/cmp" qt "github.com/frankban/quicktest" + "golang.org/x/exp/slices" ) func TestCheckTypeCompatibility(t *testing.T) { @@ -712,6 +713,11 @@ func BenchmarkCORESkBuff(b *testing.B) { skbID, err := spec.TypeID(skb) qt.Assert(b, err, qt.IsNil) + lenIndex := slices.IndexFunc(skb.Members, func(m Member) bool { + return m.Name == "len" + }) + qt.Assert(b, lenIndex, qt.Not(qt.Equals), -1) + var pktHashTypes *Enum err = spec.TypeByName("pkt_hash_types", &pktHashTypes) qt.Assert(b, err, qt.IsNil) @@ -720,12 +726,12 @@ func BenchmarkCORESkBuff(b *testing.B) { qt.Assert(b, err, qt.IsNil) for _, relo := range []*CORERelocation{ - {skb, coreAccessor{0, 0}, reloFieldByteOffset, skbID}, - {skb, coreAccessor{0, 0}, reloFieldByteSize, skbID}, - {skb, coreAccessor{0, 0}, reloFieldExists, skbID}, - {skb, coreAccessor{0, 0}, reloFieldSigned, skbID}, - {skb, coreAccessor{0, 0}, reloFieldLShiftU64, skbID}, - {skb, coreAccessor{0, 0}, reloFieldRShiftU64, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldByteOffset, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldByteSize, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldExists, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldSigned, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldLShiftU64, skbID}, + {skb, coreAccessor{0, lenIndex}, reloFieldRShiftU64, skbID}, {skb, coreAccessor{0}, reloTypeIDLocal, skbID}, {skb, coreAccessor{0}, reloTypeIDTarget, skbID}, {skb, coreAccessor{0}, reloTypeExists, skbID}, diff --git a/map_test.go b/map_test.go index 9de341b6a..6e7710a62 100644 --- a/map_test.go +++ b/map_test.go @@ -1910,27 +1910,26 @@ func BenchmarkMarshaling(b *testing.B) { } func BenchmarkPerCPUMarshalling(b *testing.B) { - newMap := func(valueSize uint32) *Map { - m, err := NewMap(&MapSpec{ - Type: PerCPUHash, - KeySize: 8, - ValueSize: valueSize, - MaxEntries: 1, - }) - if err != nil { - b.Fatal(err) - } - return m + key := uint64(1) + val := make([]uint64, MustPossibleCPU()) + for i := range val { + val[i] = uint64(i) } - key := uint64(1) - val := []uint64{1, 2, 3, 4, 5, 6, 7, 8} + m, err := NewMap(&MapSpec{ + Type: PerCPUHash, + KeySize: 8, + ValueSize: 8, + MaxEntries: 1, + }) + if err != nil { + b.Fatal(err) + } - m := newMap(8) + b.Cleanup(func() { m.Close() }) if err := m.Put(key, val[0:]); err != nil { b.Fatal(err) } - b.Cleanup(func() { m.Close() }) b.Run("reflection", func(b *testing.B) { b.ReportAllocs() @@ -2041,9 +2040,9 @@ func BenchmarkIterate(b *testing.B) { values[i] = uint64(i) } - if _, err := m.BatchUpdate(keys, values, nil); err != nil { - b.Fatal(err) - } + _, err = m.BatchUpdate(keys, values, nil) + testutils.SkipIfNotSupported(b, err) + qt.Assert(b, err, qt.IsNil) b.Run("MapIterator", func(b *testing.B) { var k, v uint64