| 108 | } |
| 109 | |
| 110 | func TestCacheConcurrentModule(t *testing.T) { |
| 111 | if _, err := os.Stat("/sys/kernel/btf/bpf_testmod"); os.IsNotExist(err) { |
| 112 | t.Skip("/sys/kernel/btf/bpf_testmod not present") |
| 113 | } |
| 114 | |
| 115 | const goroutines = 8 |
| 116 | |
| 117 | c := NewCache() |
| 118 | specs := make([]*Spec, goroutines) |
| 119 | errs := make([]error, goroutines) |
| 120 | |
| 121 | var wg sync.WaitGroup |
| 122 | wg.Add(goroutines) |
| 123 | for i := range goroutines { |
| 124 | go func(i int) { |
| 125 | defer wg.Done() |
| 126 | specs[i], errs[i] = c.Module("bpf_testmod") |
| 127 | }(i) |
| 128 | } |
| 129 | wg.Wait() |
| 130 | |
| 131 | for _, err := range errs { |
| 132 | qt.Assert(t, qt.IsNil(err)) |
| 133 | } |
| 134 | for i := 1; i < goroutines; i++ { |
| 135 | qt.Assert(t, qt.Equals(specs[0], specs[i])) |
| 136 | } |
| 137 | } |