Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 2 | # |
Madhukar Pappireddy | 06ed91d | 2022-05-20 15:19:21 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2022 Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 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 | |
| 16 | set -e |
| 17 | |
Madhukar Pappireddy | 06ed91d | 2022-05-20 15:19:21 -0500 | [diff] [blame] | 18 | if ! [ -x "$(command -v gawk)" ]; then |
| 19 | echo "Error: gawk is not installed." |
| 20 | echo "Run 'apt-get install gawk' to install" |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 24 | extract_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 | |
| 36 | progname="$(readlink -f $0)" |
| 37 | root_fs="$(readlink -f ${root_fs:?})" |
| 38 | img_file="$(readlink -f ${img_file:?})" |
| 39 | |
| 40 | mount_dir="${mount_dir:-/mnt}" |
| 41 | mount_dir="$(readlink -f $mount_dir)" |
| 42 | |
| 43 | # Create an image file. We assume 5G is enough |
| 44 | size_gb="${size_gb:-5}" |
| 45 | echo "Creating image file $img_file (${size_gb}GB)..." |
| 46 | dd 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. |
| 50 | echo "Creating partitions in $img_file..." |
| 51 | sed 's/ *#.*$//' <<EOF | fdisk "$img_file" &>/dev/null |
| 52 | o # Create new partition table |
| 53 | n # New partition |
| 54 | p # Primary partition |
| 55 | # Default partition number |
| 56 | # Default start sector |
| 57 | +1M # Dummy partition of 1MB |
| 58 | n # New partition |
| 59 | p # Primary partition |
| 60 | # Default partition number |
| 61 | # Default start sector |
| 62 | # Default end sector |
| 63 | w |
| 64 | q |
| 65 | EOF |
| 66 | |
| 67 | # Get the offset of partition |
| 68 | fdisk_out="$(fdisk -l "$img_file" | sed -n '$p')" |
| 69 | |
| 70 | offset="$(echo "$fdisk_out" | awk '{print $2 * 512}')" |
| 71 | size="$(echo "$fdisk_out" | awk '{print (($3 - $2) * 512)}')" |
| 72 | |
| 73 | # Setup and identify loop device |
| 74 | loop_dev="$(losetup --offset "$offset" --sizelimit "$size" --show --find \ |
| 75 | "$img_file")" |
| 76 | |
| 77 | # Create ext2 file system on the mount |
| 78 | echo "Formatting partition as ext2 in $img_file..." |
| 79 | mkfs.ext2 "$loop_dev" &>/dev/null |
| 80 | |
| 81 | # Mount loop device |
| 82 | mount "$loop_dev" "$mount_dir" |
| 83 | |
| 84 | # Extract the root file system into the mount |
| 85 | cd "$mount_dir" |
| 86 | echo "Extracting $root_fs to $img_file..." |
| 87 | tar -xzf "$root_fs" |
| 88 | |
| 89 | tests_dir="$mount_dir/opt/tests" |
| 90 | mkdir -p "$tests_dir" |
| 91 | cd "$tests_dir" |
| 92 | |
| 93 | # Extract embedded scripts into the disk image |
| 94 | name="hotplug" extract_script |
| 95 | name="execute_pmqa" extract_script |
| 96 | |
| 97 | echo |
| 98 | rm -rf "test_assets" |
| 99 | echo "Cloning test assets..." |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 100 | git clone -q --depth 1 https://gerrit.oss.arm.com/tests/test_assets |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 101 | echo "Cloned test assets." |
| 102 | |
| 103 | cd test_assets |
| 104 | rm -rf "pm-qa" |
| 105 | echo "Cloning pm-qa..." |
Arvind Ram Prakash | 7900f3a | 2024-10-14 11:20:28 -0500 | [diff] [blame] | 106 | git clone -q --depth 1 https://git.linaro.org/tools/pm-qa.git |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 107 | echo "Cloned pm-qa." |
| 108 | |
| 109 | cd |
| 110 | umount "$mount_dir" |
| 111 | |
| 112 | losetup -d "$loop_dev" |
| 113 | |
| 114 | if [ "$SUDO_USER" ]; then |
| 115 | chown "$SUDO_USER:$SUDO_USER" "$img_file" |
| 116 | fi |
| 117 | |
| 118 | echo "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 |