mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 19:58:50 +00:00
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.
This commit is contained in:
parent
81db7a786c
commit
1e047a9331
9 changed files with 87 additions and 59 deletions
|
@ -13,7 +13,7 @@ TESTS_ = lib_hash.at lib_prng.at lib_watcher.at lib_sandbox.at \
|
||||||
|
|
||||||
# Helper programs for testing
|
# Helper programs for testing
|
||||||
|
|
||||||
check_HEADERS = check_lib.h
|
check_HEADERS = check_util.h
|
||||||
check_PROGRAMS =
|
check_PROGRAMS =
|
||||||
|
|
||||||
if BOOKMARKFS_UTIL
|
if BOOKMARKFS_UTIL
|
||||||
|
@ -22,7 +22,7 @@ if BOOKMARKFS_UTIL
|
||||||
check_util_lib_CPPFLAGS = -I$(top_srcdir)/src
|
check_util_lib_CPPFLAGS = -I$(top_srcdir)/src
|
||||||
check_util_lib_LDADD = $(top_builddir)/src/libbookmarkfs_util.la
|
check_util_lib_LDADD = $(top_builddir)/src/libbookmarkfs_util.la
|
||||||
check_util_lib_SOURCES = check_lib.c check_watcher.c check_sandbox.c \
|
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
|
endif # BOOKMARKFS_UTIL
|
||||||
|
|
||||||
if BOOKMARKFS_MOUNT
|
if BOOKMARKFS_MOUNT
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "check_lib.h"
|
#include "check_util.h"
|
||||||
#include "frontend_util.h"
|
#include "frontend_util.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "prng.h"
|
#include "prng.h"
|
||||||
|
@ -169,8 +169,8 @@ check_hashmap (
|
||||||
char *argv[]
|
char *argv[]
|
||||||
) {
|
) {
|
||||||
uint64_t seed_buf[4], *seed = NULL;
|
uint64_t seed_buf[4], *seed = NULL;
|
||||||
int n = -1;
|
int size_exp = -1;
|
||||||
int r = -1;
|
int rounds = -1;
|
||||||
|
|
||||||
OPT_START(argc, argv, "s:n:r:")
|
OPT_START(argc, argv, "s:n:r:")
|
||||||
OPT_OPT('s') {
|
OPT_OPT('s') {
|
||||||
|
@ -181,26 +181,26 @@ check_hashmap (
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
OPT_OPT('n') {
|
OPT_OPT('n') {
|
||||||
n = atoi(optarg);
|
size_exp = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
OPT_OPT('r') {
|
OPT_OPT('r') {
|
||||||
r = atoi(optarg);
|
rounds = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
OPT_END
|
OPT_END
|
||||||
|
|
||||||
if (n < 10 || n > 30) {
|
if (size_exp < 10 || size_exp > 30) {
|
||||||
log_printf("bad size %d", n);
|
log_printf("bad size %d", size_exp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (r < 0) {
|
if (rounds < 0) {
|
||||||
log_printf("bad rounds cnt %d", r);
|
log_printf("bad rounds cnt %d", rounds);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != prng_seed(seed)) {
|
if (0 != prng_seed(seed)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return do_check_hashmap(1u << n, r);
|
return do_check_hashmap(1u << size_exp, rounds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "check_lib.h"
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -31,6 +29,7 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "check_util.h"
|
||||||
#include "frontend_util.h"
|
#include "frontend_util.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "prng.h"
|
#include "prng.h"
|
||||||
|
@ -131,21 +130,6 @@ subcmd_prng (
|
||||||
return 0;
|
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
|
int
|
||||||
main (
|
main (
|
||||||
int argc,
|
int argc,
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "check_lib.h"
|
#include "check_util.h"
|
||||||
#include "frontend_util.h"
|
#include "frontend_util.h"
|
||||||
#include "sandbox.h"
|
#include "sandbox.h"
|
||||||
|
|
||||||
|
|
43
tests/check_util.c
Normal file
43
tests/check_util.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* bookmarkfs/tests/check_util.c
|
||||||
|
* ----
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 CismonX <admin@cismon.net>
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "check_util.h"
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* bookmarkfs/tests/check_lib.h
|
* bookmarkfs/tests/check_util.h
|
||||||
* ----
|
* ----
|
||||||
*
|
*
|
||||||
* Copyright (C) 2025 CismonX <admin@cismon.net>
|
* Copyright (C) 2025 CismonX <admin@cismon.net>
|
||||||
|
@ -18,21 +18,21 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BOOKMARKFS_CHECK_LIB_H_
|
#ifndef BOOKMARKFS_CHECK_UTIL_H_
|
||||||
#define BOOKMARKFS_CHECK_LIB_H_
|
#define BOOKMARKFS_CHECK_UTIL_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "xstd.h"
|
#include "xstd.h"
|
||||||
|
|
||||||
#define ASSERT_EXPR_INT(expr, r, cond, action_if_false) \
|
#define ASSERT_EXPR_INT(expr, r, cond, action_if_false) \
|
||||||
do { \
|
do { \
|
||||||
int r = (expr); \
|
long r = (expr); \
|
||||||
if (cond) { \
|
if (cond) { \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
log_printf("assertion failed: (%d == %s)", r, #expr); \
|
log_printf("assertion failed: (%ld == %s)", r, #expr); \
|
||||||
action_if_false \
|
action_if_false \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -59,4 +59,4 @@ prng_seed_from_hex (
|
||||||
char const *str
|
char const *str
|
||||||
);
|
);
|
||||||
|
|
||||||
#endif /* !defined(BOOKMARKFS_CHECK_LIB_H_) */
|
#endif /* !defined(BOOKMARKFS_CHECK_UTIL_H_) */
|
|
@ -31,7 +31,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "check_lib.h"
|
#include "check_util.h"
|
||||||
#include "frontend_util.h"
|
#include "frontend_util.h"
|
||||||
#include "sandbox.h"
|
#include "sandbox.h"
|
||||||
#include "watcher.h"
|
#include "watcher.h"
|
||||||
|
|
|
@ -12,17 +12,17 @@ AT_KEYWORDS([fs basic])
|
||||||
|
|
||||||
# Tests for basic filesystem operations (e.g., create, rename, delete)
|
# Tests for basic filesystem operations (e.g., create, rename, delete)
|
||||||
# which are backend-agnostic.
|
# which are backend-agnostic.
|
||||||
ATX_CHECK_FS_NEW_ANY([eol], [
|
ATX_CHECK_FS_NEW_ANY([eol], , [
|
||||||
ATX_RUN_REPEAT([8], [
|
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([
|
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
|
echo "$content_1" > $name_1
|
||||||
test "$(cat $name_1)" = "$content_1"
|
test "$(cat $name_1)" = "$content_1"
|
||||||
echo "$content_2" > $name_2
|
echo "$content_2" > $name_2
|
||||||
|
|
|
@ -145,7 +145,7 @@ m4_define([ATX_CHECK_FS], [
|
||||||
])
|
])
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl ATX_CHECK_FS_NEW(backend, [options], target, [check])
|
dnl ATX_CHECK_FS_NEW(backend, [options], target, [prepare], [check])
|
||||||
dnl
|
dnl
|
||||||
dnl Perform filesystem checks using a new bookmark storage
|
dnl Perform filesystem checks using a new bookmark storage
|
||||||
dnl created with mkfs.bookmarkfs.
|
dnl created with mkfs.bookmarkfs.
|
||||||
|
@ -153,22 +153,23 @@ dnl
|
||||||
m4_define([ATX_CHECK_FS_NEW], [
|
m4_define([ATX_CHECK_FS_NEW], [
|
||||||
ATX_CHECK_FS([$1], [rw,$2], [bookmarks-$1], [$3], [
|
ATX_CHECK_FS([$1], [rw,$2], [bookmarks-$1], [$3], [
|
||||||
ATX_FEAT_PREREQ([bookmarkfs-mkfs], [backend-$1-write])
|
ATX_FEAT_PREREQ([bookmarkfs-mkfs], [backend-$1-write])
|
||||||
|
$4
|
||||||
"$buildsrcdir/mkfs.bookmarkfs" \
|
"$buildsrcdir/mkfs.bookmarkfs" \
|
||||||
-o "backend=ATX_OPT_MODULE([backend_$1]),force" \
|
-o "backend=ATX_OPT_MODULE([backend_$1]),force" \
|
||||||
"bookmarks-$1" || exit 1
|
"bookmarks-$1" || exit 1
|
||||||
mkdir -p "$3"
|
mkdir -p "$3"
|
||||||
], [$4])
|
], [$5])
|
||||||
])
|
])
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl ATX_CHECK_FS_NEW_ANY([options], [check])
|
dnl ATX_CHECK_FS_NEW_ANY([options], [prepare], [check])
|
||||||
dnl
|
dnl
|
||||||
m4_define([ATX_CHECK_FS_NEW_ANY], [
|
m4_define([ATX_CHECK_FS_NEW_ANY], [
|
||||||
ATX_CHECK_FS_NEW([firefox], [$1], [mnt.tmp], [
|
ATX_CHECK_FS_NEW([firefox], [$1], [mnt.tmp], [$2], [
|
||||||
ATX_RUN_IN_DIR([mnt.tmp/bookmarks/unfiled], [$2])
|
ATX_RUN_IN_DIR([mnt.tmp/bookmarks/unfiled], [$3])
|
||||||
])
|
])
|
||||||
ATX_CHECK_FS_NEW([chromium], [$1], [mnt.tmp], [
|
ATX_CHECK_FS_NEW([chromium], [$1], [mnt.tmp], [$2], [
|
||||||
ATX_RUN_IN_DIR([mnt.tmp/bookmarks/Other bookmarks], [$2])
|
ATX_RUN_IN_DIR([mnt.tmp/bookmarks/Other bookmarks], [$3])
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue