Skip to content

Commit c78ae7b

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add test for checking zero copy related parameter
ublk zero copy usually requires to set dma and segment parameter correctly, so hard-code null target's dma & segment parameter in non-default value, and verify if they are setup correctly by ublk driver. Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 8c77861 commit c78ae7b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LDLIBS += -lpthread -lm -luring
55

66
TEST_PROGS := test_generic_01.sh
77
TEST_PROGS += test_generic_02.sh
8+
TEST_PROGS += test_generic_03.sh
89

910
TEST_PROGS += test_null_01.sh
1011
TEST_PROGS += test_null_02.sh

tools/testing/selftests/ublk/null.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ static int ublk_null_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
1717

1818
dev->tgt.dev_size = dev_size;
1919
dev->tgt.params = (struct ublk_params) {
20-
.types = UBLK_PARAM_TYPE_BASIC,
20+
.types = UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DMA_ALIGN |
21+
UBLK_PARAM_TYPE_SEGMENT,
2122
.basic = {
2223
.logical_bs_shift = 9,
2324
.physical_bs_shift = 12,
@@ -26,6 +27,14 @@ static int ublk_null_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
2627
.max_sectors = info->max_io_buf_bytes >> 9,
2728
.dev_sectors = dev_size >> 9,
2829
},
30+
.dma = {
31+
.alignment = 4095,
32+
},
33+
.seg = {
34+
.seg_boundary_mask = 4095,
35+
.max_segment_size = 32 << 10,
36+
.max_segments = 32,
37+
},
2938
};
3039

3140
if (info->flags & UBLK_F_SUPPORT_ZERO_COPY)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
5+
6+
TID="generic_03"
7+
ERR_CODE=0
8+
9+
_prep_test "null" "check dma & segment limits for zero copy"
10+
11+
dev_id=$(_add_ublk_dev -t null -z)
12+
_check_add_dev $TID $?
13+
14+
sysfs_path=/sys/block/ublkb"${dev_id}"
15+
dma_align=$(cat "$sysfs_path"/queue/dma_alignment)
16+
max_segments=$(cat "$sysfs_path"/queue/max_segments)
17+
max_segment_size=$(cat "$sysfs_path"/queue/max_segment_size)
18+
if [ "$dma_align" != "4095" ]; then
19+
ERR_CODE=255
20+
fi
21+
if [ "$max_segments" != "32" ]; then
22+
ERR_CODE=255
23+
fi
24+
if [ "$max_segment_size" != "32768" ]; then
25+
ERR_CODE=255
26+
fi
27+
_cleanup_test "null"
28+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)