File: time.cpp

package info (click to toggle)
liblsl 1.16.2b1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,724 kB
  • sloc: cpp: 12,515; ansic: 666; python: 28; sh: 25; makefile: 18
file content (44 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "../common/create_streampair.hpp"
#include <atomic>
#include <catch2/catch.hpp>
#include <lsl_cpp.h>
#include <thread>

// clazy:excludeall=non-pod-global-static

namespace {

TEST_CASE("simple timesync", "[timesync][basic]") {
	auto sp = create_streampair(lsl::stream_info("timesync", "Test"));
	double offset = sp.in_.time_correction(5.) * 1000;
	CHECK(offset < 1);
	CAPTURE(offset);

	double remote_time, uncertainty;
	offset = sp.in_.time_correction(&remote_time, &uncertainty, 5.) * 1000;
	CHECK(offset < 1);
	CHECK(uncertainty * 1000 < 1);
	CHECK(remote_time < lsl::local_clock());
}


TEST_CASE("timeouts", "[pull][basic]") {
	auto sp = create_streampair(
		lsl::stream_info("timeouts", "Test", 1, lsl::IRREGULAR_RATE, lsl::cf_int8, "timeouts"));
	std::atomic<bool> done{false};

	// Push a sample after some time so the test can continue even if the timeout isn't honored
	std::thread saver([&]() {
		char val;
		auto end = lsl::local_clock() + 2;
		while (!done && lsl::local_clock() < end)
			std::this_thread::sleep_for(std::chrono::milliseconds(50));
		sp.out_.push_sample(&val);
	});

	char val;
	REQUIRE(sp.in_.pull_sample(&val, 1, 0.5) == Approx(0.0));
	done = true;
	saver.join();
}
} // namespace