File: bench_timesync.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 (32 lines) | stat: -rw-r--r-- 1,015 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
#include "stream_info_impl.h"
#include "udp_server.h"
#include <catch2/catch.hpp>
#include <sstream>
#include <thread>

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

using namespace asio::ip;

TEST_CASE("timesync", "[basic][latency]") {
	auto info =
		std::make_shared<lsl::stream_info_impl>("Dummy", "dummy", 1, 1., cft_int8, "abcdef123");
	asio::io_context ctx;
	auto udp_server = std::make_shared<lsl::udp_server>(info, ctx, udp::v4());
	udp::endpoint ep(address_v4(0x7f000001), info->v4service_port());

	INFO(info->to_shortinfo_message())
	udp_server->begin_serving();
	std::thread iothread([&ctx]() { ctx.run(); });

	const char request[] = "LSL:timedata\n1 0.0";
	asio::basic_datagram_socket<udp, asio::io_context::executor_type> sock(ctx, udp::endpoint());
	char buf[500]={0};
	BENCHMARK("timedata") {
		sock.send_to(asio::const_buffer(request, sizeof(request) - 1), ep);
		REQUIRE(sock.receive(asio::mutable_buffer(buf, sizeof(buf) - 1)) > 0);
	};
	udp_server->end_serving();
	ctx.stop();
	iothread.join();
}