Merge "Pass in gce-driver-param into acloud command."
diff --git a/src/com/android/tradefed/device/TestDeviceOptions.java b/src/com/android/tradefed/device/TestDeviceOptions.java
index dcc0974..753f9db 100644
--- a/src/com/android/tradefed/device/TestDeviceOptions.java
+++ b/src/com/android/tradefed/device/TestDeviceOptions.java
@@ -176,7 +176,7 @@
 
     @Option(
         name = "gce-driver-param",
-        description = " Additional key-value pairs to pass down to " + "gce driver as parameters."
+        description = "Additional args to pass to gce driver as parameters."
     )
     private List<String> mGceDriverParams = new ArrayList<>();
 
@@ -192,9 +192,9 @@
     private String mGceAccount = null;
 
     @Option(
-            name = "max-gce-attempt",
-            description =
-                    "Maximum number of attempts to start Gce " + "before throwing an exception.")
+        name = "max-gce-attempt",
+        description = "Maximum number of attempts to start Gce before throwing an exception."
+    )
     private int mGceMaxAttempt = 1;
 
     @Option(
diff --git a/src/com/android/tradefed/device/cloud/GceManager.java b/src/com/android/tradefed/device/cloud/GceManager.java
index 4336736..b4ec118 100644
--- a/src/com/android/tradefed/device/cloud/GceManager.java
+++ b/src/com/android/tradefed/device/cloud/GceManager.java
@@ -274,6 +274,9 @@
         mGceBootFailureSerialLog = FileUtil.createTempFile("gce_serial_boot", ".tar.gz");
         gceArgs.add("--serial_log_file");
         gceArgs.add(mGceBootFailureSerialLog.getAbsolutePath());
+
+        // Add additional args passed in.
+        gceArgs.addAll(getTestDeviceOptions().getGceDriverParams());
         return gceArgs;
     }
 
diff --git a/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java b/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
index 16efe13..469d4bd 100644
--- a/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
+++ b/tests/src/com/android/tradefed/device/cloud/GceManagerTest.java
@@ -295,6 +295,55 @@
         EasyMock.verify(mMockBuildInfo);
     }
 
+    /** Test {@link GceManager#buildGceCmd(File, IBuildInfo)}. */
+    @Test
+    public void testBuildGceCommandWithGceDriverParam() throws Exception {
+        IBuildInfo mMockBuildInfo = EasyMock.createMock(IBuildInfo.class);
+        EasyMock.expect(mMockBuildInfo.getBuildAttributes())
+                .andReturn(Collections.<String, String>emptyMap());
+        EasyMock.expect(mMockBuildInfo.getBuildFlavor()).andReturn("FLAVOR");
+        EasyMock.expect(mMockBuildInfo.getBuildBranch()).andReturn("BRANCH");
+        EasyMock.expect(mMockBuildInfo.getBuildId()).andReturn("BUILDID");
+        EasyMock.replay(mMockBuildInfo);
+        File reportFile = null;
+        OptionSetter setter = new OptionSetter(mOptions);
+        setter.setOptionValue("gce-driver-param", "--report-internal-ip");
+        setter.setOptionValue("gce-driver-param", "--no-autoconnect");
+        try {
+            reportFile = FileUtil.createTempFile("test-gce-cmd", "report");
+            List<String> result = mGceManager.buildGceCmd(reportFile, mMockBuildInfo);
+            List<String> expected =
+                    ArrayUtil.list(
+                            mOptions.getAvdDriverBinary().getAbsolutePath(),
+                            "create",
+                            "--build_target",
+                            "FLAVOR",
+                            "--branch",
+                            "BRANCH",
+                            "--build_id",
+                            "BUILDID",
+                            "--config_file",
+                            mGceManager.getAvdConfigFile().getAbsolutePath(),
+                            "--report_file",
+                            reportFile.getAbsolutePath(),
+                            "-v",
+                            "--logcat_file",
+                            mGceManager.getGceBootLogcatLog().getAbsolutePath(),
+                            "--serial_log_file",
+                            mGceManager.getGceBootSerialLog().getAbsolutePath(),
+                            "--report-internal-ip",
+                            "--no-autoconnect");
+            assertEquals(expected, result);
+            assertTrue(mGceManager.getGceBootLogcatLog().exists());
+            assertTrue(mGceManager.getGceBootSerialLog().exists());
+        } finally {
+            FileUtil.deleteFile(reportFile);
+            FileUtil.deleteFile(mGceManager.getGceBootLogcatLog());
+            FileUtil.deleteFile(mGceManager.getGceBootSerialLog());
+        }
+        EasyMock.verify(mMockBuildInfo);
+    }
+
     /** Ensure exception is thrown after a timeout from the acloud command. */
     @Test
     public void testStartGce_timeout() throws Exception {