Add host side script to support OMX test.

* Init IOmx hal and call listNodes to get all registed IOmxNode component.
* Create test cases with different component info to each test binary.

Bug: 32023356
Test: make vts && run vts -m VtsHalMediaOmxV1_0Target
Change-Id: I3e33dec5ba462e759d3aa093916e58b25960c2da
diff --git a/media/__init__.py b/media/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/__init__.py
diff --git a/media/omx/V1_0/__init__.py b/media/omx/V1_0/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/omx/V1_0/__init__.py
diff --git a/media/omx/V1_0/host/Android.mk b/media/omx/V1_0/host/Android.mk
new file mode 100644
index 0000000..6244a05
--- /dev/null
+++ b/media/omx/V1_0/host/Android.mk
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := VtsHalMediaOmxV1_0Host
+VTS_CONFIG_SRC_DIR := testcases/hal/media/omx/V1_0/host
+include test/vts/tools/build/Android.host_config.mk
diff --git a/media/omx/V1_0/host/AndroidTest.xml b/media/omx/V1_0/host/AndroidTest.xml
new file mode 100644
index 0000000..3edbb0e
--- /dev/null
+++ b/media/omx/V1_0/host/AndroidTest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<configuration description="Config for VTS VtsHalMediaOmxV1_0Host test cases">
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
+        <option name="abort-on-push-failure" value="true"/>
+        <option name="push-group" value="HalHidlHostTest.push"/>
+        <option name="cleanup" value="true"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/GraphicBufferSource.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/GraphicBufferSource.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/Omx.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/Omx.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/OmxBufferSource.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/OmxBufferSource.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/OmxNode.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/OmxNode.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/OmxObserver.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/OmxObserver.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/omx/1.0/vts/types.vts->/data/local/tmp/spec/android/hardware/media/omx/1.0/types.vts"/>
+        <option name="push" value="spec/hardware/interfaces/graphics/common/1.0/vts/types.vts->/data/local/tmp/spec/android/hardware/graphics/common/1.0/types.vts"/>
+        <option name="push" value="spec/hardware/interfaces/media/1.0/vts/types.vts->/data/local/tmp/spec/android/hardware/media/1.0/types.vts"/>
+        <option name="push" value="DATA/lib/android.hardware.graphics.bufferqueue@1.0-vts.driver.so->/data/local/tmp/32/android.hardware.graphics.bufferqueue@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib64/android.hardware.graphics.bufferqueue@1.0-vts.driver.so->/data/local/tmp/64/android.hardware.graphics.bufferqueue@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib/android.hardware.graphics.common@1.0-vts.driver.so->/data/local/tmp/32/android.hardware.graphics.common@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib64/android.hardware.graphics.common@1.0-vts.driver.so->/data/local/tmp/64/android.hardware.graphics.common@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib/android.hardware.media@1.0-vts.driver.so->/data/local/tmp/32/android.hardware.media@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib64/android.hardware.media@1.0-vts.driver.so->/data/local/tmp/64/android.hardware.media@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib/android.hardware.media.omx@1.0-vts.driver.so->/data/local/tmp/32/android.hardware.media.omx@1.0-vts.driver.so"/>
+        <option name="push" value="DATA/lib64/android.hardware.media.omx@1.0-vts.driver.so->/data/local/tmp/64/android.hardware.media.omx@1.0-vts.driver.so"/>
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer"/>
+    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
+        <option name="test-module-name" value="VtsHalMediaOmxV1_0Host"/>
+        <option name="test-case-path" value="vts/testcases/hal/media/omx/V1_0/host/VtsHalMediaOmxV1_0HostTest"/>
+        <option name="binary-test-source" value="_64bit::DATA/nativetest64/VtsHalMediaOmxV1_0TargetComponentTest/VtsHalMediaOmxV1_0TargetComponentTest"/>
+        <option name="hal-hidl-package-name" value="android.hardware.media.omx@1.0"/>
+        <option name="precondition-lshal" value="android.hardware.media.omx@1.0"/>
+        <option name="test-timeout" value="30m"/>
+    </test>
+</configuration>
diff --git a/media/omx/V1_0/host/VtsHalMediaOmxV1_0HostTest.py b/media/omx/V1_0/host/VtsHalMediaOmxV1_0HostTest.py
new file mode 100644
index 0000000..4b3862a
--- /dev/null
+++ b/media/omx/V1_0/host/VtsHalMediaOmxV1_0HostTest.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import logging
+import time
+
+from vts.runners.host import asserts
+from vts.runners.host import keys
+from vts.runners.host import test_runner
+from vts.testcases.template.hal_hidl_gtest import hal_hidl_gtest
+import VtsHalMediaOmxV1_0TestCase as omx_test_case
+
+
+class VtsHalMediaOmxV1_0Host(hal_hidl_gtest.HidlHalGTest):
+    """Host test class to run the Media_Omx HAL."""
+
+    def CreateTestCases(self):
+        """Get all registered test components and create test case objects."""
+        # Init the IOmx hal.
+        self._dut.hal.InitHidlHal(
+            target_type="media_omx",
+            target_basepaths=self._dut.libPaths,
+            target_version=1.0,
+            target_package="android.hardware.media.omx",
+            target_component_name="IOmx",
+            bits=64 if self._dut.is64Bit else 32)
+
+        # Call listNodes to get all registered components.
+        self.vtypes = self._dut.hal.media_omx.GetHidlTypeInterface("types")
+        status, nodeList = self._dut.hal.media_omx.listNodes()
+        asserts.assertEqual(self.vtypes.Status.OK, status)
+
+        self.components = {}
+        for node in nodeList:
+            self.components[node['mName']] = node['mRoles']
+
+        super(VtsHalMediaOmxV1_0Host, self).CreateTestCases()
+
+    # @Override
+    def CreateTestCase(self, path, tag=''):
+        """Create a list of VtsHalMediaOmxV1_0testCase objects.
+
+        For each target side gtest test case, create a set of new test cases
+        argumented with different component and role values.
+
+        Args:
+            path: string, absolute path of a gtest binary on device
+            tag: string, a tag that will be appended to the end of test name
+
+        Returns:
+            A list of VtsHalMediaOmxV1_0TestCase objects
+        """
+        gtest_cases = super(VtsHalMediaOmxV1_0Host, self).CreateTestCase(
+            path, tag)
+        test_cases = []
+
+        for gtest_case in gtest_cases:
+            test_suite = gtest_case.GetFullName()
+            for component, roles in self.components.iteritems():
+                for role in roles:
+                    test_name = component + '_' + role
+                    # TODO (zhuoyao): get instance name using lshal.
+                    instance_name = "default"
+                    test_case = omx_test_case.VtsHalMediaOmxV1_0TestCase(
+                        component, role, instance_name, test_suite, test_name,
+                        path)
+                test_cases.append(test_case)
+        logging.info("num of test_testcases: %s", len(test_cases))
+        return test_cases
+
+
+if __name__ == "__main__":
+    test_runner.main()
diff --git a/media/omx/V1_0/host/VtsHalMediaOmxV1_0TestCase.py b/media/omx/V1_0/host/VtsHalMediaOmxV1_0TestCase.py
new file mode 100644
index 0000000..53b2189
--- /dev/null
+++ b/media/omx/V1_0/host/VtsHalMediaOmxV1_0TestCase.py
@@ -0,0 +1,50 @@
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import logging
+import os
+
+from vts.testcases.template.gtest_binary_test import gtest_test_case
+
+class VtsHalMediaOmxV1_0TestCase(gtest_test_case.GtestTestCase):
+    """A class to represent a media_omx test case.
+
+    Attributes:
+        component: string, name of a IOmxNode component.
+        role: string, role of a IOmxNode component.
+        instance: string, name of the binderized hal server instance.
+    """
+
+    def __init__(self, component, role, instance, *args, **kwargs):
+        super(VtsHalMediaOmxV1_0TestCase, self).__init__(*args, **kwargs)
+        self._component = component
+        self._role = role
+        self._instance = instance
+
+    # @Override
+    def GetRunCommand(self):
+        """Get the command to run the test. """
+
+        orig_cmds = super(VtsHalMediaOmxV1_0TestCase,
+                          self).GetRunCommand(test_name=self.test_suite),
+
+        new_cmd = [('{cmd} -I {instance} -C {component} -R {role}').format(
+            cmd=orig_cmds[0][0],
+            instance=self._instance,
+            component=self._component,
+            role=self._role), orig_cmds[0][1]]
+
+        return new_cmd
diff --git a/media/omx/V1_0/host/__init__.py b/media/omx/V1_0/host/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/omx/V1_0/host/__init__.py
diff --git a/media/omx/__init__.py b/media/omx/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/media/omx/__init__.py