Elffuss BraidHub

kikocis/kleidiai public

655592420abd · 5.9 KiB · executableRawPermalink
1#! /bin/bash
2#
3# SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
4#
5# SPDX-License-Identifier: Apache-2.0
6#
7# Brief: fvp.sh — helper to run an Arm FVP (Fixed Virtual Platform) with a Linux®
8# root filesystem image and a temporary startup script. It copies a
9# rootfs image to a temp file, injects a startup script that mounts a
10# host directory via 9p, and runs the provided test executable inside
11# the emulated environment.
12#
13# Main options (CLI):
14# --host-path Path on the host to expose to the emulated target (default: $PWD)
15# --target-path Mount point inside the emulated target (default: same as host-path)
16# --model-extra Extra FVP model parameters to append to the invocation
17# <executable> Test executable (and args) to run inside the guest (required)
18#
19# Environment variables might be used as alternative to command line options:
20# FVP_HOST_PATH set from --host-path or defaults to $PWD
21# FVP_TARGET_PATH set from --target-path or same as $FVP_HOST_PATH
22# FVP_MODEL_EXTRA optional additional model parameters
23#
24# in addition to script these are passed automatically to FVP target
25# GTEST_* GoogleTest variables
26#
27
28set -exu -o pipefail
29
30cleanup()
31{
32 [ -n "${ROOTFS_IMAGE:-}" ] && rm -fv ${ROOTFS_IMAGE}
33 [ -n "${TMP_FILE:-}" ] && rm -fv ${TMP_FILE}
34}
35
36trap cleanup EXIT INT
37
38# Default values
39HOST_PATH="${FVP_HOST_PATH:-}"
40TARGET_PATH="${FVP_TARGET_PATH:-}"
41MODEL_EXTRA="${FVP_MODEL_EXTRA:-}"
42
43# Use getopt for argument parsing
44OPTS=$(getopt -o 'h:t:l:m:' --long host-path:,target-path:,model-extra:, -n "$0" -- "$@")
45
46if [ $? != 0 ]; then
47 echo "Failed to parse arguments." >&2
48 exit 1
49fi
50
51eval set -- "$OPTS"
52
53while true; do
54 case "$1" in
55 --host-path)
56 HOST_PATH="$2"
57 shift 2
58 ;;
59 --target-path)
60 TARGET_PATH="$2"
61 shift 2
62 ;;
63 --model-extra)
64 MODEL_EXTRA="$2"
65 shift 2
66 ;;
67 --)
68 shift
69 break
70 ;;
71 --*)
72 echo "Unknown argument: $1"
73 exit 1
74 ;;
75 esac
76done
77
78# FVP executable and parameters take rest of arguments
79FVP_TEST_EXECUTABLE="$*"
80# Check executable is set
81[ -z "$FVP_TEST_EXECUTABLE" ] && exit 1
82
83# Export variables for later use
84FVP_HOST_PATH="${HOST_PATH:-$PWD}"
85
86# Set target path, use host as default
87FVP_TARGET_PATH="${TARGET_PATH:-$FVP_HOST_PATH}"
88
89# Set extra model parameters
90FVP_MODEL_EXTRA="$MODEL_EXTRA"
91
92export FVP_HOST_PATH
93export FVP_TARGET_PATH
94export FVP_MODEL_EXTRA
95
96# Temporary file for startup script
97TMP_FILE=$(mktemp -t kaiXXXXXX)
98
99cat > $TMP_FILE <<EOF
100#!/bin/sh
101
102set -e
103echo '=================================================='
104echo '== START =='
105echo '=================================================='
106echo '== CPU INFO =='
107if [ ! -f /proc/cpuinfo ]; then mount -vt proc -o rw,nosuid,nodev,noexec proc /proc; fi
108cat /proc/cpuinfo
109echo '=================================================='
110
111set -x
112
113mkdir -vp '$FVP_TARGET_PATH'
114mount -vt 9p -o trans=virtio,version=9p2000.L FM '$FVP_TARGET_PATH'
115
116# Import GTest environment variables from host env
117$(printenv | awk -F= '/^GTEST_/ {print "export " $1 "=\"" $2 "\"" }')
118
119cd '$FVP_TARGET_PATH'
120# Disable immediate exit on error
121set +e
122${FVP_TEST_EXECUTABLE} && echo 'FINISHED WITHOUT ERROR'
123sync
124
125echo '=================================================='
126echo '== END =='
127echo '=================================================='
128EOF
129
130# Copy root fs to a temporary file to allow parallel execution in a same instance
131ROOTFS_IMAGE=$(mktemp -t kaiXXXXXX)
132cp /opt/devtools/linux-rootfs.img ${ROOTFS_IMAGE}
133
134e2cp -O 0 -G 0 -P 755 $TMP_FILE ${ROOTFS_IMAGE}:/root/startup
135
136FVP_TOOL_BINARY=(/opt/devtools/fvp_base_aemva/models/Linux64*GCC-9.3/FVP_Base_RevC-2xAEMvA)
137if [ "${#FVP_TOOL_BINARY[@]}" -ne 1 ]; then
138 echo "Error: Several FVP executables found. Must have exactly one element, found ${#FVP_TOOL_BINARY[@]}"
139 exit 1
140fi
141
142${FVP_TOOL_BINARY[0]} \
143 -C cache_state_modelled=0 \
144 -C bp.refcounter.non_arch_start_at_default=1 \
145 -C bp.secure_memory=0 \
146 -C bp.pl011_uart0.out_file=- \
147 -C bp.pl011_uart0.shutdown_tag="System halted" \
148 -C bp.pl011_uart0.unbuffered_output=1 \
149 -C bp.terminal_0.mode=telnet \
150 -C bp.terminal_0.start_telnet=0 \
151 -C bp.terminal_1.mode=raw \
152 -C bp.terminal_1.start_telnet=0 \
153 -C bp.terminal_2.mode=raw \
154 -C bp.terminal_2.start_telnet=0 \
155 -C bp.terminal_3.mode=raw \
156 -C bp.terminal_3.start_telnet=0 \
157 -C pctl.startup=*.*.*.* \
158 -C cluster1.NUM_CORES=0 \
159 -C cluster0.NUM_CORES=2 \
160 -C cluster0.has_arm_v8-1=1 \
161 -C cluster0.has_arm_v8-2=1 \
162 -C cluster0.has_arm_v8-3=1 \
163 -C cluster0.has_arm_v8-4=1 \
164 -C cluster0.has_arm_v8-5=1 \
165 -C cluster0.has_arm_v8-6=1 \
166 -C cluster0.has_arm_v8-7=1 \
167 -C cluster0.has_arm_v8-8=1 \
168 -C cluster0.has_arm_v8-9=1 \
169 -C cluster0.has_arm_v9-0=1 \
170 -C cluster0.has_arm_v9-1=1 \
171 -C cluster0.has_arm_v9-2=1 \
172 -C cluster0.has_arm_v9-3=1 \
173 -C cluster0.has_arm_v9-4=1 \
174 -C cluster0.has_arm_v9-5=1 \
175 -C cluster0.has_arm_v9-6=1 \
176 -C cluster0.has_sve=1 \
177 -C cluster0.sve.has_b16b16=1 \
178 -C cluster0.sve.has_sve2=1 \
179 -C cluster0.sve.has_sme=1 \
180 -C cluster0.sve.has_sme2=1 \
181 -C cluster0.sve.has_sme_f16f16=1 \
182 -C cluster0.sve.has_sme_fa64=1 \
183 -C cluster0.sve.has_sme_lutv2=1 \
184 -C cluster0.sve.sme2_version=1 \
185 -C cluster0.sve.veclen=2 \
186 -C cluster0.sve.sme_veclens_implemented=4 \
187 -C bp.virtio_rng.enabled=1 \
188 -C bp.virtioblockdevice.image_path=$ROOTFS_IMAGE \
189 -C bp.vis.disable_visualisation=1 \
190 -C bp.virtiop9device.root_path=$FVP_HOST_PATH \
191 -a cluster*.cpu*=/opt/devtools/linux-system.axf \
192 --stat \
193 ${FVP_MODEL_EXTRA:-} |& tee $TMP_FILE
194
195grep -q "FINISHED WITHOUT ERROR" $TMP_FILE