-
Notifications
You must be signed in to change notification settings - Fork 31
Test framework #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Test framework #116
Conversation
15514cb to
1866a9e
Compare
|
This is a huge contribution. Unit tests have long been much needed. Thank you! The CI is currently failing with: |
I recommend opening separate issues for these in https://github.com/HEASARC/cfitsio/issues/ I would then delete the ISSUES file from the pull request. |
|
Removed ISSUES and created issues 117-119. PTAL |
|
Checking the test failures on ubuntu. |
The pseudo-random number generator in test_rcomp_high_entropy() used
signed integer arithmetic that overflows when i >= 2:
original[i] = ((i * 1103515245 + 12345) >> 16) & 0x7FFF;
The multiplication i * 1103515245 exceeds INT_MAX (2147483647) at i=2,
producing 2207030490 which cannot be represented as a signed int. This
is undefined behavior per the C standard (C11 6.5/5).
GCC on Ubuntu ARM with -O2 exploits this UB via aggressive loop
optimizations (-Waggressive-loop-optimizations), causing the test
to abort with a core dump during distcheck. The compiler warning:
warning: iteration 2 invokes undefined behavior
The fix uses unsigned arithmetic throughout:
original[i] = (((unsigned)i * 1103515245U + 12345U) >> 16) & 0x7FFF;
This produces identical pseudo-random values but with well-defined
overflow semantics (modulo 2^32 per C11 6.2.5/9).
The fits_rcomp, fits_rcomp_short, and fits_rcomp_byte functions do not
perform end-of-buffer checking. As documented in ricecomp.c:
"Note that beginning with CFITSIO v3.08, EOB checking was removed
to improve speed, and so now the input compressed bytes buffers
must have been allocated big enough so that they will never be
overflowed."
The removed tests passed intentionally undersized buffers expecting
the library to detect this and return an error. Instead, the library
writes past the buffer bounds, causing stack corruption. This was
detected on Linux by FORTIFY_SOURCE/glibc, triggering SIGABRT.
The test_rdecomp_buffer_too_small test is retained since decompression
reads from the buffer (bounded by clen parameter) rather than writing.
|
All CI workflows are passing now. LGTM. |
Add a simplistic test framework. testprog only exercises about 16% of the code (as reported by gcov), and 22 files have zero coverage. This adds some basic unit testing to exercise a larger chunk of the code base to protect against regressions.
A few issues discovered while developing the tests are mentioned in tests/ISSUES