Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame^] | 1 | #!/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 | |
| 16 | set -e |
| 17 | |
| 18 | extract_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 | |
| 30 | progname="$(readlink -f $0)" |
| 31 | root_fs="$(readlink -f ${root_fs:?})" |
| 32 | img_file="$(readlink -f ${img_file:?})" |
| 33 | |
| 34 | mount_dir="${mount_dir:-/mnt}" |
| 35 | mount_dir="$(readlink -f $mount_dir)" |
| 36 | |
| 37 | # Create an image file. We assume 5G is enough |
| 38 | size_gb="${size_gb:-5}" |
| 39 | echo "Creating image file $img_file (${size_gb}GB)..." |
| 40 | dd 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. |
| 44 | echo "Creating partitions in $img_file..." |
| 45 | sed 's/ *#.*$//' <<EOF | fdisk "$img_file" &>/dev/null |
| 46 | o # Create new partition table |
| 47 | n # New partition |
| 48 | p # Primary partition |
| 49 | # Default partition number |
| 50 | # Default start sector |
| 51 | +1M # Dummy partition of 1MB |
| 52 | n # New partition |
| 53 | p # Primary partition |
| 54 | # Default partition number |
| 55 | # Default start sector |
| 56 | # Default end sector |
| 57 | w |
| 58 | q |
| 59 | EOF |
| 60 | |
| 61 | # Get the offset of partition |
| 62 | fdisk_out="$(fdisk -l "$img_file" | sed -n '$p')" |
| 63 | |
| 64 | offset="$(echo "$fdisk_out" | awk '{print $2 * 512}')" |
| 65 | size="$(echo "$fdisk_out" | awk '{print (($3 - $2) * 512)}')" |
| 66 | |
| 67 | # Setup and identify loop device |
| 68 | loop_dev="$(losetup --offset "$offset" --sizelimit "$size" --show --find \ |
| 69 | "$img_file")" |
| 70 | |
| 71 | # Create ext2 file system on the mount |
| 72 | echo "Formatting partition as ext2 in $img_file..." |
| 73 | mkfs.ext2 "$loop_dev" &>/dev/null |
| 74 | |
| 75 | # Mount loop device |
| 76 | mount "$loop_dev" "$mount_dir" |
| 77 | |
| 78 | # Extract the root file system into the mount |
| 79 | cd "$mount_dir" |
| 80 | echo "Extracting $root_fs to $img_file..." |
| 81 | tar -xzf "$root_fs" |
| 82 | |
| 83 | tests_dir="$mount_dir/opt/tests" |
| 84 | mkdir -p "$tests_dir" |
| 85 | cd "$tests_dir" |
| 86 | |
| 87 | # Extract embedded scripts into the disk image |
| 88 | name="hotplug" extract_script |
| 89 | name="execute_pmqa" extract_script |
| 90 | |
| 91 | echo |
| 92 | rm -rf "test_assets" |
| 93 | echo "Cloning test assets..." |
| 94 | git clone -q --depth 1 http://ssg-sw.cambridge.arm.com/gerrit/tests/test_assets.git |
| 95 | echo "Cloned test assets." |
| 96 | |
| 97 | cd test_assets |
| 98 | rm -rf "pm-qa" |
| 99 | echo "Cloning pm-qa..." |
| 100 | git clone -q --depth 1 git://git.linaro.org/tools/pm-qa.git |
| 101 | echo "Cloned pm-qa." |
| 102 | |
| 103 | cd |
| 104 | umount "$mount_dir" |
| 105 | |
| 106 | losetup -d "$loop_dev" |
| 107 | |
| 108 | if [ "$SUDO_USER" ]; then |
| 109 | chown "$SUDO_USER:$SUDO_USER" "$img_file" |
| 110 | fi |
| 111 | |
| 112 | echo "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 |