Skip to content

Commit

Permalink
fixup! link: add test for uprobe multi link
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Jan 23, 2024
1 parent 9830564 commit 7b782ca
Showing 1 changed file with 15 additions and 67 deletions.
82 changes: 15 additions & 67 deletions link/uprobe_multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,89 +108,37 @@ func TestUprobeMultiInput(t *testing.T) {

func TestUprobeMultiResolveOk(t *testing.T) {
addrSym1, err := bashEx.address(bashSyms[0], 0, 0)
if err != nil {
t.Fatal(err)
}
qt.Assert(t, qt.IsNil(err))
addrSym2, err := bashEx.address(bashSyms[1], 0, 0)
if err != nil {
t.Fatal(err)
}
qt.Assert(t, qt.IsNil(err))
addrSym3, err := bashEx.address(bashSyms[2], 0, 0)
if err != nil {
t.Fatal(err)
}
qt.Assert(t, qt.IsNil(err))

// symbols only
opts := &UprobeMultiOptions{}
addrs, err := bashEx.addresses(bashSyms, nil, nil)
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.DeepEquals(addrs, []uint64{addrSym1, addrSym2, addrSym3}))

err = bashEx.uprobeMultiResolve(bashSyms, opts)
if err != nil {
t.Fatal(err)
}
addrs, err = bashEx.addresses(bashSyms, nil, []uint64{5, 10, 11})
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.DeepEquals(addrs, []uint64{addrSym1 + 5, addrSym2 + 10, addrSym3 + 11}))

qt.Assert(t, qt.Equals(len(opts.Addresses), 3))
qt.Assert(t, qt.Equals(opts.Addresses[0], addrSym1))
qt.Assert(t, qt.Equals(opts.Addresses[1], addrSym2))
qt.Assert(t, qt.Equals(opts.Addresses[2], addrSym3))

// symbols with offsets
opts = &UprobeMultiOptions{
Offsets: []uint64{5, 10, 11}}

err = bashEx.uprobeMultiResolve(bashSyms, opts)
if err != nil {
t.Fatal(err)
}

qt.Assert(t, qt.Equals(len(opts.Addresses), 3))
qt.Assert(t, qt.Equals(opts.Addresses[0], addrSym1+5))
qt.Assert(t, qt.Equals(opts.Addresses[1], addrSym2+10))
qt.Assert(t, qt.Equals(opts.Addresses[2], addrSym3+11))

// addresses only
opts = &UprobeMultiOptions{
Addresses: []uint64{addrSym1, addrSym2, addrSym3}}

err = bashEx.uprobeMultiResolve(nil, opts)
if err != nil {
t.Fatal(err)
}

qt.Assert(t, qt.Equals(len(opts.Addresses), 3))
qt.Assert(t, qt.Equals(opts.Addresses[0], addrSym1))
qt.Assert(t, qt.Equals(opts.Addresses[1], addrSym2))
qt.Assert(t, qt.Equals(opts.Addresses[2], addrSym3))

// addresses with offsets
opts = &UprobeMultiOptions{
Addresses: []uint64{addrSym1, addrSym2, addrSym3},
Offsets: []uint64{5, 10, 11}}

err = bashEx.uprobeMultiResolve(nil, opts)
if err != nil {
t.Fatal(err)
}
addrs, err = bashEx.addresses(bashSyms, []uint64{1, 2, 3}, nil)
qt.Assert(t, qt.IsNil(err))

qt.Assert(t, qt.Equals(len(opts.Addresses), 3))
qt.Assert(t, qt.Equals(opts.Addresses[0], addrSym1+5))
qt.Assert(t, qt.Equals(opts.Addresses[1], addrSym2+10))
qt.Assert(t, qt.Equals(opts.Addresses[2], addrSym3+11))
qt.Assert(t, qt.DeepEquals(addrs, []uint64{1, 2, 3}))
}

func TestUprobeMultiResolveFail(t *testing.T) {
// No input
err := bashEx.uprobeMultiResolve(nil, &UprobeMultiOptions{})
_, err := bashEx.addresses(nil, nil, nil)
qt.Assert(t, qt.ErrorIs(err, errInvalidInput))

// Different dimensions for Addresses and Offsets
err = bashEx.uprobeMultiResolve(nil, &UprobeMultiOptions{
Addresses: []uint64{100, 200},
Offsets: []uint64{5, 10, 11}})
_, err = bashEx.addresses(nil, []uint64{100, 200}, []uint64{5, 10, 11})
qt.Assert(t, qt.ErrorIs(err, errInvalidInput))

// Different dimensions for symbols and Offsets
err = bashEx.uprobeMultiResolve(bashSyms, &UprobeMultiOptions{
Offsets: []uint64{5, 10}})
_, err = bashEx.addresses(bashSyms, nil, []uint64{5, 10})
qt.Assert(t, qt.ErrorIs(err, errInvalidInput))
}

Expand Down

0 comments on commit 7b782ca

Please sign in to comment.