-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests DashboardPage::drawPlot(). Signed-off-by: Sergio Martins <[email protected]>
- Loading branch information
Showing
5 changed files
with
328 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
blocks: | ||
- name: ClockSource | ||
id: gr::basic::ClockSource | ||
template_args: "float" | ||
parameters: | ||
chunk_size: 100 | ||
do_zero_order_hold: true | ||
n_samples_max: 100000000 | ||
repeat_period: 2000000000 | ||
sample_rate: 1000.000000 | ||
verbose_console: false | ||
tag_times: | ||
- 10000000 # 10 ms in ns | ||
- 100000000 # 100 ms in ns | ||
- 300000000 # 300 ms in ns | ||
- 350000000 # 350 ms in ns | ||
- 550000000 # 550 ms in ns | ||
- 560000000 # 560 ms in ns | ||
- 650000000 # 650 ms in ns | ||
- 800000000 # 800 ms in ns | ||
- 850000000 # 850 ms in ns | ||
tag_values: | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=1" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=2" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=3" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=4" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=5" | ||
- "CMD_DIAG_TRIGGER1" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=6" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=7" | ||
- "CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=8" | ||
- name: DipoleCurrentGenerator | ||
id: gr::basic::FunctionGenerator | ||
template_args: "float" | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 0.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: Const | ||
start_value: 0.000000 | ||
ctx_parameters: | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=1 | ||
time: 0 | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 0.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: Const | ||
start_value: 5.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=2 | ||
time: 0 | ||
parameters: | ||
duration: 0.200000 | ||
final_value: 30.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: LinearRamp | ||
start_value: 5.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=3 | ||
time: 0 | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 0.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: Const | ||
start_value: 30.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=4 | ||
time: 0 | ||
parameters: | ||
duration: 0.100000 | ||
final_value: 20.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.020000 | ||
sample_rate: 1000.000000 | ||
signal_type: ParabolicRamp | ||
start_value: 30.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=5 | ||
time: 0 | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 0.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: Const | ||
start_value: 20.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=6 | ||
time: 0 | ||
parameters: | ||
duration: 0.100000 | ||
final_value: 10.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: CubicSpline | ||
start_value: 20.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=7 | ||
time: 0 | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 0.000000 | ||
impulse_time0: 0.000000 | ||
impulse_time1: 0.000000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: Const | ||
start_value: 10.000000 | ||
- context: CMD_BP_START/FAIR.SELECTOR.C=1:S=1:P=8 | ||
time: 0 | ||
parameters: | ||
duration: 0.000000 | ||
final_value: 20.000000 | ||
impulse_time0: 0.020000 | ||
impulse_time1: 0.060000 | ||
round_off_time: 0.000000 | ||
sample_rate: 1000.000000 | ||
signal_type: ImpulseResponse | ||
start_value: 5.000000 | ||
- name: DipoleCurrentSink | ||
id: opendigitizer::ImPlotSink | ||
template_args: float | ||
parameters: | ||
signal_name: dipole current | ||
signal_unit: A | ||
connections: | ||
- [ClockSource, 0, DipoleCurrentGenerator, 0] | ||
- [DipoleCurrentGenerator, 0, DipoleCurrentSink, 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sources: | ||
- name: sink 1 | ||
block: DipoleCurrentSink | ||
port: 0 | ||
color: 4281816053 | ||
plots: | ||
- name: Plot 1 | ||
axes: | ||
- axis: X | ||
min: 0.1 | ||
max: 3000.0 | ||
- axis: Y | ||
min: -1.991981029510498 | ||
max: 1.9978399276733398 | ||
sources: | ||
- sink 1 | ||
rect: | ||
- 8 | ||
- 0 | ||
- 8 | ||
- 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include "imgui.h" | ||
#include "imgui_test_engine/imgui_te_context.h" | ||
|
||
#include <boost/ut.hpp> | ||
|
||
#include "ImGuiTestApp.hpp" | ||
|
||
#include <Dashboard.hpp> | ||
#include <DashboardPage.hpp> | ||
#include <Flowgraph.hpp> | ||
|
||
// TODO: blocks are locally included/registered for this test -> should become a global feature | ||
#include "blocks/Arithmetic.hpp" | ||
#include "blocks/ImPlotSink.hpp" | ||
#include "blocks/SineSource.hpp" | ||
#include "gnuradio-4.0/basic/FunctionGenerator.hpp" | ||
#include "gnuradio-4.0/basic/clock_source.hpp" | ||
#include "imgui_test_engine/imgui_te_internal.h" | ||
#include <gnuradio-4.0/Scheduler.hpp> | ||
#include <gnuradio-4.0/fourier/fft.hpp> | ||
|
||
#include <cmrc/cmrc.hpp> | ||
#include <gnuradio-4.0/Graph_yaml_importer.hpp> | ||
#include <gnuradio-4.0/Profiler.hpp> | ||
#include <gnuradio-4.0/Scheduler.hpp> | ||
#include <memory.h> | ||
|
||
CMRC_DECLARE(ui_test_assets); | ||
|
||
using namespace boost; | ||
using namespace boost::ut; | ||
|
||
// We derive from gr's scheduler just to make stop() public | ||
template<gr::profiling::ProfilerLike TProfiler = gr::profiling::null::Profiler> | ||
class TestScheduler : public gr::scheduler::Simple<gr::scheduler::ExecutionPolicy::singleThreaded, TProfiler> { | ||
public: | ||
explicit TestScheduler(gr::Graph&& graph) : gr::scheduler::Simple<gr::scheduler::ExecutionPolicy::singleThreaded, TProfiler>(std::move(graph)) {} | ||
void stop() { gr::scheduler::Simple<gr::scheduler::ExecutionPolicy::singleThreaded, TProfiler>::stop(); } | ||
}; | ||
|
||
struct TestState { | ||
std::shared_ptr<DigitizerUi::Dashboard> dashboard; | ||
std::function<void()> stopFunction; | ||
std::thread schedulerThread; | ||
std::unique_ptr<TestScheduler<gr::profiling::null::Profiler>> scheduler; | ||
|
||
void startScheduler(gr::Graph&& graph) { | ||
schedulerThread = std::thread([&] { | ||
scheduler = std::make_unique<TestScheduler<gr::profiling::null::Profiler>>(std::move(graph)); | ||
scheduler->runAndWait(); | ||
}); | ||
} | ||
|
||
void stopScheduler() { | ||
dashboard = {}; | ||
scheduler->stop(); | ||
schedulerThread.join(); | ||
} | ||
}; | ||
|
||
TestState g_state; | ||
|
||
struct TestApp : public DigitizerUi::test::ImGuiTestApp { | ||
using DigitizerUi::test::ImGuiTestApp::ImGuiTestApp; | ||
|
||
void registerTests() override { | ||
|
||
ImGuiTest* t = IM_REGISTER_TEST(engine(), "chart_dashboard", "DashboardPage::drawPlot"); | ||
t->SetVarsDataType<TestState>(); | ||
|
||
t->GuiFunc = [](ImGuiTestContext*) { | ||
ImGui::Begin("Test Window", nullptr, ImGuiWindowFlags_NoSavedSettings); | ||
|
||
ImGui::SetWindowPos({0, 0}); | ||
ImGui::SetWindowSize(ImVec2(500, 500)); | ||
|
||
if (g_state.dashboard) { | ||
ut::expect(!g_state.dashboard->plots().empty()); | ||
auto plot = g_state.dashboard->plots()[0]; | ||
|
||
if (ImPlot::BeginPlot("Line Plot")) { | ||
DigitizerUi::DashboardPage::drawPlot(*g_state.dashboard, plot); | ||
ImPlot::EndPlot(); | ||
} | ||
} | ||
|
||
ImGui::End(); | ||
}; | ||
|
||
t->TestFunc = [](ImGuiTestContext* ctx) { | ||
"DashboardPage::drawPlot"_test = [ctx] { | ||
ctx->SetRef("Test Window"); | ||
|
||
// For our test we stop the graph after a certain amount samples. | ||
// TODO: Once Ivan finishes his new ImPlotSink registry class we can remove these reinterpret_cast. | ||
|
||
auto execution = g_state.dashboard->localFlowGraph.createExecutionContext(); | ||
auto blockModel = g_state.dashboard->localFlowGraph.findPlotSinkGrBlock("sink 3"); | ||
ut::expect(blockModel); | ||
auto plotBlockModel = reinterpret_cast<gr::BlockWrapper<opendigitizer::ImPlotSink<float>>*>(blockModel); | ||
auto implotSink = reinterpret_cast<opendigitizer::ImPlotSink<float>*>(plotBlockModel->raw()); | ||
|
||
const int maxSamples = 1400; | ||
while (g_state.dashboard && implotSink->data.size() < maxSamples) { | ||
ImGuiTestEngine_Yield(ctx->Engine); | ||
} | ||
|
||
captureScreenshot(*ctx); | ||
|
||
g_state.stopScheduler(); | ||
}; | ||
}; | ||
} | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
auto options = DigitizerUi::test::TestOptions::fromArgs(argc, argv); | ||
options.screenshotPrefix = "chart"; | ||
|
||
options.speedMode = ImGuiTestRunSpeed_Normal; | ||
TestApp app(options); | ||
|
||
// init early, as Dashboard invokes ImGui style stuff | ||
app.initImGui(); | ||
|
||
auto loader = DigitizerUi::test::ImGuiTestApp::createPluginLoader(); | ||
|
||
// TODO: fg_dipole_intensity_ramp fails to load, somthing about unkown_type when parsing port | ||
// auto fs = cmrc::ui_test_assets::get_filesystem(); | ||
// auto grcFile = fs.open("examples/fg_dipole_intensity_ramp.grc"); | ||
// auto dashboardFile = fs.open("examples/fg_dipole_intensity_ramp.yml"); | ||
|
||
auto fs = cmrc::sample_dashboards::get_filesystem(); | ||
auto grcFile = fs.open("assets/sampleDashboards/DemoDashboard.grc"); | ||
auto dashboardFile = fs.open("assets/sampleDashboards/DemoDashboard.yml"); | ||
|
||
auto dashBoardDescription = DigitizerUi::DashboardDescription::createEmpty("empty"); | ||
g_state.dashboard = DigitizerUi::Dashboard::create(/**fgItem=*/nullptr, dashBoardDescription); | ||
g_state.dashboard->setPluginLoader(loader); | ||
g_state.dashboard->load(std::string(grcFile.begin(), grcFile.end()), std::string(dashboardFile.begin(), dashboardFile.end())); | ||
|
||
auto execution = g_state.dashboard->localFlowGraph.createExecutionContext(); | ||
g_state.dashboard->localFlowGraph.setPlotSinkGrBlocks(std::move(execution.plotSinkGrBlocks)); | ||
|
||
g_state.startScheduler(std::move(execution.graph)); | ||
|
||
return app.runTests() ? 0 : 1; | ||
} |