OSDN Git Service

Cert: Do not use ANDROID_ build environment variables in test
authorJack He <siyuanh@google.com>
Tue, 3 Mar 2020 23:39:37 +0000 (15:39 -0800)
committerJack He <siyuanh@google.com>
Wed, 4 Mar 2020 00:44:15 +0000 (16:44 -0800)
* Various environment variables should come from the build artifacts
  instead of the running environment.
* Hence getting rid of varioud usage of ANDROID_* variables in test
  files and figure them out through build artifacts
* Generate environment_provider.py at build time to provide
  build specific variables to the test at run time

Test: source cert/run
Bug: 150321998
Change-Id: I783c3784ad6018cb807a46701675fa5307e39175

gd/Android.mk
gd/cert/gd_base_test_facade_only.py
gd/cert/gd_device_base.py
gd/cert/python3.8-gd
gd/cert/run
gd/cert/run_pts_l2cap.sh
gd/cert/set_up_virtualenv.sh

index 0a213e2..a3b5c9d 100644 (file)
@@ -22,7 +22,6 @@ bluetooth_cert_test_file_list := \
     security/cert/simple_security_test.py \
     shim/cert/stack_test.py
 
-
 bluetooth_cert_test_file_list := $(addprefix $(LOCAL_PATH)/,$(bluetooth_cert_test_file_list))
 
 bluetooth_cert_test_file_list += \
@@ -36,12 +35,22 @@ bluetooth_cert_test_file_list += \
     $(TARGET_OUT_SHARED_LIBRARIES)/libgrpc++_unsecure.so \
     $(HOST_OUT_NATIVE_TESTS)/root-canal/root-canal
 
+bluetooth_cert_env_provider_path := \
+    $(call intermediates-dir-for,PACKAGING,bluetooth_cert_test_package,HOST)/system/bt/gd/cert/environment_provider.py
+
+$(bluetooth_cert_env_provider_path):
+       @mkdir -p $(dir $@)
+       $(hide) echo "PRODUCT_DEVICE = \"$(PRODUCT_DEVICE)\"" > $@
+
 bluetooth_cert_zip_path := \
     $(call intermediates-dir-for,PACKAGING,bluetooth_cert_test_package,HOST)/bluetooth_cert_test.zip
 
 $(bluetooth_cert_zip_path): PRIVATE_BLUETOOTH_CERT_TEST_FILE_LIST := $(bluetooth_cert_test_file_list)
 
-$(bluetooth_cert_zip_path) : $(SOONG_ZIP) $(bluetooth_cert_test_file_list)
-       $(hide) $(SOONG_ZIP) -d -o $@ $(addprefix -f ,$(PRIVATE_BLUETOOTH_CERT_TEST_FILE_LIST))
+$(bluetooth_cert_zip_path): PRIVATE_BLUETOOTH_CERT_ENV_PROVIDER_PATH := $(bluetooth_cert_env_provider_path)
+
+$(bluetooth_cert_zip_path) : $(SOONG_ZIP) $(bluetooth_cert_env_provider_path) $(bluetooth_cert_test_file_list)
+       $(hide) $(SOONG_ZIP) -d -o $@ $(addprefix -f ,$(PRIVATE_BLUETOOTH_CERT_TEST_FILE_LIST)) \
+               -C $(call intermediates-dir-for,PACKAGING,bluetooth_cert_test_package,HOST) -f $(PRIVATE_BLUETOOTH_CERT_ENV_PROVIDER_PATH)
 
 $(call dist-for-goals,bluetooth_stack_with_facade,$(bluetooth_cert_zip_path):bluetooth_cert_test.zip)
index 3e40cd1..cdda85a 100644 (file)
@@ -23,8 +23,6 @@ import os
 import signal
 import subprocess
 
-ANDROID_BUILD_TOP = os.environ.get('ANDROID_BUILD_TOP')
-
 
 class GdFacadeOnlyBaseTestClass(BaseTestClass):
 
@@ -42,8 +40,9 @@ class GdFacadeOnlyBaseTestClass(BaseTestClass):
             self.rootcanal_logs = open(rootcanal_logpath, 'w')
             rootcanal_config = self.controller_configs['rootcanal']
             rootcanal_hci_port = str(rootcanal_config.get("hci_port", "6402"))
-            android_host_out = os.environ.get('ANDROID_HOST_OUT')
-            rootcanal = android_host_out + "/nativetest64/root-canal/root-canal"
+            rootcanal = os.path.join(
+                os.getcwd(),
+                "out/host/linux-x86/nativetest64/root-canal/root-canal")
             self.rootcanal_process = subprocess.Popen(
                 [
                     rootcanal,
@@ -51,7 +50,7 @@ class GdFacadeOnlyBaseTestClass(BaseTestClass):
                     rootcanal_hci_port,
                     str(rootcanal_config.get("link_layer_port", "6403"))
                 ],
-                cwd=ANDROID_BUILD_TOP,
+                cwd=os.getcwd(),
                 env=os.environ.copy(),
                 stdout=self.rootcanal_logs,
                 stderr=self.rootcanal_logs)
