ngscopeclient / scopehal

Test and measurement hardware abstraction library and protocol decodes. This is the library only. Most users should use scopehal-apps.
BSD 3-Clause "New" or "Revised" License
216 stars 97 forks source link

Segfault in tests Filter_FrequencyMeasurement and Primitive_SampleOnRisingEdges #672

Closed electroniceel closed 2 years ago

electroniceel commented 2 years ago

When running ctest I get:

Test project /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/redhat-linux-build/tests
    Start 1: OpenCL support: not present at compile time. GPU acceleration disabled.
1/7 Test #1: OpenCL support: not present at compile time. GPU acceleration disabled. ...   Passed    0.07 sec
    Start 2: Buffers_CpuOnly
2/7 Test #2: Buffers_CpuOnly ...........................................................   Passed    0.07 sec
    Start 3: Buffers_CpuGpu
3/7 Test #3: Buffers_CpuGpu ............................................................   Passed    0.07 sec
    Start 4: OpenCL support: not present at compile time. GPU acceleration disabled.
4/7 Test #4: OpenCL support: not present at compile time. GPU acceleration disabled. ...   Passed    0.03 sec
    Start 5: Filter_FrequencyMeasurement
5/7 Test #5: Filter_FrequencyMeasurement ...............................................***Exception: SegFault  0.23 sec
    Start 6: OpenCL support: not present at compile time. GPU acceleration disabled.
6/7 Test #6: OpenCL support: not present at compile time. GPU acceleration disabled. ...   Passed    0.03 sec
    Start 7: Primitive_SampleOnRisingEdges
7/7 Test #7: Primitive_SampleOnRisingEdges .............................................***Exception: SegFault  0.21 sec

71% tests passed, 2 tests failed out of 7

Total Test time (real) =   0.70 sec

The following tests FAILED:
          5 - Filter_FrequencyMeasurement (SEGFAULT)
          7 - Primitive_SampleOnRisingEdges (SEGFAULT)

When doing a backtrace both seem to fail in AllocateCpuBuffer, so I guess it is the same issue.

Filter_FrequencyMeasurement:

