From 1e3637af595b88954efe37b2d294fb24b3043854 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 10 Aug 2019 23:04:00 +0300 Subject: [PATCH] mdbx-test: refine long_stochastic-script for FreeBSD compatibility. Change-Id: I411b628d9381a54bebbea33a2bfde3145bdba74b --- test/long_stochastic.sh | 71 ++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/test/long_stochastic.sh b/test/long_stochastic.sh index 026c9a41..954d1826 100755 --- a/test/long_stochastic.sh +++ b/test/long_stochastic.sh @@ -1,24 +1,49 @@ #!/bin/bash if ! which make cc c++ tee lz4 >/dev/null; then echo "Please install the following prerequisites: make cc c++ tee lz4" >&2 - exit -1 + exit 1 fi set -euo pipefail -TESTDB_PREFIX=${1:-/dev/shm/mdbx-gc-test}. -rm -f $(dirname ${TESTDB_PREFIX})/* +UNAME="$(uname -s 2>/dev/null || echo Unknown)" +case ${UNAME} in + Linux) + MAKE=make + if [[ ! -v TESTDB_DIR || -z "$TESTDB_DIR" ]]; then + TESTDB_DIR="/dev/shm/mdbx-test.$$" + fi + mkdir -p $TESTDB_DIR && rm -f $TESTDB_DIR/* + if LC_ALL=C free | grep -q -i available; then + ram_avail_mb=$(($(LC_ALL=C free | grep -i Mem: | tr -s [:blank:] ' ' | cut -d ' ' -f 7) / 1024)) + else + ram_avail_mb=$(($(LC_ALL=C free | grep -i Mem: | tr -s [:blank:] ' ' | cut -d ' ' -f 4) / 1024)) + fi + ;; + FreeBSD) + MAKE=gmake + if [[ ! -v TESTDB_DIR || -z "$TESTDB_DIR" ]]; then + for old_test_dir in $(ls -d /tmp/mdbx-test.[0-9]*); do + umount $old_test_dir && rm -r $old_test_dir + done + TESTDB_DIR="/tmp/mdbx-test.$$" + rm -rf $TESTDB_DIR && mkdir -p $TESTDB_DIR && mount -t tmpfs tmpfs $TESTDB_DIR + else + mkdir -p $TESTDB_DIR && rm -f $TESTDB_DIR/* + fi + ram_avail_mb=$(($(LC_ALL=C vmstat -s | grep -ie '[0-9] pages free$' | cut -d p -f 1) * ($(LC_ALL=C vmstat -s | grep -ie '[0-9] bytes per page$' | cut -d b -f 1) / 1024) / 1024)) + ;; + *) + echo "FIXME: ${UNAME} not supported by this script" + exit 2 + ;; +esac -if LC_ALL=C free | grep -q -i available; then - ram_avail_mb=$(($(LC_ALL=C free | grep -i Mem: | tr -s [:blank:] ' ' | cut -d ' ' -f 7) / 1024)) -else - ram_avail_mb=$(($(LC_ALL=C free | grep -i Mem: | tr -s [:blank:] ' ' | cut -d ' ' -f 4) / 1024)) -fi - -ram_reserve4logs_mb=3333 -if [ ${ram_avail_mb} -lt ${ram_reserve4logs_mb} ]; then +echo "=== ${ram_avail_mb}M RAM available" +ram_reserve4logs_mb=1234 +if [ $ram_avail_mb -lt $ram_reserve4logs_mb ]; then echo "=== At least ${ram_reserve4logs_mb}Mb RAM required" - exit -2 + exit 3 fi # @@ -39,14 +64,14 @@ fi # that malloc() will not return the allocated memory to the # system immediately, as well some space is required for logs. # -db_size_mb=$(expr '(' ${ram_avail_mb} - ${ram_reserve4logs_mb} ')' / 4) -if [ ${db_size_mb} -gt 3072 ]; then -db_size_mb=3072 +db_size_mb=$(((ram_avail_mb - ram_reserve4logs_mb) / 4)) +if [ $db_size_mb -gt 3072 ]; then + db_size_mb=3072 fi -echo "=== ${ram_avail_mb}M RAM available, use ${db_size_mb}M for DB" +echo "=== use ${db_size_mb}M for DB" -make check -rm -f $(dirname ${TESTDB_PREFIX})/* +${MAKE} TESTDB=${TESTDB_DIR}/smoke.db TESTLOG=${TESTDB_DIR}/smoke.log check +rm -f ${TESTDB_DIR}/* ############################################################################### @@ -69,10 +94,10 @@ function bits2list { function probe { echo "=============================================== $(date)" echo "${caption}: $*" - rm -f ${TESTDB_PREFIX}* \ - && ./mdbx_test --ignore-dbfull --repeat=42 --pathname=${TESTDB_PREFIX}db "$@" | lz4 > ${TESTDB_PREFIX}log.lz4 \ - && ./mdbx_chk -nvvv ${TESTDB_PREFIX}db | tee ${TESTDB_PREFIX}chk \ - && ([ ! -e ${TESTDB_PREFIX}db-copy ] || ./mdbx_chk -nvvv ${TESTDB_PREFIX}db-copy | tee ${TESTDB_PREFIX}chk-copy) \ + rm -f ${TESTDB_DIR}/* \ + && ./mdbx_test --ignore-dbfull --repeat=42 --pathname=${TESTDB_DIR}/long.db "$@" | lz4 > ${TESTDB_DIR}/long.log.lz4 \ + && ./mdbx_chk -nvvv ${TESTDB_DIR}/long.db | tee ${TESTDB_DIR}/long-chk.log \ + && ([ ! -e ${TESTDB_DIR}/long.db-copy ] || ./mdbx_chk -nvvv ${TESTDB_DIR}/long.db-copy | tee ${TESTDB_DIR}/long-chk-copy.log) \ || (echo "FAILED"; exit 1) } @@ -84,7 +109,7 @@ for nops in $(seq 2 6); do loops=$(((111 >> nops) / nops + 3)) for ((rep=0; rep++ < loops; )); do for ((bits=2**${#options[@]}; --bits >= 0; )); do - seed=$(date +%N) + seed=$(($(date +%s) + RANDOM)) caption="Probe #$((++count)) int-key,w/o-dups, repeat ${rep} of ${loops}" probe \ --pagesize=min --size-upper=${db_size_mb}M --table=+key.integer,-data.dups --keylen.min=min --keylen.max=max --datalen.min=min --datalen.max=1111 \ --nops=$( rep9 $nops ) --batch.write=$( rep9 $wbatch ) --mode=$(bits2list options $bits) \