index bd2c2d2..e18adaa 100644 (file)
@@ -28,9 +28,12 @@ from acts.controllers.adb import AdbProxy
 
 import grpc
 
-ANDROID_BUILD_TOP = os.environ.get('ANDROID_BUILD_TOP')
-ANDROID_HOST_OUT = os.environ.get('ANDROID_HOST_OUT')
-ANDROID_PRODUCT_OUT = os.environ.get('ANDROID_PRODUCT_OUT')
+from cert.environment_provider import PRODUCT_DEVICE
+
+ANDROID_PRODUCT_OUT = os.path.join(
+    os.getcwd(), "out/dist/bluetooth_cert_test/out/target/product",
+    PRODUCT_DEVICE)
+
 WAIT_CHANNEL_READY_TIMEOUT = 10
 
 
@@ -43,7 +46,8 @@ def replace_vars(string, config):
         rootcanal_port = ""
     if serial_number == "DUT" or serial_number == "CERT":
         raise Exception("Did you forget to configure the serial number?")
-    return string.replace("$ANDROID_HOST_OUT", ANDROID_HOST_OUT) \
+    android_host_out = os.path.join(os.getcwd(), "out/host/linux-x86")
+    return string.replace("$ANDROID_HOST_OUT", android_host_out) \
                  .replace("$(grpc_port)", config.get("grpc_port")) \
                  .replace("$(grpc_root_server_port)", config.get("grpc_root_server_port")) \
                  .replace("$(rootcanal_port)", rootcanal_port) \
@@ -103,7 +107,7 @@ class GdDeviceBase:
 
         self.backing_process = subprocess.Popen(
             cmd,
-            cwd=ANDROID_BUILD_TOP,
+            cwd=os.getcwd(),
             env=os.environ.copy(),
             stdout=self.backing_process_logs,
             stderr=self.backing_process_logs)
index 7ecc0fd..f77adfc 100755 (executable)
@@ -1,2 +1,4 @@
 #! /bin/bash
-PYTHONPATH=$PYTHONPATH:$ANDROID_BUILD_TOP/out/host/linux-x86/lib64:$ANDROID_BUILD_TOP/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd python3.8 "$@"
+PYTHONPATH=$ANDROID_BUILD_TOP/out/host/linux-x86/lib64:$ANDROID_BUILD_TOP/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd:$PYTHONPATH \
+PATH=$ANDROID_HOST_OUT/nativetest64/root-canal:$ANDROID_HOST_OUT/nativetest64/bin:$PATH \
+ python3.8 "$@"
index 2621c89..22f53d0 100755 (executable)
@@ -37,8 +37,15 @@ set -- "${POSITIONAL[@]}" # restore positional parameters
 unzip -o -q $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py.zip \
    -d $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py
 
-PYTHONPATH=$PYTHONPATH:$ANDROID_BUILD_TOP/out/host/linux-x86/lib64:$ANDROID_BUILD_TOP/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd \
+unzip -o -q $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test.zip \
+   -d $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test
+
+pushd .
+cd $ANDROID_BUILD_TOP
+PYTHONPATH=$ANDROID_BUILD_TOP/out/host/linux-x86/lib64:$ANDROID_BUILD_TOP/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test/system/bt/gd:$ANDROID_BUILD_TOP/system/bt/gd:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd:$PYTHONPATH \
+PATH=$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test/out/host/linux-x86/nativetest64/root-canal:$ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test/out/host/linux-x86/bin:$PATH \
     python3.8 `which act.py`\
       -c $TEST_CONFIG \
       $TEST_FILTER \
       -tp $ANDROID_BUILD_TOP/system/bt/gd
+popd
\ No newline at end of file
index e05c0f7..92fc7cd 100755 (executable)
@@ -3,4 +3,7 @@
 unzip -u $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py.zip -d $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py
 
 # For bluetooth_packets_python3
+pushd .
+cd $ANDROID_BUILD_TOP
 python3.8-gd `which act.py` -c $ANDROID_BUILD_TOP/system/bt/gd/cert/pts.json -tf $ANDROID_BUILD_TOP/system/bt/gd/cert/pts_l2cap_testcase -tp $ANDROID_BUILD_TOP/system/bt/gd
+popd
\ No newline at end of file
index 00e86eb..50f3d48 100644 (file)
@@ -161,7 +161,7 @@ pushd .
 cd $ANDROID_BUILD_TOP/system/bt/gd/gd_cert_venv/lib/python3.8/site-packages
 # Python generated code
 ln -sfT $ANDROID_BUILD_TOP/tools/test/connectivity/acts/framework/acts acts
-ln -sfT $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd/cert cert
+ln -sfT $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_test/system/bt/gd/cert cert
 ln -sfT $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd/facade facade
 ln -sfT $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd/hal hal
 ln -sfT $ANDROID_BUILD_TOP/out/dist/bluetooth_cert_generated_py/system/bt/gd/hci hci