Program received signal SIGSEGV, Segmentation fault.
std::make_unique<vk::raii::Buffer, vk::raii::Device&, vk::BufferCreateInfo&> () at /usr/include/c++/12/bits/unique_ptr.h:1065
1065        { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
Missing separate debuginfos, use: dnf debuginfo-install ffts-0.9-20170617.fe86885.fc34.x86_64 systemd-libs-250.8-1.fc36.x86_64
(gdb) bt
#0  std::make_unique<vk::raii::Buffer, vk::raii::Device&, vk::BufferCreateInfo&>(vk::raii::Device&, vk::BufferCreateInfo&) () at /usr/include/c++/12/bits/unique_ptr.h:1065
#1  AcceleratorBuffer<long>::AllocateCpuBuffer(unsigned long) (this=0x5555556279b8, size=<optimized out>)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopeprotocols/../scopehal/AcceleratorBuffer.h:915
#2  0x00007ffff7d0db7d in AcceleratorBuffer<long>::Reallocate(unsigned long) (this=0x5555556279b8, size=1000000)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopeprotocols/../scopehal/AcceleratorBuffer.h:530
#3  0x00007ffff7a26180 in AcceleratorBuffer<long>::reserve(unsigned long) (size=1000000, this=0x5555556279b8)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopehal/AcceleratorBuffer.h:423
#4  AcceleratorBuffer<long>::resize(unsigned long) (size=1000000, this=0x5555556279b8) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopehal/AcceleratorBuffer.h:402
#5  Waveform<float>::Resize(unsigned long) (size=1000000, this=0x555555627980) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopehal/Waveform.h:213
#6  TestWaveformSource::GenerateNoisySinewave(float, float, float, long, unsigned long, float)
    (this=this@entry=0x7fffffffc930, amplitude=amplitude@entry=0.0941821188, startphase=startphase@entry=0.636817455, period=period@entry=1999595.5, sampleperiod=sampleperiod@entry=20000, depth=depth@entry=1000000, noise_amplitude=noise_amplitude@entry=0) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/lib/scopehal/TestWaveformSource.cpp:119
#7  0x00005555555cf10c in C_A_T_C_H_T_E_S_T_0() () at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Filters/FrequencyMeasurement.cpp:69
#8  0x0000555555578038 in Catch::TestInvokerAsFunction::invoke() const (this=<optimized out>) at /usr/include/catch2/catch.hpp:14328
#9  Catch::TestCase::invoke() const (this=<optimized out>) at /usr/include/catch2/catch.hpp:14167
#10 Catch::RunContext::invokeActiveTestCase() (this=0x7fffffffd020) at /usr/include/catch2/catch.hpp:13027
#11 0x000055555558b2b8 in Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (this=0x7fffffffd020, redirectedCout="", redirectedCerr="") at /usr/include/catch2/catch.hpp:13000
#12 0x0000555555598bd5 in Catch::RunContext::runTest(Catch::TestCase const&) (this=0x7fffffffd020, testCase=...) at /usr/include/catch2/catch.hpp:12761
#13 0x00005555555a2c98 in Catch::(anonymous namespace)::TestGroup::execute (this=0x7fffffffd010) at /usr/include/catch2/catch.hpp:13354
#14 Catch::Session::runInternal() (this=0x7fffffffd300) at /usr/include/catch2/catch.hpp:13560
#15 0x00005555555a325a in Catch::Session::run() (this=this@entry=0x7fffffffd300) at /usr/include/catch2/catch.hpp:13516
#16 0x000055555556eb99 in Catch::Session::run<char>(int, char const* const*) (argv=0x7fffffffd5d8, argc=1, this=0x7fffffffd300) at /usr/include/catch2/catch.hpp:13238
#17 Catch::Session::run<char>(int, char const* const*) (argv=0x7fffffffd5d8, argc=1, this=0x7fffffffd300) at /usr/include/catch2/catch.hpp:13233
#18 main(int, char**) (argc=1, argv=0x7fffffffd5d8) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Filters/main.cpp:63

Primitive_SampleOnRisingEdges:

Program received signal SIGSEGV, Segmentation fault.
std::make_unique<vk::raii::Buffer, vk::raii::Device&, vk::BufferCreateInfo&> () at /usr/include/c++/12/bits/unique_ptr.h:1065
1065        { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
Missing separate debuginfos, use: dnf debuginfo-install ffts-0.9-20170617.fe86885.fc34.x86_64 systemd-libs-250.8-1.fc36.x86_64
(gdb) bt
#0  std::make_unique<vk::raii::Buffer, vk::raii::Device&, vk::BufferCreateInfo&>(vk::raii::Device&, vk::BufferCreateInfo&) () at /usr/include/c++/12/bits/unique_ptr.h:1065
#1  AcceleratorBuffer<long>::AllocateCpuBuffer(unsigned long) (this=0x7fffffffc5d8, size=<optimized out>)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/../../lib/scopehal/AcceleratorBuffer.h:915
#2  0x00005555555e1ba5 in AcceleratorBuffer<long>::Reallocate(unsigned long) (this=this@entry=0x7fffffffc5d8, size=size@entry=1)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/../../lib/scopehal/AcceleratorBuffer.h:530
#3  0x00005555555d7620 in AcceleratorBuffer<long>::reserve(unsigned long) (size=1, this=0x7fffffffc5d8)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/../../lib/scopehal/AcceleratorBuffer.h:423
#4  AcceleratorBuffer<long>::resize(unsigned long) (size=1, this=0x7fffffffc5d8) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/../../lib/scopehal/AcceleratorBuffer.h:402
#5  AcceleratorBuffer<long>::push_back(long const&) (value=<optimized out>, this=0x7fffffffc5d8)
    at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/../../lib/scopehal/AcceleratorBuffer.h:629
#6  C_A_T_C_H_T_E_S_T_0() () at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/Sampling.cpp:72
#7  0x00005555555802e8 in Catch::TestInvokerAsFunction::invoke() const (this=<optimized out>) at /usr/include/catch2/catch.hpp:14328
#8  Catch::TestCase::invoke() const (this=<optimized out>) at /usr/include/catch2/catch.hpp:14167
#9  Catch::RunContext::invokeActiveTestCase() (this=0x7fffffffd050) at /usr/include/catch2/catch.hpp:13027
#10 0x0000555555593378 in Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (this=0x7fffffffd050, redirectedCout="", redirectedCerr="") at /usr/include/catch2/catch.hpp:13000
#11 0x00005555555a0d35 in Catch::RunContext::runTest(Catch::TestCase const&) (this=0x7fffffffd050, testCase=...) at /usr/include/catch2/catch.hpp:12761
#12 0x00005555555aada8 in Catch::(anonymous namespace)::TestGroup::execute (this=0x7fffffffd040) at /usr/include/catch2/catch.hpp:13354
#13 Catch::Session::runInternal() (this=0x7fffffffd2f0) at /usr/include/catch2/catch.hpp:13560
#14 0x00005555555ab36a in Catch::Session::run() (this=this@entry=0x7fffffffd2f0) at /usr/include/catch2/catch.hpp:13516
#15 0x0000555555576ca5 in Catch::Session::run<char>(int, char const* const*) (argv=0x7fffffffd5c8, argc=1, this=0x7fffffffd2f0) at /usr/include/catch2/catch.hpp:13238
#16 Catch::Session::run<char>(int, char const* const*) (argv=0x7fffffffd5c8, argc=1, this=0x7fffffffd2f0) at /usr/include/catch2/catch.hpp:13233
#17 main(int, char**) (argc=1, argv=0x7fffffffd5c8) at /home/gerd/rpmbuild/BUILD/scopehal-apps-3bc6b5f/tests/Primitives/main.cpp:57

This is on Fedora 36 x86_64, with the complete OpenCL stuff disabled. Tested code is commit 3bc6b5f29650c555a83cbe3dfbb39e3d00467496 of scopehal-apps.

azonenberg commented 2 years ago

Use after free in the test case, now fixed.