Fix & Improve Test-Building and -Running Scripts

(This is a merge of wvgerrit/24922)

This contains several fixes and improvements to the
build_and_run_all_unit_tests.sh and run_all_unit_tests.sh scripts:

* All tests are now identified as vendor binaries and thus are stored in
  the /vendor/bin/ directory instead of /system/bin/. Previously, some
  tests had moved to /vendor/bin/ but the scripts had not been updated,
  causing these tests to fail to run.
* The -j parameter can now be passed to build_and_run_all_unit_tests.sh,
  for those who want to speed up their build by using multiple cores.
* The 64-bit library directories are now added to the library search
  path, in anticipation of devices with 64-bit DRM Plugins.
* Checking for Verity protection is now done in
  build_and_run_all_unit_tests.sh (which is the script that actually
  modifies the file system) instead of just in run_all_unit_tests.sh.
* The library search path is no longer set unnecessarily for
  libwvdrmengine_hidl_test.
* The Treble-only tests and non-Treble-only tests now only run on
  devices that meet their respective criteria.

Bug: 36071236
Test: Ran build_and_run_all_unit_tests.sh
Change-Id: Iea236880c4445858111c801dfa278a528bca0f6c
This commit is contained in:
John W. Bruce
2017-03-29 19:01:04 -07:00
parent 92dff24180
commit f2463075ac
6 changed files with 99 additions and 42 deletions

View File

