MCPcopy Create free account
hub / github.com/google/nftables / TestBitwise

Function TestBitwise

expr/bitwise_test.go:12–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestBitwise(t *testing.T) {
13 t.Parallel()
14 tests := []struct {
15 name string
16 bw Bitwise
17 }{
18 {
19 name: "Unmarshal Bitwise IPv4 case",
20 bw: Bitwise{
21 SourceRegister: 1,
22 DestRegister: 2,
23 Len: 4,
24 // By specifying Xor to 0x0,0x0,0x0,0x0 and Mask to 0xff,0xff,0x0,0x0
25 // an expression will match /16 IPv4 address.
26 Xor: []byte{0x0, 0x0, 0x0, 0x0},
27 Mask: []byte{0xff, 0xff, 0x0, 0x0},
28 },
29 },
30 }
31
32 for _, tt := range tests {
33 t.Run(tt.name, func(t *testing.T) {
34 nbw := Bitwise{}
35 data, err := tt.bw.marshal(0 /* don't care in this test */)
36 if err != nil {
37 t.Fatalf("marshal error: %+v", err)
38
39 }
40 ad, err := netlink.NewAttributeDecoder(data)
41 if err != nil {
42 t.Fatalf("NewAttributeDecoder() error: %+v", err)
43 }
44 ad.ByteOrder = binary.BigEndian
45 for ad.Next() {
46 if ad.Type() == unix.NFTA_EXPR_DATA {
47 if err := nbw.unmarshal(0, ad.Bytes()); err != nil {
48 t.Errorf("unmarshal error: %+v", err)
49 break
50 }
51 }
52 }
53 if !reflect.DeepEqual(tt.bw, nbw) {
54 t.Fatalf("original %+v and recovered %+v Bitwise structs are different", tt.bw, nbw)
55 }
56 })
57 }
58}

Callers

nothing calls this directly

Calls 2

unmarshalMethod · 0.95
marshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…