From 1e047a9331d990fa50c57fb75cdad79cd78b757f Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 1 Apr 2025 22:01:44 +0800 Subject: [PATCH] test: misc refactor - Move common defs and helper functions to check_util.h/check_utils.c. - Add a prepare script argument for ATX_CHECK_FS* macros. - ASSERT_EXPR_INT(): Use long int as expression result type. - Other misc updates. --- tests/Makefile.am | 4 +-- tests/check_hashmap.c | 20 +++++++------- tests/check_lib.c | 18 +----------- tests/check_sandbox.c | 2 +- tests/check_util.c | 43 +++++++++++++++++++++++++++++ tests/{check_lib.h => check_util.h} | 24 ++++++++-------- tests/check_watcher.c | 2 +- tests/fs_basic.at | 18 ++++++------ tests/testsuite.at | 15 +++++----- 9 files changed, 87 insertions(+), 59 deletions(-) create mode 100644 tests/check_util.c rename tests/{check_lib.h => check_util.h} (60%) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d5032e..3a7a02d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,7 +13,7 @@ TESTS_ = lib_hash.at lib_prng.at lib_watcher.at lib_sandbox.at \ # Helper programs for testing -check_HEADERS = check_lib.h +check_HEADERS = check_util.h check_PROGRAMS = if BOOKMARKFS_UTIL @@ -22,7 +22,7 @@ if BOOKMARKFS_UTIL check_util_lib_CPPFLAGS = -I$(top_srcdir)/src check_util_lib_LDADD = $(top_builddir)/src/libbookmarkfs_util.la check_util_lib_SOURCES = check_lib.c check_watcher.c check_sandbox.c \ - check_hashmap.c + check_hashmap.c check_util.c endif # BOOKMARKFS_UTIL if BOOKMARKFS_MOUNT diff --git a/tests/check_hashmap.c b/tests/check_hashmap.c index 21c58d7..2d613a2 100644 --- a/tests/check_hashmap.c +++ b/tests/check_hashmap.c @@ -25,7 +25,7 @@ #include #include -#include "check_lib.h" +#include "check_util.h" #include "frontend_util.h" #include "hashmap.h" #include "prng.h" @@ -169,8 +169,8 @@ check_hashmap ( char *argv[] ) { uint64_t seed_buf[4], *seed = NULL; - int n = -1; - int r = -1; + int size_exp = -1; + int rounds = -1; OPT_START(argc, argv, "s:n:r:") OPT_OPT('s') { @@ -181,26 +181,26 @@ check_hashmap ( break; } OPT_OPT('n') { - n = atoi(optarg); + size_exp = atoi(optarg); break; } OPT_OPT('r') { - r = atoi(optarg); + rounds = atoi(optarg); break; } OPT_END - if (n < 10 || n > 30) { - log_printf("bad size %d", n); + if (size_exp < 10 || size_exp > 30) { + log_printf("bad size %d", size_exp); return -1; } - if (r < 0) { - log_printf("bad rounds cnt %d", r); + if (rounds < 0) { + log_printf("bad rounds cnt %d", rounds); return -1; } if (0 != prng_seed(seed)) { return -1; } - return do_check_hashmap(1u << n, r); + return do_check_hashmap(1u << size_exp, rounds); } diff --git a/tests/check_lib.c b/tests/check_lib.c index 28c0b64..781f0dc 100644 --- a/tests/check_lib.c +++ b/tests/check_lib.c @@ -22,8 +22,6 @@ # include "config.h" #endif -#include "check_lib.h" - #include #include #include @@ -31,6 +29,7 @@ #include +#include "check_util.h" #include "frontend_util.h" #include "hash.h" #include "prng.h" @@ -131,21 +130,6 @@ subcmd_prng ( return 0; } -int -prng_seed_from_hex ( - uint64_t *buf, - char const *str -) { - int cnt = sscanf(str, - "%16" SCNx64 "%16" SCNx64 "%16" SCNx64 "%16" SCNx64, - &buf[0], &buf[1], &buf[2], &buf[3]); - if (cnt != 4) { - log_printf("bad seed '%s'", optarg); - return -1; - } - return 0; -} - int main ( int argc, diff --git a/tests/check_sandbox.c b/tests/check_sandbox.c index 641bab2..fc8ea82 100644 --- a/tests/check_sandbox.c +++ b/tests/check_sandbox.c @@ -32,7 +32,7 @@ #include #include -#include "check_lib.h" +#include "check_util.h" #include "frontend_util.h" #include "sandbox.h" diff --git a/tests/check_util.c b/tests/check_util.c new file mode 100644 index 0000000..41a3e48 --- /dev/null +++ b/tests/check_util.c @@ -0,0 +1,43 @@ +/** + * bookmarkfs/tests/check_util.c + * ---- + * + * Copyright (C) 2025 CismonX + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "check_util.h" + +#include +#include + +int +prng_seed_from_hex ( + uint64_t *buf, + char const *str +) { + int cnt = sscanf(str, + "%16" SCNx64 "%16" SCNx64 "%16" SCNx64 "%16" SCNx64, + &buf[0], &buf[1], &buf[2], &buf[3]); + if (cnt != 4) { + log_printf("bad seed '%s'", str); + return -1; + } + return 0; +} diff --git a/tests/check_lib.h b/tests/check_util.h similarity index 60% rename from tests/check_lib.h rename to tests/check_util.h index f35fb88..68cbaed 100644 --- a/tests/check_lib.h +++ b/tests/check_util.h @@ -1,5 +1,5 @@ /** - * bookmarkfs/tests/check_lib.h + * bookmarkfs/tests/check_util.h * ---- * * Copyright (C) 2025 CismonX @@ -18,21 +18,21 @@ * along with this program. If not, see . */ -#ifndef BOOKMARKFS_CHECK_LIB_H_ -#define BOOKMARKFS_CHECK_LIB_H_ +#ifndef BOOKMARKFS_CHECK_UTIL_H_ +#define BOOKMARKFS_CHECK_UTIL_H_ #include #include "xstd.h" -#define ASSERT_EXPR_INT(expr, r, cond, action_if_false) \ - do { \ - int r = (expr); \ - if (cond) { \ - break; \ - } \ - log_printf("assertion failed: (%d == %s)", r, #expr); \ - action_if_false \ +#define ASSERT_EXPR_INT(expr, r, cond, action_if_false) \ + do { \ + long r = (expr); \ + if (cond) { \ + break; \ + } \ + log_printf("assertion failed: (%ld == %s)", r, #expr); \ + action_if_false \ } while (0) int @@ -59,4 +59,4 @@ prng_seed_from_hex ( char const *str ); -#endif /* !defined(BOOKMARKFS_CHECK_LIB_H_) */ +#endif /* !defined(BOOKMARKFS_CHECK_UTIL_H_) */ diff --git a/tests/check_watcher.c b/tests/check_watcher.c index a7128c8..b00609d 100644 --- a/tests/check_watcher.c +++ b/tests/check_watcher.c @@ -31,7 +31,7 @@ #include #include -#include "check_lib.h" +#include "check_util.h" #include "frontend_util.h" #include "sandbox.h" #include "watcher.h" diff --git a/tests/fs_basic.at b/tests/fs_basic.at index d190227..4097545 100644 --- a/tests/fs_basic.at +++ b/tests/fs_basic.at @@ -12,17 +12,17 @@ AT_KEYWORDS([fs basic]) # Tests for basic filesystem operations (e.g., create, rename, delete) # which are backend-agnostic. -ATX_CHECK_FS_NEW_ANY([eol], [ +ATX_CHECK_FS_NEW_ANY([eol], , [ ATX_RUN_REPEAT([8], [ + name=$(ath_fn_rand_u64_hex) + name_1=${name}_1 + name_2=${name}_2 + + content=foo:$(ath_fn_rand_u64_hex) + content_1=${content}/1 + content_2=${content}/2 + ATX_RUN([ - name=$(ath_fn_rand_u64_hex) - name_1=${name}_1 - name_2=${name}_2 - - content=foo:$(ath_fn_rand_u64_hex) - content_1=${content}/1 - content_2=${content}/2 - echo "$content_1" > $name_1 test "$(cat $name_1)" = "$content_1" echo "$content_2" > $name_2 diff --git a/tests/testsuite.at b/tests/testsuite.at index 38f2af5..9b07014 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -145,7 +145,7 @@ m4_define([ATX_CHECK_FS], [ ]) dnl -dnl ATX_CHECK_FS_NEW(backend, [options], target, [check]) +dnl ATX_CHECK_FS_NEW(backend, [options], target, [prepare], [check]) dnl dnl Perform filesystem checks using a new bookmark storage dnl created with mkfs.bookmarkfs. @@ -153,22 +153,23 @@ dnl m4_define([ATX_CHECK_FS_NEW], [ ATX_CHECK_FS([$1], [rw,$2], [bookmarks-$1], [$3], [ ATX_FEAT_PREREQ([bookmarkfs-mkfs], [backend-$1-write]) + $4 "$buildsrcdir/mkfs.bookmarkfs" \ -o "backend=ATX_OPT_MODULE([backend_$1]),force" \ "bookmarks-$1" || exit 1 mkdir -p "$3" - ], [$4]) + ], [$5]) ]) dnl -dnl ATX_CHECK_FS_NEW_ANY([options], [check]) +dnl ATX_CHECK_FS_NEW_ANY([options], [prepare], [check]) dnl m4_define([ATX_CHECK_FS_NEW_ANY], [ - ATX_CHECK_FS_NEW([firefox], [$1], [mnt.tmp], [ - ATX_RUN_IN_DIR([mnt.tmp/bookmarks/unfiled], [$2]) + ATX_CHECK_FS_NEW([firefox], [$1], [mnt.tmp], [$2], [ + ATX_RUN_IN_DIR([mnt.tmp/bookmarks/unfiled], [$3]) ]) - ATX_CHECK_FS_NEW([chromium], [$1], [mnt.tmp], [ - ATX_RUN_IN_DIR([mnt.tmp/bookmarks/Other bookmarks], [$2]) + ATX_CHECK_FS_NEW([chromium], [$1], [mnt.tmp], [$2], [ + ATX_RUN_IN_DIR([mnt.tmp/bookmarks/Other bookmarks], [$3]) ]) ])