mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-25 21:45:57 +00:00
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.
36 lines
1.2 KiB
C++
36 lines
1.2 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// Helpers for libc C unittests.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "test/UnitTest/LibcCTest.h"
|
|
#include "test/UnitTest/LibcTest.h"
|
|
|
|
namespace {
|
|
class CTest : public LIBC_NAMESPACE::testing::Test {
|
|
public:
|
|
CTest() { addTest(this); }
|
|
void Run() override { libc_c_test_run(); }
|
|
const char *getName() const override { return LIBC_C_TEST_NAME; }
|
|
};
|
|
} // namespace
|
|
|
|
static CTest c_test_instance;
|
|
|
|
extern "C" void libc_c_test_anchor() {}
|
|
|
|
extern "C" void libc_c_test_fail(const char *cond, int expected,
|
|
const char *file, int line) {
|
|
LIBC_NAMESPACE::testing::internal::test(
|
|
LIBC_NAMESPACE::testing::TestCond::EQ, !expected,
|
|
static_cast<bool>(expected), cond, expected ? "true" : "false",
|
|
LIBC_NAMESPACE::testing::internal::Location(file, line));
|
|
}
|