isobusfs: selftest: Handle read requests larger than file size

Add expected_size field to test patterns to properly validate cases
where the requested read size exceeds the actual file size. This allows
testing the server's behavior when clients request more data than is
available.

When a read request is larger than the file, the server correctly
returns data up to EOF. The test framework now distinguishes between
this expected scenario and genuine read failures.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
pull/629/head
Oleksij Rempel 2026-01-04 18:42:14 +01:00 committed by Oleksij Rempel
parent 95aae6bf83
commit 5a681968a2
1 changed files with 40 additions and 22 deletions

View File

@ -603,23 +603,24 @@ struct isobusfs_cli_test_rf_path {
uint8_t flags; uint8_t flags;
uint32_t offset; uint32_t offset;
uint32_t read_size; uint32_t read_size;
uint32_t expected_size;
bool expect_pass; bool expect_pass;
}; };
static struct isobusfs_cli_test_rf_path test_rf_patterns[] = { static struct isobusfs_cli_test_rf_path test_rf_patterns[] = {
/* expected result \\vol1\dir1\dir2\ */ /* expected result \\vol1\dir1\dir2\ */
{ "\\\\vol1\\dir1\\dir2\\file1k", 0, 0, 0, true }, { "\\\\vol1\\dir1\\dir2\\file1k", 0, 0, 0, 0, true },
{ "\\\\vol1\\dir1\\dir2\\file1k", 0, 0, 1, true }, { "\\\\vol1\\dir1\\dir2\\file1k", 0, 0, 1, 1, true },
{ "\\\\vol1\\dir1\\dir2\\file1k", 0, 1, 1, true }, { "\\\\vol1\\dir1\\dir2\\file1k", 0, 1, 1, 1, true },
{ "\\\\vol1\\dir1\\dir2\\file1k", 0, 2, 1, true }, { "\\\\vol1\\dir1\\dir2\\file1k", 0, 2, 1, 1, true },
{ "\\\\vol1\\dir1\\dir2\\file1k", 0, 3, 1, true }, { "\\\\vol1\\dir1\\dir2\\file1k", 0, 3, 1, 1, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, 8, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, 8, 8, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, 8 * 100, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, 8 * 100, 8 * 100, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 100, 8 * 100, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 100, 8 * 100, 8 * 100, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, ISOBUSFS_MAX_DATA_LENGH, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, ISOBUSFS_MAX_DATA_LENGH, ISOBUSFS_MAX_DATA_LENGH, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, (ISOBUSFS_MAX_DATA_LENGH & ~3) + 16, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, (ISOBUSFS_MAX_DATA_LENGH & ~3) + 16, (ISOBUSFS_MAX_DATA_LENGH & ~3) + 16, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, ISOBUSFS_MAX_DATA_LENGH + 1, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, ISOBUSFS_MAX_DATA_LENGH + 1, ISOBUSFS_MAX_DATA_LENGH + 1, true },
{ "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, -1, true }, { "\\\\vol1\\dir1\\dir2\\file1m", 0, 0, UINT32_MAX, 1024 * 1024, true },
}; };
size_t current_rf_pattern_test; size_t current_rf_pattern_test;
@ -678,7 +679,8 @@ static int isobusfs_cli_test_rf_req(struct isobusfs_priv *priv, bool *complete)
&test_rf_patterns[current_rf_pattern_test]; &test_rf_patterns[current_rf_pattern_test];
uint32_t actual_sum, expected_sum; uint32_t actual_sum, expected_sum;
struct timespec current_time; struct timespec current_time;
ssize_t remaining_size, read_size; int64_t remaining_size;
ssize_t read_size;
int ret; int ret;
clock_gettime(CLOCK_MONOTONIC, &current_time); clock_gettime(CLOCK_MONOTONIC, &current_time);
@ -801,16 +803,23 @@ static int isobusfs_cli_test_rf_req(struct isobusfs_priv *priv, bool *complete)
free(priv->read_data); free(priv->read_data);
priv->read_data = NULL; priv->read_data = NULL;
remaining_size = (tp->offset + tp->read_size) - remaining_size = ((int64_t)tp->offset + tp->read_size) -
(priv->read_offset + priv->read_data_len); ((int64_t)priv->read_offset + priv->read_data_len);
pr_debug("remaining_size: %zd, read_offset: %zu, read_data_len: %zu, test read size: %zu, test offset %zu", pr_debug("remaining_size: %lld, read_offset: %zu, read_data_len: %zu, test read size: %u, test offset %u",
remaining_size, priv->read_offset, priv->read_data_len, (long long)remaining_size, priv->read_offset, priv->read_data_len,
tp->read_size, tp->offset); tp->read_size, tp->offset);
if (remaining_size < 0) { if (remaining_size < 0) {
pr_err("pattern test failed: %s. Read size is too big", pr_err("pattern test failed: %s. Read size is too big",
tp->path_name); tp->path_name);
ret = -EINVAL; ret = -EINVAL;
goto test_fail; goto test_fail;
} else if (remaining_size == 0) {
if (tp->read_size > tp->expected_size) {
pr_err("read test failed: %s. Server returned more data than expected file size (%u > %u)",
tp->path_name, tp->read_size, tp->expected_size);
ret = -EINVAL;
goto test_fail;
}
} else if (remaining_size > 0 && priv->read_data_len != 0) { } else if (remaining_size > 0 && priv->read_data_len != 0) {
priv->read_offset += priv->read_data_len; priv->read_offset += priv->read_data_len;
@ -825,11 +834,20 @@ static int isobusfs_cli_test_rf_req(struct isobusfs_priv *priv, bool *complete)
goto test_fail; goto test_fail;
test_start_time = current_time; test_start_time = current_time;
break; break;
} else if (remaining_size > 0 && priv->read_data_len == 0 && tp->expect_pass) { } else if (remaining_size > 0 && priv->read_data_len == 0) {
pr_err("read test failed: %s. Read size is zero, but expected more data: %zd", if (tp->read_size > tp->expected_size &&
tp->path_name, remaining_size); tp->read_size - remaining_size == tp->expected_size) {
ret = -EINVAL; /* this is acceptable case when read size
goto test_fail; * is larger than actual file size
*/
pr_info("read test passed: %s. Reached end of file as expected.",
tp->path_name);
} else {
pr_err("read test failed: %s. Server returned zero bytes, but expected more data: %lld",
tp->path_name, (long long)remaining_size);
ret = -EINVAL;
goto test_fail;
}
} }
/* fall troth */ /* fall troth */