blob: bca8b4db7cdfd3c0481d31aa23e8df24640bda47 (
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
#!/usr/bin/env bash
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../..)
source $rootdir/test/common/autotest_common.sh
source $rootdir/test/pmem/common.sh
rpc_py="$rootdir/scripts/rpc.py "
enable_script_debug=false
test_info=false
test_create=false
test_delete=false
test_construct_bdev=false
test_delete_bdev=false
test_all=true
test_all_get=false
default_pool_file="$testdir/pool_file"
obj_pool_file="$testdir/obj_pool_file"
bdev_name=pmem0
function usage() {
[[ -n $2 ]] && (
echo "$2"
echo ""
)
echo "Shortcut script for automated RPC tests for PMEM"
echo
echo "Usage: $(basename $1) [OPTIONS]"
echo
echo "-h, --help Print help and exit"
echo "-x set -x for script debug"
echo " --info Run test cases for bdev_pmem_get_pool_info"
echo " --create Run test cases for bdev_pmem_create_pool"
echo " --delete Run test cases for bdev_pmem_delete_pool"
echo " --construct_bdev Run test cases for constructing pmem bdevs"
echo " --delete_bdev Run test cases for deleting pmem bdevs"
echo " --all Run all test cases (default)"
exit 0
}
while getopts 'xh-:' optchar; do
case "$optchar" in
-)
case "$OPTARG" in
help) usage $0 ;;
info)
test_info=true
test_all=false
;;
create)
test_create=true
test_all=false
;;
delete)
test_delete=true
test_all=false
;;
construct_bdev)
test_construct_bdev=true
test_all=false
;;
delete_bdev)
test_delete_bdev=true
test_all=false
;;
all) test_all_get=true ;;
*) usage $0 "Invalid argument '$OPTARG'" ;;
esac
;;
h) usage $0 ;;
x) enable_script_debug=true ;;
*) usage $0 "Invalid argument '$OPTARG'" ;;
esac
done
if $test_all_get; then
test_all=true
fi
if [[ $EUID -ne 0 ]]; then
echo "Go away user come back as root"
exit 1
fi
#================================================
# bdev_pmem_get_pool_info tests
#================================================
function bdev_pmem_get_pool_info_tc1() {
pmem_print_tc_name ${FUNCNAME[0]}
if $rpc_py bdev_pmem_get_pool_info; then
error "bdev_pmem_get_pool_info passed with missing argument!"
fi
return 0
}
function bdev_pmem_get_pool_info_tc2() {
pmem_print_tc_name ${FUNCNAME[0]}
if $rpc_py bdev_pmem_get_pool_info $rootdir/non/existing/path/non_existent_file; then
error "bdev_pmem_get_pool_info passed with invalid path!"
fi
return 0
}
function bdev_pmem_get_pool_info_tc3() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file $obj_pool_file
echo "Creating new type OBJ pool file"
if hash pmempool; then
pmempool create -s 32000000 obj $obj_pool_file
else
echo "Warning: pmempool package not found! Creating stub file."
truncate -s "32M" $obj_pool_file
fi
if $rpc_py bdev_pmem_get_pool_info $obj_pool_file; then
pmem_clean_pool_file $obj_pool_file
error "Pmem_pool_info passed with invalid pool_file type!"
fi
pmem_clean_pool_file $obj_pool_file
return 0
}
function bdev_pmem_get_pool_info_tc4() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get bdev_pmem_get_pool_info!"
fi
pmem_clean_pool_file
return 0
}
#================================================
# bdev_pmem_create_pool tests
#================================================
function bdev_pmem_create_pool_tc1() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if $rpc_py bdev_pmem_create_pool 32 512; then
error "Mem pool file created w/out given path!"
fi
if $rpc_py bdev_pmem_create_pool $default_pool_file; then
error "Mem pool file created w/out size & block size arguments!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "bdev_pmem_create_pool created invalid pool file!"
fi
if $rpc_py bdev_pmem_create_pool $default_pool_file 32; then
error "Mem pool file created w/out block size argument!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "bdev_pmem_create_pool created invalid pool file!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc2() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if $rpc_py bdev_pmem_create_pool $rootdir/non/existing/path/non_existent_file 32 512; then
error "Mem pool file created with incorrect path!"
fi
if $rpc_py bdev_pmem_get_pool_info $rootdir/non/existing/path/non_existent_file; then
error "bdev_pmem_create_pool created invalid pool file!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc3() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if ! $rpc_py bdev_pmem_create_pool $default_pool_file 256 512; then
error "Failed to create pmem pool!"
fi
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get pmem info"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pool file!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Got pmem file info but file should be deleted"
fi
if [ -f $default_pool_file ]; then
error "Failed to delete pmem file!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc4() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_unmount_ramspace
mkdir $rootdir/test/pmem/ramspace
mount -t tmpfs -o size=300m tmpfs $rootdir/test/pmem/ramspace
if ! $rpc_py bdev_pmem_create_pool $rootdir/test/pmem/ramspace/pool_file 256 512; then
pmem_unmount_ramspace
error "Failed to create pmem pool!"
fi
if ! $rpc_py bdev_pmem_get_pool_info $rootdir/test/pmem/ramspace/pool_file; then
pmem_unmount_ramspace
error "Failed to get pmem info"
fi
if ! $rpc_py bdev_pmem_delete_pool $rootdir/test/pmem/ramspace/pool_file; then
pmem_unmount_ramspace
error "Failed to delete pool file!"
fi
if [ -f $rootdir/test/pmem/ramspace/pool_file ]; then
pmem_unmount_ramspace
error "Failed to delete pmem file / file still exists!"
fi
pmem_unmount_ramspace
return 0
}
function bdev_pmem_create_pool_tc5() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
local pmem_block_size
local pmem_num_block
if ! $rpc_py bdev_pmem_create_pool $default_pool_file 256 512; then
error "Failed to create pmem pool!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
pmem_block_size=$($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .block_size')
pmem_num_block=$($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .num_blocks')
else
error "Failed to get pmem info!"
fi
if $rpc_py bdev_pmem_create_pool $default_pool_file 512 4096; then
error "Pmem pool with already occupied path has been created!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
if [ $pmem_block_size != $($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .block_size') ]; then
error "Invalid block size of pmem pool!"
fi
if [ $pmem_num_block != $($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .num_blocks') ]; then
error "Invalid number of blocks of pmem pool!"
fi
else
error "Failed to get pmem info!"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pmem file!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc6() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
local created_pmem_block_size
for i in 511 512 1024 2048 4096 131072 262144; do
if ! $rpc_py bdev_pmem_create_pool $default_pool_file 256 $i; then
error "Failed to create pmem pool!"
fi
if ! created_pmem_block_size=$($rpc_py bdev_pmem_get_pool_info $default_pool_file | jq -r '.[] .block_size'); then
error "Failed to get pmem info!"
fi
if [ $i != $created_pmem_block_size ]; then
error "Invalid block size of pmem pool!"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pmem file!"
fi
done
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc7() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if $rpc_py bdev_pmem_create_pool $default_pool_file 15 512; then
error "Created pmem pool with invalid size!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Pmem file shouldn' exist!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc8() {
pmem_print_tc_name "bdev_pmem_create_pool_tc8"
pmem_clean_pool_file
if $rpc_py bdev_pmem_create_pool $default_pool_file 32 65536; then
error "Created pmem pool with invalid block number!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Pmem file shouldn' exist!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_pool_tc9() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if $rpc_py bdev_pmem_create_pool $default_pool_file 256 -1; then
error "Created pmem pool with negative block size number!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "bdev_pmem_create_pool create invalid pool file!"
fi
if $rpc_py bdev_pmem_create_pool $default_pool_file -1 512; then
error "Created pmem pool with negative size number!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "bdev_pmem_create_pool create invalid pool file!"
fi
pmem_clean_pool_file
return 0
}
#================================================
# bdev_pmem_delete_pool tests
#================================================
function bdev_pmem_delete_pool_tc1() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
if $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "bdev_pmem_delete_pool deleted inexistant pool file!"
fi
return 0
}
function bdev_pmem_delete_pool_tc2() {
pmem_print_tc_name "bdev_pmem_delete_pool_tc2"
pmem_clean_pool_file $obj_pool_file
echo "Creating new type OBJ pool file"
if hash pmempool; then
pmempool create -s 32000000 obj $obj_pool_file
else
echo "Warning: pmempool package not found! Creating stub file."
truncate -s "32M" $obj_pool_file
fi
if $rpc_py bdev_pmem_delete_pool $obj_pool_file; then
pmem_clean_pool_file $obj_pool_file
error "bdev_pmem_delete_pool deleted invalid pmem pool type!"
fi
pmem_clean_pool_file $obj_pool_file
return 0
}
function bdev_pmem_delete_pool_tc3() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get info on pmem pool file!"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pmem pool file!"
fi
if $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Pmem pool file exists after using bdev_pmem_get_pool_info!"
fi
return 0
}
function bdev_pmem_delete_pool_tc4() {
pmem_print_tc_name ${FUNCNAME[0]}
bdev_pmem_delete_pool_tc3
if $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Deleted pmem pool file that shouldn't exist!"
fi
return 0
}
#================================================
# bdev_pmem_create tests
#================================================
function bdev_pmem_create_tc1() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file
if $rpc_py bdev_pmem_create; then
error "bdev_pmem_create passed with missing argument!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_tc2() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file
if $rpc_py bdev_pmem_create -n $bdev_name $rootdir/non/existing/path/non_existent_file; then
error "Created pmem bdev w/out valid pool file!"
fi
if $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi pmem; then
error "bdev_pmem_create passed with invalid argument!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_tc3() {
pmem_print_tc_name ${FUNCNAME[0]}
truncate -s 32M $rootdir/test/pmem/random_file
if $rpc_py bdev_pmem_create -n $bdev_name $rootdir/test/pmem/random_file; then
error "Created pmem bdev from random file!"
fi
if [ -f $rootdir/test/pmem/random_file ]; then
echo "Deleting previously created random file"
rm $rootdir/test/pmem/random_file
fi
return 0
}
function bdev_pmem_create_tc4() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file $obj_pool_file
echo "Creating new type OBJ pool file"
if hash pmempool; then
pmempool create -s 32000000 obj $obj_pool_file
else
echo "Warning: pmempool package not found! Creating stub file."
truncate -s "32M" $obj_pool_file
fi
if $rpc_py bdev_pmem_create -n $bdev_name $obj_pool_file; then
pmem_clean_pool_file $obj_pool_file
error "Created pmem bdev from obj type pmem file!"
fi
pmem_clean_pool_file $obj_pool_file
return 0
}
function bdev_pmem_create_tc5() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file
local pmem_bdev_name
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get pmem info!"
fi
if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
error "Failed to create pmem bdev"
fi
if ! $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi $pmem_bdev_name; then
error "Pmem bdev not found!"
fi
if ! $rpc_py bdev_pmem_delete $pmem_bdev_name; then
error "Failed to delete pmem bdev!"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pmem pool file!"
fi
pmem_clean_pool_file
return 0
}
function bdev_pmem_create_tc6() {
pmem_print_tc_name ${FUNCNAME[0]}
local pmem_bdev_name
pmem_clean_pool_file
pmem_create_pool_file
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get info on pmem pool file!"
fi
if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
error "Failed to create pmem bdev!"
fi
if ! $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi $pmem_bdev_name; then
error "Pmem bdev not found!"
fi
if $rpc_py bdev_pmem_create -n $bdev_name $default_pool_file; then
error "Constructed pmem bdev with occupied path!"
fi
if ! $rpc_py bdev_pmem_delete $pmem_bdev_name; then
error "Failed to delete pmem bdev!"
fi
if ! $rpc_py bdev_pmem_delete_pool $default_pool_file; then
error "Failed to delete pmem pool file!"
fi
pmem_clean_pool_file
return 0
}
#================================================
# bdev_pmem_delete tests
#================================================
function delete_bdev_tc1() {
pmem_print_tc_name ${FUNCNAME[0]}
local pmem_bdev_name
local bdevs_names
pmem_clean_pool_file
pmem_create_pool_file $default_pool_file 256 512
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get pmem info!"
fi
if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
error "Failed to create pmem bdev!"
fi
if ! $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi $pmem_bdev_name; then
error "$pmem_bdev_name bdev not found!"
fi
if ! $rpc_py bdev_pmem_delete $pmem_bdev_name; then
error "Failed to delete $pmem_bdev_name bdev!"
fi
bdevs_names=$($rpc_py bdev_get_bdevs | jq -r '.[] .name')
if echo $bdevs_names | grep -qi $pmem_bdev_name; then
error "$pmem_bdev_name bdev is not deleted!"
fi
pmem_clean_pool_file
return 0
}
function delete_bdev_tc2() {
pmem_print_tc_name ${FUNCNAME[0]}
pmem_clean_pool_file
pmem_create_pool_file $default_pool_file 256 512
local pmem_bdev_name
if ! $rpc_py bdev_pmem_get_pool_info $default_pool_file; then
error "Failed to get pmem info!"
fi
if ! pmem_bdev_name=$($rpc_py bdev_pmem_create -n $bdev_name $default_pool_file); then
error "Failed to create pmem bdev"
fi
if ! $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi $pmem_bdev_name; then
error "Pmem bdev not found!"
fi
if ! $rpc_py bdev_pmem_delete $pmem_bdev_name; then
error "Failed to delete pmem bdev!"
fi
if $rpc_py bdev_pmem_delete $pmem_bdev_name; then
error "bdev_pmem_delete deleted pmem bdev for second time!"
fi
pmem_clean_pool_file
return 0
}
vhost_start
if ! $enable_script_debug; then
set +x
fi
if $test_info || $test_all; then
bdev_pmem_get_pool_info_tc1
bdev_pmem_get_pool_info_tc2
bdev_pmem_get_pool_info_tc3
bdev_pmem_get_pool_info_tc4
fi
if $test_create || $test_all; then
bdev_pmem_create_pool_tc1
bdev_pmem_create_pool_tc2
bdev_pmem_create_pool_tc3
bdev_pmem_create_pool_tc4
bdev_pmem_create_pool_tc5
bdev_pmem_create_pool_tc6
bdev_pmem_create_pool_tc7
bdev_pmem_create_pool_tc8
bdev_pmem_create_pool_tc9
fi
if $test_delete || $test_all; then
bdev_pmem_delete_pool_tc1
bdev_pmem_delete_pool_tc2
bdev_pmem_delete_pool_tc3
bdev_pmem_delete_pool_tc4
fi
if $test_construct_bdev || $test_all; then
bdev_pmem_create_tc1
bdev_pmem_create_tc2
bdev_pmem_create_tc3
bdev_pmem_create_tc4
bdev_pmem_create_tc5
bdev_pmem_create_tc6
fi
if $test_delete_bdev || $test_all; then
delete_bdev_tc1
delete_bdev_tc2
fi
pmem_clean_pool_file
vhost_kill 0
|