API
 
Loading...
Searching...
No Matches
dm_test.cpp
Go to the documentation of this file.
1// #define CATCH_CONFIG_MAIN
2#include "../../../../tests/catch2/catch.hpp"
3
4#include <mx/sys/timeUtils.hpp>
5
6#include "dm_test.hpp"
7
8
9/** \defgroup dm_tests libXWC::app::dev::dm Unit Tests
10 * \ingroup app_dev_unit_tests
11 */
12
13/// Test dm Configuration
14/**
15 * \ingroup dm_tests
16 */
17TEST_CASE( "Test dm Configuration", "[dev::dm]" )
18{
19 SECTION( "a config file with no [dm] section, loading defaults" )
20 {
21 // Just a dummy config setting
22 mx::app::writeConfigFile( "/tmp/dm_test.conf", { "none" }, { "nada" }, { "0" } );
23
24 mx::app::appConfigurator config;
25
26 dm_tests::dmTest pdt( "xx", false );
27
28 int rv;
29 rv = pdt.setupConfig( config );
30 REQUIRE( rv == 0 );
31
32 config.readConfig( "/tmp/dm_test.conf" );
33
34 rv = pdt.loadConfig( config );
35 REQUIRE( rv == 0 );
36
37 REQUIRE( pdt.calibPath() == "/tmp/dmtest_calibs/dmtest" );
38
39 // There will be no shmimName set
40 REQUIRE( pdt.shmimName() == "" );
41 }
42
43 /// \todo finish implementing this
44 SECTION( "a config file with a [dm] section changing everything" )
45 {
46
47 std::vector<std::string> s, k, v;
48
49 s.push_back( "dm" );
50 k.push_back( "calibPath" );
51 v.push_back( "/tmp/dmtest_calibs2/dmtest2" );
52
53 mx::app::writeConfigFile( "/tmp/dm_test.conf", s, k, v );
54
55 mx::app::appConfigurator config;
56
57 dm_tests::dmTest pdt( "xx", false );
58
59 int rv;
60 rv = pdt.setupConfig( config );
61 REQUIRE( rv == 0 );
62
63 config.readConfig( "/tmp/dm_test.conf" );
64
65 rv = pdt.loadConfig( config );
66 REQUIRE( rv == 0 );
67
68 REQUIRE( pdt.calibPath() == "/tmp/dmtest_calibs2/dmtest2" );
69 }
70
71#ifdef XWCTEST_DOX_REF
75#endif
76}
77
78/// Test dmcomb detection, configuration, and manipulation
79/**
80 * \ingroup dm_tests
81 */
82TEST_CASE( "Test dmcomb detection, configuration, and manipulation", "[dev::dm]" )
83{
84 mx::ioutils::createDirectories( "/tmp/dmtest/shm" );
85
86 char ppath[1024];
87 snprintf( ppath, sizeof( ppath ), "%s=/tmp/dmtest/shm", "MILK_SHM_DIR" );
88 putenv( ppath );
89
90 mx::improc::milkImage<float> ch0, ch1, ch2, ch3, ch4, chT;
91 try
92 {
93
94 ch0.create( "dmtest00", 50, 50 );
95 ch0().setConstant(1);
96
97 ch1.create( "dmtest01", 50, 50 );
98 ch1().setConstant(2);
99
100 ch2.create( "dmtest02", 50, 50 );
101 ch2().setConstant(3);
102
103 ch3.create( "dmtest03", 50, 50 );
104 ch3().setConstant(4);
105
106 ch4.create( "dmtest04", 50, 50 );
107 ch4().setConstant(5);
108
109 chT.create( "dmtest", 50, 50 );
110 chT() = ch0() + ch1() + ch2() + ch3() + ch4();
111
112 }
113 catch( const std::exception &e )
114 {
115 std::cerr << "dm_test: Exception creating dm channels: " << e.what() << '\n';
116 }
117
118 std::vector<std::string> s, k, v;
119
120 s.push_back( "dm" );
121 k.push_back( "shmimName" );
122 v.push_back( "dmtest" );
123
124 s.push_back( "dm" );
125 k.push_back( "width" );
126 v.push_back( "50" );
127
128 s.push_back( "dm" );
129 k.push_back( "height" );
130 v.push_back( "50" );
131
132 s.push_back( "dm" );
133 k.push_back( "deltaChannels" );
134 v.push_back( "dmtest02,dmtest03" );
135
136 mx::app::writeConfigFile( "/tmp/dm_test.conf", s, k, v );
137
138 mx::app::appConfigurator config;
139
140 dm_tests::dmTest pdt( "xx", false );
141
142 int rv;
143 rv = pdt.setupConfig( config );
144 REQUIRE( rv == 0 );
145
146 config.readConfig( "/tmp/dm_test.conf" );
147
148 rv = pdt.loadConfig( config );
149 REQUIRE( rv == 0 );
150
151 REQUIRE( pdt.shmimName() == "dmtest" );
152
153 pdt.setSize( 50, 50, IMAGESTRUCT_FLOAT );
154
155 rv = pdt.allocate( MagAOX::app::dev::shmimT() );
156
157 REQUIRE( rv == 0 );
158
159 int rows = pdt.instSatMap().rows();
160 REQUIRE( rows == 50 );
161
162 int cols = pdt.instSatMap().cols();
163 REQUIRE( cols == 50 );
164
165 rows = pdt.accumSatMap().rows();
166 REQUIRE( rows == 50 );
167
168 cols = pdt.accumSatMap().cols();
169 REQUIRE( cols == 50 );
170
171 rows = pdt.satPercMap().rows();
172 REQUIRE( rows == 50 );
173
174 cols = pdt.satPercMap().cols();
175 REQUIRE( cols == 50 );
176
177 int nc = pdt.numChannels();
178 REQUIRE( nc == 5 );
179
180 size_t nd = pdt.deltaChannels().size();
181 REQUIRE( nd == 2);
182
183 const std::vector<size_t> &notDeltas = pdt.notDeltas();
184 REQUIRE(notDeltas.size() == 3);
185 REQUIRE(notDeltas[0] == 0);
186 REQUIRE(notDeltas[1] == 1);
187 REQUIRE(notDeltas[2] == 4);
188
189 mx::improc::milkImage<float> outputShape;
190 bool pass = false;
191 try
192 {
193 outputShape.open("dmtest_shape");
194 pass = true;
195 }
196 catch(...)
197 {}
198
199 REQUIRE(pass == true);
200 REQUIRE(outputShape.rows() == 50);
201 REQUIRE(outputShape.cols() == 50);
202 REQUIRE(outputShape().sum() == 0);
203
204 outputShape = chT;
205 float sum = outputShape().sum();
206 REQUIRE(sum == (50*50)*(1+2+3+4+5));
207
208 mx::improc::milkImage<float> outputDelta;
209 pass = false;
210 try
211 {
212 outputDelta.open("dmtest_delta");
213 pass = true;
214 }
215 catch(...)
216 {}
217
218 REQUIRE(pass == true);
219 REQUIRE(outputDelta.rows() == 50);
220 REQUIRE(outputDelta.cols() == 50);
221 REQUIRE(outputDelta().sum() == 0);
222
223 rows = pdt.totalFlat().rows();
224 REQUIRE( rows == 50 );
225
226 cols = pdt.totalFlat().cols();
227 REQUIRE( cols == 50 );
228
229 sum = pdt.totalFlat().sum();
230 REQUIRE(sum == 0);
231
232 pdt.makeDelta();
233
234 sum = pdt.totalFlat().sum();
235 REQUIRE(sum == (50*50)*(1+2+5));
236
237 //Check that it's still the same
238 sum = outputShape().sum();
239 REQUIRE(sum == (50*50)*(1+2+3+4+5));
240
241 sum = outputDelta().sum();
242 REQUIRE(sum == (50*50)*(3+4));
243
244}
245
246#if 0
247/// Test dm app logic
248/**
249 * \ingroup dm_tests
250 */
251TEST_CASE( "Test dm app logic", "[dev::dm]" )
252{
253 SECTION( "no errors" )
254 {
255 // Just a dummy config setting
256 mx::app::writeConfigFile( "/tmp/dm_test.conf", { "none" }, { "nada" }, { "0" } );
257
258 mx::app::appConfigurator config;
259
260 dm_tests::dmTest pdt( "xx", false );
261
262 int rv;
263 rv = pdt.setupConfig( config );
264 REQUIRE( rv == 0 );
265
266 config.readConfig( "/tmp/dm_test.conf" );
267
268 rv = pdt.loadConfig( config );
269 REQUIRE( rv == 0 );
270
271 pdt.m_tel.logPath( "/tmp/telems" );
272
273 rv = pdt.appStartup();
274 REQUIRE( rv == 0 );
275
276 rv = pdt.appLogic();
277 REQUIRE( rv == 0 );
278
279 rv = pdt.appShutdown();
280 REQUIRE( rv == 0 );
281 }
282
283 SECTION( "log thread shutsdown" )
284 {
285 // Just a dummy config setting
286 mx::app::writeConfigFile( "/tmp/dm_test.conf", { "none" }, { "nada" }, { "0" } );
287
288 mx::app::appConfigurator config;
289
290 dm_tests::dmTest pdt( "xx", false );
291
292 int rv;
293 rv = pdt.setupConfig( config );
294 REQUIRE( rv == 0 );
295
296 config.readConfig( "/tmp/dm_test.conf" );
297
298 rv = pdt.loadConfig( config );
299 REQUIRE( rv == 0 );
300
301 pdt.m_tel.logPath( "/tmp/telems" );
302
303 rv = pdt.appStartup();
304 REQUIRE( rv == 0 );
305
306 rv = pdt.appLogic();
307 REQUIRE( rv == 0 );
308
309 pdt.m_tel.logShutdown( true );
310 sleep( 1 );
311
312 rv = pdt.appLogic();
313 REQUIRE( rv == -1 );
314
315 rv = pdt.appShutdown();
316 REQUIRE( rv == 0 );
317 }
318
319 #ifdef XWCTEST_DOX_REF
325 #endif
326}
327
328/// Test dm telem-logger fails to start
329/**
330 * \ingroup dm_tests
331 */
332TEST_CASE( "Test dm telem-logger fails to start", "[dev::dm]" )
333{
334 // Just a dummy config setting
335 mx::app::writeConfigFile( "/tmp/dm_test.conf", { "none" }, { "nada" }, { "0" } );
336
337 mx::app::appConfigurator config;
338
339 dm_tests::XWCTEST_TELEMETER_LOGSTART_ns::dmTest pdt( "xx", false );
340
341 int rv;
342 rv = pdt.setupConfig( config );
343 REQUIRE( rv == 0 );
344
345 config.readConfig( "/tmp/dm_test.conf" );
346
347 rv = pdt.loadConfig( config );
348 REQUIRE( rv == 0 );
349
350 pdt.m_tel.logPath( "/tmp/telems" );
351
352 rv = pdt.appStartup();
353 REQUIRE( rv == -1 );
354
355 #ifdef XWCTEST_DOX_REF
359 #endif
360}
361
362#endif
#define IMAGESTRUCT_FLOAT
int appShutdown()
DM shutdown.
Definition dm.hpp:1617
const std::string & calibPath() const
Get the.
Definition dm.hpp:822
int loadConfig(mx::app::appConfigurator &config)
load the configuration system results
Definition dm.hpp:1255
int appStartup()
Startup function.
Definition dm.hpp:1405
int setupConfig(mx::app::appConfigurator &config)
Setup the configuration system.
Definition dm.hpp:984
int appLogic()
DM application logic.
Definition dm.hpp:1551
int nc
Definition cycle.cpp:13
TEST_CASE("Test dm Configuration", "[dev::dm]")
Test dm Configuration.
Definition dm_test.cpp:17
Test harness for dev::dm.
Definition dm_test.hpp:30
int setupConfig(mx::app::appConfigurator &config)
Definition dm_test.hpp:48
int loadConfig(mx::app::appConfigurator &config)
Definition dm_test.hpp:53
void setSize(int w, int h, int d)
Definition dm_test.hpp:88