Skip to content
Snippets Groups Projects
Commit 44026628 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Update cmp_tool for improved error handling

- Ensured error handling is now consistent with the --binary option when
  model file size does not match original data size see 3321f1d8 (Add
  model file size mismatch check and update version to 0.14, 2025-01-16)
- Enhanced cmp_tool integration tests to cover model size mismatch cases
parent f840e2be
Branches
Tags
1 merge request!36Ensured error handling is now consistent with the --binary
......@@ -1315,7 +1315,7 @@ static __inline ssize_t str2uint8_arr(const char *str, uint8_t *data, uint32_t b
nptr++;
}
if (*nptr != '\0') {
fprintf(stderr, "%s: %s: Warning: The file may contain more data than specified by the samples or cmp_size parameter.\n",
fprintf(stderr, "%s: %s: Warning: The file may contain more data than read from it.\n",
PROGRAM_NAME, file_name);
}
......
......@@ -537,6 +537,19 @@ int CMP_MAIN(int argc, char **argv)
else
model_size = cmp_ent_get_original_size(decomp_entity);
size = read_file_data(model_file_name, cmp_type, NULL,
model_size, io_flags);
if (size < 0)
goto fail;
if (size < (ssize_t)model_size) {
fprintf(stderr, "%s: %s: Error: The files do not contain enough data. Expected: 0x%x, has 0x%x.\n",
PROGRAM_NAME, model_file_name, model_size, (uint32_t)size);
goto fail;
}
if (size != (ssize_t)model_size) {
fprintf(stderr, "%s: %s: Error: Model file size does not match original data size.\n", PROGRAM_NAME, model_file_name);
goto fail;
}
input_model_buf = malloc(model_size);
if (!input_model_buf) {
......@@ -548,10 +561,7 @@ int CMP_MAIN(int argc, char **argv)
model_size, io_flags);
if (size < 0)
goto fail;
if (size != (ssize_t)model_size) {
fprintf(stderr, "%s: %s: Error: Model file size does not match original data size.\n", PROGRAM_NAME, model_file_name);
goto fail;
}
printf("DONE\n");
......
......@@ -1331,7 +1331,7 @@ def test_model_fiel_erros():
del_file(output_prefix+"_upmodel.dat")
def test_decmp_model_fiel_original_size_miss_match():
def test_decmp_model_fiel_original_size_miss_match_binary():
cmp_data = b'8000000d000029000004097ce800cbd5097ce800cbfe00010108d01001000000001001001110078700'
to_large_model = b'111111111111' # should be 4 byte large in normal case
output_prefix = 'model_file_to_large'
......@@ -1356,6 +1356,37 @@ def test_decmp_model_fiel_original_size_miss_match():
finally:
del_file(cmp_data_file_name)
del_file(model_file_name)
del_file(output_prefix+'.dat')
del_file(output_prefix+'_upmodel.dat')
def test_decmp_model_fiel_original_size_miss_match_binary():
cmp_data = '8000000d000029000004097ce800cbd5097ce800cbfe00010108d01001000000001001001110078700'
to_large_model = '111111111111' # should be 4 byte large in normal case
output_prefix = 'model_file_to_large'
cmp_data_file_name = 'cmp_data.cmp'
model_file_name = 'to_large_model.dat'
try:
with open(cmp_data_file_name, 'w', encoding='utf-8') as f:
f.write(cmp_data)
with open(model_file_name, 'w', encoding='utf-8') as f:
f.write(to_large_model)
returncode, stdout, stderr = call_cmp_tool(
" -d "+cmp_data_file_name + " -m " + model_file_name + " -o "+output_prefix)
assert(returncode == EXIT_FAILURE)
assert(stdout == CMP_START_STR_DECMP +
"Importing compressed data file %s ... DONE\n" % (cmp_data_file_name) +
"Importing model file %s ... FAILED\n" % (model_file_name))
assert(stderr == "cmp_tool: %s: Error: Model file size does not match original data size.\n" % (model_file_name))
finally:
del_file(cmp_data_file_name)
del_file(model_file_name)
del_file(output_prefix+'.dat')
del_file(output_prefix+'_upmodel.dat')
def test_rdcu_pkt():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment