Skip to content

Commit 48d91be

Browse files
committed
add test for reproducing golang/go#14210 (Go 1.6 panic: runtime error: cgo argument has Go pointer to Go pointer)
1 parent 402cdf1 commit 48d91be

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: go
22

33
go:
4+
- tip
5+
- 1.6
46
- 1.5
57

68
before_install:

netfilter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ package netfilter
3232
import "C"
3333

3434
import (
35+
"fmt"
3536
"github.com/google/gopacket"
3637
"github.com/google/gopacket/layers"
37-
"fmt"
3838
"unsafe"
3939
)
4040

netfilter_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package netfilter
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
var stopCh = make(chan struct{})
9+
10+
func serve(t *testing.T, queueNum uint16) {
11+
nfq, err := NewNFQueue(queueNum, 100, NF_DEFAULT_PACKET_SIZE)
12+
if err != nil {
13+
t.Skipf("Skipping the test due to %s", err)
14+
}
15+
defer nfq.Close()
16+
packets := nfq.GetPackets()
17+
18+
t.Logf("Starting (NFQ %d)..", queueNum)
19+
for true {
20+
select {
21+
case p := <-packets:
22+
t.Logf("Accepting %s", p.Packet)
23+
p.SetVerdict(NF_ACCEPT)
24+
case <-stopCh:
25+
t.Logf("Exiting..")
26+
return
27+
}
28+
}
29+
}
30+
31+
// very dumb test, but enough for testing golang/go#14210
32+
func TestNetfilter(t *testing.T) {
33+
queueNum := 42
34+
go serve(t, uint16(queueNum))
35+
wait := 3 * time.Second
36+
t.Logf("Sleeping for %s", wait)
37+
time.Sleep(wait)
38+
close(stopCh)
39+
}

0 commit comments

Comments
 (0)