@@ -7,68 +7,95 @@ if [ -z "$ANDROID_BUILD_TOP" ]; then
exit -1
fi
# Read arguments in case the user wants to do a multicore build
NUM_CORES=1
while getopts "j:" opt; do
case $opt in
j)
NUM_CORES=$OPTARG
;;
esac
done
# Define the relevant aliases
. $ANDROID_BUILD_TOP/build/envsetup.sh
# Build all the targets
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine
pwd
mm || mma
mm -j $NUM_CORES || mma -j $NUM_CORES
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/test/unit
pwd
mm || mma
mm -j $NUM_CORES || mma -j $NUM_CORES
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/cdm/test
pwd
mm || mma
mm -j $NUM_CORES || mma -j $NUM_CORES
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/mediacrypto/test
pwd
mm || mma
mm -j $NUM_CORES || mma -j $NUM_CORES
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/mediadrm/test
pwd
mm || mma
mm -j $NUM_CORES || mma -j $NUM_CORES
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/oemcrypto/test
pwd
mm || mma
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 root && adb wait-for-device remount
ADB_OUTPUT=`adb root && adb 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."
exit -1
fi
# Push the files to the device
# Given a local path to a file, this will first try to push it to /vendor/bin
# and then, if that fails, to /data/widevine_tests.
try_adb_push() {
# Swallow the error message -- assume it is a read-only file system.
if ! adb push $@ /system/bin > /dev/null; then
if ! adb push $@ /vendor/bin &> /dev/null; then
adb shell mkdir -p /data/widevine_tests
# If this fails, the user will get the error message.
adb push $@ /data/widevine_tests
fi
}
try_adb_push $OUT/system/bin/oemcrypto_test
try_adb_push $OUT/system/bin/request_license_test
try_adb_push $OUT/system/bin/cdm_extended_duration_test
try_adb_push $OUT/system/bin/policy_engine_unittest
try_adb_push $OUT/system/bin/policy_engine_constraints_unittest
try_adb_push $OUT/system/bin/libwvdrmmediacrypto_test
try_adb_push $OUT/system/bin/libwvdrmmediacrypto_hidl_test
try_adb_push $OUT/system/bin/libwvdrmdrmplugin_test
try_adb_push $OUT/system/bin/libwvdrmdrmplugin_hidl_test
try_adb_push $OUT/system/bin/cdm_engine_test
try_adb_push $OUT/system/bin/cdm_session_unittest
try_adb_push $OUT/system/bin/file_store_unittest
try_adb_push $OUT/system/bin/file_utils_unittest
try_adb_push $OUT/system/bin/license_unittest
try_adb_push $OUT/system/bin/license_keys_unittest
try_adb_push $OUT/system/bin/initialization_data_unittest
try_adb_push $OUT/system/bin/device_files_unittest
try_adb_push $OUT/system/bin/service_certificate_unittest
try_adb_push $OUT/system/bin/timer_unittest
try_adb_push $OUT/system/bin/libwvdrmengine_test
try_adb_push $OUT/system/bin/libwvdrmengine_hidl_test
try_adb_push $OUT/system/bin/buffer_reader_test
try_adb_push $OUT/system/bin/distribution_test
try_adb_push $OUT/system/bin/event_metric_test
# Push the tests to the device
try_adb_push $OUT/vendor/bin/oemcrypto_test
try_adb_push $OUT/vendor/bin/request_license_test
try_adb_push $OUT/vendor/bin/cdm_extended_duration_test
try_adb_push $OUT/vendor/bin/policy_engine_unittest
try_adb_push $OUT/vendor/bin/policy_engine_constraints_unittest
try_adb_push $OUT/vendor/bin/libwvdrmmediacrypto_test
try_adb_push $OUT/vendor/bin/libwvdrmmediacrypto_hidl_test
try_adb_push $OUT/vendor/bin/libwvdrmdrmplugin_test
try_adb_push $OUT/vendor/bin/libwvdrmdrmplugin_hidl_test
try_adb_push $OUT/vendor/bin/cdm_engine_test
try_adb_push $OUT/vendor/bin/cdm_session_unittest
try_adb_push $OUT/vendor/bin/file_store_unittest
try_adb_push $OUT/vendor/bin/file_utils_unittest
try_adb_push $OUT/vendor/bin/license_unittest
try_adb_push $OUT/vendor/bin/license_keys_unittest
try_adb_push $OUT/vendor/bin/initialization_data_unittest
try_adb_push $OUT/vendor/bin/device_files_unittest
try_adb_push $OUT/vendor/bin/service_certificate_unittest
try_adb_push $OUT/vendor/bin/timer_unittest
try_adb_push $OUT/vendor/bin/libwvdrmengine_test
try_adb_push $OUT/vendor/bin/libwvdrmengine_hidl_test
try_adb_push $OUT/vendor/bin/buffer_reader_test
try_adb_push $OUT/vendor/bin/distribution_test
try_adb_push $OUT/vendor/bin/event_metric_test
# Run the tests using run_all_unit_tests.sh
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine
./run_all_unit_tests.sh

View File

@@ -50,6 +50,10 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_CFLAGS += -DUNIT_TEST
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(BUILD_EXECUTABLE)

View File

@@ -45,6 +45,10 @@ LOCAL_MODULE := libwvdrmmediacrypto_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(BUILD_EXECUTABLE)
@@ -106,6 +110,10 @@ LOCAL_MODULE := libwvdrmmediacrypto_hidl_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(BUILD_EXECUTABLE)

View File

@@ -46,6 +46,10 @@ LOCAL_MODULE := libwvdrmdrmplugin_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(BUILD_EXECUTABLE)
@@ -108,6 +112,10 @@ LOCAL_MODULE := libwvdrmdrmplugin_hidl_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(BUILD_EXECUTABLE)

View File

@@ -5,6 +5,10 @@ include $(CLEAR_VARS)
LOCAL_MODULE:=oemcrypto_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_TARGET_ARCH := arm x86 mips
include $(LOCAL_PATH)/common.mk

View File

@@ -19,12 +19,12 @@ fi
adb_shell_run() {
local test_file=$1
shift
if adb shell ls /data/widevine_tests/$test_file; then
if adb shell ls /data/widevine_tests/$test_file &> /dev/null; then
test_file=/data/widevine_tests/$test_file
else
test_file=/system/bin/$test_file
echo $test_file
test_file=/vendor/bin/$test_file
fi
echo $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"
@@ -88,12 +88,18 @@ adb_shell_run buffer_reader_test
adb_shell_run distribution_test
adb_shell_run event_metric_test
library_path="/system/vendor/lib/mediadrm/ "
# 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
library_path="/vendor/lib/mediadrm/:/vendor/lib64/mediadrm/"
adb_shell_run libwvdrmengine_test LD_LIBRARY_PATH=$library_path
fi
library_path="/system/vendor/lib/hw/ "
adb_shell_run libwvdrmengine_hidl_test LD_LIBRARY_PATH=$library_path
# 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
adb_shell_run libwvdrmengine_hidl_test
fi
# Re-enable DroidGuard
set_droidguard enable