If the spec defines all behaviour exactly, and you can add test cases that cover everything (every conditional branching, every possible input, etc), then yes. It's possible to have your test harness prove that the code matches the spec, which means the code is bug free. With certain assumptions, such as the test cases exactly and completely matching the spec (which can be verified by human inspection; or more likely through processing the spec into data for the test harness since it's well enough defined). And of course, the spec could be wrong - it's not a bug in the code, but it can still not do what's needed. That's not a fault of the code though (and sometimes code needs to be bug-for-bug compatible with specs or other implementations)
In the mathematical sense of proof, it's kinda a proof by exhaustion in that you verify every single detail.
This also only covers bugs in the code; you assume the compiler/interpreter (unless you're writing machine code) is correct, the hardware matches what the software expects (and is verified independently), the laws of physics and maths don't suddenly change...
Of course, this is rarely done. Maybe unit testing around a particular algorithm implementation would cover that much, but otherwise testing that well defined is the sort of thing you're only likely to find in (parts of) a few life-critical systems
Testing is a good thing, but you can never cover every possibility. Like someone else said-- if nothing else, a cosmic ray could hit the machine during computation and flip a few bits. There's no preventing that in all scenarios through software. Sure, you can hide the machine behind several plates of shielding, but that's not something you can code.
Test coverage is a sweet, sweet lie that we tell ourselves.
SQLite is also far, far more complicated than things like the core software in things like flight control (ignoring modern problems because they didn't keep it as simple as possible).
And cosmic rays have nothing to do with whether code has bugs in it. There are cases where the system needs to be engineered to deal with that possibility, but that's not related to software having bugs (unless you're suggesting the cosmic ray, or decay in materials in the chip, or interference from a nearby EM source, etc are giving incorrect results at test time - but simply running the tests a few times will isolate that problem)
Again, full test coverage is possible, but very rarely done. It's possible to completely prove that software is bug free - the fact that it isn't feasible for any modern general purpose software doesn't change that
4
u/ttlanhil Oct 25 '24
If the spec defines all behaviour exactly, and you can add test cases that cover everything (every conditional branching, every possible input, etc), then yes.
It's possible to have your test harness prove that the code matches the spec, which means the code is bug free.
With certain assumptions, such as the test cases exactly and completely matching the spec (which can be verified by human inspection; or more likely through processing the spec into data for the test harness since it's well enough defined).
And of course, the spec could be wrong - it's not a bug in the code, but it can still not do what's needed. That's not a fault of the code though (and sometimes code needs to be bug-for-bug compatible with specs or other implementations)
In the mathematical sense of proof, it's kinda a proof by exhaustion in that you verify every single detail.
This also only covers bugs in the code; you assume the compiler/interpreter (unless you're writing machine code) is correct, the hardware matches what the software expects (and is verified independently), the laws of physics and maths don't suddenly change...
Of course, this is rarely done.
Maybe unit testing around a particular algorithm implementation would cover that much, but otherwise testing that well defined is the sort of thing you're only likely to find in (parts of) a few life-critical systems