From ebd975a03b1f2d2729ebfd034461957bbbdb4eed Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 4 Aug 2026 17:13:45 +0300 Subject: [PATCH] =?UTF-8?q?mkdtemp=20=E2=86=92=20test=5Fmkdtemp=20=D0=B8?= =?UTF-8?q?=D0=B7=20test=5Futils.h=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D1=81=D0=BF=D0=BB=D0=B0=D1=82=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D1=81=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20(MSYS2/MinGW)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_media_delivery_download.c | 3 ++- tests/test_media_delivery_full.c | 4 ++-- tests/test_media_delivery_integration.c | 12 +++--------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/test_media_delivery_download.c b/tests/test_media_delivery_download.c index bd3df5ca..5d17d43f 100644 --- a/tests/test_media_delivery_download.c +++ b/tests/test_media_delivery_download.c @@ -16,6 +16,7 @@ #include "../lib/u_async.h" #include "../lib/debug_config.h" #include "../lib/mem.h" +#include "test_utils.h" #include "../transport_layer/secure_channel.h" #include "../routing_layer/topo_node_sqlite.h" #include "../routing_layer/conn_mgr.h" @@ -57,7 +58,7 @@ static int file_size(const char* path) { static void test_setup(void) { snprintf(g_temp_dir, sizeof(g_temp_dir), "%s", TEMP_DIR); - if (!mkdtemp(g_temp_dir)) { fprintf(stderr, "mkdtemp failed\n"); exit(1); } + if (test_mkdtemp(g_temp_dir) != 0) { fprintf(stderr, "mkdtemp failed\n"); exit(1); } debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); g_ua = uasync_create(); } diff --git a/tests/test_media_delivery_full.c b/tests/test_media_delivery_full.c index fb5a4164..cd68327e 100644 --- a/tests/test_media_delivery_full.c +++ b/tests/test_media_delivery_full.c @@ -22,6 +22,7 @@ #include "../lib/u_async.h" #include "../lib/debug_config.h" #include "../lib/mem.h" +#include "test_utils.h" #include #include @@ -60,7 +61,6 @@ static char* gv(const char* p, const char* k) { char* r = (strcmp(k, "pub") == 0) ? u_strdup(c->global.my_public_key_hex) : u_strdup(c->global.my_private_key_hex); free_config(c); return r; } -static void t_mkdtemp(char* t) { (void)!mkdtemp(t); } static void t_rmdir(const char* p) { char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", p); system(cmd); } static int db_count(sqlite3* db, const char* tbl, const char* wh, uint64_t val) { @@ -308,7 +308,7 @@ int main(void) { utun_instance_set_tun_init_enabled(0); srand((unsigned)time(NULL)); printf("=== test_media_delivery_full ===\n"); - t_mkdtemp(g_tdir); + test_mkdtemp(g_tdir); for (int i = 0; i < N_NODES; i++) { snprintf(g_cfg[i], sizeof(g_cfg[i]), "%s/n%d.conf", g_tdir, i); diff --git a/tests/test_media_delivery_integration.c b/tests/test_media_delivery_integration.c index 356e3db5..1dc76707 100644 --- a/tests/test_media_delivery_integration.c +++ b/tests/test_media_delivery_integration.c @@ -16,6 +16,7 @@ #include "../transport_layer/etcp.h" #include "../config_parser.h" #include "../config_updater.h" +#include "test_utils.h" #include "../routing_layer/topo_group.h" #include "../routing_layer/topo_node.h" #include "../lib/u_async.h" @@ -58,14 +59,7 @@ static char* gv(const char* p, const char* k) { free_config(c); return r; } -static void test_mkdtemp(char* tmpl) { - (void)!mkdtemp(tmpl); -} - -static void test_unlink(const char* p) { unlink(p); } -static void test_rmdir(const char* p) { - char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", p); system(cmd); -} +/* ── helpers ── */ static int count_rows(sqlite3* db, const char* tbl, const char* where, uint64_t val) { char sql[256]; @@ -303,6 +297,6 @@ done: if (g_a) { g_a->running = 0; utun_instance_destroy(g_a); g_a = NULL; } if (g_b) { g_b->running = 0; utun_instance_destroy(g_b); g_b = NULL; } if (g_ua) { uasync_destroy(g_ua, 0); g_ua = NULL; } - test_rmdir(g_tdir); + { char cmd[512]; snprintf(cmd, sizeof(cmd), "rm -rf %s", g_tdir); system(cmd); } return g_failed > 0 ? 1 : 0; }