summaryrefslogtreecommitdiffstats
path: root/extras/rpc-coverage.sh
blob: ebb92a2a148f2cafa2932cc3b7da924c6134411b (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#!/bin/bash

# This script can be used to provoke 35 fops (if afr is used),
# 28 fops (if afr is not used) (-fstat,-readdirp, and lk,xattrop calls)
# Pending are 7 procedures.
# getspec, fsyncdir, access, fentrylk, fsetxattr, fgetxattr, rchecksum
# TODO: add commands which can generate fops for missing fops

## Script tests below File Operations over RPC (when afr is used)

# CREATE
# ENTRYLK
# FINODELK
# FLUSH
# FSTAT
# FSYNC
# FTRUNCATE
# FXATTROP
# GETXATTR
# INODELK
# LINK
# LK
# LOOKUP
# MKDIR
# MKNOD
# OPEN
# OPENDIR
# READ
# READDIR
# READDIRP
# READLINK
# RELEASE
# RELEASEDIR
# REMOVEXATTR
# RENAME
# RMDIR
# SETATTR
# SETXATTR
# STAT
# STATFS
# SYMLINK
# TRUNCATE
# UNLINK
# WRITE
# XATTROP

#set -e;
set -o pipefail;

function fail() {
    echo "$*: failed."; 
    exit 1;
}

function test_mkdir()
{
    mkdir -p $PFX/dir;
    test $(stat -c '%F' $PFX/dir) == "directory" || fail "mkdir"
}


function test_create()
{
    : > $PFX/dir/file;

    test "$(stat -c '%F' $PFX/dir/file)" == "regular empty file" || fail "create"
}


function test_statfs()
{
    local size;

    size=$(stat -f -c '%s' $PFX/dir/file);
    test "x$size" != "x0" || fail "statfs"
}


function test_open()
{
    exec 4<$PFX/dir/file || fail "open"
    exec 4>&- || fail "open"
}


function test_write()
{
    dd if=/dev/zero of=$PFX/dir/file bs=65536 count=16 2>/dev/null;
    test $(stat -c '%s' $PFX/dir/file) == 1048576 || fail "open"
}


function test_read()
{
    local count;

    count=$(dd if=$PFX/dir/file bs=64k count=16 2>/dev/null | wc -c);
    test $count == 1048576 || fail "read"
}


function test_truncate()
{
    truncate -s 512 $PFX/dir/file;
    test $(stat -c '%s' $PFX/dir/file) == 512 || fail "truncate"

    truncate -s 0 $PFX/dir/file;
    test $(stat -c '%s' $PFX/dir/file) == 0 || fail "truncate"
}


function test_fstat()
{
    local msg;

    export PFX;
    msg=$(sh -c 'tail -f $PFX/dir/file --pid=$$ & sleep 1 && echo hooha > $PFX/dir/file && sleep 1');
    test "x$msg" == "xhooha" || fail "fstat"
}


function test_mknod()
{
    mknod -m 0666 $PFX/dir/block b 13 42;
    test "$(stat -c '%F %a %t %T' $PFX/dir/block)" == "block special file 666 d 2a" \
	|| fail "mknod for block device"

    mknod -m 0666 $PFX/dir/char c 13 42;
    test "$(stat -c '%F %a %t %T' $PFX/dir/char)" == "character special file 666 d 2a" \
	|| fail "mknod for character device"

    mknod -m 0666 $PFX/dir/fifo p;
    test "$(stat -c '%F %a' $PFX/dir/fifo)" == "fifo 666" || \
	fail "mknod for fifo"
}


function test_symlink()
{
    local msg;

    ln -s $PFX/dir/file $PFX/dir/symlink;
    test "$(stat -c '%F' $PFX/dir/symlink)" == "symbolic link" || fail "Creation of symlink"

    msg=$(cat $PFX/dir/symlink);
    test "x$msg" == "xhooha" || fail "Content match for symlink"
}


function test_hardlink()
{
    local ino1;
    local ino2;
    local nlink1;
    local nlink2;
    local msg;

    ln $PFX/dir/file $PFX/dir/hardlink;

    ino1=$(stat -c '%i' $PFX/dir/file);
    nlink1=$(stat -c '%h' $PFX/dir/file);
    ino2=$(stat -c '%i' $PFX/dir/hardlink);
    nlink2=$(stat -c '%h' $PFX/dir/hardlink);

    test $ino1 == $ino2 || fail "Inode comparison for hardlink"
    test $nlink1 == 2 || fail "Link count for hardlink"
    test $nlink2 == 2 || fail "Link count for hardlink"

    msg=$(cat $PFX/dir/hardlink);

    test "x$msg" == "xhooha" || fail "Content match for hardlinks"
}


function test_rename()
{
    local ino1;
    local ino2;
    local ino3;
    local msg;

    #### file

    ino1=$(stat -c '%i' $PFX/dir/file);

    mv $PFX/dir/file $PFX/dir/file2 || fail "mv"
    msg=$(cat $PFX/dir/file2);
    test "x$msg" == "xhooha" || fail "File contents comparison after mv"

    ino2=$(stat -c '%i' $PFX/dir/file2);
    test $ino1 == $ino2 || fail "Inode comparison after mv"

    mv $PFX/dir/file2 $PFX/dir/file;
    msg=$(cat $PFX/dir/file);
    test "x$msg" == "xhooha" || fail "File contents comparison after mv"

    ino3=$(stat -c '%i' $PFX/dir/file);
    test $ino1 == $ino3 || fail "Inode comparison after mv"

    #### dir

    ino1=$(stat -c '%i' $PFX/dir);

    mv $PFX/dir $PFX/dir2 || fail "Directory mv"
    ino2=$(stat -c '%i' $PFX/dir2);
    test $ino1 == $ino2 || fail "Inode comparison after directory mv"

    mv $PFX/dir2 $PFX/dir || fail "Directory mv"
    ino3=$(stat -c '%i' $PFX/dir);
    test $ino1 == $ino3 || fail "Inode comparison after directory mv"
}


function test_chmod()
{
    local mode0;
    local mode1;
    local mode2;


    #### file

    mode0=$(stat -c '%a' $PFX/dir/file);
    chmod 0753 $PFX/dir/file || fail "chmod"

    mode1=$(stat -c '%a' $PFX/dir/file);
    test 0$mode1 == 0753 || fail "Mode comparison after chmod"

    chmod 0$mode0 $PFX/dir/file || fail "chmod"
    mode2=$(stat -c '%a' $PFX/dir/file);
    test 0$mode2 == 0$mode0 || fail "Mode comparison after chmod"

    #### dir

    mode0=$(stat -c '%a' $PFX/dir);
    chmod 0753 $PFX/dir || fail "chmod"

    mode1=$(stat -c '%a' $PFX/dir);
    test 0$mode1 == 0753 || fail "Mode comparison after chmod"

    chmod 0$mode0 $PFX/dir || fail "chmod"
    mode2=$(stat -c '%a' $PFX/dir);
    test 0$mode2 == 0$mode0  || fail "Mode comparison after chmod"
}


function test_chown()
{
    local user1;
    local user2;
    local group1;
    local group2;

    #### file

    user1=$(stat -c '%u' $PFX/dir/file);
    group1=$(stat -c '%g' $PFX/dir/file);

    chown 13:42 $PFX/dir/file || fail "chown"

    user2=$(stat -c '%u' $PFX/dir/file);
    group2=$(stat -c '%g' $PFX/dir/file);

    test $user2 == 13 || fail "User comparison after chown"
    test $group2 == 42 || fail "Group comparison after chown"

    chown $user1:$group1 $PFX/dir/file || fail "chown"

    user2=$(stat -c '%u' $PFX/dir/file);
    group2=$(stat -c '%g' $PFX/dir/file);

    test $user2 == $user1 || fail "User comparison after chown"
    test $group2 == $group1 || fail "Group comparison after chown"

    #### dir

    user1=$(stat -c '%u' $PFX/dir);
    group1=$(stat -c '%g' $PFX/dir);

    chown 13:42 $PFX/dir || fail "chown"

    user2=$(stat -c '%u' $PFX/dir);
    group2=$(stat -c '%g' $PFX/dir);

    test $user2 == 13 || fail "User comparison after chown"
    test $group2 == 42 || fail "Group comparison after chown"

    chown $user1:$group1 $PFX/dir || fail "chown"

    user2=$(stat -c '%u' $PFX/dir);
    group2=$(stat -c '%g' $PFX/dir);

    test $user2 == $user1 || fail "User comparison after chown"
    test $group2 == $group1 || fail "Group comparison after chown"
}


function test_utimes()
{
    local acc0;
    local acc1;
    local acc2;
    local mod0;
    local mod1;
    local mod2;

    #### file

    acc0=$(stat -c '%X' $PFX/dir/file);
    mod0=$(stat -c '%Y' $PFX/dir/file);

    sleep 1;
    touch -a $PFX/dir/file || fail "atime change on file"

    acc1=$(stat -c '%X' $PFX/dir/file);
    mod1=$(stat -c '%Y' $PFX/dir/file);

    sleep 1;
    touch -m $PFX/dir/file || fail "mtime change on file"

    acc2=$(stat -c '%X' $PFX/dir/file);
    mod2=$(stat -c '%Y' $PFX/dir/file);

    test $acc0 != $acc1 || fail "atime mismatch comparison on file"
    test $acc1 == $acc2 || fail "atime match comparison on file"
    test $mod0 == $mod1 || fail "mtime match comparison on file"
    test $mod1 != $mod2 || fail "mtime mismatch comparison on file"

    #### dir

    acc0=$(stat -c '%X' $PFX/dir);
    mod0=$(stat -c '%Y' $PFX/dir);

    sleep 1;
    touch -a $PFX/dir || fail "atime change on directory"

    acc1=$(stat -c '%X' $PFX/dir);
    mod1=$(stat -c '%Y' $PFX/dir);

    sleep 1;
    touch -m $PFX/dir || fail "mtime change on directory"

    acc2=$(stat -c '%X' $PFX/dir);
    mod2=$(stat -c '%Y' $PFX/dir);

    test $acc0 != $acc1 || fail "atime mismatch comparison on directory"
    test $acc1 == $acc2 || fail "atime match comparison on directory"
    test $mod0 == $mod1 || fail "mtime match comparison on directory"
    test $mod1 != $mod2 || fail "mtime mismatch comparison on directory"
}


function test_locks()
{
    exec 200>$PFX/dir/lockfile || fail "exec"

    ## exclusive locks test
    flock -e 200 || fail "flock -e"
    ! flock -n -e $PFX/dir/lockfile -c true || fail "! flock -n -e"
    ! flock -n -s $PFX/dir/lockfile -c true || fail "! flock -n -s"
    flock -u 200 || fail "flock -u"

    ## shared locks test
    flock -s 200 || fail "flock -s"
    ! flock -n -e $PFX/dir/lockfile -c true || fail "! flock -n -e"
    flock -n -s $PFX/dir/lockfile -c true || fail "! flock -n -s"
    flock -u 200 || fail "flock -u"

    exec 200>&- || fail "exec"

}


function test_readdir()
{
    /bin/ls $PFX/dir >/dev/null || fail "ls"
}


function test_setxattr()
{
    setfattr -n trusted.testing -v c00k33 $PFX/dir/file || fail "setfattr"
}


function test_listxattr()
{
    getfattr -m trusted $PFX/dir/file 2>/dev/null | grep -q trusted.testing || fail "getfattr"
}


function test_getxattr()
{
    getfattr -n trusted.testing $PFX/dir/file 2>/dev/null | grep -q c00k33 || fail "getfattr"
}


function test_removexattr()
{
    setfattr -x trusted.testing $PFX/dir/file || fail "setfattr remove"
    getfattr -n trusted.testing $PFX/dir/file 2>&1 | grep -q 'No such attribute' \
	|| fail "getfattr"
}


function test_unlink()
{
    rm $PFX/dir/file || fail "rm"
}


function test_rmdir()
{
    rm -rf $PFX || fail "rm -rf"
}


function run_tests()
{
    test_mkdir;
    test_create;
    test_statfs;
    test_open;
    test_write;
    test_read;
    test_truncate;
    test_fstat;
    test_mknod;
    test_hardlink;
    test_symlink;
    test_rename;
    test_chmod;
    test_chown;
    test_utimes;
    test_locks;
    test_readdir;
    test_setxattr;
    test_listxattr;
    test_getxattr;
    test_removexattr;
    test_unlink;
    test_rmdir;
}


function _init()
{
    DIR=$(pwd);
}


function parse_cmdline()
{
    if [ "x$1" == "x" ] ; then
        echo "Usage: $0 /path/mount"
        exit 1
    fi

    DIR=$1;

    if [ ! -d "$DIR" ] ; then
        echo "$DIR: not a directory"
        exit 1
    fi

    PFX="$DIR/coverage";
    rm -rvf $PFX;
}


function main()
{
    parse_cmdline "$@";

    run_tests;

    exit 0;
}


_init && main "$@";