1#!/bin/bash 2# Copyright (C) 2016 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Include some functions from common.sh. 17SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" 18source ${SCRIPT_DIR}/common.sh 19 20OUT_DATA_DIR="test_out" 21 22# Disable REMOTE for test on local 23REMOTE="--remote" 24 25TEST_COUNT=10 26DEBUG=false 27 28 29apply_overlay() { 30 local overaly="$1" 31 local base_dts="$2" 32 local overlay_dts="$3" 33 local merged_dts="$4" 34 35 local summary=0 36 for i in $(seq 1 $TEST_COUNT); do 37 TIME=$(./apply_overlay.sh "--$overaly" $REMOTE \ 38 "$base_dts" "$overlay_dts" "$merged_dts" \ 39 | sed -E "s/.*took ([0-9]+\\.[0-9]+) secs/\\1/") 40 if $DEBUG; then 41 echo "time=$TIME" 42 fi 43 summary=$(echo "$summary + $TIME" | bc -l) 44 done 45 AVERAY=$(echo "scale=9; $summary/$TEST_COUNT" | bc -l) 46 printf "%10s Average time=%s\n" "($overaly)" "$AVERAY" 47} 48 49run_performance_test() { 50 # see ufdt_gen_test_dts.c for detail 51 local node_depth="$1" 52 local node_unused="$2" 53 local node_count="$3" 54 local append_count="$4" 55 local override_count="$5" 56 57 mkdir -p "$OUT_DATA_DIR" >& /dev/null 58 59 # 60 # Prepare dtb and dtbo files 61 # 62 local base_dts="${OUT_DATA_DIR}/base.dts" 63 echo " Base DT: depth=$node_depth unused=$node_unused nodes=$node_count" 64 ufdt_gen_test_dts -n $node_count -d $node_depth -u $node_unused \ 65 -o "$base_dts" 66 if $DEBUG; then 67 cat "$base_dts" 68 fi 69 70 local overlay_dts="${OUT_DATA_DIR}/overlay.dts" 71 echo " Overlay DT: append=$append_count override=$override_count" 72 ufdt_gen_test_dts -p -a $append_count -w $override_count \ 73 -o "$overlay_dts" 74 if $DEBUG; then 75 cat "$overlay_dts" 76 fi 77 78 local merged_dts="${OUT_DATA_DIR}/overlay_merged.dts" 79 apply_overlay fdt $base_dts $overlay_dts $merged_dts 80 apply_overlay ufdt $base_dts $overlay_dts $merged_dts 81 82 rm -rf "$OUT_DATA_DIR" 83} 84 85main() { 86 alert "========== Running Performance Tests ==========" 87 88 if [ -z "$ANDROID_BUILD_TOP" ]; then 89 die "Run envsetup.sh / lunch yet?" 90 fi 91 92 if ! command_exists ufdt_gen_test_dts || 93 ! command_exists dtc; then 94 die "Run mmma $(dirname $SCRIPT_DIR) yet?" 95 fi 96 97 if [ "$REMOTE" == "--remote" ]; then 98 adb get-state > /dev/null 99 if [ "$?" -ne "0" ]; then 100 die "adb can not connect to device." 101 fi 102 fi 103 104 # cd to ${SCRIPT_DIR} in a subshell because gen_test.sh uses relative 105 # paths for dependent files. 106 cd "${SCRIPT_DIR}" 107 108 # 109 # run_performance_test 110 # <node_depth> <node_unused> <node_count> <append_count> <override_count> 111 112 # Test case #1: node=x append=100 override=100 113 for t in $(seq 200 50 1000); do 114 run_performance_test 2 0 $t 100 100 115 done 116 # Test case #2: node=x append=100 override=100 117 for t in $(seq 200 50 1000); do 118 run_performance_test 2 $t $t 100 100 119 done 120 # Test case #3: node=2000 append=X 121 for t in $(seq 50 50 1000); do 122 run_performance_test 2 0 2000 $t 0 123 done 124 # Test case #4: node=2000 override=X 125 for t in $(seq 50 50 1000); do 126 run_performance_test 2 0 2000 0 $t 127 done 128} 129 130main "$@" 131