From 5b194a22f7e1898d11dacfe056c1fdc60b3868e6 Mon Sep 17 00:00:00 2001 From: meo Date: Tue, 7 Jan 2025 14:50:06 +0100 Subject: [PATCH] fix: time in macOS and freeBSD - use of gdate (coreutils) for macOS - switch to `ns` in place of `ms` for freeBSD --- .github/workflows/test.yml | 3 +++ testing.sh | 36 +++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02e3b01..b014837 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,9 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install coreutils + run: brew install coreutils + - name: Run testing script on macOS run: ./testing.sh diff --git a/testing.sh b/testing.sh index 108e440..f531e1e 100755 --- a/testing.sh +++ b/testing.sh @@ -42,6 +42,21 @@ function prepare() { cp -rf $test_data_src $test_pool_data_path } +# return time to the milisecond +function get_time() { + + case "$OSTYPE" in + darwin*) + date=$(gdate +%s%N) + ;; + *) + date=$(date +%s%N) + ;; + esac + + echo "$date" +} + function assertions() { # check error log is empty if grep -q '[^[:space:]]' $log_error_file; then @@ -139,30 +154,33 @@ color_echo "$Green" "Files created!" echo "Running rebalancing on small files..." # measure time taken -start_time=$(date +%s%3N) +start_time=$(get_time) ./zfs-inplace-rebalancing.sh $test_pool_data_size_path/small >> $log_std_file 2>> $log_error_file -end_time=$(date +%s%3N) -print_time_taken $((end_time - start_time)) +end_time=$(get_time) +time_taken=$(( (end_time - start_time) / 1000000 )) +print_time_taken $time_taken assertions color_echo "$Green" "Tests passed!" echo "Running rebalancing on big files..." rm -f rebalance_db.txt # measure time taken -start_time=$(date +%s%3N) +start_time=$(get_time) ./zfs-inplace-rebalancing.sh $test_pool_data_size_path/big >> $log_std_file 2>> $log_error_file -end_time=$(date +%s%3N) -print_time_taken $((end_time - start_time)) +end_time=$(get_time) +time_taken=$(( (end_time - start_time) / 1000000 )) +print_time_taken $time_taken assertions color_echo "$Green" "Tests passed!" echo "Running rebalancing on all files..." rm -f rebalance_db.txt # measure time taken -start_time=$(date +%s%3N) +start_time=$(get_time) ./zfs-inplace-rebalancing.sh $test_pool_data_size_path >> $log_std_file 2>> $log_error_file -end_time=$(date +%s%3N) -print_time_taken $((end_time - start_time)) +end_time=$(get_time) +time_taken=$(( (end_time - start_time) / 1000000 )) +print_time_taken $time_taken assertions color_echo "$Green" "Tests passed!"