| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
TS_TOPDIR="${0%/*}/../.." |
| 4 |
TS_DESC="count file contents in core" |
| 5 |
|
| 6 |
. "$TS_TOPDIR"/functions.sh |
| 7 |
ts_init "$*" |
| 8 |
|
| 9 |
ts_check_test_command "$TS_CMD_FINDMNT" |
| 10 |
ts_check_test_command "$TS_HELPER_SYSINFO" |
| 11 |
|
| 12 |
FS="$("$TS_CMD_FINDMNT" -nr -o FSTYPE -T "$TS_OUTDIR")" |
| 13 |
if [[ "$FS" = "tmpfs" || "$FS" = "overlay" || "$FS" = "" ]]; then |
| 14 |
ts_skip "fincore does not work on tmpfs or unknown fs" |
| 15 |
fi |
| 16 |
|
| 17 |
# https://github.com/util-linux/util-linux/pull/3529 |
| 18 |
if [ "$($TS_HELPER_SYSINFO fts)" != FTS ]; then |
| 19 |
ts_skip "fts_open() is unreliable on this setup" |
| 20 |
fi |
| 21 |
|
| 22 |
function footer |
| 23 |
{ |
| 24 |
echo "return value: $1" |
| 25 |
} |
| 26 |
|
| 27 |
function make_input_name |
| 28 |
{ |
| 29 |
header=$1 |
| 30 |
prefix=i_ |
| 31 |
echo ${prefix}$(sed -e "s/[^-+a-zA-Z0-9_/]/_/g"<<<"$header") |
| 32 |
} |
| 33 |
|
| 34 |
function _dd |
| 35 |
{ |
| 36 |
local msg |
| 37 |
local ret=0 |
| 38 |
|
| 39 |
msg=$(dd "$@" 2>&1) |
| 40 |
ret=$? |
| 41 |
if [ $ret != 0 ]; then |
| 42 |
echo "failed: dd $@" >&2 |
| 43 |
echo "$msg" >&2 |
| 44 |
fi |
| 45 |
return $ret |
| 46 |
} |
| 47 |
|
| 48 |
function check_dd_fs_feat |
| 49 |
{ |
| 50 |
local testf="$TS_OUTDIR/ddtest" |
| 51 |
rm -f "$testf" |
| 52 |
touch "$testf" |
| 53 |
|
| 54 |
# NFS seems to fail for direct AND append |
| 55 |
_dd if=/dev/zero of="$testf" bs=1k count=2 oflag=direct,append &>/dev/null \ |
| 56 |
|| ts_skip "unsupported: dd oflag=direct,append" |
| 57 |
|
| 58 |
# TODO: Should we check for sparse file support? |
| 59 |
|
| 60 |
rm -f "$testf" |
| 61 |
} |
| 62 |
|
| 63 |
function run_dd_test |
| 64 |
{ |
| 65 |
header=$1 |
| 66 |
bs=$2 |
| 67 |
flags=$3 |
| 68 |
|
| 69 |
input=$(make_input_name "$header") |
| 70 |
INPUT="${INPUT} ${input}" |
| 71 |
rm -f "$input" |
| 72 |
|
| 73 |
if [ "$bs" = 0 ]; then |
| 74 |
touch $input |
| 75 |
else |
| 76 |
_dd if=/dev/zero of=$input count=1 bs=$bs $flags || return |
| 77 |
fi |
| 78 |
|
| 79 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings $input |
| 80 |
|
| 81 |
footer "$?" |
| 82 |
} |
| 83 |
|
| 84 |
function run_dd_dd_test |
| 85 |
{ |
| 86 |
header=$1 |
| 87 |
flags0=$2 |
| 88 |
flags1=$3 |
| 89 |
|
| 90 |
bs=$PAGE_SIZE |
| 91 |
|
| 92 |
input=$(make_input_name "$header") |
| 93 |
INPUT="${INPUT} ${input}" |
| 94 |
rm -f "$input" |
| 95 |
|
| 96 |
_dd if=/dev/zero of=$input count=1 bs=$bs $flags0 || return |
| 97 |
_dd if=/dev/zero of=$input count=1 bs=$bs $flags1 || return |
| 98 |
|
| 99 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings $input |
| 100 |
|
| 101 |
footer "$?" |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize) |
| 106 |
WINDOW_SIZE=$(( 32 * 1024 * PAGE_SIZE )) |
| 107 |
|
| 108 |
AGG_OUT="$TS_OUTDIR/count.aggregate" |
| 109 |
AGG_ERR="$TS_OUTDIR/count.err.aggregate" |
| 110 |
|
| 111 |
# we use PAGE_SIZE dependent output for a few systems |
| 112 |
if test -f "$TS_EXPECTED.$PAGE_SIZE"; then |
| 113 |
cat "$TS_EXPECTED.$PAGE_SIZE" >"$AGG_OUT" |
| 114 |
OUT_COLUMNS="PAGES,SIZE,FILE" |
| 115 |
else |
| 116 |
cat "$TS_EXPECTED.nosize" >"$AGG_OUT" |
| 117 |
OUT_COLUMNS="PAGES,FILE" |
| 118 |
fi |
| 119 |
|
| 120 |
cat "$TS_EXPECTED.total" >>"$AGG_OUT" |
| 121 |
cat "$TS_EXPECTED_ERR" >"$AGG_ERR" |
| 122 |
|
| 123 |
if ! $TS_CMD_FINCORE --recursive |& grep -q 'recursive option is not supported' ; then |
| 124 |
RECURSIVE=1 |
| 125 |
if test -f "$TS_EXPECTED.$PAGE_SIZE"; then |
| 126 |
cat "$TS_EXPECTED.$PAGE_SIZE.recursive" >> "$AGG_OUT" |
| 127 |
else |
| 128 |
cat "$TS_EXPECTED.nosize.recursive" >> "$AGG_OUT" |
| 129 |
fi |
| 130 |
echo '[ RECURSIVE SCAN ]' >> "$AGG_ERR" |
| 131 |
fi |
| 132 |
|
| 133 |
TS_EXPECTED="$AGG_OUT" |
| 134 |
TS_EXPECTED_ERR="$AGG_ERR" |
| 135 |
|
| 136 |
ts_check_test_command "$TS_CMD_FINCORE" |
| 137 |
ts_cd "$TS_OUTDIR" |
| 138 |
|
| 139 |
check_dd_fs_feat |
| 140 |
|
| 141 |
INPUT= |
| 142 |
input= |
| 143 |
|
| 144 |
ts_log_both "[ NON EXISTING FILE ]" |
| 145 |
{ |
| 146 |
input=no_such_file |
| 147 |
INPUT="${INPUT} ${input}" |
| 148 |
|
| 149 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings $input |
| 150 |
footer "$?" |
| 151 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 152 |
|
| 153 |
{ |
| 154 |
run_dd_test "EMPTY FILE" 0 |
| 155 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 156 |
|
| 157 |
{ |
| 158 |
run_dd_test "PAGESIZE -1 (incore)" $(( PAGE_SIZE - 1 )) |
| 159 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 160 |
|
| 161 |
{ |
| 162 |
run_dd_test "JUST PAGESIZE(incore)" $(( PAGE_SIZE )) |
| 163 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 164 |
|
| 165 |
{ |
| 166 |
run_dd_test "JUST PAGESIZE(directio)" $(( PAGE_SIZE )) "oflag=direct" |
| 167 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 168 |
|
| 169 |
{ |
| 170 |
run_dd_test "TWO PAGES(incore)" $(( 2 * PAGE_SIZE )) |
| 171 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 172 |
|
| 173 |
{ |
| 174 |
run_dd_test "TWO PAGES(directio)" $(( 2 * PAGE_SIZE )) "oflag=direct" |
| 175 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 176 |
|
| 177 |
{ |
| 178 |
run_dd_dd_test "TWO PAGES(mixed directio,incore)" \ |
| 179 |
oflag=direct \ |
| 180 |
"oflag=append seek=1" |
| 181 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 182 |
|
| 183 |
{ |
| 184 |
run_dd_dd_test "TWO PAGES(mixed incore,directio)" \ |
| 185 |
"" \ |
| 186 |
"oflag=direct,append seek=1" |
| 187 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 188 |
|
| 189 |
{ |
| 190 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 )) |
| 191 |
run_dd_dd_test "WINDOW SIZE(incore-sparse-incore)" \ |
| 192 |
"" \ |
| 193 |
"oflag=append seek=$hole_count" |
| 194 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 195 |
|
| 196 |
{ |
| 197 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 )) |
| 198 |
run_dd_dd_test "WINDOW SIZE(directio-sparse-directio)" \ |
| 199 |
"oflag=direct" \ |
| 200 |
"oflag=append,direct seek=$hole_count" |
| 201 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 202 |
|
| 203 |
{ |
| 204 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 )) |
| 205 |
run_dd_dd_test "WINDOW SIZE(incore-sparse-directio)" \ |
| 206 |
"" \ |
| 207 |
"oflag=append,direct seek=$hole_count" |
| 208 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 209 |
|
| 210 |
{ |
| 211 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 2 )) |
| 212 |
run_dd_dd_test "WINDOW SIZE(directio-sparse-incore)" \ |
| 213 |
"oflag=direct" \ |
| 214 |
"oflag=append seek=$hole_count" |
| 215 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 216 |
|
| 217 |
{ |
| 218 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 )) |
| 219 |
run_dd_dd_test "WINDOW SIZE + 1 page(incore-sparse-incore)" \ |
| 220 |
"" \ |
| 221 |
"oflag=append seek=$hole_count" |
| 222 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 223 |
|
| 224 |
{ |
| 225 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 )) |
| 226 |
run_dd_dd_test "WINDOW SIZE + 1 page(directio-sparse-directio)" \ |
| 227 |
"oflag=direct" \ |
| 228 |
"oflag=append,direct seek=$hole_count" |
| 229 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 230 |
|
| 231 |
{ |
| 232 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 )) |
| 233 |
run_dd_dd_test "WINDOW SIZE + 1 page(incore-sparse-directio)" \ |
| 234 |
"" \ |
| 235 |
"oflag=append,direct seek=$hole_count" |
| 236 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 237 |
|
| 238 |
{ |
| 239 |
hole_count=$(( WINDOW_SIZE / PAGE_SIZE - 1 )) |
| 240 |
run_dd_dd_test "WINDOW SIZE + 1 page(directio-sparse-incore)" \ |
| 241 |
"oflag=direct" \ |
| 242 |
"oflag=append seek=$hole_count" |
| 243 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 244 |
|
| 245 |
ts_log_both "[ MULTIPLE FILES ]" |
| 246 |
{ |
| 247 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes $INPUT |
| 248 |
footer "$?" |
| 249 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 250 |
|
| 251 |
rm -f $INPUT |
| 252 |
INPUT= |
| 253 |
|
| 254 |
OLD_COLUMNS=$OUT_COLUMNS |
| 255 |
OUT_COLUMNS=SIZE,FILE |
| 256 |
|
| 257 |
{ |
| 258 |
run_dd_test "EMPTY" 0 |
| 259 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 260 |
|
| 261 |
{ |
| 262 |
run_dd_test 1b 1 |
| 263 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 264 |
|
| 265 |
{ |
| 266 |
run_dd_test 1k 1024 |
| 267 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 268 |
|
| 269 |
{ |
| 270 |
run_dd_test 10k 10240 |
| 271 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 272 |
|
| 273 |
ts_log_both "[ GRAND TOTAL SIZE ]" |
| 274 |
{ |
| 275 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings --total $INPUT |
| 276 |
footer "$?" |
| 277 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 278 |
|
| 279 |
rm -f $INPUT |
| 280 |
INPUT= |
| 281 |
|
| 282 |
OUT_COLUMNS=PAGES,FILE |
| 283 |
|
| 284 |
{ |
| 285 |
run_dd_test "EMPTY" 0 |
| 286 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 287 |
|
| 288 |
{ |
| 289 |
run_dd_test 1b 1 |
| 290 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 291 |
|
| 292 |
{ |
| 293 |
run_dd_test 'ONE PAGE' $PAGE_SIZE |
| 294 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 295 |
|
| 296 |
{ |
| 297 |
run_dd_test 'TWO PAGES' $(( 2 * PAGE_SIZE )) |
| 298 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 299 |
|
| 300 |
{ |
| 301 |
run_dd_test 'TEN PAGES' $(( 10 * PAGE_SIZE )) |
| 302 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 303 |
|
| 304 |
ts_log_both "[ GRAND TOTAL PAGES ]" |
| 305 |
{ |
| 306 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --noheadings --total $INPUT |
| 307 |
footer "$?" |
| 308 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 309 |
|
| 310 |
OUT_COLUMNS=$OLD_COLUMNS |
| 311 |
|
| 312 |
if [ -n "$RECURSIVE" ]; then |
| 313 |
dir=$(make_input_name dir) |
| 314 |
mkdir -p "$dir" |
| 315 |
|
| 316 |
{ |
| 317 |
run_dd_test "dir/EMPTY FILE" 0 |
| 318 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 319 |
|
| 320 |
{ |
| 321 |
run_dd_test "dir/PAGESIZE -1 (incore)" $(( PAGE_SIZE - 1 )) |
| 322 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 323 |
|
| 324 |
{ |
| 325 |
run_dd_test "dir/JUST PAGESIZE(incore)" $(( PAGE_SIZE )) |
| 326 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 327 |
|
| 328 |
ts_log_both "[ RECURSIVE SCAN ]" |
| 329 |
{ |
| 330 |
$TS_CMD_FINCORE --raw --output $OUT_COLUMNS --bytes --recursive --raw "$dir" |sort |
| 331 |
footer "$?" |
| 332 |
} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 333 |
fi |
| 334 |
|
| 335 |
rm -f $INPUT |
| 336 |
ts_finalize |