Skip to content

Commit 966b940

Browse files
author
Rafal Stefanowski
committed
Refactor existing tests
Change-Id: I107349f86aef598b5ec112d1a6df5de20ea4a2c3 Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
1 parent 060b9b1 commit 966b940

File tree

12 files changed

+738
-312
lines changed

12 files changed

+738
-312
lines changed

test/ocf/common.sh

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,57 @@
77
source "$rootdir/test/common/autotest_common.sh"
88

99
rpc_py="$rootdir/scripts/rpc.py"
10-
cache_dev_persistent_addr=(05:00.0 06:00.0 08:00.0)
10+
11+
# Change those depending on physical persistent storage availability:
12+
persistent_cache_addr=(05:00.0 06:00.0 08:00.0)
13+
persistent_cache_create() {
14+
# $1: name of bdev to create
15+
# $2: address/path of specific device
16+
17+
if [ $# -ne 2 ]; then
18+
echo >&2 "invalid number of arguments"
19+
exit 1
20+
fi
21+
22+
local name=$1
23+
local addr=$2
24+
25+
$rpc_py bdev_virtio_attach_controller -t pci -a $addr -d blk $name
26+
}
27+
persistent_cache_destroy() {
28+
# $1: name of bdev to destroy
29+
30+
if [ $# -ne 1 ]; then
31+
echo >&2 "invalid number of arguments"
32+
exit 1
33+
fi
34+
35+
local name=$1
36+
37+
$rpc_py bdev_virtio_detach_controller $name
38+
}
39+
40+
cache_line_sizes=(4 8 16 32 64)
41+
cache_modes=("wt" "wb" "wa" "wo" "wi" "pt")
42+
promotion_policies=("always" "nhit")
43+
promotion_nhit_insertion_threshold_range=(2 1000)
44+
promotion_nhit_trigger_threshold_range=(0 100)
45+
cleaning_policies=("alru" "acp" "nop")
46+
cleaning_acp_wake_up_time_range=(0 10000)
47+
cleaning_acp_flush_max_buffers_range=(1 10000)
48+
cleaning_alru_wake_up_time_range=(0 3600)
49+
cleaning_alru_flush_max_buffers_range=(1 10000)
50+
cleaning_alru_staleness_time_range=(1 3600)
51+
cleaning_alru_activity_threshold_range=(0 1000000)
52+
cleaning_alru_max_dirty_ratio_range=(0 100)
53+
seqcutoff_policies=("always" "full" "never")
54+
seqcutoff_policy_default="full"
55+
seqcutoff_threshold_range=(1 4194181)
56+
seqcutoff_threshold_default=1
57+
seqcutoff_promotion_count_range=(1 65535)
58+
seqcutoff_promotion_count_default=8
59+
seqcutoff_promote_on_threshold_range=(0 1)
60+
seqcutoff_promote_on_threshold_default=false
1161

1262
start_spdk() {
1363
$SPDK_BIN_DIR/spdk_tgt "$@" &
@@ -42,7 +92,7 @@ destroy_caches() {
4292

4393
create_caches_persistent() {
4494
for i in {1..3}; do
45-
$rpc_py bdev_virtio_attach_controller -t pci -a "${cache_dev_persistent_addr[i - 1]}" -d blk Cache_dev$i
95+
persistent_cache_create Cache_dev$i "${persistent_cache_addr[i - 1]}"
4696
done
4797

4898
# Give a bit more time to settle, because this will be called after
@@ -55,7 +105,7 @@ create_caches_persistent() {
55105

56106
destroy_caches_persistent() {
57107
for i in {1..3}; do
58-
$rpc_py bdev_virtio_detach_controller Cache_dev$i
108+
persistent_cache_destroy Cache_dev$i
59109
done
60110
$rpc_py bdev_ocf_get_bdevs | jq -e '.'
61111
}
@@ -135,6 +185,14 @@ remove_cores() {
135185
$rpc_py bdev_ocf_get_bdevs | jq -e '.'
136186
}
137187

188+
__check_caches_base_claimed() {
189+
$rpc_py bdev_get_bdevs | jq -e '.[] | select(.name | test("Cache_dev")) | .claimed'
190+
}
191+
192+
__check_caches_base_not_claimed() {
193+
$rpc_py bdev_get_bdevs | jq -e '.[] | select(.name | test("Cache_dev")) | .claimed | not'
194+
}
195+
138196
__check_caches_empty() {
139197
$rpc_py bdev_ocf_get_bdevs | jq -e '.caches | length == 0'
140198
}
@@ -149,6 +207,14 @@ __check_caches_detached() {
149207
$rpc_py bdev_ocf_get_bdevs | jq -e '.caches[].base_attached | not'
150208
}
151209

210+
__check_cores_base_claimed() {
211+
$rpc_py bdev_get_bdevs | jq -e '.[] | select(.name | test("Core_dev")) | .claimed'
212+
}
213+
214+
__check_cores_base_not_claimed() {
215+
$rpc_py bdev_get_bdevs | jq -e '.[] | select(.name | test("Core_dev")) | .claimed | not'
216+
}
217+
152218
__check_cores_empty() {
153219
$rpc_py bdev_ocf_get_bdevs | jq -e '.caches[].cores | length == 0'
154220
$rpc_py bdev_ocf_get_bdevs | jq -e '.caches[].cores_count == 0'

test/ocf/management/config_change.sh

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,22 @@
77
#
88

99
curdir=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
10-
rootdir=$(readlink -f $curdir/../../..)
10+
rootdir=$(readlink -f "$curdir/../../..")
1111
source "$rootdir/test/ocf/common.sh"
1212

13-
cache_modes=("wt" "wb" "wa" "wo" "wi" "pt")
14-
15-
promotion_policies=("always" "nhit")
16-
promotion_nhit_insertion_threshold_range=(2 1000)
17-
promotion_nhit_trigger_threshold_range=(0 100)
18-
19-
cleaning_policies=("alru" "acp" "nop")
20-
cleaning_acp_wake_up_time_range=(0 10000)
21-
cleaning_acp_flush_max_buffers_range=(1 10000)
22-
cleaning_alru_wake_up_time_range=(0 3600)
23-
cleaning_alru_flush_max_buffers_range=(1 10000)
24-
cleaning_alru_staleness_time_range=(1 3600)
25-
cleaning_alru_activity_threshold_range=(0 1000000)
26-
cleaning_alru_max_dirty_ratio_range=(0 100)
27-
28-
seqcutoff_policies=("always" "full" "never")
29-
seqcutoff_policy_default="full"
30-
seqcutoff_threshold_range=(1 4194181)
31-
seqcutoff_threshold_default=1
32-
seqcutoff_promotion_count_range=(1 65535)
33-
seqcutoff_promotion_count_default=8
34-
seqcutoff_promote_on_threshold_range=(0 1)
35-
seqcutoff_promote_on_threshold_default=false
13+
start_caches_with_cache_line_size() {
14+
if [ $# -ne 1 ]; then
15+
echo >&2 "invalid number of arguments"
16+
exit 1
17+
fi
18+
19+
local cache_line_size=$1
20+
21+
for i in {1..3}; do
22+
$rpc_py bdev_ocf_start_cache Ocf_cache$i Cache_dev$i --cache-line-size $cache_line_size --no-load
23+
done
24+
$rpc_py bdev_ocf_get_bdevs | jq -e '.'
25+
}
3626

3727
set_cache_mode() {
3828
if [ $# -ne 1 ]; then
@@ -183,6 +173,18 @@ set_seqcutoff_params_all() {
183173
$rpc_py bdev_ocf_get_bdevs | jq -e '.'
184174
}
185175

176+
__check_cache_line_size() {
177+
if [ $# -ne 1 ]; then
178+
echo >&2 "invalid number of arguments"
179+
exit 1
180+
fi
181+
182+
local cache_line_size=$1
183+
184+
$rpc_py bdev_ocf_get_bdevs | jq -e --argjson cache_line_size $cache_line_size \
185+
'.caches[].cache_line_size == $cache_line_size * 1024'
186+
}
187+
186188
__check_cache_mode() {
187189
if [ $# -ne 1 ]; then
188190
echo >&2 "invalid number of arguments"
@@ -355,33 +357,36 @@ __check_seqcutoff_params_all() {
355357
(.promote_on_threshold == $promote_on_threshold)'
356358
}
357359

358-
# cache modes:
360+
# cache line sizes and cache modes:
359361

360-
for add_cores in false true; do
361-
for create_caches in false true; do
362-
for stop_caches in false true; do
363-
start_spdk
364-
start_caches
365-
if [ $create_caches = true ]; then
366-
create_caches
367-
__check_caches_attached
368-
if [ $add_cores = true ]; then
369-
create_cores
370-
add_cores
371-
__check_cores_attached
362+
for cache_line_size in "${cache_line_sizes[@]}"; do
363+
for add_cores in false true; do
364+
for create_caches in false true; do
365+
for stop_caches in false true; do
366+
start_spdk
367+
start_caches_with_cache_line_size $cache_line_size
368+
if [ $create_caches == true ]; then
369+
create_caches
370+
__check_caches_attached
371+
if [ $add_cores == true ]; then
372+
create_cores
373+
add_cores
374+
__check_cores_attached
375+
fi
376+
else
377+
__check_caches_detached
372378
fi
373-
else
374-
__check_caches_detached
375-
fi
376-
for cache_mode in "${cache_modes[@]}"; do
377-
set_cache_mode $cache_mode
378-
__check_cache_mode $cache_mode
379+
__check_cache_line_size $cache_line_size
380+
for cache_mode in "${cache_modes[@]}"; do
381+
set_cache_mode $cache_mode
382+
__check_cache_mode $cache_mode
383+
done
384+
if [ $stop_caches == true ]; then
385+
stop_caches
386+
__check_caches_empty
387+
fi
388+
stop_spdk
379389
done
380-
if [ $stop_caches = true ]; then
381-
stop_caches
382-
__check_caches_empty
383-
fi
384-
stop_spdk
385390
done
386391
done
387392
done
@@ -395,21 +400,21 @@ for promotion_policy in "${promotion_policies[@]}"; do
395400
create_caches
396401
start_caches
397402
__check_caches_attached
398-
if [ $add_cores = true ]; then
403+
if [ $add_cores == true ]; then
399404
create_cores
400405
add_cores
401406
__check_cores_attached
402407
fi
403-
if [ $promotion_policy = always ]; then
408+
if [ $promotion_policy == always ]; then
404409
set_promotion_always_params $promotion_policy
405410
__check_promotion_always_params $promotion_policy
406-
elif [ $promotion_policy = nhit ]; then
411+
elif [ $promotion_policy == nhit ]; then
407412
insertion_threshold=$(random_number ${promotion_nhit_insertion_threshold_range[0]} ${promotion_nhit_insertion_threshold_range[1]})
408413
trigger_threshold=$(random_number ${promotion_nhit_trigger_threshold_range[0]} ${promotion_nhit_trigger_threshold_range[1]})
409414
set_promotion_nhit_params $promotion_policy $insertion_threshold $trigger_threshold
410415
__check_promotion_nhit_params $promotion_policy $insertion_threshold $trigger_threshold
411416
fi
412-
if [ $stop_caches = true ]; then
417+
if [ $stop_caches == true ]; then
413418
stop_caches
414419
__check_caches_empty
415420
fi
@@ -427,29 +432,29 @@ for cleaning_policy in "${cleaning_policies[@]}"; do
427432
create_caches
428433
start_caches
429434
__check_caches_attached
430-
if [ $add_cores = true ]; then
435+
if [ $add_cores == true ]; then
431436
create_cores
432437
add_cores
433438
__check_cores_attached
434439
fi
435-
if [ $cleaning_policy = alru ]; then
440+
if [ $cleaning_policy == alru ]; then
436441
wake_up_time=$(random_number ${cleaning_alru_wake_up_time_range[0]} ${cleaning_alru_wake_up_time_range[1]})
437442
flush_max_buffers=$(random_number ${cleaning_alru_flush_max_buffers_range[0]} ${cleaning_alru_flush_max_buffers_range[1]})
438443
staleness_time=$(random_number ${cleaning_alru_staleness_time_range[0]} ${cleaning_alru_staleness_time_range[1]})
439444
activity_threshold=$(random_number ${cleaning_alru_activity_threshold_range[0]} ${cleaning_alru_activity_threshold_range[1]})
440445
max_dirty_ratio=$(random_number ${cleaning_alru_max_dirty_ratio_range[0]} ${cleaning_alru_max_dirty_ratio_range[1]})
441446
set_cleaning_alru_params $cleaning_policy $wake_up_time $flush_max_buffers $staleness_time $activity_threshold $max_dirty_ratio
442447
__check_cleaning_alru_params $cleaning_policy $wake_up_time $flush_max_buffers $staleness_time $activity_threshold $max_dirty_ratio
443-
elif [ $cleaning_policy = acp ]; then
448+
elif [ $cleaning_policy == acp ]; then
444449
wake_up_time=$(random_number ${cleaning_acp_wake_up_time_range[0]} ${cleaning_acp_wake_up_time_range[1]})
445450
flush_max_buffers=$(random_number ${cleaning_acp_flush_max_buffers_range[0]} ${cleaning_acp_flush_max_buffers_range[1]})
446451
set_cleaning_acp_params $cleaning_policy $wake_up_time $flush_max_buffers
447452
__check_cleaning_acp_params $cleaning_policy $wake_up_time $flush_max_buffers
448-
elif [ $cleaning_policy = nop ]; then
453+
elif [ $cleaning_policy == nop ]; then
449454
set_cleaning_nop_params $cleaning_policy
450455
__check_cleaning_nop_params $cleaning_policy
451456
fi
452-
if [ $stop_caches = true ]; then
457+
if [ $stop_caches == true ]; then
453458
stop_caches
454459
__check_caches_empty
455460
fi
@@ -473,14 +478,14 @@ for device in core cache; do
473478
threshold=$(random_number ${seqcutoff_threshold_range[0]} ${seqcutoff_threshold_range[1]})
474479
promotion_count=$(random_number ${seqcutoff_promotion_count_range[0]} ${seqcutoff_promotion_count_range[1]})
475480
promote_on_threshold=$(random_number ${seqcutoff_promote_on_threshold_range[0]} ${seqcutoff_promote_on_threshold_range[1]})
476-
if [ $device = core ]; then
481+
if [ $device == core ]; then
477482
set_seqcutoff_params $seqcutoff_policy $threshold $promotion_count $promote_on_threshold
478483
__check_seqcutoff_params $seqcutoff_policy $threshold $promotion_count $promote_on_threshold
479-
elif [ $device = cache ]; then
484+
elif [ $device == cache ]; then
480485
set_seqcutoff_params_all $seqcutoff_policy $threshold $promotion_count $promote_on_threshold
481486
__check_seqcutoff_params_all $seqcutoff_policy $threshold $promotion_count $promote_on_threshold
482487
fi
483-
if [ $stop_caches = true ]; then
488+
if [ $stop_caches == true ]; then
484489
stop_caches
485490
__check_caches_empty
486491
fi

0 commit comments

Comments
 (0)