• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import logging
19import threading
20import time
21
22from vts.runners.host import asserts
23from vts.runners.host import base_test
24from vts.runners.host import test_runner
25from vts.utils.python.controllers import android_device
26from vts.utils.python.precondition import precondition_utils
27
28
29class ContextHubCallback:
30    def __init__(self, hub_id):
31        self.hub_id = hub_id
32        self.event = threading.Event()
33
34    def wait_on_callback(timeout=None):
35        """Wait on the next callback in this object to be invoked.
36
37        Args:
38            timeout: (fractional) seconds to wait before timing out, or None
39
40        Returns:
41            True when a callback was received, False if a timeout occurred
42        """
43        return self.event.wait(timeout)
44
45    def prepare():
46        # TODO: cleaner method of doing this, so that we clear --> call HAL
47        # method --> wait for CB, all wrapped into one
48        self.event.clear()
49
50    def ignore_client_msg(self, msg):
51        logging.debug("Ignoring client message from hubId %s: %s", self.hub_id, msg)
52        self.event.set()
53
54    def ignore_txn_result(self, txnId, result):
55        logging.debug("Ignoring transaction result from hubId %s: %s", self.hub_id, msg)
56        self.event.set()
57
58    def ignore_hub_event(self, evt):
59        logging.debug("Ignoring hub event from hubId %s: %s", self.hub_id, evt)
60        self.event.set()
61
62    def ignore_apps_info(self, appInfo):
63        logging.debug("Ignoring app info data from hubId %s: %s", self.hub_id, appInfo)
64        self.event.set()
65
66
67class ContexthubHidlTest(base_test.BaseTestClass):
68    """A set of test cases for the context hub HIDL HAL"""
69
70    def setUpClass(self):
71        """Creates a mirror and turns on the framework-layer CONTEXTHUB service."""
72        self.dut = self.registerController(android_device)[0]
73
74        self.dut.shell.InvokeTerminal("one")
75        self.dut.shell.one.Execute("setenforce 0")  # SELinux permissive mode
76        if not precondition_utils.CanRunHidlHalTest(
77            self, self.dut, self.dut.shell.one):
78            self._skip_all_testcases = True
79            return
80
81        if self.profiling.enabled:
82            self.profiling.EnableVTSProfiling(self.dut.shell.one)
83
84        # Bring down the Android runtime so it doesn't interfere with the test
85        #self.dut.shell.one.Execute("stop")
86
87        self.dut.hal.InitHidlHal(
88            target_type="contexthub",
89            target_basepaths=self.dut.libPaths,
90            target_version=1.0,
91            target_package="android.hardware.contexthub",
92            target_component_name="IContexthub",
93            hw_binder_service_name="contexthub",
94            bits=int(self.abi_bitness))
95
96        self.types = self.dut.hal.contexthub.GetHidlTypeInterface("types")
97        logging.info("types: %s", self.types)
98
99    def tearDownClass(self):
100        # Restart the Android runtime
101        #self.dut.shell.one.Execute("start")
102        if not self._skip_all_testcases and self.profiling.enabled:
103            self.profiling.ProcessAndUploadTraceData()
104
105    def tearDown(self):
106        """Process trace data.
107        """
108        if self.profiling.enabled:
109            self.profiling.ProcessTraceDataForTestCase(self.dut)
110            self.profiling.DisableVTSProfiling(self.dut.shell.one)
111
112    def testContexthubBasic(self):
113        logging.info("About to call gethubs!!!")
114        hubs = self.dut.hal.contexthub.getHubs()
115        logging.info("Got result: %s", hubs)
116        #
117        #hub_id = 0 # TODO: should get this from hub list
118        #
119        #cb = ContextHubCallback(hub_id)
120        #client_callback = self.dut.hal.contexthub.GetHidlCallbackInterface(
121        #    "IContexthubCallback",
122        #    handleClientMsg=cb.ignore_client_msg,
123        #    handleTxnResult=cb.ignore_txn_result,
124        #    handleHubEvent=cb.ignore_hub_event,
125        #    handleAppsInfo=cb.ignore_apps_info)
126        #
127        #logging.info("About to call registerCallback")
128        #result = self.dut.hal.contexthub.registerCallback(hub_id,
129        #                                                  client_callback)
130        #logging.info("registerCallback returned result: %s", result)
131        #
132        #logging.info("About to call queryApps")
133        #result = self.dut.hal.contexthub.queryApps(hub_id)
134        #logging.info("queryApps returned result: %s", result)
135        #
136        #got_callback = cb.wait_on_callback(5)
137        #logging.info("Wait on callback returned %s", got_callback)
138
139if __name__ == "__main__":
140    test_runner.main()
141