|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 | 4 | """Tests for checking the rate limiter on /drives resources."""
|
5 |
| - |
| 5 | +import json |
6 | 6 | import os
|
7 | 7 |
|
8 | 8 | import host_tools.drive as drive_tools
|
|
12 | 12 |
|
13 | 13 | def check_iops_limit(ssh_connection, block_size, count, min_time, max_time):
|
14 | 14 | """Verify if the rate limiter throttles block iops using dd."""
|
15 |
| - obs = block_size |
| 15 | + |
16 | 16 | byte_count = block_size * count
|
17 |
| - dd = "dd if=/dev/zero of=/dev/vdb ibs={} obs={} count={} oflag=direct".format( |
18 |
| - block_size, obs, count |
19 |
| - ) |
20 |
| - print("Running cmd {}".format(dd)) |
21 |
| - # Check write iops (writing with oflag=direct is more reliable). |
22 |
| - _, _, stderr = ssh_connection.check_output(dd) |
23 | 17 |
|
24 |
| - # "dd" writes to stderr by design. We drop first lines |
25 |
| - lines = stderr.split("\n") |
26 |
| - dd_result = lines[2].strip() |
| 18 | + fio = f"fio --name=fixed-job --direct=1 --rw=write --blocksize={block_size} --size={byte_count} --filename=/dev/vdb --zero_buffers --output-format=json" |
| 19 | + |
| 20 | + _, stdout, _ = ssh_connection.check_output(fio) |
27 | 21 |
|
28 |
| - # Interesting output looks like this: |
29 |
| - # 4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.0528524 s, 79.4 MB/s |
30 |
| - tokens = dd_result.split() |
| 22 | + data = json.loads(stdout) |
| 23 | + runtime_ms = data["jobs"][0]["write"]["runtime"] |
| 24 | + io_bytes = data["jobs"][0]["write"]["io_bytes"] |
31 | 25 |
|
32 | 26 | # Check total read bytes.
|
33 |
| - assert int(tokens[0]) == byte_count |
| 27 | + assert io_bytes == byte_count |
34 | 28 | # Check duration.
|
35 |
| - assert float(tokens[7]) > min_time |
36 |
| - assert float(tokens[7]) < max_time |
| 29 | + assert runtime_ms > min_time * 1000 |
| 30 | + assert runtime_ms < max_time * 1000 |
37 | 31 |
|
38 | 32 |
|
39 | 33 | def test_patch_drive_limiter(uvm_plain):
|
|
0 commit comments