2024-06-13 15:46:55 +02:00
|
|
|
/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "instr.h"
|
|
|
|
#include "ovni.h"
|
|
|
|
|
|
|
|
enum {
|
2024-06-17 13:51:40 +02:00
|
|
|
MARK_PROGRESS = 1,
|
|
|
|
MARK_COLORS = 2,
|
2024-06-14 16:05:43 +02:00
|
|
|
COL_BLUE = 1,
|
|
|
|
COL_GRAY = 2,
|
|
|
|
COL_RED = 3,
|
2024-06-13 15:46:55 +02:00
|
|
|
};
|
|
|
|
|
2024-06-17 13:51:40 +02:00
|
|
|
static void
|
|
|
|
rand_sleep(int max_us)
|
|
|
|
{
|
|
|
|
int t = rand() % max_us;
|
|
|
|
sleep_us(t);
|
|
|
|
}
|
|
|
|
|
2024-06-13 15:46:55 +02:00
|
|
|
/* Check ovni_mark_* API. */
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2024-06-14 16:05:43 +02:00
|
|
|
int rank = atoi(getenv("OVNI_RANK"));
|
|
|
|
int nranks = atoi(getenv("OVNI_NRANKS"));
|
|
|
|
instr_start(rank, nranks);
|
2024-06-13 15:46:55 +02:00
|
|
|
|
2024-06-17 13:51:40 +02:00
|
|
|
/* Deterministic rand() */
|
2024-07-24 17:02:57 +02:00
|
|
|
srand(100U + (unsigned) rank);
|
2024-06-17 13:51:40 +02:00
|
|
|
|
|
|
|
/* Test set without labels */
|
|
|
|
|
|
|
|
ovni_mark_type(MARK_PROGRESS, 0, "Progress");
|
|
|
|
|
|
|
|
/* Test push/pop */
|
|
|
|
|
2024-06-14 13:30:38 +02:00
|
|
|
ovni_mark_type(MARK_COLORS, OVNI_MARK_STACK, "Colors");
|
2024-06-13 15:46:55 +02:00
|
|
|
|
|
|
|
if(!ovni_attr_has("ovni.mark.1.title"))
|
|
|
|
die("missing mark title");
|
|
|
|
|
2024-06-14 16:05:43 +02:00
|
|
|
ovni_mark_label(MARK_COLORS, COL_BLUE, "Blue");
|
|
|
|
ovni_mark_label(MARK_COLORS, COL_GRAY, "Gray");
|
|
|
|
ovni_mark_label(MARK_COLORS, COL_RED, "Red");
|
2024-06-13 15:46:55 +02:00
|
|
|
|
2024-06-20 11:32:20 +02:00
|
|
|
for (int i = 1; i <= 100; i++) {
|
2024-06-17 13:51:40 +02:00
|
|
|
int which = 1 + (rand() % 3);
|
|
|
|
|
2024-06-19 13:13:18 +02:00
|
|
|
/* Simulate a thread goes to sleep */
|
|
|
|
if (rank == 0 && i == 25)
|
|
|
|
instr_thread_pause();
|
|
|
|
|
2024-06-17 13:51:40 +02:00
|
|
|
ovni_mark_push(MARK_COLORS, which);
|
|
|
|
rand_sleep(500);
|
|
|
|
ovni_mark_pop(MARK_COLORS, which);
|
2024-06-19 13:13:18 +02:00
|
|
|
|
|
|
|
if (rank == 0 && i == 75)
|
|
|
|
instr_thread_resume();
|
2024-06-17 13:51:40 +02:00
|
|
|
|
2024-06-20 11:32:20 +02:00
|
|
|
ovni_mark_set(MARK_PROGRESS, i);
|
|
|
|
}
|
2024-06-13 15:46:55 +02:00
|
|
|
|
2024-06-20 11:41:38 +02:00
|
|
|
/* Ensure we can emit the same value several times */
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
sleep_us(10);
|
|
|
|
ovni_mark_set(MARK_PROGRESS, 100);
|
|
|
|
}
|
|
|
|
|
2024-06-13 15:46:55 +02:00
|
|
|
instr_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|