From 8f4aa5914807a2d4442b42a1ab3caa183ad8e54c Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 17 Sep 2024 08:27:51 +0200 Subject: [PATCH] Fix unit-stream test --- test/unit/CMakeLists.txt | 2 +- test/unit/stream.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 639ad80..efdbd6a 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -15,7 +15,7 @@ unit_test(cpu.c) unit_test(loom.c) unit_test(mux.c) unit_test(prv.c) -#unit_test(stream.c) #FIXME +unit_test(stream.c) unit_test(task.c) unit_test(value.c) unit_test(version.c) diff --git a/test/unit/stream.c b/test/unit/stream.c index 53b8079..362e2d5 100644 --- a/test/unit/stream.c +++ b/test/unit/stream.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) +/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ #include @@ -11,10 +11,27 @@ #include "ovni.h" #include "unittest.h" +static void +write_dummy_json(const char *path) +{ + const char *json = "{ \"version\" : 3 }"; + FILE *f = fopen(path, "w"); + + if (f == NULL) + die("fopen json failed:"); + + if (fwrite(json, strlen(json), 1, f) != 1) + die("fwrite json failed:"); + + fclose(f); +} + static void test_ok(void) { - const char *fname = "stream-ok.obs"; + OK(mkdir("ok", 0755)); + + const char *fname = "ok/stream.obs"; FILE *f = fopen(fname, "w"); if (f == NULL) @@ -30,8 +47,10 @@ test_ok(void) fclose(f); + write_dummy_json("ok/stream.json"); + struct stream stream; - OK(stream_load(&stream, ".", fname)); + OK(stream_load(&stream, ".", "ok")); if (stream.active) die("stream is active"); @@ -42,7 +61,9 @@ test_ok(void) static void test_bad(void) { - const char *fname = "stream-bad.obs"; + OK(mkdir("bad", 0755)); + + const char *fname = "bad/stream.obs"; FILE *f = fopen(fname, "w"); if (f == NULL) @@ -58,8 +79,10 @@ test_bad(void) fclose(f); + write_dummy_json("bad/stream.json"); + struct stream stream; - ERR(stream_load(&stream, ".", fname)); + ERR(stream_load(&stream, ".", "bad")); err("OK"); }