blob: 1e73d0c1fbc617490d3a823e925fcfcf44f7a378 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Madhukar Pappireddy06ed91d2022-05-20 15:19:21 -05003# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#
8# When pointed to a root file system archive ($root_fs) this script creates a
9# disk image file ($img_file of size $size_gb, or 5GB by default) with 2
10# partitions. Linaro OE ramdisk specifies the second partition as root device;
11# the first partition is unused. The second partition is formatted as ext2, and
12# the root file system extracted into it.
13#
14# Test suites for stress testing are created under /opt/tests.
15
16set -e
17
Madhukar Pappireddy06ed91d2022-05-20 15:19:21 -050018if ! [ -x "$(command -v gawk)" ]; then
19 echo "Error: gawk is not installed."
20 echo "Run 'apt-get install gawk' to install"
21 exit 1
22fi
23
Fathi Boudra422bf772019-12-02 11:10:16 +020024extract_script() {
25 local to="${name:?}.sh"
26
27 sed -n "/BEGIN $name/,/END $name/ {
28 /^#\\(BEGIN\\|END\\)/d
29 s/^#//
30 p
31 }" < "${progname:?}" > "$to"
32
33 chmod +x "$to"
34}
35
36progname="$(readlink -f $0)"
37root_fs="$(readlink -f ${root_fs:?})"
38img_file="$(readlink -f ${img_file:?})"
39
40mount_dir="${mount_dir:-/mnt}"
41mount_dir="$(readlink -f $mount_dir)"
42
43# Create an image file. We assume 5G is enough
44size_gb="${size_gb:-5}"
45echo "Creating image file $img_file (${size_gb}GB)..."
46dd if=/dev/zero of="$img_file" bs=1M count="${size_gb}000" &>/dev/null
47
48# Create a partition table, and then create 2 partitions. The boot expects the
49# root file system to be present in the second partition.
50echo "Creating partitions in $img_file..."
51sed 's/ *#.*$//' <<EOF | fdisk "$img_file" &>/dev/null
52o # Create new partition table
53n # New partition
54p # Primary partition
55 # Default partition number
56 # Default start sector
57+1M # Dummy partition of 1MB
58n # New partition
59p # Primary partition
60 # Default partition number
61 # Default start sector
62 # Default end sector
63w
64q
65EOF
66
67# Get the offset of partition
68fdisk_out="$(fdisk -l "$img_file" | sed -n '$p')"
69
70offset="$(echo "$fdisk_out" | awk '{print $2 * 512}')"
71size="$(echo "$fdisk_out" | awk '{print (($3 - $2) * 512)}')"
72
73# Setup and identify loop device
74loop_dev="$(losetup --offset "$offset" --sizelimit "$size" --show --find \
75 "$img_file")"
76
77# Create ext2 file system on the mount
78echo "Formatting partition as ext2 in $img_file..."
79mkfs.ext2 "$loop_dev" &>/dev/null
80
81# Mount loop device
82mount "$loop_dev" "$mount_dir"
83
84# Extract the root file system into the mount
85cd "$mount_dir"
86echo "Extracting $root_fs to $img_file..."
87tar -xzf "$root_fs"
88
89tests_dir="$mount_dir/opt/tests"
90mkdir -p "$tests_dir"
91cd "$tests_dir"
92
93# Extract embedded scripts into the disk image
94name="hotplug" extract_script
95name="execute_pmqa" extract_script
96
97echo
98rm -rf "test_assets"
99echo "Cloning test assets..."
Zelalem1af7a7b2020-08-04 17:34:32 -0500100git clone -q --depth 1 https://gerrit.oss.arm.com/tests/test_assets
Fathi Boudra422bf772019-12-02 11:10:16 +0200101echo "Cloned test assets."
102
103cd test_assets
104rm -rf "pm-qa"
105echo "Cloning pm-qa..."
Arvind Ram Prakash7900f3a2024-10-14 11:20:28 -0500106git clone -q --depth 1 https://git.linaro.org/tools/pm-qa.git
Fathi Boudra422bf772019-12-02 11:10:16 +0200107echo "Cloned pm-qa."
108
109cd
110umount "$mount_dir"
111
112losetup -d "$loop_dev"
113
114if [ "$SUDO_USER" ]; then
115 chown "$SUDO_USER:$SUDO_USER" "$img_file"
116fi
117
118echo "Updated $img_file with stress tests."
119
120#BEGIN hotplug
121##!/bin/sh
122#
123#if [ -n "$1" ]
124#then
125# min_cpu=$1
126# shift
127#fi
128#
129#if [ -n "$1" ]
130#then
131# max_cpu=$1
132# shift
133#fi
134#
135#f_kconfig="/proc/config.gz"
136#f_max_cpus="/sys/devices/system/cpu/present"
137#hp_support=0
138#hp="`gunzip -c /proc/config.gz | sed -n '/HOTPLUG.*=/p' 2>/dev/null`"
139#
140#if [ ! -f "$f_kconfig" ]
141#then
142# if [ ! -f "$f_max_cpus" ]
143# then
144# echo "Unable to detect hotplug support. Exiting..."
145# exit -1
146# else
147# hp_support=1
148# fi
149#else
150# if [ -n "$hp" ]
151# then
152# hp_support=1
153# else
154# echo "Unable to detect hotplug support. Exiting..."
155# exit -1
156# fi
157#fi
158#
159#if [ -z "$max_cpu" ]
160#then
161# max_cpu=`sed -E -n 's/([0-9]+)-([0-9]+)/\2/gpI' < $f_max_cpus`
162#fi
163#if [ -z "$min_cpu" ]
164#then
165# min_cpu=`sed -E -n 's/([0-9]+)-([0-9]+)/\1/gpI' < $f_max_cpus`
166#fi
167#
168#max_cpu=$(($max_cpu + 1))
169#min_cpu=$(($min_cpu + 1))
170#max_op=2
171#
172#while :
173#do
174# cpu=$((RANDOM % max_cpu))
175# op=$((RANDOM % max_op))
176#
177# if [ $op -eq 0 ]
178# then
179## echo "Hotpluging out cpu$cpu..."
180## echo $op > /sys/devices/system/cpu/cpu$cpu/online >/dev/null
181## echo $op > /sys/devices/system/cpu/cpu$cpu/online | grep -i "err"
182# echo $op > /sys/devices/system/cpu/cpu$cpu/online
183# else
184## echo "Hotpluging in cpu$cpu..."
185## echo $op > /sys/devices/system/cpu/cpu$cpu/online >/dev/null
186## echo $op > /sys/devices/system/cpu/cpu$cpu/online | grep -i "err"
187# echo $op > /sys/devices/system/cpu/cpu$cpu/online
188#
189# fi
190#done
191#
192#exit 0
193#
194#MAXCOUNT=10
195#count=1
196#
197#echo
198#echo "$MAXCOUNT random numbers:"
199#echo "-----------------"
200#while [ "$count" -le $MAXCOUNT ] # Generate 10 ($MAXCOUNT) random integers.
201#do
202# number=$RANDOM
203# echo $number
204# count=$(($count + 1))
205#done
206#echo "-----------------"
207#END hotplug
208
209
210#BEGIN execute_pmqa
211##!/bin/sh
212#
213#usage ()
214#{
215# printf "\n*************** Usage *******************\n"
216# printf "sh execute_pmqa.sh args\n"
217# printf "args:\n"
218# printf "t -> -t|--targets=Folders (tests) within PM QA folder to be executed by make, i.e. cpufreq, cpuidle, etc. Defaults to . (all)\n"
219# printf "\t -> -a|--assets=Test assets folder (within the FS) where resides the PM QA folder. Required.\n"
220#}
221#
222#for i in "$@"
223#do
224# case $i in
225# -t=*|--targets=*)
226# TARGETS="${i#*=}"
227# ;;
228# -a=*|--assets=*)
229# TEST_ASSETS_FOLDER="${i#*=}"
230# ;;
231# *)
232# # unknown option
233# printf "Unknown argument $i in arguments $@\n"
234# usage
235# exit 1
236# ;;
237# esac
238#done
239#
240#if [ -z "$TEST_ASSETS_FOLDER" ]; then
241# usage
242# exit 1
243#fi
244#
245#TARGETS=${TARGETS:-'.'}
246#cd $TEST_ASSETS_FOLDER/pm-qa && make -C utils
247#for j in $TARGETS
248#do
249# make -k -C "$j" check
250#done
251#make clean
252#rm -f ./utils/cpuidle_killer
253#tar -zcvf ../pm-qa.tar.gz ./
254#END execute_pmqa