Skip to content

Commit

Permalink
picolibc: tests with meson
Browse files Browse the repository at this point in the history
Switch from manually building picolibc tests to bilding and running them
as part of picolibc build. This enables tests, which were not included
in the manual build.

Several fixes were necessary:

1. Add '-nostdlib' to picolibc c_args
This prevents errors like:
  ld.lld: error: unable to find library -lc
in checks for compiler flags support in picolibs build scripts.
Example of failing check:
  has_link_defsym = meson.get_cross_property('has_link_defsym', cc.has_link_argument('-Wl,--defsym=' + global_prefix + '_start=0'))

2. Make picolibc use compiler_rt in place of libgcc.

3. Change machines used with qemu and adjust memory layouts.
Some of picolibc tests need more memory, than previous machines
provided. Example error:
  ld.lld: error: section '.text' will not fit in region 'flash': overflowed by 34504 bytes

4. Postpone building picolibc tests to the test step. compiler_rt
requires picolibc to be installed. picolibc tests require compiler_rt.
The delayed tests enable picolibc to be installed before compiler_rt is built.
  • Loading branch information
domin144 committed Jun 15, 2023
1 parent ee6b80d commit aa20239
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 143 deletions.
244 changes: 111 additions & 133 deletions CMakeLists.txt

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cmake/meson-cross-build.txt.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[binaries]
c = [@meson_c_args@]
c = [@meson_c_args@, '-nostdlib']
ar = '@LLVM_BINARY_DIR@/bin/llvm-ar@CMAKE_EXECUTABLE_SUFFIX@'
strip = '@LLVM_BINARY_DIR@/bin/llvm-strip@CMAKE_EXECUTABLE_SUFFIX@'
# only needed to run tests
exe_wrapper = ['sh', '-c', 'test -z "$PICOLIBC_TEST" || run-@cpu_family@ "$@"', 'run-@cpu_family@']
exe_wrapper = [
'sh',
'-c',
'test -z "$PICOLIBC_TEST" || @CMAKE_CURRENT_SOURCE_DIR@/test-support/run-picolibc-test.py "$@"',
'@CMAKE_CURRENT_SOURCE_DIR@/test-support/run-picolibc-test.py',
@run_picolibc_test_args@]

[host_machine]
system = 'none'
Expand All @@ -13,3 +18,9 @@ endian = 'little'

[properties]
skip_sanity_check = true
libgcc ='-lclang_rt.builtins'
default_flash_addr = '@default_flash_addr@'
default_flash_size = '@default_flash_size@'
default_ram_addr = '@default_ram_addr@'
default_ram_size = '@default_ram_size@'
default_stack_size = '@default_stack_size@'
6 changes: 5 additions & 1 deletion test-support/lit-exec-qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def run(args):
image_args = command[1:]
qemu_params = args.qemu_params.split(':')
qemu_cmd = ([args.qemu_command] + qemu_params +
['-semihosting', '-nographic', '-kernel', image])
['-semihosting', '-nographic'])
if qemu_params.count("virt"):
qemu_cmd += ["-kernel", image]
else:
qemu_cmd += ["-device", f"loader,file={image},cpu-num=0"]
if image_args:
image_args_concat = ','.join(['arg=' + arg.replace(',', ',,')
for arg in image_args])
Expand Down
88 changes: 88 additions & 0 deletions test-support/run-picolibc-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env python3

# Copyright (c) 2023, Arm Limited and affiliates.

# This is a wrapper script to run picolibc tests with qemu

import sys
import argparse
import subprocess

# This script requires Python 3.6 or later
assert sys.version_info >= (3, 6)

disabled_tests = [
"picolibc_aarch64-build/test/math_errhandling",
"picolibc_armv7em_hard_fpv4_sp_d16-build/test/math_errhandling",
"picolibc_armv7em_hard_fpv5_d16-build/test/math_errhandling",
"picolibc_armv8m.main_hard_fp-build/test/printf_scanf",
"picolibc_armv8m.main_hard_fp-build/test/printff_scanff",
"picolibc_armv8m.main_hard_fp-build/test/printff-tests",
"picolibc_armv8m.main_hard_fp-build/test/math_errhandling",
"picolibc_armv8m.main_hard_fp-build/test/rounding-mode",
"picolibc_armv8m.main_hard_fp-build/test/long_double",
"picolibc_armv8m.main_hard_fp-build/test/rand",
"picolibc_armv8m.main_hard_fp-build/test/fenv",
"picolibc_armv8m.main_hard_fp-build/test/math-funcs",
"picolibc_armv8m.main_hard_fp-build/test/test-strtod",
"picolibc_armv8m.main_hard_fp-build/test/test-efcvt",
"picolibc_armv8m.main_hard_fp-build/test/complex-funcs",
"picolibc_armv8m.main_hard_fp-build/test/semihost/semihost-times",
"picolibc_armv8m.main_hard_fp-build/newlib/libm/test/math_test",
"picolibc_armv8m.main_hard_fp-build/test/libc-testsuite/sscanf",
"picolibc_armv8m.main_hard_fp-build/test/libc-testsuite/strtod",
"picolibc_armv8.1m.main_soft_nofp_nomve-build/newlib/libm/test/math_test",
"picolibc_armv8.1m.main_hard_fp-build/test/math_errhandling",
"picolibc_armv8.1m.main_hard_fp-build/newlib/libm/test/math_test",
"picolibc_armv8.1m.main_hard_nofp_mve-build/test/fenv",
"picolibc_armv8.1m.main_hard_nofp_mve-build/newlib/libm/test/math_test",
"picolibc_armv8.1m.main_hard_nofp_mve-build/test/math_errhandling"
]

