X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=test%2Flogicdatasnapshot.cpp;h=3dd72285e52d85dba5f8a134150beb61dd170498;hp=5041c1b327bf689c2a0fa3ecb74c70447d44ab9e;hb=fe48aaeba282c95336583aa9dfe31c8c259480c6;hpb=4f767cf7100023341f94fa9f0d1befc5101c3d6d diff --git a/test/logicdatasnapshot.cpp b/test/logicdatasnapshot.cpp index 5041c1b3..3dd72285 100644 --- a/test/logicdatasnapshot.cpp +++ b/test/logicdatasnapshot.cpp @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth * @@ -18,15 +18,19 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #define __STDC_LIMIT_MACROS #include #include -#include "../logicdatasnapshot.h" +#include "../pv/logicdatasnapshot.h" using namespace std; +using pv::LogicDataSnapshot; + BOOST_AUTO_TEST_SUITE(LogicDataSnapshotTest) void push_logic(LogicDataSnapshot &s, unsigned int length, uint8_t value) @@ -42,8 +46,6 @@ void push_logic(LogicDataSnapshot &s, unsigned int length, uint8_t value) BOOST_AUTO_TEST_CASE(Pow2) { - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-2, 0), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-1, 0), -1); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(0, 0), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(1, 0), 1); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(2, 0), 2); @@ -53,9 +55,6 @@ BOOST_AUTO_TEST_CASE(Pow2) BOOST_CHECK_EQUAL( LogicDataSnapshot::pow2_ceil(INT64_MAX, 0), INT64_MAX); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-3, 1), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-2, 1), -2); - BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(-1, 1), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(0, 1), 0); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(1, 1), 2); BOOST_CHECK_EQUAL(LogicDataSnapshot::pow2_ceil(2, 1), 2); @@ -75,7 +74,7 @@ BOOST_AUTO_TEST_CASE(Basic) //----- Test LogicDataSnapshot::push_logic -----// BOOST_CHECK(s.get_sample_count() == 0); - for(int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) + for(unsigned int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); @@ -89,7 +88,7 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_CHECK(s.get_sample_count() == 8); // There should not be enough samples to have a single mip map sample - for(int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) + for(unsigned int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); @@ -109,7 +108,7 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[0], 0x11); // The higher levels should still be empty - for(int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) + for(unsigned int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); @@ -124,7 +123,7 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_CHECK_EQUAL(m0.data_length, LogicDataSnapshot::MipMapDataUnit); BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[1], 0x11); - for(int i = 2; i < m0.length; i++) + for(unsigned int i = 2; i < m0.length; i++) BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[i], 0); const LogicDataSnapshot::MipMapLevel &m1 = s._mip_map[1]; @@ -159,7 +158,7 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_AUTO_TEST_CASE(LargeData) { uint8_t prev_sample; - const int Length = 1000000; + const unsigned int Length = 1000000; sr_datafeed_logic logic; logic.unitsize = 1; @@ -167,7 +166,7 @@ BOOST_AUTO_TEST_CASE(LargeData) logic.data = new uint8_t[Length]; uint8_t *data = (uint8_t*)logic.data; - for(int i = 0; i < Length; i++) + for(unsigned int i = 0; i < Length; i++) *data++ = (uint8_t)(i >> 8); LogicDataSnapshot s(logic); @@ -182,7 +181,7 @@ BOOST_AUTO_TEST_CASE(LargeData) BOOST_REQUIRE(s._mip_map[0].data != NULL); prev_sample = 0; - for(int i = 0; i < s._mip_map[0].length;) + for(unsigned int i = 0; i < s._mip_map[0].length;) { BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]"); @@ -205,7 +204,7 @@ BOOST_AUTO_TEST_CASE(LargeData) BOOST_REQUIRE(s._mip_map[1].data != NULL); prev_sample = 0; - for(int i = 0; i < s._mip_map[1].length; i++) + for(unsigned int i = 0; i < s._mip_map[1].length; i++) { BOOST_TEST_MESSAGE("Testing mip_map[1].data[" << i << "]"); @@ -223,7 +222,7 @@ BOOST_AUTO_TEST_CASE(LargeData) BOOST_REQUIRE(s._mip_map[2].data != NULL); prev_sample = 0; - for(int i = 0; i < s._mip_map[2].length; i++) + for(unsigned int i = 0; i < s._mip_map[2].length; i++) { BOOST_TEST_MESSAGE("Testing mip_map[2].data[" << i << "]"); @@ -240,12 +239,12 @@ BOOST_AUTO_TEST_CASE(LargeData) LogicDataSnapshot::MipMapDataUnit); BOOST_REQUIRE(s._mip_map[3].data != NULL); - for(int i = 0; i < s._mip_map[3].length; i++) + for(unsigned int i = 0; i < s._mip_map[3].length; i++) BOOST_CHECK_EQUAL(*((uint8_t*)s._mip_map[3].data + i), 0xFF); // Check the higher levels - for(int i = 4; i < LogicDataSnapshot::ScaleStepCount; i++) + for(unsigned int i = 4; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); @@ -254,19 +253,25 @@ BOOST_AUTO_TEST_CASE(LargeData) } //----- Test LogicDataSnapshot::get_subsampled_edges -----// + // Check in normal case vector edges; - s.get_subsampled_edges(edges, 0, Length-1, 1, 7); BOOST_CHECK_EQUAL(edges.size(), 32); - for(int i = 0; i < edges.size() - 1; i++) + for(unsigned int i = 0; i < edges.size() - 1; i++) { BOOST_CHECK_EQUAL(edges[i].first, i * 32768); BOOST_CHECK_EQUAL(edges[i].second, i & 1); } BOOST_CHECK_EQUAL(edges[31].first, 999999); + + // Check in very low zoom case + edges.clear(); + s.get_subsampled_edges(edges, 0, Length-1, 50e6f, 7); + + BOOST_CHECK_EQUAL(edges.size(), 2); } BOOST_AUTO_TEST_CASE(Pulses) @@ -300,7 +305,7 @@ BOOST_AUTO_TEST_CASE(Pulses) LogicDataSnapshot::MipMapDataUnit); BOOST_REQUIRE(s._mip_map[0].data != NULL); - for(int i = 0; i < s._mip_map[0].length;) { + for(unsigned int i = 0; i < s._mip_map[0].length;) { BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]"); BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0xFF); @@ -314,7 +319,7 @@ BOOST_AUTO_TEST_CASE(Pulses) } // Check the higher levels are all inactive - for(int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { + for(unsigned int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); @@ -326,7 +331,7 @@ BOOST_AUTO_TEST_CASE(Pulses) BOOST_REQUIRE_EQUAL(edges.size(), Cycles + 2); BOOST_CHECK_EQUAL(0, false); - for(int i = 1; i < edges.size(); i++) + for(unsigned int i = 1; i < edges.size(); i++) BOOST_CHECK_EQUAL(edges[i].second, false); } @@ -350,7 +355,7 @@ BOOST_AUTO_TEST_CASE(LongPulses) for(int i = 0; i < Cycles; i++) { for(j = 0; j < PulseWidth; j++) *p++ = ~0; - for(j; j < Period; j++) + for(; j < Period; j++) *p++ = 0; } @@ -364,14 +369,14 @@ BOOST_AUTO_TEST_CASE(LongPulses) LogicDataSnapshot::MipMapDataUnit); BOOST_REQUIRE(s._mip_map[0].data != NULL); - for(int i = 0; i < s._mip_map[0].length;) { + for(unsigned int i = 0; i < s._mip_map[0].length;) { for(j = 0; i < s._mip_map[0].length && j < 2; j++) { BOOST_TEST_MESSAGE( "Testing mip_map[0].data[" << i << "]"); BOOST_CHECK_EQUAL(s.get_subsample(0, i++), ~0); } - for(j; i < s._mip_map[0].length && + for(; i < s._mip_map[0].length && j < Period/LogicDataSnapshot::MipMapScaleFactor; j++) { BOOST_TEST_MESSAGE( "Testing mip_map[0].data[" << i << "]"); @@ -380,7 +385,7 @@ BOOST_AUTO_TEST_CASE(LongPulses) } // Check the higher levels are all inactive - for(int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { + for(unsigned int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); @@ -419,4 +424,52 @@ BOOST_AUTO_TEST_CASE(LongPulses) BOOST_CHECK_EQUAL(edges.back().second, false); } +BOOST_AUTO_TEST_CASE(LisaMUsbHid) +{ + /* This test was created from the beginning of the USB_DM signal in + * sigrok-dumps-usb/lisa_m_usbhid/lisa_m_usbhid.sr + */ + + const int Edges[] = { + 7028, 7033, 7036, 7041, 7044, 7049, 7053, 7066, 7073, 7079, + 7086, 7095, 7103, 7108, 7111, 7116, 7119, 7124, 7136, 7141, + 7148, 7162, 7500 + }; + const int Length = Edges[countof(Edges) - 1]; + + bool state = false; + int lastEdgePos = 0; + + //----- Create a LogicDataSnapshot -----// + sr_datafeed_logic logic; + logic.unitsize = 1; + logic.length = Length; + logic.data = new uint8_t[Length]; + uint8_t *data = (uint8_t*)logic.data; + + for(unsigned int i = 0; i < countof(Edges); i++) { + const int edgePos = Edges[i]; + memset(&data[lastEdgePos], state ? 0x02 : 0, + edgePos - lastEdgePos - 1); + + lastEdgePos = edgePos; + state = !state; + } + + LogicDataSnapshot s(logic); + delete[] (uint64_t*)logic.data; + + vector edges; + + + /* The trailing edge of the pulse train is falling in the source data. + * Check this is always true at different scales + */ + + edges.clear(); + s.get_subsampled_edges(edges, 0, Length-1, 33.333332f, 1); + BOOST_CHECK_EQUAL(edges[edges.size() - 2].second, false); +} + + BOOST_AUTO_TEST_SUITE_END()