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