bookmarkfs/tests/lib_hash.at
CismonX bced141b98
test: misc fix and refactor
- Do not exit with status 99.  It is considered a "hard failure"
  in Autotest, and cleanup script won't be executed.
- Fix ATX_FEAT_PREREQ().
- Remove unneeded helper macros.
- Add more log output.
2025-03-24 19:30:32 +08:00

41 lines
1.1 KiB
Text

dnl
dnl Copyright (C) 2025 CismonX <admin@cismon.net>
dnl
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty,
dnl provided the copyright notice and this notice are preserved.
dnl This file is offered as-is, without any warranty.
dnl
AT_SETUP([util lib: hash function])
AT_KEYWORDS([lib hash])
# This test only serves as a basic sanity check.
#
# For reliable testing of hash functions,
# see <https://github.com/Cyan4973/xxHash/tree/dev/tests>.
ATX_CHECK_LIB([
calc_digest() {
echo "$2" | check-util-lib hash -s$1
}
seed=$(ath_fn_rand_u64_hex)
input=$(ath_fn_rand_base64 300)
hash_1=$(calc_digest $seed $input)
hash_2=$(calc_digest $seed $input)
hash_3=$(calc_digest $seed $input)
hash_x=$(calc_digest $seed $input+)
if test "$hash_1" != "$hash_2" -o "$hash_2" != "$hash_3"; then
echo 'bad hash function: inconsistent digest'
exit 1
fi
if test "$hash_1" = "$hash_x"; then
echo 'bad hash function: collision'
exit 1
fi
])
AT_CLEANUP