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 url_link_last_modified_string=$(curl -sI ${url} | grep -i "last-modified" | cut -d: -f2- | xargs) 96 url_link_time_stamp=$(date -d "${url_link_last_modified_string}" +%s ) 97 if [[ ${file_download_time} -lt ${url_link_time_stamp} ]]; then 98 echo "The file is out of date, trying to download it" 99 rm ${file} 100 wget -q ${url} || true 101 else 102 echo "The file is up to date, skip downloading" 103 fi 104 fi 105 echo "Done" 106 popd > /dev/null 107 } 108 109files=( 110 "android-mcts-adbd.zip" 111 "android-mcts-adservices.zip" 112 "android-mcts-appsearch.zip" 113 "android-mcts-art.zip" 114 "android-mcts-bluetooth.zip" 115 "android-mcts-cellbroadcast.zip" 116 "android-mcts-configinfrastructure.zip" 117 "android-mcts-conscrypt.zip" 118 "android-mcts-cronet.zip" 119 "android-mcts-dnsresolver.zip" 120 "android-mcts-documentsui.zip" 121 "android-mcts-extservices.zip" 122 "android-mcts-healthfitness.zip" 123 "android-mcts-ipsec.zip" 124 "android-mcts-media.zip" 125 "android-mcts-mediaprovider.zip" 126 "android-mcts-networking.zip" 127 "android-mcts-neuralnetworks.zip" 128 "android-mcts-ondevicepersonalization.zip" 129 "android-mcts-permission.zip" 130 "android-mcts-rkpd.zip" 131 "android-mcts-scheduling.zip" 132 "android-mcts-sdkextensions.zip" 133 "android-mcts-statsd.zip" 134 "android-mcts-tethering.zip" 135 "android-mcts-tzdata.zip" 136 "android-mcts-uwb.zip" 137 "android-mcts-wifi.zip" 138) 139 140download_wget_and_curl_if_needed 141echo "The files will be download at $full_dir_path" 142for file in ${files[@]}; do 143 download_mcts $path $file 144done 145chmod -R 777 $full_dir_path 146for file in $full_dir_path/* ; do 147 echo "touch $file to update the timestamp" 148 touch $file 149done 150 151echo "Download all files" 152