From b2d91391b33c09ea71bec92b5585f593de690cee Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 6 Sep 2024 11:58:19 +0200 Subject: [PATCH] Add sort-into-previous-region emu test --- test/emu/ovni/CMakeLists.txt | 1 + test/emu/ovni/sort-into-previous-region.c | 74 +++++++++++++++++++ .../ovni/sort-into-previous-region.driver.sh | 25 +++++++ 3 files changed, 100 insertions(+) create mode 100644 test/emu/ovni/sort-into-previous-region.c create mode 100644 test/emu/ovni/sort-into-previous-region.driver.sh diff --git a/test/emu/ovni/CMakeLists.txt b/test/emu/ovni/CMakeLists.txt index b7559f3..e011ce2 100644 --- a/test/emu/ovni/CMakeLists.txt +++ b/test/emu/ovni/CMakeLists.txt @@ -5,6 +5,7 @@ test_emu(flush-overhead.c DISABLED) test_emu(flush.c) test_emu(sort.c SORT) test_emu(sort-flush.c SORT) +test_emu(sort-into-previous-region.c SORT DRIVER "sort-into-previous-region.driver.sh") test_emu(empty-sort.c SORT) test_emu(sort-first-and-full-ring.c SORT SHOULD_FAIL REGEX "cannot find a event previous to clock") diff --git a/test/emu/ovni/sort-into-previous-region.c b/test/emu/ovni/sort-into-previous-region.c new file mode 100644 index 0000000..01142f1 --- /dev/null +++ b/test/emu/ovni/sort-into-previous-region.c @@ -0,0 +1,74 @@ +/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include "compat.h" +#include "instr.h" +#include "ovni.h" + +/* Test the case in which events from a secondary unsorted region are + * introduced before the previous unsorted region: + * + * [bbbb][BBbb] + * bbbbBB[]bb[] + * + * The events B contain 16 bytes of payload, so pointer to events in previous + * positions are now pointing to garbage. + * + * See: https://pm.bsc.es/gitlab/rarias/ovni/-/issues/199 + */ + +static void +emit(char *mcv, int64_t clock, int size) +{ + struct ovni_ev ev = {0}; + ovni_ev_set_mcv(&ev, mcv); + ovni_ev_set_clock(&ev, clock); + + if (size) { + uint8_t buf[64] = { 0 }; + ovni_payload_add(&ev, buf, size); + } + + ovni_ev_emit(&ev); +} + +int +main(void) +{ + instr_start(0, 1); + + /* Leave some room to prevent clashes */ + sleep_us(100); /* 100000 us */ + int64_t t0 = ovni_clock_now(); + sleep_us(100); /* 100000 us */ + + /* We want it to end like this: + * + * t0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 + * b b b b B B [ ] b b [ ] + * + * But we emit it like this: + * + * +6 +0 +1 +2 +3 +7 +10 +4 +5 +8 +9 +11 + * [ b b b b ] [ B B b b ] + */ + + emit("OU[", t0 + 6, 0); + emit("OB.", t0 + 0, 0); + emit("OB.", t0 + 1, 0); + emit("OB.", t0 + 2, 0); + emit("OB.", t0 + 3, 0); + emit("OU]", t0 + 7, 0); + + emit("OU[", t0 + 10, 0); + emit("OB.", t0 + 4, 16); + emit("OB.", t0 + 5, 16); + emit("OB.", t0 + 8, 0); + emit("OB.", t0 + 9, 0); + emit("OU]", t0 + 11, 0); + + instr_end(); + + return 0; +} diff --git a/test/emu/ovni/sort-into-previous-region.driver.sh b/test/emu/ovni/sort-into-previous-region.driver.sh new file mode 100644 index 0000000..042f271 --- /dev/null +++ b/test/emu/ovni/sort-into-previous-region.driver.sh @@ -0,0 +1,25 @@ +target=$OVNI_TEST_BIN + +$target +ovnisort ovni +ovnidump ovni +ovnidump ovni | awk 'NR == 1 {next} NR==2{t=$1} {print $1-t,$2} NR==13{exit}' > found + +cat > expected <