]> sigrok.org Git - pulseview.git/blame - test/data/logicsnapshot.cpp
Build system: Fix issue with unit tests, simplify code.
[pulseview.git] / test / data / logicsnapshot.cpp
CommitLineData
4ceab49a 1/*
b3f22de0 2 * This file is part of the PulseView project.
4ceab49a
JH
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
cef18fc6
JH
21#include <extdef.h>
22
8743e7cb
JH
23#include <stdint.h>
24
4ceab49a
JH
25#include <boost/test/unit_test.hpp>
26
2acdb232 27#include <pv/data/logicsnapshot.hpp>
4ceab49a 28
1b1ec774 29using pv::data::LogicSnapshot;
819f4c25 30using std::vector;
51e77110 31
48ecc1fc 32#if 0
1b1ec774 33BOOST_AUTO_TEST_SUITE(LogicSnapshotTest)
ecda6ca9 34
1b1ec774 35void push_logic(LogicSnapshot &s, unsigned int length, uint8_t value)
4ceab49a
JH
36{
37 sr_datafeed_logic logic;
38 logic.unitsize = 1;
39 logic.length = length;
40 logic.data = new uint8_t[length];
41 memset(logic.data, value, length * logic.unitsize);
42 s.append_payload(logic);
43 delete[] (uint8_t*)logic.data;
44}
45
8743e7cb
JH
46BOOST_AUTO_TEST_CASE(Pow2)
47{
1b1ec774
JH
48 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(0, 0), 0);
49 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(1, 0), 1);
50 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(2, 0), 2);
8743e7cb
JH
51
52 BOOST_CHECK_EQUAL(
1b1ec774 53 LogicSnapshot::pow2_ceil(INT64_MIN, 0), INT64_MIN);
8743e7cb 54 BOOST_CHECK_EQUAL(
1b1ec774 55 LogicSnapshot::pow2_ceil(INT64_MAX, 0), INT64_MAX);
8743e7cb 56
1b1ec774
JH
57 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(0, 1), 0);
58 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(1, 1), 2);
59 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(2, 1), 2);
60 BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(3, 1), 4);
8743e7cb
JH
61}
62
ecda6ca9 63BOOST_AUTO_TEST_CASE(Basic)
4ceab49a 64{
1b1ec774 65 // Create an empty LogicSnapshot object
4ceab49a
JH
66 sr_datafeed_logic logic;
67 logic.length = 0;
68 logic.unitsize = 1;
69 logic.data = NULL;
70
1b1ec774 71 LogicSnapshot s(logic);
4ceab49a 72
1b1ec774 73 //----- Test LogicSnapshot::push_logic -----//
0b02e057 74
4ceab49a 75 BOOST_CHECK(s.get_sample_count() == 0);
1b1ec774 76 for (unsigned int i = 0; i < LogicSnapshot::ScaleStepCount; i++)
4ceab49a 77 {
8dbbc7f0 78 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
79 BOOST_CHECK_EQUAL(m.length, 0);
80 BOOST_CHECK_EQUAL(m.data_length, 0);
81 BOOST_CHECK(m.data == NULL);
82 }
83
84 // Push 8 samples of all zeros
85 push_logic(s, 8, 0);
86
87 BOOST_CHECK(s.get_sample_count() == 8);
88
89 // There should not be enough samples to have a single mip map sample
1b1ec774 90 for (unsigned int i = 0; i < LogicSnapshot::ScaleStepCount; i++)
4ceab49a 91 {
8dbbc7f0 92 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
93 BOOST_CHECK_EQUAL(m.length, 0);
94 BOOST_CHECK_EQUAL(m.data_length, 0);
95 BOOST_CHECK(m.data == NULL);
96 }
97
98 // Push 8 samples of 0x11s to bring the total up to 16
99 push_logic(s, 8, 0x11);
100
101 // There should now be enough data for exactly one sample
102 // in mip map level 0, and that sample should be 0
8dbbc7f0 103 const LogicSnapshot::MipMapLevel &m0 = s.mip_map_[0];
4ceab49a 104 BOOST_CHECK_EQUAL(m0.length, 1);
1b1ec774 105 BOOST_CHECK_EQUAL(m0.data_length, LogicSnapshot::MipMapDataUnit);
4ceab49a
JH
106 BOOST_REQUIRE(m0.data != NULL);
107 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[0], 0x11);
108
109 // The higher levels should still be empty
1b1ec774 110 for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++)
4ceab49a 111 {
8dbbc7f0 112 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
113 BOOST_CHECK_EQUAL(m.length, 0);
114 BOOST_CHECK_EQUAL(m.data_length, 0);
115 BOOST_CHECK(m.data == NULL);
116 }
117
118 // Push 240 samples of all zeros to bring the total up to 256
119 push_logic(s, 240, 0);
120
121 BOOST_CHECK_EQUAL(m0.length, 16);
1b1ec774 122 BOOST_CHECK_EQUAL(m0.data_length, LogicSnapshot::MipMapDataUnit);
4ceab49a
JH
123
124 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[1], 0x11);
333d5bbc 125 for (unsigned int i = 2; i < m0.length; i++)
4ceab49a
JH
126 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[i], 0);
127
8dbbc7f0 128 const LogicSnapshot::MipMapLevel &m1 = s.mip_map_[1];
4ceab49a 129 BOOST_CHECK_EQUAL(m1.length, 1);
1b1ec774 130 BOOST_CHECK_EQUAL(m1.data_length, LogicSnapshot::MipMapDataUnit);
4ceab49a
JH
131 BOOST_REQUIRE(m1.data != NULL);
132 BOOST_CHECK_EQUAL(((uint8_t*)m1.data)[0], 0x11);
0b02e057 133
1b1ec774 134 //----- Test LogicSnapshot::get_subsampled_edges -----//
0b02e057
JH
135
136 // Test a full view at full zoom.
1b1ec774 137 vector<LogicSnapshot::EdgePair> edges;
0b02e057
JH
138 s.get_subsampled_edges(edges, 0, 255, 1, 0);
139 BOOST_REQUIRE_EQUAL(edges.size(), 4);
140
141 BOOST_CHECK_EQUAL(edges[0].first, 0);
142 BOOST_CHECK_EQUAL(edges[1].first, 8);
143 BOOST_CHECK_EQUAL(edges[2].first, 16);
175d6573 144 BOOST_CHECK_EQUAL(edges[3].first, 256);
0b02e057
JH
145
146 // Test a subset at high zoom
147 edges.clear();
148 s.get_subsampled_edges(edges, 6, 17, 0.05f, 0);
149 BOOST_REQUIRE_EQUAL(edges.size(), 4);
150
151 BOOST_CHECK_EQUAL(edges[0].first, 6);
152 BOOST_CHECK_EQUAL(edges[1].first, 8);
153 BOOST_CHECK_EQUAL(edges[2].first, 16);
175d6573 154 BOOST_CHECK_EQUAL(edges[3].first, 18);
4ceab49a 155}
ecda6ca9
JH
156
157BOOST_AUTO_TEST_CASE(LargeData)
158{
159 uint8_t prev_sample;
38f5609e 160 const unsigned int Length = 1000000;
ecda6ca9
JH
161
162 sr_datafeed_logic logic;
163 logic.unitsize = 1;
164 logic.length = Length;
165 logic.data = new uint8_t[Length];
166 uint8_t *data = (uint8_t*)logic.data;
167
333d5bbc 168 for (unsigned int i = 0; i < Length; i++)
ecda6ca9
JH
169 *data++ = (uint8_t)(i >> 8);
170
1b1ec774 171 LogicSnapshot s(logic);
ecda6ca9
JH
172 delete[] (uint8_t*)logic.data;
173
174 BOOST_CHECK(s.get_sample_count() == Length);
175
176 // Check mip map level 0
8dbbc7f0
JH
177 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 62500);
178 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
1b1ec774 179 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 180 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
ecda6ca9
JH
181
182 prev_sample = 0;
8dbbc7f0 183 for (unsigned int i = 0; i < s.mip_map_[0].length;)
ecda6ca9
JH
184 {
185 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
186
187 const uint8_t sample = (uint8_t)((i*16) >> 8);
b2bcbe51 188 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF,
ecda6ca9
JH
189 prev_sample ^ sample);
190 prev_sample = sample;
191
8dbbc7f0 192 for (int j = 1; i < s.mip_map_[0].length && j < 16; j++)
ecda6ca9
JH
193 {
194 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
b2bcbe51 195 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0);
ecda6ca9
JH
196 }
197 }
198
199 // Check mip map level 1
8dbbc7f0
JH
200 BOOST_CHECK_EQUAL(s.mip_map_[1].length, 3906);
201 BOOST_CHECK_EQUAL(s.mip_map_[1].data_length,
1b1ec774 202 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 203 BOOST_REQUIRE(s.mip_map_[1].data != NULL);
ecda6ca9
JH
204
205 prev_sample = 0;
8dbbc7f0 206 for (unsigned int i = 0; i < s.mip_map_[1].length; i++)
ecda6ca9
JH
207 {
208 BOOST_TEST_MESSAGE("Testing mip_map[1].data[" << i << "]");
209
210 const uint8_t sample = i;
211 const uint8_t expected = sample ^ prev_sample;
212 prev_sample = i;
213
b2bcbe51 214 BOOST_CHECK_EQUAL(s.get_subsample(1, i) & 0xFF, expected);
ecda6ca9
JH
215 }
216
217 // Check mip map level 2
8dbbc7f0
JH
218 BOOST_CHECK_EQUAL(s.mip_map_[2].length, 244);
219 BOOST_CHECK_EQUAL(s.mip_map_[2].data_length,
1b1ec774 220 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 221 BOOST_REQUIRE(s.mip_map_[2].data != NULL);
ecda6ca9
JH
222
223 prev_sample = 0;
8dbbc7f0 224 for (unsigned int i = 0; i < s.mip_map_[2].length; i++)
ecda6ca9
JH
225 {
226 BOOST_TEST_MESSAGE("Testing mip_map[2].data[" << i << "]");
227
228 const uint8_t sample = i << 4;
229 const uint8_t expected = (sample ^ prev_sample) | 0x0F;
230 prev_sample = sample;
231
b2bcbe51 232 BOOST_CHECK_EQUAL(s.get_subsample(2, i) & 0xFF, expected);
ecda6ca9
JH
233 }
234
235 // Check mip map level 3
8dbbc7f0
JH
236 BOOST_CHECK_EQUAL(s.mip_map_[3].length, 15);
237 BOOST_CHECK_EQUAL(s.mip_map_[3].data_length,
1b1ec774 238 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 239 BOOST_REQUIRE(s.mip_map_[3].data != NULL);
ecda6ca9 240
8dbbc7f0
JH
241 for (unsigned int i = 0; i < s.mip_map_[3].length; i++)
242 BOOST_CHECK_EQUAL(*((uint8_t*)s.mip_map_[3].data + i),
ecda6ca9
JH
243 0xFF);
244
245 // Check the higher levels
1b1ec774 246 for (unsigned int i = 4; i < LogicSnapshot::ScaleStepCount; i++)
ecda6ca9 247 {
8dbbc7f0 248 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
ecda6ca9
JH
249 BOOST_CHECK_EQUAL(m.length, 0);
250 BOOST_CHECK_EQUAL(m.data_length, 0);
251 BOOST_CHECK(m.data == NULL);
252 }
253
1b1ec774 254 //----- Test LogicSnapshot::get_subsampled_edges -----//
ac7aa636 255 // Check in normal case
1b1ec774 256 vector<LogicSnapshot::EdgePair> edges;
ecda6ca9 257 s.get_subsampled_edges(edges, 0, Length-1, 1, 7);
ecda6ca9 258
39f6e56e
JH
259 BOOST_CHECK_EQUAL(edges.size(), 32);
260
333d5bbc 261 for (unsigned int i = 0; i < edges.size() - 1; i++)
ecda6ca9 262 {
39f6e56e
JH
263 BOOST_CHECK_EQUAL(edges[i].first, i * 32768);
264 BOOST_CHECK_EQUAL(edges[i].second, i & 1);
ecda6ca9
JH
265 }
266
175d6573 267 BOOST_CHECK_EQUAL(edges[31].first, 1000000);
ac7aa636
JH
268
269 // Check in very low zoom case
270 edges.clear();
271 s.get_subsampled_edges(edges, 0, Length-1, 50e6f, 7);
272
273 BOOST_CHECK_EQUAL(edges.size(), 2);
ecda6ca9
JH
274}
275
3db297c4
JH
276BOOST_AUTO_TEST_CASE(Pulses)
277{
278 const int Cycles = 3;
279 const int Period = 64;
280 const int Length = Cycles * Period;
281
1b1ec774 282 vector<LogicSnapshot::EdgePair> edges;
3db297c4 283
1b1ec774 284 //----- Create a LogicSnapshot -----//
3db297c4
JH
285 sr_datafeed_logic logic;
286 logic.unitsize = 1;
287 logic.length = Length;
288 logic.data = (uint64_t*)new uint8_t[Length];
289 uint8_t *p = (uint8_t*)logic.data;
290
333d5bbc 291 for (int i = 0; i < Cycles; i++) {
3db297c4 292 *p++ = 0xFF;
333d5bbc 293 for (int j = 1; j < Period; j++)
3db297c4
JH
294 *p++ = 0x00;
295 }
296
1b1ec774 297 LogicSnapshot s(logic);
821f23af 298 delete[] (uint8_t*)logic.data;
3db297c4
JH
299
300 //----- Check the mip-map -----//
301 // Check mip map level 0
8dbbc7f0
JH
302 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12);
303 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
1b1ec774 304 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 305 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
3db297c4 306
8dbbc7f0 307 for (unsigned int i = 0; i < s.mip_map_[0].length;) {
3db297c4
JH
308 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
309 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0xFF);
310
333d5bbc 311 for (int j = 1;
8dbbc7f0 312 i < s.mip_map_[0].length &&
1b1ec774 313 j < Period/LogicSnapshot::MipMapScaleFactor; j++) {
3db297c4
JH
314 BOOST_TEST_MESSAGE(
315 "Testing mip_map[0].data[" << i << "]");
316 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0x00);
317 }
318 }
319
320 // Check the higher levels are all inactive
1b1ec774 321 for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++) {
8dbbc7f0 322 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
3db297c4
JH
323 BOOST_CHECK_EQUAL(m.length, 0);
324 BOOST_CHECK_EQUAL(m.data_length, 0);
325 BOOST_CHECK(m.data == NULL);
326 }
327
328 //----- Test get_subsampled_edges at reduced scale -----//
329 s.get_subsampled_edges(edges, 0, Length-1, 16.0f, 2);
7d0d64f9 330 BOOST_REQUIRE_EQUAL(edges.size(), Cycles + 2);
3db297c4 331
7d0d64f9 332 BOOST_CHECK_EQUAL(0, false);
333d5bbc 333 for (unsigned int i = 1; i < edges.size(); i++)
3db297c4
JH
334 BOOST_CHECK_EQUAL(edges[i].second, false);
335}
336
910b16ec
JH
337BOOST_AUTO_TEST_CASE(LongPulses)
338{
339 const int Cycles = 3;
340 const int Period = 64;
341 const int PulseWidth = 16;
342 const int Length = Cycles * Period;
343
344 int j;
1b1ec774 345 vector<LogicSnapshot::EdgePair> edges;
910b16ec 346
1b1ec774 347 //----- Create a LogicSnapshot -----//
910b16ec 348 sr_datafeed_logic logic;
4f767cf7 349 logic.unitsize = 8;
37fdce0a 350 logic.length = Length * 8;
4f767cf7
JH
351 logic.data = (uint64_t*)new uint64_t[Length];
352 uint64_t *p = (uint64_t*)logic.data;
910b16ec 353
333d5bbc
UH
354 for (int i = 0; i < Cycles; i++) {
355 for (j = 0; j < PulseWidth; j++)
4f767cf7 356 *p++ = ~0;
333d5bbc 357 for (; j < Period; j++)
4f767cf7 358 *p++ = 0;
910b16ec
JH
359 }
360
1b1ec774 361 LogicSnapshot s(logic);
ba3c4dae 362 delete[] (uint64_t*)logic.data;
910b16ec
JH
363
364 //----- Check the mip-map -----//
365 // Check mip map level 0
8dbbc7f0
JH
366 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12);
367 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
1b1ec774 368 LogicSnapshot::MipMapDataUnit);
8dbbc7f0 369 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
910b16ec 370
8dbbc7f0
JH
371 for (unsigned int i = 0; i < s.mip_map_[0].length;) {
372 for (j = 0; i < s.mip_map_[0].length && j < 2; j++) {
910b16ec
JH
373 BOOST_TEST_MESSAGE(
374 "Testing mip_map[0].data[" << i << "]");
4f767cf7 375 BOOST_CHECK_EQUAL(s.get_subsample(0, i++), ~0);
910b16ec
JH
376 }
377
8dbbc7f0 378 for (; i < s.mip_map_[0].length &&
1b1ec774 379 j < Period/LogicSnapshot::MipMapScaleFactor; j++) {
910b16ec
JH
380 BOOST_TEST_MESSAGE(
381 "Testing mip_map[0].data[" << i << "]");
4f767cf7 382 BOOST_CHECK_EQUAL(s.get_subsample(0, i++), 0);
910b16ec
JH
383 }
384 }
385
386 // Check the higher levels are all inactive
1b1ec774 387 for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++) {
8dbbc7f0 388 const LogicSnapshot::MipMapLevel &m = s.mip_map_[i];
910b16ec
JH
389 BOOST_CHECK_EQUAL(m.length, 0);
390 BOOST_CHECK_EQUAL(m.data_length, 0);
391 BOOST_CHECK(m.data == NULL);
392 }
393
394 //----- Test get_subsampled_edges at a full scale -----//
395 s.get_subsampled_edges(edges, 0, Length-1, 16.0f, 2);
396 BOOST_REQUIRE_EQUAL(edges.size(), Cycles * 2 + 1);
397
333d5bbc 398 for (int i = 0; i < Cycles; i++) {
910b16ec
JH
399 BOOST_CHECK_EQUAL(edges[i*2].first, i * Period);
400 BOOST_CHECK_EQUAL(edges[i*2].second, true);
401 BOOST_CHECK_EQUAL(edges[i*2+1].first, i * Period + PulseWidth);
402 BOOST_CHECK_EQUAL(edges[i*2+1].second, false);
403 }
404
175d6573 405 BOOST_CHECK_EQUAL(edges.back().first, Length);
910b16ec
JH
406 BOOST_CHECK_EQUAL(edges.back().second, false);
407
408 //----- Test get_subsampled_edges at a simplified scale -----//
409 edges.clear();
410 s.get_subsampled_edges(edges, 0, Length-1, 17.0f, 2);
411
7d0d64f9
JH
412 BOOST_CHECK_EQUAL(edges[0].first, 0);
413 BOOST_CHECK_EQUAL(edges[0].second, true);
414 BOOST_CHECK_EQUAL(edges[1].first, 16);
415 BOOST_CHECK_EQUAL(edges[1].second, false);
416
333d5bbc 417 for (int i = 1; i < Cycles; i++) {
7d0d64f9
JH
418 BOOST_CHECK_EQUAL(edges[i+1].first, i * Period);
419 BOOST_CHECK_EQUAL(edges[i+1].second, false);
910b16ec
JH
420 }
421
175d6573 422 BOOST_CHECK_EQUAL(edges.back().first, Length);
910b16ec
JH
423 BOOST_CHECK_EQUAL(edges.back().second, false);
424}
425
a126c277
JH
426BOOST_AUTO_TEST_CASE(LisaMUsbHid)
427{
428 /* This test was created from the beginning of the USB_DM signal in
429 * sigrok-dumps-usb/lisa_m_usbhid/lisa_m_usbhid.sr
430 */
431
432 const int Edges[] = {
433 7028, 7033, 7036, 7041, 7044, 7049, 7053, 7066, 7073, 7079,
434 7086, 7095, 7103, 7108, 7111, 7116, 7119, 7124, 7136, 7141,
435 7148, 7162, 7500
436 };
437 const int Length = Edges[countof(Edges) - 1];
438
439 bool state = false;
440 int lastEdgePos = 0;
441
1b1ec774 442 //----- Create a LogicSnapshot -----//
a126c277
JH
443 sr_datafeed_logic logic;
444 logic.unitsize = 1;
445 logic.length = Length;
446 logic.data = new uint8_t[Length];
447 uint8_t *data = (uint8_t*)logic.data;
448
333d5bbc 449 for (unsigned int i = 0; i < countof(Edges); i++) {
a126c277
JH
450 const int edgePos = Edges[i];
451 memset(&data[lastEdgePos], state ? 0x02 : 0,
452 edgePos - lastEdgePos - 1);
453
454 lastEdgePos = edgePos;
455 state = !state;
456 }
457
1b1ec774 458 LogicSnapshot s(logic);
a126c277
JH
459 delete[] (uint64_t*)logic.data;
460
1b1ec774 461 vector<LogicSnapshot::EdgePair> edges;
a126c277
JH
462
463
464 /* The trailing edge of the pulse train is falling in the source data.
465 * Check this is always true at different scales
466 */
467
468 edges.clear();
469 s.get_subsampled_edges(edges, 0, Length-1, 33.333332f, 1);
470 BOOST_CHECK_EQUAL(edges[edges.size() - 2].second, false);
471}
472
6092d96f 473/*
6ac6242b 474 * This test checks the rendering of wide data (more than 8 channels)
6092d96f 475 * Probe signals are either all-high, or all-low, but are interleaved such that
6ac6242b 476 * they would toggle during every sample if treated like 8 channels.
6092d96f
AG
477 * The packet contains a large number of samples, so the mipmap generation kicks
478 * in.
479 *
480 * The signals should not toggle (have exactly two edges: the start and end)
481 */
482BOOST_AUTO_TEST_CASE(WideData)
483{
484 const int Length = 512<<10;
485 uint16_t *data = new uint16_t[Length];
486
487 sr_datafeed_logic logic;
488 logic.unitsize = sizeof(data[0]);
489 logic.length = Length * sizeof(data[0]);
490 logic.data = data;
491
9ba4ca35 492 for (int i = 0; i < Length; i++)
6092d96f
AG
493 data[i] = 0x0FF0;
494
495 LogicSnapshot s(logic);
496
497 vector<LogicSnapshot::EdgePair> edges;
498
499 edges.clear();
500 s.get_subsampled_edges(edges, 0, Length-1, 1, 0);
501 BOOST_CHECK_EQUAL(edges.size(), 2);
502
503 edges.clear();
504 s.get_subsampled_edges(edges, 0, Length-1, 1, 8);
505 BOOST_CHECK_EQUAL(edges.size(), 2);
506
507 // Cleanup
508 delete [] data;
509}
a126c277 510
c6013ca7
JH
511/*
512 * This test is a replica of sixteen.sr attached to Bug #33.
513 */
514BOOST_AUTO_TEST_CASE(Sixteen)
515{
516 const int Length = 8;
517 uint16_t data[Length];
518
519 sr_datafeed_logic logic;
520 logic.unitsize = sizeof(data[0]);
521 logic.length = Length * sizeof(data[0]);
522 logic.data = data;
523
9ba4ca35 524 for (int i = 0; i < Length; i++)
c6013ca7
JH
525 data[i] = 0xFFFE;
526
527 LogicSnapshot s(logic);
528
529 vector<LogicSnapshot::EdgePair> edges;
530 s.get_subsampled_edges(edges, 0, 2, 0.0004, 1);
531
532 BOOST_CHECK_EQUAL(edges.size(), 2);
533}
534
ecda6ca9 535BOOST_AUTO_TEST_SUITE_END()
48ecc1fc 536#endif