-
Notifications
You must be signed in to change notification settings - Fork 17
/
integration_test.go
193 lines (177 loc) · 6 KB
/
integration_test.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
188
189
190
191
192
193
// Package viamcartographer_test tests the functions that require injected components (such as robot and camera)
// in order to be run. It utilizes the internal package located in testhelper.go to access
// certain exported functions which we do not want to make available to the user. It also runs integration tests
// that test the interaction with the core C++ viam-cartographer code and the Golang implementation of the
// cartographer slam service.
package viamcartographer_test
import (
"os"
"path/filepath"
"testing"
"time"
"go.viam.com/rdk/logging"
"go.viam.com/test"
viamcartographer "github.com/viam-modules/viam-cartographer"
"github.com/viam-modules/viam-cartographer/cartofacade"
"github.com/viam-modules/viam-cartographer/testhelper"
)
// saveInternalState saves cartographer's internal state in the data directory.
func saveInternalState(t *testing.T, internalState []byte, dataDir string) string {
timeStamp := time.Now().UTC()
internalStateDir := filepath.Join(dataDir, "internal_state")
err := os.Mkdir(internalStateDir, 0o755)
test.That(t, err, test.ShouldBeNil)
filename := filepath.Join(internalStateDir, "map_data_"+timeStamp.UTC().Format(testhelper.SlamTimeFormat)+".pbstream")
err = os.WriteFile(filename, internalState, 0o644)
test.That(t, err, test.ShouldBeNil)
return filename
}
// TestIntegrationCartographer provides end-to-end testing of viam-cartographer using a combination of live vs. replay cameras
// and imu enabled mode.
func TestIntegrationCartographer(t *testing.T) {
logger := logging.NewTestLogger(t)
cases := []struct {
description string
online bool
imuEnabled bool
odometerEnabled bool
mode cartofacade.SlamMode
subAlgo viamcartographer.SubAlgo
}{
// Online run with lidar only
{
description: "online mapping mode 2D with lidar only",
online: true,
imuEnabled: false,
odometerEnabled: false,
mode: cartofacade.MappingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online localizing mode 2D with lidar only",
online: true,
imuEnabled: false,
odometerEnabled: false,
mode: cartofacade.LocalizingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online updating mode 2D with lidar only",
online: true,
imuEnabled: false,
odometerEnabled: false,
mode: cartofacade.UpdatingMode,
subAlgo: viamcartographer.Dim2d,
},
// Offline run with lidar only
{
description: "offline mapping mode 2D with lidar only",
online: false,
imuEnabled: false,
odometerEnabled: false,
mode: cartofacade.MappingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "offline updating mode 2D with lidar only",
online: false,
imuEnabled: false,
odometerEnabled: false,
mode: cartofacade.UpdatingMode,
subAlgo: viamcartographer.Dim2d,
},
// Online run with lidar + imu
{
description: "online mapping mode 2D with lidar + imu",
online: true,
imuEnabled: true,
odometerEnabled: false,
mode: cartofacade.MappingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online localizing mode 2D with lidar + imu",
online: true,
imuEnabled: true,
odometerEnabled: false,
mode: cartofacade.LocalizingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online updating mode 2D with lidar + imu",
online: true,
imuEnabled: true,
odometerEnabled: false,
mode: cartofacade.UpdatingMode,
subAlgo: viamcartographer.Dim2d,
},
// Online run with lidar + odometer
{
description: "online mapping mode 2D with lidar + odometer",
online: true,
imuEnabled: false,
odometerEnabled: true,
mode: cartofacade.MappingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online localizing mode 2D with lidar + odometer",
online: true,
imuEnabled: false,
odometerEnabled: true,
mode: cartofacade.LocalizingMode,
subAlgo: viamcartographer.Dim2d,
},
{
description: "online updating mode 2D with lidar + odometer",
online: true,
imuEnabled: false,
odometerEnabled: true,
mode: cartofacade.UpdatingMode,
subAlgo: viamcartographer.Dim2d,
},
}
// Loop over defined test cases, resetting the directories between slam sessions
for _, tt := range cases {
t.Run(tt.description, func(t *testing.T) {
// 1. Run cartographer in mapping mode
enableMapping := true
// Prep first run directory
dataDirectory1, err := os.MkdirTemp("", "*")
test.That(t, err, test.ShouldBeNil)
defer func() {
err := os.RemoveAll(dataDirectory1)
test.That(t, err, test.ShouldBeNil)
}()
// Run mapping test
internalState := testhelper.IntegrationCartographer(
t, "", tt.subAlgo, logger, tt.online,
tt.imuEnabled, tt.odometerEnabled, enableMapping, cartofacade.MappingMode,
)
// 2. Return if we're only testing mapping mode, as we are done with
// mapping at this point
if tt.mode == cartofacade.MappingMode {
return
}
// 3. Run cartographer either in localizing or updating mode
if tt.mode == cartofacade.LocalizingMode {
enableMapping = false
}
// Prep second run directory
dataDirectory2, err := os.MkdirTemp("", "*")
test.That(t, err, test.ShouldBeNil)
defer func() {
err := os.RemoveAll(dataDirectory2)
test.That(t, err, test.ShouldBeNil)
}()
// Save internal state
existingMap := saveInternalState(t, internalState, dataDirectory2)
test.That(t, existingMap, test.ShouldNotEqual, "")
// Run follow-up updating or localizing test
testhelper.IntegrationCartographer(
t, existingMap, tt.subAlgo, logger, tt.online,
tt.imuEnabled, tt.odometerEnabled, enableMapping, tt.mode,
)
})
}
}