From 7653f2dc15ee89cbfcce1245a246062ceb1bb726 Mon Sep 17 00:00:00 2001 From: Rahul Frias Date: Tue, 4 Dec 2018 23:33:11 -0800 Subject: [PATCH] Allow tests to take serial number as a parameter [ Merge of http://go/wvgerrit/67583 ] The new command formats are $ build_and_run_all_unit_tests.sh [-j ] [-s ] $ run_all_unit_tests.sh [-s ] Bug: 120519038 Test: WV unit/integration tests with a single device and with two devices connected (with and without specifying a target serial number) Change-Id: I518038c3fc178a7eb658fcd4cf82dd13dfa7131f --- .../build_and_run_all_unit_tests.sh | 20 ++++++++----- libwvdrmengine/run_all_unit_tests.sh | 29 +++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/libwvdrmengine/build_and_run_all_unit_tests.sh b/libwvdrmengine/build_and_run_all_unit_tests.sh index 4136209c..988cd9c4 100755 --- a/libwvdrmengine/build_and_run_all_unit_tests.sh +++ b/libwvdrmengine/build_and_run_all_unit_tests.sh @@ -7,13 +7,18 @@ if [ -z "$ANDROID_BUILD_TOP" ]; then exit -1 fi -# Read arguments in case the user wants to do a multicore build +# Read arguments in case the user wants to do a multicore build or +# copy files to a specific android device by providing a serial number NUM_CORES=1 -while getopts "j:" opt; do +SERIAL_NUM="" +while getopts "j:s:" opt; do case $opt in j) NUM_CORES=$OPTARG ;; + s) + SERIAL_NUM="-s $OPTARG" + ;; esac done @@ -47,13 +52,13 @@ mm -j $NUM_CORES || mma -j $NUM_CORES # Detect the device and check if Verity is going to stop the script from working echo "waiting for device" -ADB_OUTPUT=`adb root && echo ". " && adb wait-for-device remount` +ADB_OUTPUT=`adb $SERIAL_NUM root && echo ". " && adb $SERIAL_NUM wait-for-device remount` echo $ADB_OUTPUT if echo $ADB_OUTPUT | grep -qi "verity"; then echo echo "ERROR: This device has Verity enabled. build_and_run_all_unit_tests.sh " echo "does not work if Verity is enabled. Please disable Verity with" - echo "\"adb disable-verity\" and try again." + echo "\"adb $SERIAL_NUM disable-verity\" and try again." exit -1 fi @@ -70,8 +75,8 @@ try_adb_push() { echo "I think it should be in $OUT/data/bin" exit 1 fi - adb shell mkdir -p /data/bin - adb push $test_file /data/bin/$1 + adb $SERIAL_NUM shell mkdir -p /data/bin + adb $SERIAL_NUM push $test_file /data/bin/$1 } # Push the tests to the device @@ -83,7 +88,6 @@ try_adb_push cdm_extended_duration_test try_adb_push cdm_session_unittest try_adb_push counter_metric_unittest try_adb_push crypto_session_unittest -try_adb_push generic_crypto_unittest try_adb_push device_files_unittest try_adb_push distribution_unittest try_adb_push event_metric_unittest @@ -111,4 +115,4 @@ try_adb_push wv_cdm_metrics_test # Run the tests using run_all_unit_tests.sh cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine -./run_all_unit_tests.sh +./run_all_unit_tests.sh $SERIAL_NUM diff --git a/libwvdrmengine/run_all_unit_tests.sh b/libwvdrmengine/run_all_unit_tests.sh index dc5752e1..6dbff6d8 100755 --- a/libwvdrmengine/run_all_unit_tests.sh +++ b/libwvdrmengine/run_all_unit_tests.sh @@ -1,5 +1,16 @@ #!/bin/sh +# Read arguments in case the user wants to copy files to a specific +# android device by providing a serial number +SERIAL_NUM="" +while getopts "j:s:" opt; do + case $opt in + s) + SERIAL_NUM="-s $OPTARG" + ;; + esac +done + final_result=0 failed_tests=() @@ -19,7 +30,7 @@ fi adb_shell_run() { local test_file=$1 shift - if adb shell ls /data/bin/$test_file &> /dev/null; then + if adb $SERIAL_NUM shell ls /data/bin/$test_file &> /dev/null; then test_file=/data/bin/$test_file else echo "Please install the test on the device in /data/bin, " @@ -29,7 +40,7 @@ adb_shell_run() { echo "------ Starting: $test_file" local tmp_log="$OUT/mediadrmtest.log" local adb_error="[ADB SHELL] $@ $test_file failed" - adb shell "GTEST_FILTER=$GTEST_FILTER $@ $test_file" \|\| echo "$adb_error" | tee "$tmp_log" + adb $SERIAL_NUM shell "GTEST_FILTER=$GTEST_FILTER $@ $test_file" \|\| echo "$adb_error" | tee "$tmp_log" ! grep -Fq "$adb_error" "$tmp_log" local result=$? if [ $result -ne 0 ]; then @@ -42,7 +53,7 @@ adb_shell_run() { # Disabling DroidGuard during the test run prevents concurrency issues # with provisioning status. set_droidguard() { - adb shell pm $1 com.google.android.gms/com.google.android.gms.droidguard.DroidGuardService + adb $SERIAL_NUM shell pm $1 com.google.android.gms/com.google.android.gms.droidguard.DroidGuardService } if [ -z "$ANDROID_BUILD_TOP" ]; then @@ -51,13 +62,13 @@ if [ -z "$ANDROID_BUILD_TOP" ]; then fi echo "waiting for device" -ADB_OUTPUT=`adb root && echo ". " && adb wait-for-device remount` +ADB_OUTPUT=`adb $SERIAL_NUM root && echo ". " && adb $SERIAL_NUM wait-for-device remount` echo $ADB_OUTPUT if echo $ADB_OUTPUT | grep -qi "verity"; then echo echo "ERROR: This device has Verity enabled. run_all_unit_tests.sh does not " echo "work if Verity is enabled. Please disable Verity with" - echo "\"adb disable-verity\" and try again." + echo "\"adb $SERIAL_NUM disable-verity\" and try again." exit -1 fi @@ -108,15 +119,15 @@ adb_shell_run value_metric_unittest adb_shell_run wv_cdm_metrics_test # Run the non-Treble test on non-Treble devices -if adb shell ls /vendor/lib/mediadrm/libwvdrmengine.so &> /dev/null || - adb shell ls /vendor/lib64/mediadrm/libwvdrmengine.so &> /dev/null; then +if adb $SERIAL_NUM shell ls /vendor/lib/mediadrm/libwvdrmengine.so &> /dev/null || + adb $SERIAL_NUM shell ls /vendor/lib64/mediadrm/libwvdrmengine.so &> /dev/null; then library_path="/vendor/lib/mediadrm/:/vendor/lib64/mediadrm/" adb_shell_run libwvdrmengine_test LD_LIBRARY_PATH=$library_path fi # Run the Treble test on Treble devices -if adb shell ls /vendor/lib/libwvhidl.so &> /dev/null || - adb shell ls /vendor/lib64/libwvhidl.so &> /dev/null; then +if adb $SERIAL_NUM shell ls /vendor/lib/libwvhidl.so &> /dev/null || + adb $SERIAL_NUM shell ls /vendor/lib64/libwvhidl.so &> /dev/null; then adb_shell_run libwvdrmengine_hidl_test fi