tests/truncate: add regression tests for -s %SIZE round-up bug#10901
tests/truncate: add regression tests for -s %SIZE round-up bug#10901ChrisDryden merged 1 commit intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
I am not expert with coreutils' CI ; but checking some others, it seems to be 2 scenarios that are used to fail ; I do not see how they are related to this commit. The purpose of this contribution is to avoid other regressions that lead to wrong sizes. |
tests/by-util/test_truncate.rs
Outdated
|
|
||
| /// Regression test: round up when file is smaller than the rounding unit. | ||
| /// | ||
| /// `truncate -s %4K` on a 10-byte file must produce 4096 bytes, not 20. |
There was a problem hiding this comment.
More of a style nit and personal preference but do you think it would be possible to make the test names descriptive enough to not require the comment above to make it more consise? Same with the additional code of "expected '{expected}' got '{actual}'" I think if it fails it will provide the left and right descriptions
|
Thanks for adding more test cases, always good to have even if the underlying issue was already fixed. The tests seem correct to me just was hoping that we could reduce the size a bit |
|
@ChrisDryden : this issue/ regression had been critical for ATF, so the purpose is to harden with the related use case thru those tests. I'll check about your comments on cosmetics. |
The old RoundUp formula `fsize + fsize % size` was incorrect. For example, `truncate -s %128K` on a 24696-byte file produced 49392 bytes instead of the correct 131072 bytes. This was incidentally fixed in commit fe97933 ("truncate: eliminate duplicate stat() syscall") by replacing the formula with `fsize.checked_next_multiple_of(size)`. However, the existing test `test_round_up` used values (fsize=10, size=4) where both the buggy and correct formulas give the same result (12), so the bug was never caught by the test suite. Add unit and integration tests that would have caught this bug: - File smaller than rounding unit (the reported scenario) - File larger than rounding unit but not aligned - File already aligned to the rounding unit - Division by zero (RoundUp with size=0) Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210 Signed-off-by: Vincent Jardin <vjardin@free.fr>
d661faf to
31f52d7
Compare
|
@ChrisDryden : done, feel free to comment if you want some more adjustments. |
|
GNU testsuite comparison: |
…s#10901) The old RoundUp formula `fsize + fsize % size` was incorrect. For example, `truncate -s %128K` on a 24696-byte file produced 49392 bytes instead of the correct 131072 bytes. This was incidentally fixed in commit fe97933 ("truncate: eliminate duplicate stat() syscall") by replacing the formula with `fsize.checked_next_multiple_of(size)`. However, the existing test `test_round_up` used values (fsize=10, size=4) where both the buggy and correct formulas give the same result (12), so the bug was never caught by the test suite. Add unit and integration tests that would have caught this bug: - File smaller than rounding unit (the reported scenario) - File larger than rounding unit but not aligned - File already aligned to the rounding unit - Division by zero (RoundUp with size=0) Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210 Signed-off-by: Vincent Jardin <vjardin@free.fr>
The old RoundUp formula
fsize + fsize % sizewas incorrect. For example,truncate -s %128Kon a 24696-byte file produced 49392 bytes instead of the correct 131072 bytes.Maybe, this was incidentally fixed in commit fe97933 ("truncate: eliminate duplicate stat() syscall") by replacing the formula with
fsize.checked_next_multiple_of(size). However, the existing testtest_round_upused values (fsize=10, size=4) where both the buggy and correct formulas give the same result (12), so the bug was never caught by the test suite.Add unit and integration tests that would have caught this bug:
Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210