Skip to content

Commit 3d5def3

Browse files
Iulian Barbuluminitavoicu
authored andcommitted
block: used bytes reporting regression test
Signed-off-by: Iulian Barbu <[email protected]> Signed-off-by: Alin Dima <[email protected]>
1 parent 7d674c0 commit 3d5def3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/integration_tests/functional/test_drives.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import host_tools.drive as drive_tools
1212
import host_tools.network as net_tools # pylint: disable=import-error
1313

14+
MB = 1024 * 1024
15+
1416

1517
def test_rescan_file(test_microvm_with_ssh, network_config):
1618
"""Verify that rescan works with a file-backed virtio device."""
@@ -24,9 +26,11 @@ def test_rescan_file(test_microvm_with_ssh, network_config):
2426

2527
_tap, _, _ = test_microvm_with_ssh.ssh_network_config(network_config, '1')
2628

29+
block_size = 2
2730
# Add a scratch block device.
2831
fs = drive_tools.FilesystemFile(
29-
os.path.join(test_microvm.fsfiles, 'scratch')
32+
os.path.join(test_microvm.fsfiles, 'scratch'),
33+
size=block_size
3034
)
3135
response = test_microvm.drive.put(
3236
drive_id='scratch',
@@ -42,8 +46,16 @@ def test_rescan_file(test_microvm_with_ssh, network_config):
4246

4347
_check_scratch_size(ssh_connection, fs.size())
4448

45-
# Resize the filesystem from 256 MiB (default) to 512 MiB.
46-
fs.resize(512)
49+
# Check if reading from the entire disk results in a file of the same size
50+
# or errors out, after a truncate on the host.
51+
truncated_size = block_size//2
52+
utils.run_cmd(f"truncate --size {truncated_size}M {fs.path}")
53+
block_copy_name = "dev_vdb_copy"
54+
_, _, stderr = ssh_connection.execute_command(
55+
f"dd if=/dev/vdb of={block_copy_name} bs=1M count={block_size}")
56+
assert "dd: error reading '/dev/vdb': Input/output error" in stderr.read()
57+
_check_file_size(ssh_connection, f'{block_copy_name}',
58+
truncated_size * MB)
4759

4860
response = test_microvm.drive.patch(
4961
drive_id='scratch',
@@ -300,6 +312,15 @@ def _check_scratch_size(ssh_connection, size):
300312
assert stdout.readline().strip() == str(size)
301313

302314

315+
def _check_file_size(ssh_connection, dev_path, size):
316+
_, stdout, stderr = ssh_connection.execute_command(
317+
'stat --format=%s {}'.format(dev_path)
318+
)
319+
320+
assert stderr.read() == ''
321+
assert stdout.readline().strip() == str(size)
322+
323+
303324
def _process_blockdev_output(blockdev_out, assert_dict, keys_array):
304325
blockdev_out_lines = blockdev_out.splitlines()
305326

0 commit comments

Comments
 (0)