QUELLCODE / SH
run_native.sh
pico/tests/run_native.sh
1#!/usr/bin/env bash2# OpenAss: nur privater, experimenteller Gebrauch; auf eigene Verantwortung.3# Niemals Unternehmensrechner, Produktivsysteme, Industrieanlagen oder4# sicherheitskritische Systeme anschließen oder bedienen.5# Haftungshinweis und gesetzliche Grenzen: ../../DISCLAIMER.txt.6set -euo pipefail78hb_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)9hb_temp=$(mktemp -d "${TMPDIR:-/tmp}/hb-native.XXXXXX")10trap 'rm -rf -- "$hb_temp"' EXIT1112if [[ -n "${CC:-}" ]]; then13 hb_compiler=$CC14elif command -v clang >/dev/null 2>&1; then15 hb_compiler=clang16else17 hb_compiler=cc18fi19hb_flags=(-std=c11 -Wall -Wextra -Werror -g)20hb_mode=${HB_SANITIZE:-auto}21case "$hb_mode" in22 auto|1|0) ;;23 *) printf '%s\n' 'HB_SANITIZE must be auto, 1, or 0.' >&2; exit 2 ;;24esac25if [[ "$hb_mode" != 0 ]]; then26 printf 'int main(void) { return 0; }\n' > "$hb_temp/probe.c"27 if "$hb_compiler" -fsanitize=address,undefined "$hb_temp/probe.c" -o "$hb_temp/probe" >/dev/null 2>&1 && "$hb_temp/probe" >/dev/null 2>&1; then28 hb_flags+=(-fsanitize=address,undefined)29 printf '%s\n' 'Native tests: AddressSanitizer and UndefinedBehaviorSanitizer enabled.'30 elif [[ "$hb_mode" == 1 ]]; then31 printf '%s\n' 'Required sanitizers are unavailable for this compiler/runtime.' >&232 exit 133 else34 printf '%s\n' 'Native tests: sanitizers unavailable; falling back to normal checked builds.' >&235 fi36fi37"$hb_compiler" "${hb_flags[@]}" -I "$hb_root" "$hb_root/protocol.c" "$hb_root/tests/protocol_test.c" -o "$hb_temp/protocol-test"38"$hb_temp/protocol-test"39"$hb_compiler" "${hb_flags[@]}" -I "$hb_root/tests/fake_pico" -I "$hb_root" "$hb_root/protocol.c" "$hb_root/tests/firmware_test.c" -o "$hb_temp/firmware-test"40"$hb_temp/firmware-test"41if [[ -n "${HB_TINYUSB_PATH:-}" ]]; then42 if [[ ! -f "$HB_TINYUSB_PATH/src/tusb.h" ]]; then43 printf '%s\n' 'HB_TINYUSB_PATH must be a TinyUSB source checkout with src/tusb.h.' >&244 exit 245 fi46 "$hb_compiler" "${hb_flags[@]}" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DCFG_TUSB_OS=OPT_OS_NONE \47 -I "$HB_TINYUSB_PATH/src" -I "$hb_root" -I "$hb_root/tests/fake_pico" \48 "$hb_root/usb_descriptors.c" "$hb_root/tests/usb_descriptor_test.c" -o "$hb_temp/usb-descriptor-test"49 "$hb_temp/usb-descriptor-test"50fi