by dalke · 5y ago · 0 comments
Do I not check for malloc failure (in order to get 100%)?
Or do I develop some sort of instrumented version of MySQL which lets me test malloc failure? That seemed far more overkill than warranted for the small project I worked on, though I certainly know some projects which do that!
I decided to accept 99.5% or so coverage and manual inspection of the failure case.
There is a bit of diminishing returns to what I believe, but it also depends on ones dependencies and what one considers 100%.
As an example, I designed a multi-TB file-format and synchronization engine. I made that engine a dependency free library such that all the math, contracts, threading, and scheduling could be 100% tested before integration. This forced the messy integration into the core application which then was E2E tested with hundreds of randomized tests.
The key concept at play was beating all the math into the ground such that it was damn near perfect because a single flaw would lose data.
For example, there might be an "environment" API which abstracts memory management and file I/O. The plugin could use this API instead of direct calls. Then if MySQL had an option to use a specific environment implementation for a plugin, then testers could drop in their own implementation under test.
Getting that sort of support by MySQL is an example of what I think you mean by "cultural challenge."
Glibc has (or at least has had) special (unsupported) instrumentation that lets you substitute out the libc malloc at runtime with another function.
You can use this to shim in a version that fails after a specific number of executions in order to inject malloc faults.
E.g. https://github.com/xiph/opus/blob/master/tests/test_opus_api...
Having said that, I don't disagree with your choice, because messing with LD_PRELOAD is difficult, scary, and probably overkill anyway.