Change module name to go.fd.io/govpp
[govpp.git] / test / integration / stats_integration_test.go
1 //  Copyright (c) 2019 Cisco and/or its affiliates.
2 //
3 //  Licensed under the Apache License, Version 2.0 (the "License");
4 //  you may not use this file except in compliance with the License.
5 //  You may obtain a copy of the License at:
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 //  Unless required by applicable law or agreed to in writing, software
10 //  distributed under the License is distributed on an "AS IS" BASIS,
11 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //  See the License for the specific language governing permissions and
13 //  limitations under the License.
14
15 // +build integration
16
17 package integration
18
19 import (
20         "flag"
21         "testing"
22
23         "go.fd.io/govpp/adapter/statsclient"
24         "go.fd.io/govpp/api"
25         "go.fd.io/govpp/core"
26 )
27
28 var (
29         statsSocket = flag.String("socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
30 )
31
32 func TestStatClientAll(t *testing.T) {
33         client := statsclient.NewStatsClient(*statsSocket)
34
35         c, err := core.ConnectStats(client)
36         if err != nil {
37                 t.Fatal("Connecting failed:", err)
38         }
39         defer c.Disconnect()
40
41         sysStats := new(api.SystemStats)
42         nodeStats := new(api.NodeStats)
43         errorStats := new(api.ErrorStats)
44         ifaceStats := new(api.InterfaceStats)
45
46         if err = c.GetNodeStats(nodeStats); err != nil {
47                 t.Fatal("updating node stats failed:", err)
48         }
49         if err = c.GetSystemStats(sysStats); err != nil {
50                 t.Fatal("updating system stats failed:", err)
51         }
52         if err = c.GetErrorStats(errorStats); err != nil {
53                 t.Fatal("updating error stats failed:", err)
54         }
55         if err = c.GetInterfaceStats(ifaceStats); err != nil {
56                 t.Fatal("updating interface stats failed:", err)
57         }
58 }
59
60 func TestStatClientNodeStats(t *testing.T) {
61         client := statsclient.NewStatsClient(*statsSocket)
62
63         c, err := core.ConnectStats(client)
64         if err != nil {
65                 t.Fatal("Connecting failed:", err)
66         }
67         defer c.Disconnect()
68
69         stats := new(api.NodeStats)
70
71         if err := c.GetNodeStats(stats); err != nil {
72                 t.Fatal("getting node stats failed:", err)
73         }
74 }
75
76 func TestStatClientNodeStatsAgain(t *testing.T) {
77         client := statsclient.NewStatsClient(*statsSocket)
78         c, err := core.ConnectStats(client)
79         if err != nil {
80                 t.Fatal("Connecting failed:", err)
81         }
82         defer c.Disconnect()
83
84         stats := new(api.NodeStats)
85
86         if err := c.GetNodeStats(stats); err != nil {
87                 t.Fatal("getting node stats failed:", err)
88         }
89         if err := c.GetNodeStats(stats); err != nil {
90                 t.Fatal("getting node stats failed:", err)
91         }
92 }
93
94 func BenchmarkStatClientNodeStatsGet1(b *testing.B)  { benchStatClientNodeStatsGet(b, 1) }
95 func BenchmarkStatClientNodeStatsGet10(b *testing.B) { benchStatClientNodeStatsGet(b, 10) }
96
97 func benchStatClientNodeStatsGet(b *testing.B, repeatN int) {
98         client := statsclient.NewStatsClient(*statsSocket)
99         c, err := core.ConnectStats(client)
100         if err != nil {
101                 b.Fatal("Connecting failed:", err)
102         }
103         defer c.Disconnect()
104
105         b.ResetTimer()
106         nodeStats := new(api.NodeStats)
107         for i := 0; i < b.N; i++ {
108                 for r := 0; r < repeatN; r++ {
109                         if err = c.GetNodeStats(nodeStats); err != nil {
110                                 b.Fatal("getting node stats failed:", err)
111                         }
112                 }
113         }
114         b.StopTimer()
115 }
116
117 func BenchmarkStatClientNodeStatsUpdate1(b *testing.B)  { benchStatClientNodeStatsLoad(b, 1) }
118 func BenchmarkStatClientNodeStatsUpdate10(b *testing.B) { benchStatClientNodeStatsLoad(b, 10) }
119
120 func benchStatClientNodeStatsLoad(b *testing.B, repeatN int) {
121         client := statsclient.NewStatsClient(*statsSocket)
122         c, err := core.ConnectStats(client)
123         if err != nil {
124                 b.Fatal("Connecting failed:", err)
125         }
126         defer c.Disconnect()
127         nodeStats := new(api.NodeStats)
128
129         b.ResetTimer()
130         for i := 0; i < b.N; i++ {
131                 for r := 0; r < repeatN; r++ {
132                         if err = c.GetNodeStats(nodeStats); err != nil {
133                                 b.Fatal("getting node stats failed:", err)
134                         }
135                 }
136         }
137         b.StopTimer()
138 }
139
140 func BenchmarkStatClientStatsUpdate1(b *testing.B)   { benchStatClientStatsUpdate(b, 1) }
141 func BenchmarkStatClientStatsUpdate10(b *testing.B)  { benchStatClientStatsUpdate(b, 10) }
142 func BenchmarkStatClientStatsUpdate100(b *testing.B) { benchStatClientStatsUpdate(b, 100) }
143
144 func benchStatClientStatsUpdate(b *testing.B, repeatN int) {
145         client := statsclient.NewStatsClient(*statsSocket)
146         c, err := core.ConnectStats(client)
147         if err != nil {
148                 b.Fatal("Connecting failed:", err)
149         }
150         defer c.Disconnect()
151
152         sysStats := new(api.SystemStats)
153         nodeStats := new(api.NodeStats)
154         errorStats := new(api.ErrorStats)
155         ifaceStats := new(api.InterfaceStats)
156
157         b.ResetTimer()
158         for i := 0; i < b.N; i++ {
159                 for r := 0; r < repeatN; r++ {
160                         if err = c.GetNodeStats(nodeStats); err != nil {
161                                 b.Fatal("updating node stats failed:", err)
162                         }
163                         if err = c.GetSystemStats(sysStats); err != nil {
164                                 b.Fatal("updating system stats failed:", err)
165                         }
166                         if err = c.GetErrorStats(errorStats); err != nil {
167                                 b.Fatal("updating error stats failed:", err)
168                         }
169                         if err = c.GetInterfaceStats(ifaceStats); err != nil {
170                                 b.Fatal("updating error stats failed:", err)
171                         }
172                 }
173         }
174         b.StopTimer()
175 }