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