From 74557ab348ab9bedfd9b39841fa96cc00daca538 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 25 Jul 2023 16:26:31 +0200 Subject: [PATCH] Don't rely on temporary directories Use the current test directory instead. --- test/unit/cfg.c | 11 ++--------- test/unit/prv.c | 8 +------- test/unit/stream.c | 25 +++++++++---------------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/test/unit/cfg.c b/test/unit/cfg.c index 9b09a8e..17678a7 100644 --- a/test/unit/cfg.c +++ b/test/unit/cfg.c @@ -10,19 +10,12 @@ int main(void) { - char dir[] = "/tmp/ovni.trace.XXXXXX"; - if (mkdtemp(dir) == NULL) - die("mkdtemp failed:"); - - if (cfg_generate(dir) != 0) + if (cfg_generate(".") != 0) die("cfg_generate failed"); /* Check that one configuration file is present */ - char cfg[PATH_MAX]; - sprintf(cfg, "%s/cfg/cpu/ovni/pid.cfg", dir); - struct stat st; - if (stat(cfg, &st) != 0) + if (stat("cfg/cpu/ovni/pid.cfg", &st) != 0) die("stat failed"); return 0; diff --git a/test/unit/prv.c b/test/unit/prv.c index c486675..9050dde 100644 --- a/test/unit/prv.c +++ b/test/unit/prv.c @@ -278,11 +278,7 @@ test_same_type(const char *path) int main(void) { - /* Create temporary trace file */ - char fname[] = "/tmp/ovni.prv.XXXXXX"; - int fd = mkstemp(fname); - if (fd < 0) - die("mkstemp failed:"); + char fname[] = "ovni.prv"; test_emit(fname); test_dup(fname); @@ -290,7 +286,5 @@ int main(void) test_emitdup(fname); test_same_type(fname); - close(fd); - return 0; } diff --git a/test/unit/stream.c b/test/unit/stream.c index 67546f4..53b8079 100644 --- a/test/unit/stream.c +++ b/test/unit/stream.c @@ -5,14 +5,16 @@ #include #include #include +#include #include "common.h" #include "emu/stream.h" #include "ovni.h" #include "unittest.h" static void -test_ok(char *fname) +test_ok(void) { + const char *fname = "stream-ok.obs"; FILE *f = fopen(fname, "w"); if (f == NULL) @@ -29,8 +31,7 @@ test_ok(char *fname) fclose(f); struct stream stream; - const char *relpath = &fname[5]; - OK(stream_load(&stream, "/tmp", relpath)); + OK(stream_load(&stream, ".", fname)); if (stream.active) die("stream is active"); @@ -39,8 +40,9 @@ test_ok(char *fname) } static void -test_bad(char *fname) +test_bad(void) { + const char *fname = "stream-bad.obs"; FILE *f = fopen(fname, "w"); if (f == NULL) @@ -57,24 +59,15 @@ test_bad(char *fname) fclose(f); struct stream stream; - const char *relpath = &fname[5]; - ERR(stream_load(&stream, "/tmp", relpath)); + ERR(stream_load(&stream, ".", fname)); err("OK"); } int main(void) { - /* Create temporary trace file */ - char fname[] = "/tmp/ovni.stream.XXXXXX"; - int fd = mkstemp(fname); - if (fd < 0) - die("mkstemp failed:"); - - test_ok(fname); - test_bad(fname); - - close(fd); + test_ok(); + test_bad(); return 0; }