[libc-commits] [libc] [libc][test] Condition out tests that can't work on bare metal (PR #215830)
Simon Tatham via libc-commits
libc-commits at lists.llvm.org
Mon Aug 17 03:31:12 PDT 2026
================
@@ -10,6 +10,22 @@ add_custom_target(libc-hermetic-tests-build)
add_custom_target(libc-integration-tests-build)
add_custom_target(libc_include_tests-build)
+# Check if tests can safely include signal.h. (FPExceptMatcher.cpp can
+# use it, but can also do without it.)
+if(NOT LLVM_LIBC_FULL_BUILD)
+ # In an overlay build of libc, assume signal.h is available: the host libc
+ # will provide it even if we don't.
+ add_compile_definitions(HAVE_SIGNAL_H)
+else()
+ # In a full build, signal.h only exists if we provide it ourselves.
+ # In a bare-metal full build we might not, so check which headers
+ # we're shipping.
+ list(FIND TARGET_PUBLIC_HEADERS libc.include.signal SIGNAL_H_idx)
+ if(SIGNAL_H_idx GREATER -1)
+ add_compile_definitions(HAVE_SIGNAL_H)
+ endif()
+endif()
+
----------------
statham-arm wrote:
I'm confused by that code, because as far as I can see, the `if (TARGET ...)` construction ought to succeed all the time. In a library that doesn't have `clock`:
* `libc/src/CMakeLists.txt` still unconditionally runs `add_subdirectory(time)`
* `libc/src/time/CMakeLists.txt` unconditionally calls `add_entrypoint_object(clock ...)`
* `create_entrypoint_object()` will _unconditionally_ add a cmake target for `libc.src.time.clock`, whether that's one of the library's defined entry points or not.
The only difference if it's not an entry point is that the target will be added using `add_custom_target` which doesn't include any rules for actually building anything, and the `SKIPPED` property will be set on the target: https://github.com/llvm/llvm-project/blob/746a3438ce0c68f508b320433e665b7178f541ca/libc/cmake/modules/LLVMLibCObjectRules.cmake#L181-L191
When I tried the same thing alongside this code with `if(TARGET libc.src.signal.signal)`, I found that it enabled the signal handling tests even in my bare-metal library configuration that doesn't provide `signal()`, where they fail to compile. As you can see from my revised patch, I had to check the `SKIPPED` property on the target to find out whether `signal()` is _really_ there.
I don't understand why the same isn't true for the existing test of `clock`!
https://github.com/llvm/llvm-project/pull/215830
More information about the libc-commits
mailing list