forked from aregm/nff-go
/
types.go
187 lines (162 loc) · 4.3 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2017 Intel Corporation.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package test
import (
"encoding/json"
"fmt"
)
//go:generate stringer -type=AppType,TestType,TestStatus types.go
// TestStatus is a status of the test.
type TestStatus int
// Constants for different test statuses.
const (
TestCreated TestStatus = iota
TestInitialized
TestInvalid
TestRunning
TestReportedPassed
TestReportedFailed
TestTimedOut
TestInterrupted
)
// UnmarshalJSON unmarshals data and checks app type validity.
func (at *TestStatus) UnmarshalJSON(data []byte) error {
// Extract the string from data.
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("TestStatus should be a string, got %s", data)
}
// Use map to get int keys for string values
got, ok := map[string]TestStatus{
"TestCreated": TestCreated,
"TestInitialized": TestInitialized,
"TestInvalid": TestInvalid,
"TestRunning": TestRunning,
"TestReportedPassed": TestReportedPassed,
"TestReportedFailed": TestReportedFailed,
"TestTimedOut": TestTimedOut,
"TestInterrupted": TestInterrupted,
}[s]
if !ok {
return fmt.Errorf("invalid TestStatus %q", s)
}
*at = got
return nil
}
// AppType is a type of application.
type AppType int
// Constants for different application types.
const (
TestAppGo AppType = iota
TestAppPerf
TestAppPktgen
TestAppApacheBenchmark
TestAppLatency
TestAppWrkBenchmark
)
// UnmarshalJSON unmarshals data and checks app type validity.
func (at *AppType) UnmarshalJSON(data []byte) error {
// Extract the string from data.
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("app-type should be a string, got %s", data)
}
// Use map to get int keys for string values
got, ok := map[string]AppType{
"TestAppGo": TestAppGo,
"TestAppPerf": TestAppPerf,
"TestAppPktgen": TestAppPktgen,
"TestAppApacheBenchmark": TestAppApacheBenchmark,
"TestAppLatency": TestAppLatency,
"TestAppWrkBenchmark": TestAppWrkBenchmark,
}[s]
if !ok {
return fmt.Errorf("invalid AppType %q", s)
}
*at = got
return nil
}
// TestType is a type of the test.
type TestType int
// Constants for different test types.
const (
TestTypeBenchmark TestType = iota
TestTypeScenario
TestTypeApacheBenchmark
TestTypeLatency
TestTypeWrkBenchmark
)
// UnmarshalJSON unmarshals data and checks test type validity.
func (at *TestType) UnmarshalJSON(data []byte) error {
// Extract the string from data.
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("app-type should be a string, got %s", data)
}
// Use map to get int keys for string values
got, ok := map[string]TestType{
"TestTypeBenchmark": TestTypeBenchmark,
"TestTypeScenario": TestTypeScenario,
"TestTypeApacheBenchmark": TestTypeApacheBenchmark,
"TestTypeLatency": TestTypeLatency,
"TestTypeWrkBenchmark": TestTypeWrkBenchmark,
}[s]
if !ok {
return fmt.Errorf("invalid TestType %q", s)
}
*at = got
return nil
}
// PktgenMeasurement has measured by pktgen benchmark values.
type PktgenMeasurement struct {
PktsTX, MbitsTX, PktsRX, MbitsRX int64
}
// CoresInfo has info about used and free cores.
type CoresInfo struct {
CoresUsed, CoresFree int
}
// ReportCoresInfo has info about cores for final report
type ReportCoresInfo struct {
CoresInfo
CoreLastValue int
CoreDecreased bool
}
// Indexes in array of Apache Benchmark stats ApacheBenchmarkStats
const (
AbRequestsPerSecond = iota
AbTimePerRequest
AbTimePerRequestConcurrent
AbTransferRate
)
// ApacheBenchmarkStats has info about running Apache Benchmark web
// client.
type ApacheBenchmarkStats struct {
Stats [4]float64
}
// Indexes in array of latency stats LatencyStats
const (
ReceivedSentRatio = iota
Speed
MedianLatency
AverageLatency
Stddev
)
// LatencyStats has info about finished latency perf test
type LatencyStats struct {
Stats [5]float64
}
// Indexes in array of Wireshark Benchmark stats WrkBenchmarkStats
const (
WrkRequestsPerSecond = iota
WrkTransferRate
)
type WrkBenchmarkStats struct {
Stats [2]float64
}
// TestReport has info about test status and application.
type TestReport struct {
AppIndex int
AppStatus TestStatus
msg string
}