Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tetragon: debugging map duplication extending prog/map testers #2455

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions pkg/testutils/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,25 @@ type prog struct {
mark bool
}

func findProgram(cache []*prog, name string, typ ebpf.ProgramType, match ProgMatch) *prog {
func findProgram(cache []*prog, name string, typ ebpf.ProgramType, match ProgMatch) []*prog {
var p []*prog

for _, c := range cache {
if c.prog.Type != typ {
continue
}
switch match {
case ProgMatchPartial:
if strings.Contains(c.name, name) {
return c
p = append(p, c)
}
case ProgMatchFull:
if c.name == name {
return c
p = append(p, c)
}
}
}
return nil
return p
}

func mergeSensorMaps(t *testing.T, maps1, maps2 []SensorMap, progs1, progs2 []SensorProg) ([]SensorMap, []SensorProg) {
Expand Down Expand Up @@ -188,12 +190,14 @@ func CheckSensorLoad(sensors []*sensors.Sensor, sensorMaps []SensorMap, sensorPr

// check that we loaded expected programs
for _, tp := range sensorProgs {
c := findProgram(cache, tp.Name, tp.Type, tp.Match)
if c == nil {
cs := findProgram(cache, tp.Name, tp.Type, tp.Match)
if len(cs) == 0 {
t.Fatalf("could not find program %v in sensor", tp.Name)
}
c.mark = true
t.Logf("Found prog %v type %s\n", c.name, c.prog.Type)
for _, c := range cs {
c.mark = true
t.Logf("Found prog %v type %s\n", c.name, c.prog.Type)
}
}

var extra bool
Expand Down Expand Up @@ -224,26 +228,28 @@ func CheckSensorLoad(sensors []*sensors.Sensor, sensorMaps []SensorMap, sensorPr
for _, idx := range tm.Progs {
tp := sensorProgs[idx]

c := findProgram(cache, tp.Name, tp.Type, tp.Match)
if c == nil {
cs := findProgram(cache, tp.Name, tp.Type, tp.Match)
if len(cs) == 0 {
t.Fatalf("could not find program %v in sensor\n", tp.Name)
}

m := findMapForProg(c.coll, tm.Name, c.prog)
if m == nil {
t.Fatalf("could not find map %v in program %v\n", tm.Name, tp.Name)
}
for _, c := range cs {
m := findMapForProg(c.coll, tm.Name, c.prog)
if m == nil {
t.Fatalf("could not find map %v in program %v\n", tm.Name, tp.Name)
}

t.Logf("\tFound map %v id %v in prog %v\n", tm.Name, m.ID, tp.Name)
t.Logf("\tFound map %v id %v in prog %v\n", tm.Name, m.ID, tp.Name)

if sharedId == 0 {
sharedId = m.ID
}
if sharedId == 0 {
sharedId = m.ID
}

if m.ID != sharedId {
t.Fatalf("map %v has wrong shared id %v != %v\n", tm.Name, m.ID, sharedId)
if m.ID != sharedId {
t.Fatalf("map %v has wrong shared id %v != %v\n", tm.Name, m.ID, sharedId)
}
c.mark = true
}
c.mark = true
}

// check that rest of the loaded programs DO NOT share the map
Expand Down
Loading