Files
terebi/Checks/seek-queue.cpp
T

82 lines
4.2 KiB
C++

// Include the implementation to inspect pending commands without adding a public test API.
#include "../Sources/Core/player.cpp"
#include <cstdlib>
static void require(bool condition, const char *message) {
if (!condition) { std::fprintf(stderr, "FAIL: %s\n", message); std::exit(1); }
}
int main(int argc, char **argv) {
Player player;
// Join before submitting anything: the queue exercise has no executing worker,
// media I/O, device clock or scheduling-dependent queue depth.
player.shutdown();
player.stopping.store(false);
auto reset = [&] {
player.commands.clear();
player.state = {};
player.state.status = PLAYER_PAUSED;
player.state.can_seek = true;
player.state.has_video = true;
player.publishedEpoch = player.requestedEpoch.load();
};
reset();
player.state.position = 7;
player.state.buffered_start = 6;
player.state.buffered_end = 9;
constexpr unsigned requests = 100000;
unsigned accepted = 0;
for (unsigned i = 0; i < requests; ++i)
accepted += player_seek(&player, double(i));
std::printf("Native pending seek burst: requested=%u accepted=%u queued=%zu latest=%.0f\n",
requests, accepted, player.commands.size(), player.commands.back().seconds);
if (argc == 2 && std::strcmp(argv[1], "--measure") == 0) return 0;
require(argc == 1, "only --measure is supported");
require(accepted == requests && player.commands.size() == 1 &&
player.commands.back().seconds == requests - 1,
"every superseding seek is accepted and only the latest target remains");
require(player.state.seek_pending && player.state.revision == requests &&
player.state.buffered_start == 0 && player.state.buffered_end == 0 &&
player.state.position == 7 && player.state.status == PLAYER_PAUSED,
"each accepted seek publishes pending and invalidates buffering, not acknowledged position");
reset();
for (std::size_t i = 0; i < commandLimit - 1; ++i)
require(player_pause(&player), "fill queue with command barriers");
require(player_seek(&player, 1) && player_seek(&player, 2),
"latest queued seek can be replaced even at capacity");
require(player.commands.size() == commandLimit && player.commands.back().seconds == 2 &&
!player_play(&player), "coalescing does not relax capacity for other commands");
for (Action barrier : {Action::Play, Action::Pause, Action::Step,
Action::Open, Action::Close, Action::Remote}) {
reset();
require(player_seek(&player, 1), "seek before barrier");
Command command{barrier, {}};
command.direction = 1;
require(player.enqueue(std::move(command)) && player_seek(&player, 2), "seek after barrier");
require(player.commands.size() == 3 && player.commands[0].action == Action::Seek &&
player.commands[0].seconds == 1 && player.commands[1].action == barrier &&
player.commands[2].action == Action::Seek && player.commands[2].seconds == 2,
"no seek replacement crosses another action");
if (barrier == Action::Open || barrier == Action::Close)
require(player.commands[0].epoch != player.commands[2].epoch,
"timeline replacement separates seek epochs");
}
reset();
require(player_seek(&player, 1), "seek before API error boundary");
player.apiError("queue check boundary");
require(player_seek(&player, 2) && player.commands.size() == 2 &&
player.commands[0].epoch != player.commands[1].epoch,
"adjacent seeks from different epochs remain distinct");
reset();
require(player_seek(&player, 1), "first seek queued");
auto executing = std::move(player.commands.front());
player.commands.pop_front(); // The worker removes a seek before executing it.
require(player_seek(&player, 2) && player_seek(&player, 3) &&
executing.seconds == 1 && player.commands.size() == 1 && player.commands.back().seconds == 3,
"replacement never changes a seek already removed for execution");
std::puts("PASS native seek burst/capacity/publication/action barriers/epochs/executing seek");
}