1#!/bin/bash 2 3# Copyright (C) 2024 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Command tools to download the released MCTS to local. 18 19# Command examples: 20# 1) First, you need to download the MCTS test cases corresponding to the 21# Android API level of the DUT. Please use the command below as an example, 22# remember to input the correct device abi and android version. 23# Below is an example when the arm64 device is Android U (34). 24# 25# ./download_mcts.sh --abi arm64 --android_version 34 26 27# 2) Second, you need to download the MCTS test cases corresponding to the 28# preloaded Mainline Train version of the DUT. If you ensure that the DUT 29# doesn't have mainline train prebuilt, you can skip this command. 30# Please use the command below as an example, remember to input the correct 31# device abi and mainline train version. Below is an example when the 32# arm64 device preloaded with Mainline train released in Jan 2024. 33# 34# ./download_mcts.sh --abi arm64 --year 2024 --month 01 35 36# All the files will be downloaded to 37# $HOME/xts/mcts_dynamic_download/android/xts/mcts/android_version/abi/ 38 39set -e 40 41# Parse command line arguments 42while [[ $# -gt 0 ]]; do 43 case "$1" in 44 --abi) abi="$2";; # arm64 or x86_64 45 --android_version) android_version="$2";; 46 --year) year="$2";; 47 --month) month="$2";; 48 *) echo "Unknown argument $1"; 49 esac 50 shift # skip key 51 shift # skip value 52 done 53 54path="" 55 56if [[ -n ${year} ]] && [[ -n ${month} ]]; then 57 path="${year}-${month}/${abi}" 58fi 59 60if [[ -n ${android_version} ]]; then 61 path="${android_version}/${abi}" 62fi 63 64dir_prefix="$HOME/xts/mcts_dynamic_download/android/xts/mcts" 65full_dir_path="$dir_prefix/$path" 66mkdir -p $full_dir_path 67 68function download_wget_and_curl_if_needed() { 69 if [[ "$OSTYPE" == "linux-gnu" ]] 70 then 71 [[ -x `which wget` ]] || sudo apt-get install wget 72 [[ -x `which curl` ]] || sudo apt-get install curl 73 elif [[ "$OSTYPE" == "darwin"* ]] 74 then 75 [[ -x `which wget` ]] || brew install wget 76 [[ -x `which curl` ]] || sudo apt-get install curl 77 fi 78} 79 80function download_mcts() 81 { 82 pushd $full_dir_path > /dev/null 83 local path=$1 84 local file=$2 85 local url="https://dl.google.com/android/xts/mcts/${path}/${file}" 86 # Download the file if it doesn't exist. 87 if [ ! -f ${file} ]; then 88 echo "There is no ${file}, trying to download it" 89 wget -q ${url} || true 90 else 91 echo "There is ${file}, checking if it is up to date" 92 # %W time of file birth, seconds since Epoch 93 # %s seconds since the Epoch (1970-01-01 00:00 UTC) 94 file_download_time=$(date -d "@$(stat -c %W ${file})" +%s ) 95 # The OS Ubuntu below 20.10 version does not support stat command and 96 # return "0" by default, so we need to use debugfs to get the file 97 # creation time. 98 if [[ ${file_download_time} == "0" ]]; then 99 file_download_time=$(get_crtime ${file}) 100 fi 101 url_link_last_modified_string=$(curl -sI ${url} | grep -i "last-modified" | cut -d: -f2- | xargs) 102 url_link_time_stamp=$(date -d "${url_link_last_modified_string}" +%s ) 103 if [[ ${file_download_time} -lt ${url_link_time_stamp} ]]; then 104 echo "The file is out of date, trying to download it" 105 rm ${file} 106 wget -q ${url} || true 107 else 108 echo "The file is up to date, skip downloading" 109 fi 110 fi 111 echo "Done" 112 popd > /dev/null 113 } 114 115function get_crtime() { 116 local target=$1 117 inode=$(stat -c '%i' "${target}") 118 fs=$(df --output=source "${target}" | tail -1) 119 crtime=$(debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null | grep -oP 'crtime.*--\s*\K.*') 120 file_download_time=$(date -d "${crtime}" +%s) 121 echo ${file_download_time} 122} 123 124files=( 125 "android-mcts-adbd.zip" 126 "android-mcts-adservices.zip" 127 "android-mcts-appsearch.zip" 128 "android-mcts-art.zip" 129 "android-mcts-bluetooth.zip" 130 "android-mcts-cellbroadcast.zip" 131 "android-mcts-configinfrastructure.zip" 132 "android-mcts-conscrypt.zip" 133 "android-mcts-cronet.zip" 134 "android-mcts-dnsresolver.zip" 135 "android-mcts-documentsui.zip" 136 "android-mcts-extservices.zip" 137 "android-mcts-healthfitness.zip" 138 "android-mcts-ipsec.zip" 139 "android-mcts-media.zip" 140 "android-mcts-mediaprovider.zip" 141 "android-mcts-networking.zip" 142 "android-mcts-neuralnetworks.zip" 143 "android-mcts-ondevicepersonalization.zip" 144 "android-mcts-permission.zip" 145 "android-mcts-rkpd.zip" 146 "android-mcts-scheduling.zip" 147 "android-mcts-sdkextensions.zip" 148 "android-mcts-statsd.zip" 149 "android-mcts-tethering.zip" 150 "android-mcts-tzdata.zip" 151 "android-mcts-uwb.zip" 152 "android-mcts-wifi.zip" 153) 154 155download_wget_and_curl_if_needed 156echo "The files will be download at $full_dir_path" 157for file in ${files[@]}; do 158 download_mcts $path $file 159done 160chmod -R 777 $full_dir_path 161for file in $full_dir_path/* ; do 162 echo "touch $file to update the timestamp" 163 touch $file 164done 165 166echo "Download all files" 167