def is_disabled(image):
return any([image.endswith(t) for t in disabled_tests])

def run(args):
"""Execute the program using QEMU and return the subprocess return code."""
command = args.command
assert command
image = command[0]
image_args = command[1:]
if image_args[0:1] == ['--']:
image_args = image_args[1:]
if is_disabled(image):
return 77
semihosting = ','.join(
["enable=on", "chardev=stdio0"]
+ ['arg=' + arg.replace(',', ',,') for arg in image_args])
qemu_params = args.qemu_params.split(':') + [
"-chardev", "stdio,mux=on,id=stdio0",
"-semihosting-config", semihosting,
"-monitor", "none",
"-serial", "none",
"-nographic"]
if qemu_params.count("virt"):
qemu_params += ["-kernel", image]
else:
qemu_params += ["-device", f"loader,file={image},cpu-num=0"]
qemu_cmd = [args.qemu_command] + qemu_params
print(f"qemu_cmd : {qemu_cmd}")
result = subprocess.run(qemu_cmd, stdout=subprocess.PIPE,
stderr=sys.stderr,
check=False)
sys.stdout.buffer.write(result.stdout)
return result.returncode

def main():
parser = argparse.ArgumentParser(description='Run a single test using qemu')
parser.add_argument('--qemu-command', required=True, help='qemu-system-<arch> path')
parser.add_argument('--qemu-params', required=True,
help='list of arguments to pass to qemu, separated with ":"')
parser.add_argument('command', nargs=argparse.REMAINDER,
help='image file to execute with optional arguments')
args = parser.parse_args()
ret_code = run(args)
sys.exit(ret_code)

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions tests/ldscripts/picolibc_armv4t.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__flash = 0x00010000;
__flash = 0x00000000;
__flash_size = 0x00400000;
__ram = 0x00500000;
__ram = 0x20000000;
__ram_size = 0x00200000;
__stack_size = 4k;

Expand Down
4 changes: 2 additions & 2 deletions tests/ldscripts/picolibc_armv5te.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__flash = 0x00010000;
__flash = 0x00000000;
__flash_size = 0x00400000;
__ram = 0x00500000;
__ram = 0x20000000;
__ram_size = 0x00200000;
__stack_size = 4k;

Expand Down
5 changes: 4 additions & 1 deletion tests/ldscripts/picolibc_armv8.1m.main_hard_fp.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__flash_size = 0x00400000;
__flash = 0x10000000;
__flash_size = 0x00200000;
__ram = 0x60000000;
__ram_size = 0x00200000;
__stack_size = 4k;

INCLUDE picolibcpp.ld
5 changes: 4 additions & 1 deletion tests/ldscripts/picolibc_armv8.1m.main_hard_nofp_mve.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__flash_size = 0x00400000;
__flash = 0x10000000;
__flash_size = 0x00200000;
__ram = 0x60000000;
__ram_size = 0x00200000;
__stack_size = 4k;

INCLUDE picolibcpp.ld
5 changes: 4 additions & 1 deletion tests/ldscripts/picolibc_armv8.1m.main_soft_nofp_nomve.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__flash_size = 0x00400000;
__flash = 0x10000000;
__flash_size = 0x00200000;
__ram = 0x60000000;
__ram_size = 0x00200000;
__stack_size = 4k;

INCLUDE picolibcpp.ld
4 changes: 4 additions & 0 deletions tests/ldscripts/picolibc_armv8m.main_hard_fp.ld
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__flash = 0x10000000;
__flash_size = 0x00400000;
__ram = 0x80000000;
__ram_size = 0x01000000;
__stack_size = 4k;

INCLUDE picolibcpp.ld
3 changes: 3 additions & 0 deletions tests/ldscripts/picolibc_armv8m.main_soft_nofp.ld
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__flash = 0x10000000;
__flash_size = 0x00400000;
__ram = 0x80000000;
__ram_size = 0x01000000;
__stack_size = 4k;

INCLUDE picolibcpp.ld

0 comments on commit aa20239

Please sign in to comment.