Skip to content

Commit 90158ed

Browse files
authored
[ATfE] Add hermetic testing in LLVM-libc (#420)
Adds hermetic test support (`ninja check-llvmlibc`) with ARMv7-M and ARMv8-M as an experimental feature. This runs the tests provided upstream by `libc/test`, using their framework. It does not pass every test, however, it runs all the available tests. This also rearranges the `samples` to use a new linker script, `llvmlibc.ld`. This is based on `picolibc.ld`.
1 parent 482683e commit 90158ed

File tree

12 files changed

+75
-262
lines changed

12 files changed

+75
-262
lines changed

arm-software/embedded/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ if(LLVM_TOOLCHAIN_C_LIBRARY STREQUAL llvmlibc)
384384

385385
install(
386386
DIRECTORY
387-
${CMAKE_CURRENT_SOURCE_DIR}/llvmlibc-samples/src
387+
${CMAKE_CURRENT_SOURCE_DIR}/llvmlibc-samples/
388388
DESTINATION samples
389389
COMPONENT llvm-toolchain-llvmlibc-configs
390390
)

arm-software/embedded/arm-multilib/json/variants/armv7m_soft_nofp_exn_rtti_size.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"llvmlibc": {
3434
"ENABLE_CXX_LIBS": "ON",
35-
"ENABLE_LIBC_TESTS": "OFF",
35+
"ENABLE_LIBC_TESTS": "ON",
3636
"ENABLE_COMPILER_RT_TESTS": "OFF",
3737
"ENABLE_LIBCXX_TESTS": "OFF"
3838
}

arm-software/embedded/arm-multilib/json/variants/armv8m.main_hard_fp_unaligned_size.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"llvmlibc": {
3434
"ENABLE_CXX_LIBS": "ON",
35-
"ENABLE_LIBC_TESTS": "OFF",
35+
"ENABLE_LIBC_TESTS": "ON",
3636
"ENABLE_COMPILER_RT_TESTS": "OFF",
3737
"ENABLE_LIBCXX_TESTS": "OFF"
3838
}

arm-software/embedded/arm-runtimes/CMakeLists.txt

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ if(ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
159159
set(picocrt "crt0-semihost-fvp")
160160
endif()
161161
set(test_link_flags "-nostartfiles -l${picocrt} -lsemihost -T picolibcpp.ld")
162+
elseif(C_LIBRARY STREQUAL llvmlibc)
163+
# QEMU logic handled later
162164
else()
163-
message(FATAL_ERROR "Tests can only be enabled using picolibc.")
165+
message(FATAL_ERROR "Tests can only be enabled using picolibc or llvmlibc.")
164166
endif()
165167

166168
if(TEST_EXECUTOR STREQUAL qemu)
@@ -633,10 +635,10 @@ endif()
633635
###############################################################################
634636

635637
if(C_LIBRARY STREQUAL llvmlibc)
636-
if(ENABLE_LIBC_TESTS)
637-
message(FATAL_ERROR "Tests cannot yet be enabled using llvm libc.")
638+
if(NOT(TEST_EXECUTOR STREQUAL qemu))
639+
message(FATAL_ERROR "Using LLVM-libc and FVPs together is unsupported")
638640
endif()
639-
641+
set(test_cmd "qemu-system-arm -M ${QEMU_MACHINE} -semihosting -nographic -device loader$<COMMA>file=@BINARY@")
640642
set(lib_compile_flags "${lib_compile_flags} -Wno-error=atomic-alignment")
641643

642644
set(common_llvmlibc_cmake_args
@@ -679,9 +681,11 @@ if(C_LIBRARY STREQUAL llvmlibc)
679681
-DLLVM_CMAKE_DIR=${LLVM_BINARY_DIR}/lib/cmake/llvm
680682
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
681683
-DLLVM_ENABLE_RUNTIMES=libc
682-
-DLLVM_INCLUDE_TESTS=OFF # llvmlibc's tests require C++, so can't be built until llvmlibc can support libc++
683684
-DLLVM_LIBC_ALL_HEADERS=ON
684685
-DLLVM_LIBC_FULL_BUILD=ON
686+
-DLIBC_TEST_LINK_OPTIONS_DEFAULT=-nostartfiles,-lcrt0-semihost,-lsemihost,-T,llvmlibc.ld
687+
-DLIBC_TEST_CMD=${test_cmd}
688+
-DLIBC_TEST_HERMETIC_ONLY=true
685689
STEP_TARGETS configure build install
686690
USES_TERMINAL_CONFIGURE TRUE
687691
USES_TERMINAL_BUILD TRUE
@@ -716,6 +720,13 @@ if(C_LIBRARY STREQUAL llvmlibc)
716720
CMAKE_ARGS
717721
${compiler_launcher_cmake_args}
718722
${common_llvmlibc_cmake_args}
723+
-DBOOT_FLASH_ADDRESS=${BOOT_FLASH_ADDRESS}
724+
-DBOOT_FLASH_SIZE=${BOOT_FLASH_SIZE}
725+
-DFLASH_ADDRESS=${FLASH_ADDRESS}
726+
-DFLASH_SIZE=${FLASH_SIZE}
727+
-DRAM_ADDRESS=${RAM_ADDRESS}
728+
-DRAM_SIZE=${RAM_SIZE}
729+
-DSTACK_SIZE=${STACK_SIZE}
719730
STEP_TARGETS build install
720731
USES_TERMINAL_CONFIGURE TRUE
721732
USES_TERMINAL_BUILD TRUE
@@ -724,6 +735,33 @@ if(C_LIBRARY STREQUAL llvmlibc)
724735
LIST_SEPARATOR ,
725736
CONFIGURE_HANDLED_BY_BUILD TRUE
726737
)
738+
739+
if(ENABLE_LIBC_TESTS)
740+
add_custom_target(check-llvmlibc)
741+
add_dependencies(check-all check-llvmlibc)
742+
743+
ExternalProject_Add_Step(
744+
llvmlibc
745+
check
746+
COMMAND "${CMAKE_COMMAND}" --build <BINARY_DIR> --target libc-hermetic-tests
747+
DEPENDEES install
748+
USES_TERMINAL TRUE
749+
EXCLUDE_FROM_MAIN TRUE
750+
ALWAYS TRUE
751+
)
752+
753+
ExternalProject_Add_StepTargets(llvmlibc check)
754+
ExternalProject_Add_StepDependencies(
755+
llvmlibc
756+
check
757+
llvmlibc-build
758+
llvmlibc-support-build
759+
compiler_rt-install
760+
cxxlibs-install
761+
)
762+
763+
add_dependencies(check-llvmlibc llvmlibc-check)
764+
endif()
727765
endif()
728766

729767
add_dependencies(clib-configure ${C_LIBRARY}-configure)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
__boot_flash = 0x00000000; /* fragment of the flash where interrupt vector goes */
2+
__boot_flash_size = 0x3000; /* length of flash fragment with interrupt vector */
3+
__flash = 0x00003000; /* starting address of the remaining flash */
4+
__flash_size = 0x3d000; /* length of the remaining flash */
5+
__ram = 0x20000000; /* starting address of RAM bank 0 */
6+
__ram_size = 0x4000; /* length of RAM bank 0 */
7+
__stack_size = 512;
8+
9+
INCLUDE llvmlibc.ld

arm-software/embedded/llvmlibc-samples/src/baremetal-semihosting-llvmlibc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include ../../Makefile.conf
1010
build: hello.elf
1111

1212
hello.elf: *.c
13-
$(BIN_PATH)/clang --config=llvmlibc.cfg $(MICROBIT_TARGET) $(CRT_SEMIHOST) -lm -g -fno-exceptions -fno-rtti -T microbit-llvmlibc.ld -o hello.elf $^
13+
$(BIN_PATH)/clang --config=llvmlibc.cfg $(MICROBIT_TARGET) $(CRT_SEMIHOST) -lm -g -fno-exceptions -fno-rtti -T ../../ldscripts/llvmlibc-microbit.ld -o hello.elf $^
1414

1515
%.hex: %.elf
1616
$(BIN_PATH)/llvm-objcopy -O ihex $< $@

arm-software/embedded/llvmlibc-samples/src/baremetal-semihosting-llvmlibc/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ if exist hello.hex del /q hello.hex
4040
@exit /B 1
4141

4242
:build_fn
43-
%BIN_PATH%\clang.exe --config=llvmlibc.cfg --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T microbit-llvmlibc.ld -lm -o hello.elf hello.c
43+
%BIN_PATH%\clang.exe --config=llvmlibc.cfg --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\llvmlibc-microbit.ld -lm -o hello.elf hello.c
4444
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
4545
@exit /B

arm-software/embedded/llvmlibc-samples/src/cpp-baremetal-semihosting-llvmlibc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include ../../Makefile.conf
1010
build: hello.elf
1111

1212
hello.elf: *.cpp
13-
$(BIN_PATH)/clang++ --config=llvmlibc.cfg $(MICROBIT_TARGET) $(CRT_SEMIHOST) -lm -g -T microbit-llvmlibc.ld -o hello.elf $^
13+
$(BIN_PATH)/clang++ --config=llvmlibc.cfg $(MICROBIT_TARGET) $(CRT_SEMIHOST) -lm -g -T ../../ldscripts/llvmlibc-microbit.ld -o hello.elf $^
1414

1515
%.hex: %.elf
1616
$(BIN_PATH)/llvm-objcopy -O ihex $< $@

arm-software/embedded/llvmlibc-samples/src/cpp-baremetal-semihosting-llvmlibc/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ if exist hello.hex del /q hello.hex
4040
@exit /B 1
4141

4242
:build_fn
43-
%BIN_PATH%\clang++.exe --config=llvmlibc.cfg --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T microbit-llvmlibc.ld -lm -o hello.elf hello.cpp
43+
%BIN_PATH%\clang++.exe --config=llvmlibc.cfg --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\llvmlibc-microbit.ld -lm -o hello.elf hello.cpp
4444
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
4545
@exit /B

arm-software/embedded/llvmlibc-samples/src/cpp-baremetal-semihosting-llvmlibc/microbit-llvmlibc.ld

Lines changed: 0 additions & 241 deletions
This file was deleted.

0 commit comments

Comments
 (0)