Adds a flag to ignore invalid test control files in test image.

BUG=chromium:603302
TEST=Manually test the case on device.

Change-Id: I1d2ac46283f45e2c701a8c569f20b6ffdcf114c1
Reviewed-on: https://chromium-review.googlesource.com/339360
Commit-Ready: Michael Tang <ntang@chromium.org>
Tested-by: Michael Tang <ntang@chromium.org>
Reviewed-by: Michael Tang <ntang@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 2de8493..7947b9e 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -981,10 +981,11 @@
     stable_version_utils.delete(board=board)
 
 
-def get_tests_by_build(build):
+def get_tests_by_build(build, ignore_invalid_tests=False):
     """Get the tests that are available for the specified build.
 
     @param build: unique name by which to refer to the image.
+    @param ignore_invalid_tests: flag on if unparsable tests are ignored.
 
     @return: A sorted list of all tests that are in the build specified.
     """
@@ -1011,7 +1012,12 @@
         # Read and parse the control file
         control_file = cfile_getter.get_control_file_contents(
                 control_file_path)
-        control_obj = control_data.parse_control_string(control_file)
+        try:
+            control_obj = control_data.parse_control_string(control_file)
+        except:
+            logging.info('Failed to parse congtrol file: %s', control_file_path)
+            if not ignore_invalid_tests:
+                raise
 
         # Extract the values needed for the AFE from the control_obj.
         # The keys list represents attributes in the control_obj that
diff --git a/frontend/client/src/autotest/afe/create/CreateJobViewDisplay.java b/frontend/client/src/autotest/afe/create/CreateJobViewDisplay.java
index 0bda160..4b8f7dc 100644
--- a/frontend/client/src/autotest/afe/create/CreateJobViewDisplay.java
+++ b/frontend/client/src/autotest/afe/create/CreateJobViewDisplay.java
@@ -66,6 +66,7 @@
         "If no image is specified, regular tests will use current image on the Host. " +
         "Please note that an image is required to run a test suite.");
     private Button fetchImageTestsButton = new Button("Fetch Tests from Build");
+    private CheckBoxImpl ignoreInvalidTestsCheckBox = new CheckBoxImpl("Ignore Invalid Tests");
     private TextBox timeout = new TextBox();
     private ToolTip timeoutToolTip = new ToolTip(
         "?",
@@ -355,6 +356,7 @@
         panel.add(testSourceBuildList, "create_test_source_build");
         panel.add(testSourceBuildListToolTip, "create_test_source_build");
         panel.add(fetchImageTestsButton, "fetch_image_tests");
+        panel.add(ignoreInvalidTestsCheckBox, "ignore_invalid_tests");
         panel.add(testSelector, "create_tests");
         panel.add(controlFilePanel, "create_edit_control");
         panel.add(hostSelector, "create_host_selector");
@@ -507,6 +509,10 @@
         return fetchImageTestsButton;
     }
 
+    public ICheckBox getIgnoreInvalidTestsCheckBox() {
+      return ignoreInvalidTestsCheckBox;
+    }
+
     public ITextBox getFirmwareRWBuild() {
       return firmwareRWBuild;
     }
diff --git a/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java b/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java
index 7327583..dcc9615 100644
--- a/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java
+++ b/frontend/client/src/autotest/afe/create/CreateJobViewPresenter.java
@@ -94,6 +94,7 @@
         public HasClickHandlers getCreateTemplateJobButton();
         public HasClickHandlers getResetButton();
         public HasClickHandlers getFetchImageTestsButton();
+        public ICheckBox getIgnoreInvalidTestsCheckBox();
         public ITextBox getFirmwareRWBuild();
         public ITextBox getFirmwareROBuild();
         public ExtendedListBox getTestSourceBuildList();
@@ -1006,7 +1007,8 @@
 
         JSONObject params = new JSONObject();
         params.put("build", new JSONString(imageUrl));
-
+        params.put("ignore_invalid_tests", JSONBoolean.getInstance(
+              display.getIgnoreInvalidTestsCheckBox().getValue()));
         rpcProxy.rpcCall("get_tests_by_build", params, new JsonRpcCallback() {
             @Override
             public void onSuccess(JSONValue result) {
diff --git a/frontend/client/src/autotest/public/AfeClient.html b/frontend/client/src/autotest/public/AfeClient.html
index dceee49..187b3af 100644
--- a/frontend/client/src/autotest/public/AfeClient.html
+++ b/frontend/client/src/autotest/public/AfeClient.html
@@ -198,6 +198,7 @@
             <td class="field-name">Test source build: (optional)</td>
             <td class="has-tooltip" id="create_test_source_build"></td>
             <td class="button" id="fetch_image_tests"></td>
+            <td class="checkbox" id="ignore_invalid_tests"></td>
           </tr>
         </table>
         <br>