Repository navigation
Expand file tree
/
Copy pathvalidate_test.go
More file actions
171 lines (163 loc) · 5.21 KB
/
Copy pathvalidate_test.go
File metadata and controls
171 lines (163 loc) · 5.21 KB
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
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved. This file is part of cc-lib.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package schema
import (
"bytes"
"encoding/json"
"reflect"
"testing"
)
func TestValidateCluster(t *testing.T) {
json := []byte(`{
"name": "emmy",
"subClusters": [
{
"name": "main",
"processorType": "Intel IvyBridge",
"socketsPerNode": 2,
"coresPerSocket": 10,
"threadsPerCore": 2,
"flopRateScalar": {
"unit": {
"prefix": "G",
"base": "F/s"
},
"value": 14
},
"flopRateSimd": {
"unit": {
"prefix": "G",
"base": "F/s"
},
"value": 112
},
"memoryBandwidth": {
"unit": {
"prefix": "G",
"base": "B/s"
},
"value": 24
},
"numberOfNodes": 70,
"nodes": "w11[27-45,49-63,69-72]",
"topology": {
"node": [0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29,10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39],
"socket": [
[0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29],
[10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39]
],
"memoryDomain": [
[0,20,1,21,2,22,3,23,4,24,5,25,6,26,7,27,8,28,9,29],
[10,30,11,31,12,32,13,33,14,34,15,35,16,36,17,37,18,38,19,39]
],
"core": [
[0,20],[1,21],[2,22],[3,23],[4,24],[5,25],[6,26],[7,27],[8,28],[9,29],[10,30],[11,31],[12,32],[13,33],[14,34],[15,35],[16,36],[17,37],[18,38],[19,39]
]
}
}
],
"metricConfig": [
{
"name": "cpu_load",
"scope": "hwthread",
"unit": {"base": ""},
"aggregation": "avg",
"timestep": 60,
"peak": 4,
"normal": 2,
"caution": 1,
"alert": 0.25
}
]
}`)
if err := Validate(ClusterCfg, bytes.NewReader(json)); err != nil {
t.Errorf("Error is not nil! %v", err)
}
}
// deviceClusterJSON returns a minimal cluster.json whose single subcluster
// topology carries the given extra topology members and whose metric has the
// given native scope.
func deviceClusterJSON(topologyExtra, scope string) string {
return `{
"name": "fritz",
"subClusters": [{
"name": "main",
"processorType": "Intel Icelake",
"socketsPerNode": 1,
"coresPerSocket": 2,
"threadsPerCore": 1,
"flopRateScalar": {"unit": {"base": "F/s", "prefix": "G"}, "value": 10},
"flopRateSimd": {"unit": {"base": "F/s", "prefix": "G"}, "value": 80},
"memoryBandwidth": {"unit": {"base": "B/s", "prefix": "G"}, "value": 100},
"nodes": "f[01-02]",
"topology": {
"node": [0, 1],
"socket": [[0, 1]],
"memoryDomain": [[0, 1]],
"core": [[0], [1]]` + topologyExtra + `
}
}],
"metricConfig": [{
"name": "fs_read_bw",
"scope": "` + scope + `",
"unit": {"base": "B/s"},
"aggregation": "sum",
"timestep": 60,
"peak": 1000,
"normal": 100,
"caution": 10,
"alert": 1
}]
}`
}
func TestValidateCluster_DeviceTopology(t *testing.T) {
const devices = `,
"filesystems": [{"id": "/home", "type": "nfs"}, {"id": "/scratch", "type": "lustre"}],
"networks": [{"id": "ib0", "type": "infiniband"}]`
tests := []struct {
name string
extra string
scope string
wantErr bool
}{
{"filesystem scope with devices", devices, "filesystem", false},
{"network scope with devices", devices, "network", false},
{"no device lists", "", "node", false},
{"unknown scope", devices, "mountpoint", true},
{"unknown filesystem type", `, "filesystems": [{"id": "/home", "type": "ntfs"}]`, "filesystem", true},
{"filesystem without type", `, "filesystems": [{"id": "/home"}]`, "filesystem", true},
{"unknown network type", `, "networks": [{"id": "eth0", "type": "token-ring"}]`, "network", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := Validate(ClusterCfg, bytes.NewReader([]byte(deviceClusterJSON(tt.extra, tt.scope))))
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestValidateCluster_DeviceTopologyDecodes(t *testing.T) {
const devices = `,
"filesystems": [{"id": "/home", "type": "nfs"}, {"id": "/scratch", "type": "lustre"}],
"networks": [{"id": "ib0", "type": "infiniband"}]`
var c Cluster
if err := json.Unmarshal([]byte(deviceClusterJSON(devices, "filesystem")), &c); err != nil {
t.Fatalf("unmarshal: %v", err)
}
topo := c.SubClusters[0].Topology
if got := topo.GetFilesystemIDs(); !reflect.DeepEqual(got, []string{"/home", "/scratch"}) {
t.Errorf("filesystem ids = %v", got)
}
if topo.Filesystems[1].Type != "lustre" {
t.Errorf("filesystem type = %q, want lustre", topo.Filesystems[1].Type)
}
if got := topo.GetNetworkIDs(); !reflect.DeepEqual(got, []string{"ib0"}) {
t.Errorf("network ids = %v", got)
}
if c.MetricConfig[0].Scope != MetricScopeFilesystem {
t.Errorf("metric scope = %q, want filesystem", c.MetricConfig[0].Scope)
}
}