Keun Soo Yim | 9b3b7b9 | 2017-02-03 13:40:21 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env python3.4 |
| 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 | |
| 18 | import logging |
| 19 | import time |
| 20 | |
| 21 | from vts.runners.host import asserts |
| 22 | from vts.runners.host import base_test_with_webdb |
| 23 | from vts.runners.host import test_runner |
| 24 | from vts.utils.python.controllers import android_device |
| 25 | from vts.utils.python.coverage import coverage_utils |
| 26 | |
| 27 | PASSTHROUGH_MODE_KEY = "passthrough_mode" |
| 28 | |
| 29 | |
| 30 | class NfcHidlBasicTest(base_test_with_webdb.BaseTestWithWebDbClass): |
| 31 | """A simple testcase for the NFC HIDL HAL.""" |
| 32 | |
| 33 | def setUpClass(self): |
| 34 | """Creates a mirror and turns on the framework-layer NFC service.""" |
| 35 | self.dut = self.registerController(android_device)[0] |
| 36 | |
| 37 | self.getUserParams(opt_param_names=[PASSTHROUGH_MODE_KEY]) |
| 38 | |
| 39 | self.dut.shell.InvokeTerminal("one") |
| 40 | self.dut.shell.one.Execute("setenforce 0") # SELinux permissive mode |
| 41 | self.dut.shell.one.Execute("svc nfc disable") # Turn off |
| 42 | time.sleep(5) |
| 43 | |
| 44 | if getattr(self, PASSTHROUGH_MODE_KEY, True): |
| 45 | self.dut.shell.one.Execute( |
| 46 | "setprop vts.hal.vts.hidl.get_stub true") |
| 47 | else: |
| 48 | self.dut.shell.one.Execute( |
| 49 | "setprop vts.hal.vts.hidl.get_stub false") |
| 50 | |
| 51 | self.dut.hal.InitHidlHal( |
| 52 | target_type="nfc", |
| 53 | target_basepaths=self.dut.libPaths, |
| 54 | target_version=1.0, |
| 55 | target_package="android.hardware.nfc", |
| 56 | target_component_name="INfc", |
| 57 | bits=64 if self.dut.is64Bit else 32) |
| 58 | |
| 59 | def tearDownClass(self): |
| 60 | """Turns off the framework-layer NFC service.""" |
| 61 | # Ideally, we would want to store the nfc service's state before |
| 62 | # turning that off in setUpClass and restore the original state. |
| 63 | self.dut.shell.one.Execute("svc nfc disable") # make sure it's off |
| 64 | |
| 65 | def testBase(self): |
| 66 | """A simple test case which just calls each registered function.""" |
| 67 | # TODO: extend to make realistic testcases |
| 68 | # For example, call after CORE_INIT_RSP is received. |
| 69 | # result = self.dut.hal.nfc.coreInitialized([1]) |
| 70 | # logging.info("coreInitialized result: %s", result) |
| 71 | |
| 72 | def send_event(NfcEvent, NfcStatus): |
| 73 | logging.info("callback send_event") |
| 74 | logging.info("arg0 %s", NfcEvent) |
| 75 | logging.info("arg1 %s", NfcStatus) |
| 76 | |
| 77 | def send_data(NfcData): |
| 78 | logging.info("callback send_data") |
| 79 | logging.info("arg0 %s", NfcData) |
| 80 | |
| 81 | client_callback = self.dut.hal.nfc.GetHidlCallbackInterface( |
| 82 | "INfcClientCallback", |
| 83 | sendEvent=send_event, |
| 84 | sendData=send_data) |
| 85 | |
| 86 | result = self.dut.hal.nfc.open(client_callback) |
| 87 | logging.info("open result: %s", result) |
| 88 | |
| 89 | result = self.dut.hal.nfc.prediscover() |
| 90 | logging.info("prediscover result: %s", result) |
| 91 | |
| 92 | result = self.dut.hal.nfc.controlGranted() |
| 93 | logging.info("controlGranted result: %s", result) |
| 94 | |
| 95 | result = self.dut.hal.nfc.powerCycle() |
| 96 | logging.info("powerCycle result: %s", result) |
| 97 | |
| 98 | nfc_types = self.dut.hal.nfc.GetHidlTypeInterface("types") |
| 99 | logging.info("nfc_types: %s", nfc_types) |
| 100 | |
| 101 | result = self.dut.hal.nfc.write([0, 1, 2, 3, 4, 5]) |
| 102 | logging.info("write result: %s", result) |
| 103 | |
| 104 | result = self.dut.hal.nfc.close() |
| 105 | logging.info("close result: %s", result) |
| 106 | |
| 107 | self.SetCoverageData(coverage_utils.GetGcdaDict(self.dut)) |
| 108 | |
| 109 | if __name__ == "__main__": |
| 110 | test_runner.main() |