pothosware / gr-pothos

Pothos bindings for GNU Radio blocks
https://github.com/pothosware/gr-pothos/wiki
GNU General Public License v3.0
12 stars 1 forks source link

/gnuradio/tests/test_copy_stream... FAIL! on 32-bit zynq #11

Closed wluker closed 5 years ago

wluker commented 5 years ago

I installed gr-pothos and ran PothosUtil --self-test and got the following error.

Testing /gnuradio/tests/test_copy_stream... FAIL!
 +--------------------------------------------------------------------------------------------------------------------------------------------+
 | Testing /gnuradio/tests/test_copy_stream...                                                                                                |
 | Exception: Pothos::Testing test_simple_blocks.cc:45                                                                                        |
 |   Unexpected error after last checkpoint                                                                                                   |
 |   Proxy Exception Message: Assertion violation: CollectorSink::verifyTestPlan(): Value check for element 0: expected 347596851 -> actual 0 |
 +--------------------------------------------------------------------------------------------------------------------------------------------+

In test_simple_blocks.cc if I comment out testPlan["enableLabels"] = true; I still get the error. Which leads me to think it has something to do with testPlan["enableBuffers"] = true; ???

These same tests pass on my x86-64, so I imagine it has something to do with 32-bit. I don't understand the testing infrastructure, but if you point me in a direction, I can see what I can find.

guruofquality commented 5 years ago

So the test copy stream is basically a simple randomly generated buffer source -> through a gnuradio copy block of floats -> and to a collection sink block. The source and sink can share a test plan so the sink can validate what it received.

The best place to look is probably where the collector sink validates the floats: https://github.com/pothosware/PothosBlocks/blob/master/testers/CollectorSink.cpp#L152

There is a call where it converts the buffer to ints, which could be wrong: auto intBuffer = buffer.convert(typeid(int)), so it would be interesting to see what is in in buffer.as<const float *>()[i];

I guess the idea is see where the randomly generated float value disappeared into a 0

wluker commented 5 years ago

Thanks for the info.

If I change https://github.com/pothosware/PothosBlocks/blob/master/testers/CollectorSink.cpp#L166 to

    for (size_t i = 0; i < std::min(numActualElems, expectedValues.size()); i++)
    {
        const int value = expectedValues[i];
        auto val = buffer.as<const float *>()[i];
        std::cout << "float val = " << val << std::endl;
        std::cout << "int val =" << *((int *) &val) << std::endl;
        const auto actual = intBuffer.as<const int *>()[i];
        if (value != actual) throw Pothos::AssertionViolationException("CollectorSink::verifyTestPlan()",
            Poco::format("Value check for element %z: expected %d -> actual %d", i, value, actual));
    }

here is the output

# PothosUtil --self-test1=/gnuradio/tests/test_copy_stream
Testing /gnuradio/tests/test_copy_stream...
float val = 1.06178e-36
int val =62170942
Exception: Pothos::Testing test_simple_blocks.cc:46
  Unexpected error after last checkpoint
  Proxy Exception Message: Assertion violation: CollectorSink::verifyTestPlan(): Value check for element 0: expected 62170942 -> actual 0

If I'm understanding corretly, it looks like const auto actual = intBuffer.as<const int *>()[i]; not correct like you thought?

What about line 163 auto intBuffer = buffer.convert(typeid(int));. Is buffer.convert supposed to change the value or change the interpretation of the bits in the value?

guruofquality commented 5 years ago

buffer.convert(typeid(int));

This API is not a cast, it really allocates a new buffer and converts value wise.

Yea, so a little background, the feeder and collector basically just test signed integers, but they support other data types by using the BufferChunk convert API. And of course this means that when they test floating point types, its just generating non decimal numbers. Lazy yes, but these blocks are usually used in situations when something can be looped back (converted and converted back), so it works well enough.

So your print is telling me that the float value here for element 0 was float val = 1.06178e-36, and this is no surprise that its showing up as 0. The conversion from float -> int is only going to keep the integer part anyway.

Whats surprising is that the decimal is totally unexpected. So I guess the search is now on for where did the float wrong?

So interestingly the feeder source is just casting the floats to an int (based on the type size being 4) and setting it memory wise to be an integer: https://github.com/pothosware/PothosBlocks/blob/master/testers/FeederSource.cpp#L208

I have no idea how this is working for floats, so it might be something that just worked on x86 for floats and seems to be fine for integer types on all platforms (its primary use anyway). See what happens when you change else if (elemDType.size() == 4) buff.as<int *>()[i] = int(value); to else if (elemDType.size() == 4) buff.as<float *>()[i] = float(value);

wluker commented 5 years ago

I changed the line you recommended : else if (elemDType.size() == 4) buff.as<float *>()[i] = float(value); and this is what is printed...

# PothosUtil --self-test1=/gnuradio/tests/test_copy_stream
Testing /gnuradio/tests/test_copy_stream...
float val = 1.66669e+09
int val =1321643874
Exception: Pothos::Testing test_simple_blocks.cc:46
  Unexpected error after last checkpoint
  Proxy Exception Message: Assertion violation: CollectorSink::verifyTestPlan(): Value check for element 0: expected 1666691343 -> actual 1666691328

I'm still a little bit confused though...

guruofquality commented 5 years ago

Thanks. See: https://github.com/pothosware/PothosBlocks/issues/48