summaryrefslogtreecommitdiffstats
path: root/tests/ts/fadvise/drop
blob: 7c7eee5dc25a34f0885ad161004b9d18418f3de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

TS_TOPDIR="${0%/*}/../.."
TS_DESC="drop page caches related to a file"

. "$TS_TOPDIR"/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_FADVISE"
ts_check_test_command "$TS_CMD_FINCORE"
ts_check_test_command "$TS_CMD_FINDMNT"

ts_check_prog "dd"
ts_check_prog "sleep"

ts_cd "$TS_OUTDIR"

FILE="ddtest"
BS=4k
COUNT=8

FILE_FS="$("$TS_CMD_FINDMNT" -nr -o FSTYPE -T "$PWD")"
if [[ "$FILE_FS" = "tmpfs" ]]; then
	ts_skip "fincore does not work on tmpfs"
fi

create_file() {
    dd if=/dev/zero of="$FILE" bs=$BS count=$COUNT conv=fsync >& /dev/null
}

{
    create_file
    "$TS_CMD_FINCORE" "$FILE"
    echo

    create_file
    echo "whole file"
    "$TS_CMD_FADVISE" "$FILE"
    echo status: $?
    "$TS_CMD_FINCORE" "$FILE"
    echo

    create_file
    echo "offset: 8192"
    "$TS_CMD_FADVISE" -o 8192 "$FILE"
    echo status: $?
    "$TS_CMD_FINCORE" "$FILE"
    echo

    create_file
    echo "length: 16384"
    "$TS_CMD_FADVISE" -l 16384 "$FILE"
    echo status: $?
    "$TS_CMD_FINCORE" "$FILE"
    echo

    create_file
    echo "offset: 8192, length: 16384 fd: 42"
    "$TS_CMD_FADVISE" -o 8192 -l 16384 --fd 42 42<"$FILE"
    echo status: $?
    "$TS_CMD_FINCORE" "$FILE"
    echo

    rm "$FILE"
} >> "$TS_OUTPUT" 2>> "$TS_ERRLOG"

ts_finalize