You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
unittest, a C++-based white-box suite which tests individual functions and classes.
test, a bash-based black-box test suite which tests the ccache executable with real compilers installed in the system.
The first is fast and can be run on any system. The second is slow and relies on externally installed compilers, which is a problem since it's hard to impossible to have the full set of supported compilers installed.
Here is an idea on how to improve this:
Create a C++-based black-box test suite that executes the full ccache logic by calling a top level function like ccache_main and verifies the observable output (stdout/stderr and files created in the file system).
Refactor ccache to call into a compiler execution API instead of executing the compiler binary directly.
Make it possible for the new test suite to set up ccache to use a "fake compiler" implementation instead of a real one.
For each supported compiler, create such a fake compiler implementation that satisfies what ccache needs but not more. For instance, compiler.execute("-E foo.c") should print a faked preprocessed foo.c to stdout, compiler.execute("-c foo.c -o bar.o") should read foo.c and write something to bar.o, and so on.
Make it possible to drive the test suite with real external compilers in order to verify that the tests don't just work with the fake compilers.
I think mocking is a good idea. But why do you need your own execution API for that? Since ccache calls an external program anyway you could also write a moc-gcc and a moc-cl that does that.
What is the different between moc-gcc -c foo.c -o bar.o and compiler.execute("-c foo.c -o bar.o")?
When the original compiler is installed, you can use it instead of the mock.
But a big problem will be all the references for the object files. They have to be stored somewhere and git is not really a friend of binary files.
I agree, with the tests written as bash scripts, I definitely see problems implementing this as well. I think a modern test framework that is platform independent could be helpful here. But I'm not sure if C++ is the best choice for this, because e.g. Python together with PyTest or similar combinations save a lot of boilerplate code here.
I think mocking is a good idea. But why do you need your own execution API for that? Since ccache calls an external program anyway you could also write a moc-gcc and a moc-cl that does that. What is the different between moc-gcc -c foo.c -o bar.o and compiler.execute("-c foo.c -o bar.o")?
For clarity, just a note on word choice: With reference to e.g. this article, I'm talking about a fake (a kind of standalone working implementation), not a mock (something that the test prepares with behavior and expectations).
Say that we in the future have 1000 test cases and 20 compiler variants (think difference in behavior between versions and a handful of different compiler types). That would mean tens of thousands of calls to external compilers, which will be a bit slow, and one of the goals with this idea is fast tests.
That said, I haven't thought very much about what and what not to do – I only note that there is space to improve testing beyond the current test suites.
But a big problem will be all the references for the object files. They have to be stored somewhere and git is not really a friend of binary files.
The fake compilers don't have to produce any usable output so I don't see why there would be a need for storing object files.
I think a modern test framework that is platform independent could be helpful here.
Right, a Python-based test that calls into ccache code via a Python C module could be a good option.
Activity
rvogg commentedon Nov 2, 2021
I think mocking is a good idea. But why do you need your own execution API for that? Since ccache calls an external program anyway you could also write a
moc-gccand amoc-clthat does that.What is the different between
moc-gcc -c foo.c -o bar.oandcompiler.execute("-c foo.c -o bar.o")?When the original compiler is installed, you can use it instead of the mock.
But a big problem will be all the references for the object files. They have to be stored somewhere and git is not really a friend of binary files.
I agree, with the tests written as bash scripts, I definitely see problems implementing this as well. I think a modern test framework that is platform independent could be helpful here. But I'm not sure if C++ is the best choice for this, because e.g. Python together with PyTest or similar combinations save a lot of boilerplate code here.
jrosdahl commentedon Nov 6, 2021
@rvogg wrote:
For clarity, just a note on word choice: With reference to e.g. this article, I'm talking about a fake (a kind of standalone working implementation), not a mock (something that the test prepares with behavior and expectations).
Say that we in the future have 1000 test cases and 20 compiler variants (think difference in behavior between versions and a handful of different compiler types). That would mean tens of thousands of calls to external compilers, which will be a bit slow, and one of the goals with this idea is fast tests.
That said, I haven't thought very much about what and what not to do – I only note that there is space to improve testing beyond the current test suites.
The fake compilers don't have to produce any usable output so I don't see why there would be a need for storing object files.
Right, a Python-based test that calls into ccache code via a Python C module could be a good option.