[libc] Add a C unit test framework wrapper and convert existing tests (#213657)
This removes the dependency on the host C library (hermetic tests),
makes sure the tests actually do something in release builds (where
assert() is a noop), and makes better and more consistent failure
messages.
This is just a thin wrapper over the existing framework which repackages
the C++ interface into something consumable by C code. I tried to keep
the interface consistent, but of course, many of the framework features
are C++ only. Registering more than one test function was tricky, so the
framework currently supports only one.
The main trick here was getting the static library linker to extract
LibcCTest.cpp.o from libLibcTest.unit.a. Since C test cases don't
instantiate static CTest objects in their own translation unit like C++
tests do (they cannot do that portably), nothing in the object file
referenced LibcCTest.cpp. I made this work by introducing
libc_c_test_anchor() and calling it explicitly inside the generated
libc_c_test_run() function.
GitOrigin-RevId: 7ea6d45feaed43266ece53df274aaf6b53340238
14 files changed