Skip to content

Commit cb9bc33

Browse files
committed
Unit tests: Add optional benchmarks to unit tests
1 parent 59f1b25 commit cb9bc33

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

testing/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ add_executable(lsl_test_internal
3232
)
3333
target_link_libraries(lsl_test_internal PRIVATE lslobj lslboost catch_main)
3434

35+
if(LSL_BENCHMARKS)
36+
# to get somewhat reproducible performance numbers:
37+
# /usr/bin/time -v testing/lsl_bench_exported --benchmark-samples 100 bounce
38+
# [unix only] | binary | nr. of samples | test name
39+
add_executable(lsl_bench_exported
40+
bench_ext_bounce.cpp
41+
bench_ext_common.cpp
42+
)
43+
target_link_libraries(lsl_bench_exported PRIVATE lsl catch_main)
44+
installLSLApp(lsl_bench_exported)
45+
46+
add_executable(lsl_bench_internal
47+
bench_int_sleep.cpp
48+
)
49+
target_link_libraries(lsl_bench_internal PRIVATE lslobj lslboost catch_main)
50+
installLSLApp(lsl_bench_internal)
51+
endif()
52+
3553
set(LSL_TESTS lsl_test_exported lsl_test_internal)
3654
foreach(lsltest ${LSL_TESTS})
3755
add_test(NAME ${lsltest} COMMAND ${lsltest} --wait-for-keypress never)

testing/bench_ext_bounce.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "helpers.h"
2+
#include "catch.hpp"
3+
#include <lsl_cpp.h>
4+
5+
TEST_CASE("bounce", "[basic][latency]") {
6+
auto sp = create_streampair(lsl::stream_info("bounce", "Test"));
7+
8+
float data = .0;
9+
BENCHMARK("single bounce") {
10+
sp.out_.push_sample(&data);
11+
sp.in_.pull_sample(&data, 1.);
12+
};
13+
14+
sp.out_.push_sample(&data);
15+
BENCHMARK("primed bounce") {
16+
sp.out_.push_sample(&data);
17+
sp.in_.pull_sample(&data, 1.);
18+
};
19+
}

testing/bench_ext_common.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "catch.hpp"
2+
#include <lsl_c.h>
3+
4+
TEST_CASE("common") {
5+
BENCHMARK("lsl_clock") { return lsl_local_clock(); };
6+
}
7+

testing/bench_int_sleep.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "catch.hpp"
2+
#include <thread>
3+
4+
TEST_CASE("sleep") {
5+
BENCHMARK("sleep1ms") { std::this_thread::sleep_for(std::chrono::milliseconds(1)); };
6+
}

testing/timesync.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "helpers.h"
22
#include "catch.hpp"
33
#include <lsl_cpp.h>
4-
#include <iostream>
54

65
namespace {
76

0 commit comments

Comments
 (0)