Spdk/test/dd/posix.sh
paul luse eb53c23236 add (c) and SPDX header to bash files as needed
per Intel policy to include file commit date using git cmd
below.  The policy does not apply to non-Intel (C) notices.

git log --follow -C90% --format=%ad --date default <file> | tail -1

and then pull just the year from the result.

Intel copyrights were not added to files where Intel either had
no contribution ot the contribution lacked substance (ie license
header updates, formatting changes, etc)

For intel copyrights added, --follow and -C95% were used.

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I2ef86976095b88a9bf5b1003e59f3943cd6bbe4c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15209
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-11-29 08:27:51 +00:00

132 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2020 Intel Corporation
# All rights reserved.
#
testdir=$(readlink -f "$(dirname "$0")")
rootdir=$(readlink -f "$testdir/../../")
source "$testdir/common.sh"
cleanup() {
rm -f "$test_file0"{,.link}
rm -f "$test_file1"{,.link}
}
append() {
local dump0
local dump1
dump0=$(gen_bytes 32)
dump1=$(gen_bytes 32)
printf '%s' "$dump0" > "$test_file0"
printf '%s' "$dump1" > "$test_file1"
"${DD_APP[@]}" --if="$test_file0" --of="$test_file1" --oflag=append
[[ $(< "$test_file1") == "${dump1}${dump0}" ]]
}
directory() {
NOT "${DD_APP[@]}" --if="$test_file0" --iflag=directory --of="$test_file0"
NOT "${DD_APP[@]}" --if="$test_file0" --of="$test_file0" --oflag=directory
}
nofollow() {
local test_file0_link=$test_file0.link
local test_file1_link=$test_file1.link
ln -fs "$test_file0" "$test_file0_link"
ln -fs "$test_file1" "$test_file1_link"
NOT "${DD_APP[@]}" --if="$test_file0_link" --iflag=nofollow --of="$test_file1"
NOT "${DD_APP[@]}" --if="$test_file0" --of="$test_file1_link" --oflag=nofollow
# Do an extra step of checking if we actually can follow symlinks
gen_bytes 512 > "$test_file0"
"${DD_APP[@]}" --if="$test_file0_link" --of="$test_file1"
[[ $(< "$test_file0") == "$(< "$test_file1")" ]]
}
noatime() {
local atime_if
local atime_of
# It seems like spdk_dd doesn't update the atime in case 0 bytes are copied.
# This differs from how standard dd works for instance
gen_bytes 512 > "$test_file0"
atime_if=$(stat --printf="%X" "$test_file0")
atime_of=$(stat --printf="%X" "$test_file1")
# Make sure atime has a chance to be updated - if all tests finish within
# 1s (see %X) we may get a false negative at the last check. See:
# https://github.com/spdk/spdk/issues/2720
sleep 1
"${DD_APP[@]}" --if="$test_file0" --iflag=noatime --of="$test_file1"
((atime_if == $(stat --printf="%X" "$test_file0")))
((atime_of == $(stat --printf="%X" "$test_file1")))
"${DD_APP[@]}" --if="$test_file0" --of="$test_file1"
((atime_if < $(stat --printf="%X" "$test_file0")))
}
io() {
local flags_ro flags_rw flag_ro flag_rw
# O_NONBLOCK is actually a no-op, from a functional perspective, while
# open()ing a regular file, but let's keep it just to test its usage.
flags_ro=(direct nonblock)
flags_rw=("${flags_ro[@]}" sync dsync)
# simply check if data was correctly copied between files
for flag_ro in "${flags_ro[@]}"; do
gen_bytes 512 > "$test_file0"
for flag_rw in "${flags_rw[@]}"; do
"${DD_APP[@]}" \
--if="$test_file0" \
--iflag="$flag_ro" \
--of="$test_file1" \
--oflag="$flag_rw"
[[ $(< "$test_file0") == "$(< "$test_file1")" ]]
done
done
}
tests() {
printf '* First test run%s\n' \
"${msg[liburing_in_use]}" >&2
run_test "dd_flag_append" append
run_test "dd_flag_directory" directory
run_test "dd_flag_nofollow" nofollow
run_test "dd_flag_noatime" noatime
run_test "dd_flags_misc" io
}
tests_forced_aio() {
printf '* Second test run%s\n' \
"${msg[liburing_in_use ? 2 : 0]}" >&2
DD_APP+=("--aio")
run_test "dd_flag_append_forced_aio" append
run_test "dd_flag_directory_forced_aio" directory
run_test "dd_flag_nofollow_forced_aio" nofollow
run_test "dd_flag_noatime_forced_aio" noatime
run_test "dd_flags_misc_forced_aio" io
}
msg[0]=", using AIO"
msg[1]=", liburing in use"
msg[2]=", disabling liburing, forcing AIO"
trap "cleanup" EXIT
test_file0=$SPDK_TEST_STORAGE/dd.dump0
test_file1=$SPDK_TEST_STORAGE/dd.dump1
tests
tests_forced_aio