From ea482ce7b6d7f662701874c2ef889054831f36d5 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Tue, 8 Jan 2019 20:10:38 +0100 Subject: [PATCH] make tests work on FreeBSD --- tests/1_one_year/run.sh | 2 +- tests/2_dst_handling/run.sh | 2 +- tests/common/lib.sh | 14 +++++++++++++- tests/run-tests.sh | 2 +- .../1_bookmark_replication_intermediate/run.sh | 4 ++-- .../2_bookmark_replication_no_intermediate/run.sh | 4 ++-- tests/syncoid/3_force_delete/run.sh | 4 ++-- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/1_one_year/run.sh b/tests/1_one_year/run.sh index 1cae7b4..88100da 100755 --- a/tests/1_one_year/run.sh +++ b/tests/1_one_year/run.sh @@ -39,7 +39,7 @@ function cleanUp { trap cleanUp EXIT while [ $timestamp -le $END ]; do - date --utc --set @$timestamp; date; "${SANOID}" --cron --verbose + setdate $timestamp; date; "${SANOID}" --cron --verbose timestamp=$((timestamp+3600)) done diff --git a/tests/2_dst_handling/run.sh b/tests/2_dst_handling/run.sh index eba21ed..7d7774e 100755 --- a/tests/2_dst_handling/run.sh +++ b/tests/2_dst_handling/run.sh @@ -42,7 +42,7 @@ function cleanUp { trap cleanUp EXIT while [ $timestamp -le $END ]; do - date --utc --set @$timestamp; date; "${SANOID}" --cron --verbose + setdate $timestamp; date; "${SANOID}" --cron --verbose timestamp=$((timestamp+900)) done diff --git a/tests/common/lib.sh b/tests/common/lib.sh index 78f128b..3aee40d 100644 --- a/tests/common/lib.sh +++ b/tests/common/lib.sh @@ -1,5 +1,7 @@ #!/bin/bash +unamestr="$(uname)" + function setup { export LANG=C export LANGUAGE=C @@ -90,7 +92,7 @@ function verifySnapshotList { message="${message}monthly snapshot count is wrong: ${monthly_count}\n" fi - checksum=$(sha256sum "${RESULT}" | cut -d' ' -f1) + checksum=$(shasum -a 256 "${RESULT}" | cut -d' ' -f1) if [ "${checksum}" != "${CHECKSUM}" ]; then failed=1 message="${message}result checksum mismatch\n" @@ -105,3 +107,13 @@ function verifySnapshotList { exit 1 } + +function setdate { + TIMESTAMP="$1" + + if [ "$unamestr" == 'FreeBSD' ]; then + date -u -f '%s' "${TIMESTAMP}" + else + date --utc --set "@${TIMESTAMP}" + fi +} diff --git a/tests/run-tests.sh b/tests/run-tests.sh index a8469e9..38054b0 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -15,7 +15,7 @@ for test in */; do echo -n "Running test ${testName} ... " cd "${test}" - echo | bash run.sh > "${LOGFILE}" 2>&1 + echo -n y | bash run.sh > "${LOGFILE}" 2>&1 if [ $? -eq 0 ]; then echo "[PASS]" diff --git a/tests/syncoid/1_bookmark_replication_intermediate/run.sh b/tests/syncoid/1_bookmark_replication_intermediate/run.sh index 11edb04..66af442 100755 --- a/tests/syncoid/1_bookmark_replication_intermediate/run.sh +++ b/tests/syncoid/1_bookmark_replication_intermediate/run.sh @@ -46,8 +46,8 @@ zfs snapshot "${POOL_NAME}"/src@snap5 ../../../syncoid --debug --compress=none "${POOL_NAME}"/src "${POOL_NAME}"/dst || exit 1 # verify -output=$(zfs list -t snapshot -r "${POOL_NAME}" -H -o name) -checksum=$(echo "${output}" | grep -v syncoid_ | sha256sum) +output=$(zfs list -t snapshot -r -H -o name "${POOL_NAME}") +checksum=$(echo "${output}" | grep -v syncoid_ | shasum -a 256) if [ "${checksum}" != "${TARGET_CHECKSUM}" ]; then exit 1 diff --git a/tests/syncoid/2_bookmark_replication_no_intermediate/run.sh b/tests/syncoid/2_bookmark_replication_no_intermediate/run.sh index 94ac690..f6c1755 100755 --- a/tests/syncoid/2_bookmark_replication_no_intermediate/run.sh +++ b/tests/syncoid/2_bookmark_replication_no_intermediate/run.sh @@ -46,8 +46,8 @@ zfs snapshot "${POOL_NAME}"/src@snap5 ../../../syncoid --no-stream --no-sync-snap --debug --compress=none "${POOL_NAME}"/src "${POOL_NAME}"/dst || exit 1 # verify -output=$(zfs list -t snapshot -r "${POOL_NAME}" -H -o name) -checksum=$(echo "${output}" | sha256sum) +output=$(zfs list -t snapshot -r -H -o name "${POOL_NAME}") +checksum=$(echo "${output}" | shasum -a 256) if [ "${checksum}" != "${TARGET_CHECKSUM}" ]; then exit 1 diff --git a/tests/syncoid/3_force_delete/run.sh b/tests/syncoid/3_force_delete/run.sh index 03ad9fa..25044cb 100755 --- a/tests/syncoid/3_force_delete/run.sh +++ b/tests/syncoid/3_force_delete/run.sh @@ -37,8 +37,8 @@ sleep 1 ../../../syncoid -r --force-delete --debug --compress=none "${POOL_NAME}"/src "${POOL_NAME}"/dst || exit 1 # verify -output=$(zfs list -t snapshot -r "${POOL_NAME}" -H -o name | sed 's/@syncoid_.*$'/@syncoid_/) -checksum=$(echo "${output}" | sha256sum) +output=$(zfs list -t snapshot -r -H -o name "${POOL_NAME}" | sed 's/@syncoid_.*$'/@syncoid_/) +checksum=$(echo "${output}" | shasum -a 256) if [ "${checksum}" != "${TARGET_CHECKSUM}" ]; then exit 1