Skip to content

Commit 585739e

Browse files
committed
Initial work on EdgeDetection test
1 parent 9107f17 commit 585739e

6 files changed

Lines changed: 135 additions & 11 deletions

File tree

src/ngscopeclient/FilterGraphEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *

tests/Primitives/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_executable(Primitives
33

44
Convert8BitSamples.cpp
55
Convert16BitSamples.cpp
6+
EdgeDetection.cpp
67
Sampling.cpp
78
)
89

@@ -21,3 +22,8 @@ add_custom_command(TARGET Primitives POST_BUILD
2122
endif()
2223

2324
catch_discover_tests(Primitives)
25+
26+
add_dependencies(Primitives
27+
ngprotoshaders
28+
nghalshaders
29+
)

tests/Primitives/EdgeDetection.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/***********************************************************************************************************************
2+
* *
3+
* libscopehal *
4+
* *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
6+
* All rights reserved. *
7+
* *
8+
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9+
* following conditions are met: *
10+
* *
11+
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12+
* following disclaimer. *
13+
* *
14+
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15+
* following disclaimer in the documentation and/or other materials provided with the distribution. *
16+
* *
17+
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18+
* derived from this software without specific prior written permission. *
19+
* *
20+
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22+
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26+
* POSSIBILITY OF SUCH DAMAGE. *
27+
* *
28+
***********************************************************************************************************************/
29+
30+
/**
31+
@file
32+
@author Andrew D. Zonenberg
33+
@brief Unit test for FindZeroCrossings() and similar
34+
*/
35+
#ifdef _CATCH2_V3
36+
#include <catch2/catch_all.hpp>
37+
#else
38+
#include <catch2/catch.hpp>
39+
#endif
40+
41+
#include "../../lib/scopehal/scopehal.h"
42+
#include "../../lib/scopehal/LevelCrossingDetector.h"
43+
#include "../../lib/scopehal/TestWaveformSource.h"
44+
#include "../../lib/scopeprotocols/scopeprotocols.h"
45+
#include "Primitives.h"
46+
47+
using namespace std;
48+
49+
TEST_CASE("Primitive_FindZeroCrossings")
50+
{
51+
//Create a queue and command buffer
52+
shared_ptr<QueueHandle> queue(g_vkQueueManager->GetComputeQueue("Primitive_FindZeroCrossings.queue"));
53+
vk::CommandPoolCreateInfo poolInfo(
54+
vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
55+
queue->m_family );
56+
vk::raii::CommandPool pool(*g_vkComputeDevice, poolInfo);
57+
58+
vk::CommandBufferAllocateInfo bufinfo(*pool, vk::CommandBufferLevel::ePrimary, 1);
59+
vk::raii::CommandBuffer cmdBuf(std::move(vk::raii::CommandBuffers(*g_vkComputeDevice, bufinfo).front()));
60+
61+
const size_t depth = 50000000;
62+
63+
//Deterministic PRNG for repeatable testing
64+
minstd_rand rng;
65+
rng.seed(0);
66+
TestWaveformSource source(rng);
67+
68+
SECTION("UniformAnalogWaveform")
69+
{
70+
//Input waveforms
71+
auto wfm = dynamic_cast<UniformAnalogWaveform*>(
72+
source.GenerateNoisySinewave(1.0, 0.0, 200000, 20000, depth, 0.1));
73+
wfm->MarkModifiedFromCpu();
74+
75+
//Find the reference zero crossings using the base function
76+
float threshold = 0.05;
77+
double start = GetTime();
78+
vector<int64_t> edges;
79+
Filter::FindZeroCrossings(wfm, threshold, edges);
80+
double dt = GetTime() - start;
81+
LogNotice("CPU: %.3f ms, %zu edges, %zu samples\n", dt*1000, edges.size(), depth);
82+
83+
{
84+
LogNotice("First few ref timestamps:\n");
85+
LogIndenter li;
86+
for(size_t i=0; i<5; i++)
87+
LogNotice("%" PRIi64 "\n", edges[i]);
88+
}
89+
90+
//Do the GPU version
91+
//Run twice, second time for score, so we don't count deferred init or allocations in the benchmark
92+
LevelCrossingDetector ldet;
93+
ldet.FindZeroCrossings(wfm, threshold, cmdBuf, queue);
94+
start = GetTime();
95+
ldet.FindZeroCrossings(wfm, threshold, cmdBuf, queue);
96+
dt = GetTime() - start;
97+
LogNotice("GPU: %.3f ms, TBD\n", dt*1000);
98+
99+
/*
100+
//Initial sanity check: we should have the same number of data bits as we generated,
101+
//and all sizes should be consistent
102+
REQUIRE(nsamples == samples.m_offsets.size());
103+
REQUIRE(nsamples == samples.m_durations.size());
104+
REQUIRE(nsamples == samples.m_samples.size());
105+
106+
//Check each of the bits
107+
for(size_t i=0; i<nsamples; i++)
108+
{
109+
REQUIRE(samples.m_offsets[i] == samples_expected.m_offsets[i]);
110+
REQUIRE(samples.m_durations[i] == samples_expected.m_durations[i]);
111+
REQUIRE(samples.m_samples[i] == samples_expected.m_samples[i]);
112+
}
113+
*/
114+
115+
//done, clean up
116+
delete wfm;
117+
}
118+
}

tests/Primitives/Sampling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* libscopehal v0.1 *
3+
* libscopehal *
44
* *
5-
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *

tests/Primitives/main.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* libscopehal v0.1 *
3+
* libscopehal *
44
* *
5-
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -50,10 +50,10 @@ mt19937 g_rng;
5050
class testRunListener : public Catch::EventListenerBase
5151
{
5252
public:
53-
using Catch::EventListenerBase::EventListenerBase;
53+
using Catch::EventListenerBase::EventListenerBase;
5454

55-
void testRunStarting(Catch::TestRunInfo const&) override
56-
{
55+
void testRunStarting(Catch::TestRunInfo const&) override
56+
{
5757
g_log_sinks.emplace(g_log_sinks.begin(), new ColoredSTDLogSink(Severity::VERBOSE));
5858

5959
if(!VulkanInit(true))
@@ -69,8 +69,8 @@ class testRunListener : public Catch::EventListenerBase
6969
g_rng.seed(0);
7070
}
7171

72-
void testRunEnded([[maybe_unused]] Catch::TestRunStats const& testRunStats) override
73-
{
72+
void testRunEnded([[maybe_unused]] Catch::TestRunStats const& testRunStats) override
73+
{
7474
ScopehalStaticCleanup();
7575
}
7676
};

0 commit comments

Comments
 (0)