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.
58 lines
2.4 KiB
C
58 lines
2.4 KiB
C
//===-- Unittests for stdbit ----------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/*
|
|
* The intent of this test is validate that:
|
|
* 1. We provide the definition of the various type generic macros of stdbit.h
|
|
* (the macros are transitively included from stdbit-macros.h by stdbit.h).
|
|
* 2. It dispatches to the correct underlying function.
|
|
* Because unit tests build without public packaging, the object files produced
|
|
* do not contain non-namespaced symbols.
|
|
*/
|
|
|
|
/*
|
|
* Declare these BEFORE including stdbit-macros.h so that this test may still be
|
|
* run even if a given target doesn't yet have these individual entrypoints
|
|
* enabled.
|
|
*/
|
|
#include "stdbit_stub.h"
|
|
|
|
#include "include/llvm-libc-macros/stdbit-macros.h"
|
|
#include "test/UnitTest/LibcCTest.h"
|
|
|
|
#define CHECK_FUNCTION(FUNC_NAME, VAL) \
|
|
do { \
|
|
EXPECT_TRUE(FUNC_NAME((unsigned char)0U) == VAL##AU); \
|
|
EXPECT_TRUE(FUNC_NAME((unsigned short)0U) == VAL##BU); \
|
|
EXPECT_TRUE(FUNC_NAME(0U) == VAL##CU); \
|
|
EXPECT_TRUE(FUNC_NAME(0UL) == VAL##DU); \
|
|
EXPECT_TRUE(FUNC_NAME(0ULL) == VAL##EU); \
|
|
} while (0)
|
|
|
|
TEST(stdbit) {
|
|
CHECK_FUNCTION(stdc_leading_zeros, 0xA);
|
|
CHECK_FUNCTION(stdc_leading_ones, 0xB);
|
|
CHECK_FUNCTION(stdc_trailing_zeros, 0xC);
|
|
CHECK_FUNCTION(stdc_trailing_ones, 0xD);
|
|
CHECK_FUNCTION(stdc_first_leading_zero, 0xE);
|
|
CHECK_FUNCTION(stdc_first_leading_one, 0xF);
|
|
CHECK_FUNCTION(stdc_first_trailing_zero, 0x0);
|
|
CHECK_FUNCTION(stdc_first_trailing_one, 0x1);
|
|
CHECK_FUNCTION(stdc_count_zeros, 0x2);
|
|
CHECK_FUNCTION(stdc_count_ones, 0x3);
|
|
|
|
EXPECT_FALSE(stdc_has_single_bit((unsigned char)1U));
|
|
EXPECT_FALSE(stdc_has_single_bit((unsigned short)1U));
|
|
EXPECT_FALSE(stdc_has_single_bit(1U));
|
|
EXPECT_FALSE(stdc_has_single_bit(1UL));
|
|
EXPECT_FALSE(stdc_has_single_bit(1ULL));
|
|
|
|
CHECK_FUNCTION(stdc_bit_width, 0x4);
|
|
CHECK_FUNCTION(stdc_bit_floor, 0x5);
|
|
CHECK_FUNCTION(stdc_bit_ceil, 0x6);
|
|
}
|