Add tests for event sorting

This commit is contained in:
Rodrigo Arias 2022-10-07 12:17:14 +02:00
parent 190cd8b822
commit 6dda4e90dd
3 changed files with 139 additions and 0 deletions

View File

@ -7,5 +7,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
endif() endif()
ovni_test(flush.c) ovni_test(flush.c)
ovni_test(sort.c SORT)
ovni_test(empty-sort.c SORT)
ovni_test(mp-simple.c MP) ovni_test(mp-simple.c MP)
ovni_test(mp-rank.c MP) ovni_test(mp-rank.c MP)

View File

@ -0,0 +1,67 @@
/* Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <limits.h>
#include <linux/limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include "compat.h"
#include "ovni.h"
static inline void
init(void)
{
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, HOST_NAME_MAX) != 0) {
perror("gethostname failed");
exit(EXIT_FAILURE);
}
ovni_proc_init(0, hostname, getpid());
ovni_thread_init(gettid());
ovni_add_cpu(0, 0);
}
static void
emit(char *mcv, int64_t clock)
{
struct ovni_ev ev = {0};
ovni_ev_set_mcv(&ev, mcv);
ovni_ev_set_clock(&ev, clock);
ovni_ev_emit(&ev);
}
int
main(void)
{
init();
/* Leave some room to prevent clashes */
usleep(100); /* 100000 us */
int64_t t0 = ovni_clock_now();
emit("OU[", t0);
int64_t t = t0 - 10000;
for (int i = 0; i < 100; i++) {
emit("OB.", t);
t += 33;
}
emit("OU]", ovni_clock_now());
ovni_flush();
ovni_proc_fini();
return 0;
}

70
test/emu/ovni/sort.c Normal file
View File

@ -0,0 +1,70 @@
/* Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC)
* SPDX-License-Identifier: GPL-3.0-or-later */
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#include <limits.h>
#include <linux/limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include "compat.h"
#include "ovni.h"
#include "../instr.h"
static void
emit_jumbo(uint8_t *buf, size_t size, int64_t clock)
{
struct ovni_ev ev = {0};
ovni_ev_set_mcv(&ev, "O$$");
ovni_ev_set_clock(&ev, clock);
ovni_ev_jumbo_emit(&ev, buf, size);
}
static void
emit(char *mcv, int64_t clock)
{
struct ovni_ev ev = {0};
ovni_ev_set_mcv(&ev, mcv);
ovni_ev_set_clock(&ev, clock);
ovni_ev_emit(&ev);
}
#define BUFSIZE 128
int
main(void)
{
uint8_t buf[BUFSIZE];
instr_start(0, 1);
/* Leave some room to prevent clashes */
usleep(100); /* 100000 us */
int64_t t0 = ovni_clock_now();
emit("OU[", t0);
int64_t t = t0 - 10000;
for (int i = 0; i < 100; i++) {
emit("OB.", t);
t += 33;
}
/* Also test jumbo events */
for (int i = 0; i < BUFSIZE; i++)
buf[i] = i & 0xff;
emit_jumbo(buf, BUFSIZE, t);
emit("OU]", ovni_clock_now());
instr_end();
return 0;
}