diff --git a/test/emu/ovni/CMakeLists.txt b/test/emu/ovni/CMakeLists.txt index f699746..d51944f 100644 --- a/test/emu/ovni/CMakeLists.txt +++ b/test/emu/ovni/CMakeLists.txt @@ -21,3 +21,4 @@ test_emu(empty-stream.c SHOULD_FAIL REGEX "model_ovni_finish: thread .* is not d test_emu(require-bad-version.c SHOULD_FAIL REGEX "unsupported ovni model version (want 666.66.6, have .*)") test_emu(require-compat.c REGEX "loading trace in compatibility mode") test_emu(thread-crash.c SHOULD_FAIL REGEX "incomplete stream") +test_emu(flush-tmpdir.c MP DRIVER "flush-tmpdir.driver.sh") diff --git a/test/emu/ovni/flush-tmpdir.c b/test/emu/ovni/flush-tmpdir.c new file mode 100644 index 0000000..6fd404f --- /dev/null +++ b/test/emu/ovni/flush-tmpdir.c @@ -0,0 +1,51 @@ +/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include +#include +#include "instr.h" +#include "ovni.h" + +static void +emit(uint8_t *buf, size_t size) +{ + struct ovni_ev ev = {0}; + ovni_ev_set_mcv(&ev, "OB."); + ovni_ev_set_clock(&ev, ovni_clock_now()); + ovni_ev_jumbo_emit(&ev, buf, size); +} + +/* Test that we can flush the stream when we are working with a different tmpdir + * than the final destination (OVNI_TMPDIR is set). */ + +int +main(void) +{ + instr_start(0, 1); + + size_t payload_size = (size_t) (0.9 * (double) OVNI_MAX_EV_BUF); + uint8_t *payload_buf = calloc(1, payload_size); + + if (!payload_buf) { + perror("calloc failed"); + exit(EXIT_FAILURE); + } + + /* The first should fit, filling 90 % of the buffer */ + emit(payload_buf, payload_size); + + /* The second event would cause a flush */ + emit(payload_buf, payload_size); + + /* The third would cause the previous flush events to be written + * to disk */ + emit(payload_buf, payload_size); + + /* Flush the last event to disk manually */ + instr_end(); + + free(payload_buf); + + return 0; +} diff --git a/test/emu/ovni/flush-tmpdir.driver.sh b/test/emu/ovni/flush-tmpdir.driver.sh new file mode 100644 index 0000000..c3ce127 --- /dev/null +++ b/test/emu/ovni/flush-tmpdir.driver.sh @@ -0,0 +1,6 @@ +target=$OVNI_TEST_BIN + +mkdir tmp +export OVNI_TMPDIR=tmp +$target +ovniemu ovni