[LLVMdev] Private headers and testing

Misha Brukman brukman at gmail.com
Fri Jan 2 13:48:19 PST 2009


2009/1/2 Chris Lattner <clattner at apple.com>

> On Jan 2, 2009, at 12:21 PM, Misha Brukman wrote:
> Do you have a specific example of a unit test that would need these?  I
> really think these should stay private.
>

Let's take lib/Transforms/Utils/CodeExtractor.cpp .  The public interface
for it is in include/llvm/Transform/Utils/FunctionUtils.h, with only the
high-level API.

If I want to test some corner-case (consider the number of code paths in
that code), I have to strain to come up with some combination of a Function
and input BasicBlocks that will fit all the conditions from the outset.  Or,
I can just feed each individual method in the class exactly the corner cases
I will want it to handle, and verify its output (or side effects) exactly,
to make sure I pin-pointed the issue.

Or, let's say I want to write some tests for the LLParser -- the only public
API is "ParseAssemblyString", I can't unittest each individual method.  The
unittest for this using the public API will be very brittle as it would have
to check the contents of the returned error message, instead of calling each
Parse*() function directly and analyzing its output.

Of course, we should still have a test for the overall public API, but
that's in addition to the small unit tests to make sure each one works as it
should.

Note that this is a parallel to having an on-disk representation of IR
(which LLVM has) to a lack of such (which some other compilers had and/or
have now).  In the former case, to test an optimization, one just writes
LLVM IR and runs the pass directly on the case at hand.  In the other case,
one has to strain to come up with a front-end input source that will trigger
something in the 'blackbox' middle or back-end code, knowing that it will
get pre-digested before it gets there, and hence it's hard to know what
you're really testing on.

Misha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090102/d46222fa/attachment.html>


More information about the llvm-dev mailing list