mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 11:48:51 +00:00
test: misc refactor
This commit is contained in:
parent
ca43bc6939
commit
0b317c2727
3 changed files with 16 additions and 21 deletions
|
@ -22,8 +22,6 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -39,7 +37,7 @@ struct check_item {
|
|||
|
||||
// Forward declaration start
|
||||
static int check_one_round (struct hashmap *, struct check_item *, size_t);
|
||||
static int do_check_hashmap (int, int);
|
||||
static int do_check_hashmap (size_t, int);
|
||||
static int item_comp_func (union hashmap_key, void const *);
|
||||
static unsigned long
|
||||
item_hash_func (void const *);
|
||||
|
@ -81,14 +79,14 @@ check_one_round (
|
|||
|
||||
int
|
||||
do_check_hashmap (
|
||||
int n,
|
||||
int rounds
|
||||
size_t items_cnt,
|
||||
int rounds
|
||||
) {
|
||||
size_t items_cnt = 1u << n;
|
||||
size_t buf_size = sizeof(struct check_item) * items_cnt;
|
||||
struct check_item *items = mmap(NULL, buf_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (items == MAP_FAILED) {
|
||||
log_puts("failed to allocate memory");
|
||||
return -1;
|
||||
}
|
||||
struct hashmap *map = hashmap_create(item_comp_func, item_hash_func);
|
||||
|
@ -112,9 +110,8 @@ do_check_hashmap (
|
|||
|
||||
for (size_t i = 0; i < items_cnt; ++i) {
|
||||
struct check_item *item = items + i;
|
||||
unsigned long id = item->id;
|
||||
|
||||
if (id & 1) {
|
||||
if (item->id & 1) {
|
||||
--cnt;
|
||||
hashmap_delete(map, item, -1);
|
||||
}
|
||||
|
@ -171,18 +168,16 @@ check_hashmap (
|
|||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
static uint64_t buf[4];
|
||||
uint64_t *seed = NULL;
|
||||
|
||||
uint64_t seed_buf[4], *seed = NULL;
|
||||
int n = -1;
|
||||
int r = -1;
|
||||
|
||||
getopt_foreach(argc, argv, ":s:n:r:") {
|
||||
case 's':
|
||||
if (0 != prng_seed_from_hex(buf, optarg)) {
|
||||
if (0 != prng_seed_from_hex(seed_buf, optarg)) {
|
||||
return -1;
|
||||
}
|
||||
seed = buf;
|
||||
seed = seed_buf;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
|
@ -209,5 +204,5 @@ check_hashmap (
|
|||
if (0 != prng_seed(seed)) {
|
||||
return -1;
|
||||
}
|
||||
return do_check_hashmap(n, r);
|
||||
return do_check_hashmap(1u << n, r);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
// Forward declaration start
|
||||
static int dispatch_subcmds (int, char *[]);
|
||||
static size_t hash_cb (void *, void const **);
|
||||
static size_t hash_check_cb (void *, void const **);
|
||||
static int subcmd_hash (int, char *[]);
|
||||
static int subcmd_prng (int, char *[]);
|
||||
// Forward declaration end
|
||||
|
@ -70,7 +70,7 @@ dispatch_subcmds (
|
|||
}
|
||||
|
||||
static size_t
|
||||
hash_cb (
|
||||
hash_check_cb (
|
||||
void *UNUSED_VAR(user_data),
|
||||
void const **buf_ptr
|
||||
) {
|
||||
|
@ -98,7 +98,7 @@ subcmd_hash (
|
|||
}
|
||||
|
||||
hash_seed(seed);
|
||||
printf("%016" PRIx64 "\n", hash_digestcb(hash_cb, NULL));
|
||||
printf("%016" PRIx64 "\n", hash_digestcb(hash_check_cb, NULL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -107,16 +107,15 @@ subcmd_prng (
|
|||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
static uint64_t buf[4];
|
||||
uint64_t *seed = NULL;
|
||||
uint64_t seed_buf[4], *seed = NULL;
|
||||
int n = 0;
|
||||
|
||||
getopt_foreach(argc, argv, ":s:n:") {
|
||||
case 's':
|
||||
if (0 != prng_seed_from_hex(buf, optarg)) {
|
||||
if (0 != prng_seed_from_hex(seed_buf, optarg)) {
|
||||
return -1;
|
||||
}
|
||||
seed = buf;
|
||||
seed = seed_buf;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
|
|
|
@ -15,6 +15,7 @@ ATX_CHECK_LIB([
|
|||
if test -z "$seed"; then
|
||||
seed=$(ath_fn_prng_seed)
|
||||
fi
|
||||
echo "prng seed: $seed"
|
||||
|
||||
size="${CHECK_HASHMAP_DATA_SIZE}"
|
||||
if test -z "$size"; then
|
||||
|
|
Loading…
Add table
Reference in a new issue