Skip to content

Commit

Permalink
info: add tests for recent ProgramInfo API additions
Browse files Browse the repository at this point in the history
Added tests for:
- LineInfos()
- KsymAddrs()
- JitedInsns()
- JitedLineInfos()
- JitedFuncLens()

Signed-off-by: Timo Beckers <[email protected]>
  • Loading branch information
ti-mo committed Dec 4, 2024
1 parent beb2b31 commit f35b146
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ func TestProgramInfo(t *testing.T) {
qt.Assert(t, qt.IsTrue(ok))
qt.Assert(t, qt.IsTrue(verifiedInsns > 0))
}

if addrs, ok := info.KsymAddrs(); testutils.IsKernelLessThan(t, "4.18") {
qt.Assert(t, qt.IsFalse(ok))
} else {
qt.Assert(t, qt.IsTrue(ok))
qt.Assert(t, qt.IsTrue(len(addrs) > 0))
}

if insns, ok := info.JitedInsns(); testutils.IsKernelLessThan(t, "4.13") {
qt.Assert(t, qt.IsFalse(ok))
} else {
qt.Assert(t, qt.IsTrue(ok))
qt.Assert(t, qt.IsTrue(len(insns) > 0))
}

if infos, ok := info.JitedLineInfos(); testutils.IsKernelLessThan(t, "5.0") {
qt.Assert(t, qt.IsFalse(ok))
} else {
qt.Assert(t, qt.IsTrue(ok))
qt.Assert(t, qt.IsTrue(len(infos) > 0))
}

if lens, ok := info.JitedFuncLens(); testutils.IsKernelLessThan(t, "4.18") {
qt.Assert(t, qt.IsFalse(ok))
} else {
qt.Assert(t, qt.IsTrue(ok))
qt.Assert(t, qt.IsTrue(len(lens) > 0))
}
}

func TestProgramInfoProc(t *testing.T) {
Expand Down Expand Up @@ -517,8 +545,8 @@ func TestProgInfoKsym(t *testing.T) {
}
}

func TestProgInfoFuncInfos(t *testing.T) {
testutils.SkipOnOldKernel(t, "5.0", "Program func info")
func TestProgInfoFuncLineInfos(t *testing.T) {
testutils.SkipOnOldKernel(t, "5.0", "Program func and line info")

spec, err := LoadCollectionSpec(testutils.NativeFile(t, "testdata/loader-%s.elf"))
qt.Assert(t, qt.IsNil(err))
Expand All @@ -542,4 +570,13 @@ func TestProgInfoFuncInfos(t *testing.T) {
qt.Assert(t, qt.IsNotNil(fo.Func))
qt.Assert(t, qt.Not(qt.Equals(fo.Func.Name, "")))
}

lines, err := info.LineInfos()
qt.Assert(t, qt.IsNil(err))

qt.Assert(t, qt.HasLen(lines, 28))
for _, lo := range lines {
qt.Assert(t, qt.IsNotNil(lo.Line))
qt.Assert(t, qt.Not(qt.Equals(lo.Line.Line(), "")))
}
}
2 changes: 1 addition & 1 deletion prog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ var socketFilterSpec = &ProgramSpec{
Name: "test",
Type: SocketFilter,
Instructions: asm.Instructions{
asm.LoadImm(asm.R0, 2, asm.DWord),
asm.LoadImm(asm.R0, 2, asm.DWord).WithSource(asm.Comment("line info")),
asm.Return(),
},
License: "MIT",
Expand Down

0 comments on commit f35b146

Please sign in to comment.