Skip to content

Commit 1c1a307

Browse files
feat(disk_perf): parameterize most test variables
Signed-off-by: Mathieu Labourier <[email protected]>
1 parent af54e81 commit 1c1a307

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

tests/storage/benchmarks/conftest.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import logging
23
import os
34
import tempfile
@@ -9,7 +10,7 @@
910

1011
from lib.commands import SSHCommandFailed
1112

12-
from .helpers import load_results_from_csv
13+
from .helpers import load_results_from_csv, str_to_tuple
1314

1415
MAX_LENGTH = 64 * (1024**3) # 64GiB
1516

@@ -98,12 +99,57 @@ def temp_dir(running_unix_vm_with_fio):
9899

99100

100101
def pytest_addoption(parser):
102+
system_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
103+
101104
parser.addoption(
102105
"--prev-csv",
103106
action="store",
104107
default=None,
105108
help="Path/URI to previous CSV results file for comparison",
106109
)
110+
parser.addoption(
111+
"--block-sizes",
112+
action="store",
113+
type=lambda value: str_to_tuple(value, sep=","),
114+
default=("4k", "16k", "64k", "1M"),
115+
help="Comma separated values of block sizes to test in disk benchmarks",
116+
)
117+
parser.addoption(
118+
"--file-sizes",
119+
action="store",
120+
type=lambda value: str_to_tuple(value, sep=","),
121+
default=("1G", "4G", f"{int((system_memory // (1024.**3)) * 2)}G"),
122+
help="Comma separated values of file sizes to test in disk benchmarks",
123+
)
124+
parser.addoption(
125+
"--modes",
126+
action="store",
127+
type=lambda value: str_to_tuple(value, sep=","),
128+
default=("read", "randread", "write", "randwrite"),
129+
help="Comma separated values of rw_modes to test in disk benchmarks",
130+
)
131+
parser.addoption(
132+
"--numjobs",
133+
action="store",
134+
default=1,
135+
help="Mapped to fio's --numjobs",
136+
)
137+
parser.addoption(
138+
"--iodepth",
139+
action="store",
140+
default=1,
141+
help="Mapped to fio's --iodepth",
142+
)
143+
144+
145+
def pytest_generate_tests(metafunc):
146+
if {"block_size", "file_size", "rw_mode"} <= set(metafunc.fixturenames):
147+
block_sizes = metafunc.config.getoption("block_sizes")
148+
file_sizes = metafunc.config.getoption("file_sizes")
149+
modes = metafunc.config.getoption("modes")
150+
151+
test_cases = list(itertools.product(block_sizes, file_sizes, modes))
152+
metafunc.parametrize("block_size,file_size,rw_mode", test_cases)
107153

108154

109155
@pytest.fixture(scope="session")

tests/storage/benchmarks/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import statistics
44
from datetime import datetime
55

6+
system_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
7+
68

79
def log_result_csv(test_type, rw_mode, result_json, csv_path):
810
job = result_json["jobs"][0]
@@ -44,3 +46,7 @@ def load_results_from_csv(csv_path):
4446

4547
def mean(data, key):
4648
return statistics.mean([float(x[key]) for x in data if key in x])
49+
50+
51+
def str_to_tuple(value, sep=","):
52+
return tuple(item.strip() for item in value.split(sep))

tests/storage/benchmarks/test_disk_perf.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import itertools
21
import json
32
import logging
43
import os
@@ -22,17 +21,6 @@
2221
DEFAULT_NUMJOBS = 1
2322
DEFAULT_FILE = "fio-testfile"
2423

25-
# Tests parameters #
26-
27-
system_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
28-
29-
block_sizes = ("4k", "16k", "64k", "1M")
30-
file_sizes = ("1G", "4G", f"{int((system_memory // (1024.**3)) * 2)}G")
31-
32-
modes = ("read", "randread", "write", "randwrite")
33-
34-
# End of tests parameters #
35-
3624

3725
def run_fio(
3826
vm,
@@ -99,11 +87,11 @@ def assert_performance_not_degraded(current, previous, threshold=10):
9987

10088

10189
class TestDiskPerf:
102-
test_cases = itertools.product(block_sizes, file_sizes, modes)
10390

10491
@pytest.mark.parametrize("block_size,file_size,rw_mode", test_cases)
10592
def test_disk_benchmark(
10693
self,
94+
pytestconfig,
10795
temp_dir,
10896
local_temp_dir,
10997
prev_results,
@@ -129,6 +117,8 @@ def test_disk_benchmark(
129117
file_path=device,
130118
bs=block_size,
131119
size=file_size,
120+
iodepth=pytestconfig.getoption("iodepth"),
121+
numjobs=pytestconfig.getoption("numjobs"),
132122
)
133123
summary = log_result_csv(test_type, rw_mode, result, CSV_FILE)
134124
assert summary["IOPS"] > 0

0 commit comments

Comments
 (0)