Skip to content

Commit

Permalink
ZTS: use openssl for md5digest and sha256digest
Browse files Browse the repository at this point in the history
On larger files this should improve the speed.

Sample values of my system:

[mcmilk@xz]$ time dd if=/dev/zero bs=128k count=1k | sha256sum
254bcc3fc4f27172636df4bf32de9f107f620d559b20d760197e452b97453917  -
real    0m1,050s
user    0m0,985s
sys     0m0,153s

[mcmilk@xz]$ time dd if=/dev/zero bs=128k count=1k | openssl sha256 -r
254bcc3fc4f27172636df4bf32de9f107f620d559b20d760197e452b97453917 *stdin
real    0m0,254s
user    0m0,206s
sys     0m0,160s

I think cli_root/zdb/zdb_backup.ksh runs also an FreeBSD and I needed to
include the sysutils/coreutils package for the FreeBSD tests within the
QEMU patchset.

This could be reverted, when this pull request gets upstream

Reviewed-by: George Melikov <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Tino Reichardt <[email protected]>
Closes #16543
  • Loading branch information
mcmilk authored Sep 19, 2024
1 parent e8ede2b commit 4bf6a2a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
26 changes: 2 additions & 24 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -3460,18 +3460,7 @@ function tunable_exists
#
function md5digest
{
typeset file=$1

case "$UNAME" in
FreeBSD)
md5 -q $file
;;
*)
typeset sum _
read -r sum _ < <(md5sum -b $file)
echo $sum
;;
esac
openssl md5 -r $1 | awk '{print $1}'
}

#
Expand All @@ -3492,18 +3481,7 @@ function cmp_md5s {
#
function sha256digest
{
typeset file=$1

case "$UNAME" in
FreeBSD)
sha256 -q $file
;;
*)
typeset sum _
read -r sum _ < <(sha256sum -b $file)
echo $sum
;;
esac
openssl sha256 -r $1 | awk '{print $1}'
}

function new_fs #<args>
Expand Down
4 changes: 2 additions & 2 deletions tests/zfs-tests/tests/functional/cli_root/zdb/zdb_backup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ sync_pool $TESTPOOL
log_must eval "zfs send -ecL $snap > $tmpfile.1"
log_must eval "zdb -B $TESTPOOL/$objsetid ecL > $tmpfile.2"

typeset sum1=$(cat $tmpfile.1 | md5sum)
typeset sum2=$(cat $tmpfile.2 | md5sum)
typeset sum1=$(md5digest $tmpfile.1)
typeset sum2=$(md5digest $tmpfile.2)

log_must test "$sum1" = "$sum2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ log_assert "ensure single-disk pool resumes properly after suspend and clear"

# create a file, and take a checksum, so we can compare later
log_must dd if=/dev/urandom of=$DATAFILE bs=128K count=1
typeset sum1=$(cat $DATAFILE | md5sum)
typeset sum1=$(md5digest $DATAFILE)

# make a debug device that we can "unplug"
load_scsi_debug 100 1 1 1 '512b'
Expand Down Expand Up @@ -94,7 +94,7 @@ log_must zpool export $TESTPOOL
log_must zpool import $TESTPOOL

# sum the file we wrote earlier
typeset sum2=$(cat /$TESTPOOL/file | md5sum)
typeset sum2=$(md5digest /$TESTPOOL/file)

# make sure the checksums match
log_must test "$sum1" = "$sum2"
Expand Down

0 comments on commit 4bf6a2a

Please sign in to comment.