summaryrefslogtreecommitdiffstats
path: root/tests/ts/fincore
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:14:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 13:14:44 +0000
commit30ff6afe596eddafacf22b1a5b2d1a3d6254ea15 (patch)
tree9b788335f92174baf7ee18f03ca8330b8c19ce2b /tests/ts/fincore
parentInitial commit. (diff)
downloadutil-linux-30ff6afe596eddafacf22b1a5b2d1a3d6254ea15.tar.xz
util-linux-30ff6afe596eddafacf22b1a5b2d1a3d6254ea15.zip
Adding upstream version 2.36.1.upstream/2.36.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ts/fincore')
-rwxr-xr-xtests/ts/fincore/count227
1 files changed, 227 insertions, 0 deletions
diff --git a/tests/ts/fincore/count b/tests/ts/fincore/count
new file mode 100755
index 0000000..fb35b0f
--- /dev/null
+++ b/tests/ts/fincore/count
@@ -0,0 +1,227 @@
+#!/bin/bash
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="count file contents in core"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_HELPER_SYSINFO"
+
+# Send patch if you know how to keep it portable and robust. Thanks.
+TS_KNOWN_FAIL="yes"
+
+function footer
+{
+ echo "return value: $1"
+}
+
+function make_input_name
+{
+ header=$1
+ prefix=i_
+ echo ${prefix}$(sed -e "s/[^-+a-zA-Z0-9_]/_/g"<<<"$header")
+}
+
+function _dd
+{
+ local msg
+ local ret=0
+
+ msg=$(dd "$@" 2>&1)
+ ret=$?
+ if [ $ret != 0 ]; then
+ echo "failed: dd $@" >&2
+ echo "$msg" >&2
+ fi
+ return $ret
+}
+
+function check_dd_fs_feat
+{
+ local testf="$TS_OUTDIR/ddtest"
+ rm -f "$testf"
+ touch "$testf"
+
+ # NFS seems to fail for direct AND append
+ _dd if=/dev/zero of="$testf" bs=1k count=2 oflag=direct,append &>/dev/null \
+ || ts_skip "unsupported: dd oflag=direct,append"
+
+ # TODO: Should we check for sparse file support?
+
+ rm -f "$testf"
+}
+
+function run_dd_test
+{
+ header=$1
+ bs=$2
+ flags=$3
+
+ input=$(make_input_name "$header")
+ INPUT="${INPUT} ${input}"
+ rm -f "$input"
+
+ if [ "$bs" = 0 ]; then
+ touch $input
+ else
+ _dd if=/dev/zero of=$input count=1 bs=$bs $flags || return
+ fi
+
+ $TS_CMD_FINCORE --output $OUT_COLUMNS --bytes --noheadings $input
+
+ footer "$?"
+}
+
+function run_dd_dd_test
+{
+ header=$1
+ flags0=$2
+ flags1=$3
+
+ bs=$PAGE_SIZE
+
+ input=$(make_input_name "$header")
+ INPUT="${INPUT} ${input}"
+ rm -f "$input"
+
+ _dd if=/dev/zero of=$input count=1 bs=$bs $flags0 || return
+ _dd if=/dev/zero of=$input count=1 bs=$bs $flags1 || return
+
+ $TS_CMD_FINCORE --output $OUT_COLUMNS --bytes --noheadings $input
+
+ footer "$?"
+}
+
+
+PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize)
+WINDOW_SIZE=$(( 32 * 1024 * PAGE_SIZE ))
+
+# we use PAGE_SIZE dependent output for a few systems
+if test -f "$TS_EXPECTED.$PAGE_SIZE"; then
+ TS_EXPECTED+=".$PAGE_SIZE"
+ TS_EXPECTED_ERR+=".$PAGE_SIZE"
+ OUT_COLUMNS="PAGES,SIZE,FILE"
+else
+ TS_EXPECTED+=".nosize"
+ OUT_COLUMNS="PAGES,FILE"
+fi
+
+
+ts_check_test_command "$TS_CMD_FINCORE"
+ts_cd "$TS_OUTDIR"
+
+check_dd_fs_feat
+
+INPUT=
+input=
+
+{
+ input=no_such_file
+ INPUT="${INPUT} ${input}"
+
+ ts_log_both "[ NO EXCITING FILE ]"
+ $TS_CMD_FINCORE --output $OUT_COLUMNS --bytes --noheadings $input
+ footer "$?"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "EMPTY FILE" 0
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "PAGESIZE -1 (incore)" $(( PAGE_SIZE - 1 ))
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "JUST PAGESIZE(incore)" $(( PAGE_SIZE ))
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "JUST PAGESIZE(directio)" $(( PAGE_SIZE )) "oflag=direct"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "TWO PAGES(incore)" $(( 2 * PAGE_SIZE ))
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_test "TWO PAGES(directio)" $(( 2 * PAGE_SIZE )) "oflag=direct"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_dd_test "TWO PAGES(mixed directio/incore)" \
+ oflag=direct \
+ "oflag=append seek=1"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ run_dd_dd_test "TWO PAGES(mixed incore/directio)" \
+ "" \
+ "oflag=direct,append seek=1"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 ))
+ run_dd_dd_test "WINDOW SIZE(incore-sparse-incore)" \
+ "" \
+ "oflag=append seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 ))
+ run_dd_dd_test "WINDOW SIZE(directio-sparse-directio)" \
+ "oflag=direct" \
+ "oflag=append,direct seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 ))
+ run_dd_dd_test "WINDOW SIZE(incore-sparse-directio)" \
+ "" \
+ "oflag=append,direct seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 ))
+ run_dd_dd_test "WINDOW SIZE(directio-sparse-incore)" \
+ "oflag=direct" \
+ "oflag=append seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 ))
+ run_dd_dd_test "WINDOW SIZE + 1 page(incore-sparse-incore)" \
+ "" \
+ "oflag=append seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 ))
+ run_dd_dd_test "WINDOW SIZE + 1 page(directio-sparse-directio)" \
+ "oflag=direct" \
+ "oflag=append,direct seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 ))
+ run_dd_dd_test "WINDOW SIZE + 1 page(incore-sparse-directio)" \
+ "" \
+ "oflag=append,direct seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 ))
+ run_dd_dd_test "WINDOW SIZE + 1 page(directio-sparse-incore)" \
+ "oflag=direct" \
+ "oflag=append seek=$hole_count"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+{
+ ts_log_both "[ MULTIPLE FILES ]"
+ $TS_CMD_FINCORE --output $OUT_COLUMNS --bytes $INPUT
+ footer "$?"
+} >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+rm -f $INPUT
+ts_finalize