Closed johnklee closed 1 year ago
I'd avoid using sl4a. Please use Mobly snippets instead.
I create below test case and configuration to deal with this issue:
i748.py
:
import logging
import pprint
from mobly import asserts from mobly import base_test from mobly import test_runner from mobly.controllers import android_device from mobly.controllers.android_device_lib.services import sl4a_service
class HelloWorldTest(base_test.BaseTestClass): ''' See: https://github.com/johnklee/mobly/blob/master/docs/tutorial.md#example-4-multiple-test-beds-and-default-test-parameters ''' def setup_class(self):
# requires at least two Android devices.
self.ads = self.register_controller(android_device)
# The device used to discover Bluetooth devices.
self.dut = android_device.get_device(self.ads, label='dut')
# Sets the tag that represents this device in logs.
self.dut.debug_tag = 'dut'
# Setup MBS (Mobly Bundled Snippet)
self.dut.load_snippet(
'mbs',
'com.google.android.mobly.snippet.bundled'
)
# New: Register SL4A service
self.dut.services.register('sl4a', sl4a_service.Sl4aService)
def setup_test(self):
# Make sure bluetooth is on.
self.dut.mbs.btEnable()
# Set Bluetooth name on target device.
self.dut.mbs.btSetName('IamDUT')
def teardown_test(self):
# Turn Bluetooth off on both devices after test finishes.
self.dut.mbs.btDisable()
if name == 'main': test_runner.main()
* `i748_config.yaml`
```yaml
MoblyParams: {LogPath: /tmp/}
TestBeds:
# A test bed where adb will find Android devices.
- Name: SampleTestBed
Controllers:
AndroidDevice:
- serial: 07311JECB08252
label: dut
TestParams:
search_bluetooth_name: JohnPixel
I add debugging message and obtain below log message:
# python i748.py -c i748_config.yaml
[SampleTestBed] 05-20 05:08:12.899 INFO Test output folder: "/tmp/SampleTestBed/05-20-2021_05-08-12-898"
[SampleTestBed] 05-20 05:08:12.901 INFO ==========> HelloWorldTest <==========
[SampleTestBed] 05-20 05:08:18.750 INFO [AndroidDevice|07311JECB08252] Logging debug tag set to "dut"
[SampleTestBed] 05-20 05:08:20.840 INFO [AndroidDevice|dut] Launching snippet apk com.google.android.mobly.snippet.bundled with protocol 1.0
[10|jsonrpc_client_base|227] Connecting localhost on port=20363
[10|sl4a_service|40] Start service...
[10|jsonrpc_client_base|227] Connecting localhost on port=17019
[10|jsonrpc_client_base|227] Connecting localhost on port=17019
[10|sl4a_client|162] Start event client with host_port=17019; device_port=8080
[10|jsonrpc_client_base|227] Connecting localhost on port=17019
[30|jsonrpc_client_base|272] clear host port of JspRPC(17019)...
[30|jsonrpc_client_base|272] clear host port of JspRPC(17019)...
[30|jsonrpc_client_base|272] clear host port of JspRPC(20363)...
[SampleTestBed] 05-20 05:08:29.047 INFO Summary for test class HelloWorldTest: Error 0, Executed 0, Failed 0, Passed 0, Requested 0, Skipped 0
[SampleTestBed] 05-20 05:08:29.049 INFO Summary for test run SampleTestBed@05-20-2021_05-08-12-898: Error 0, Executed 0, Failed 0, Passed 0, Requested 0, Skipped 0
For somehow, the host port 17019
will be handled twice which leads to this issue. The fix for this issue is to check the existence of the port to be removed before executing adb command as below commit:
https://github.com/johnklee/mobly/commit/e5da1c87f28ced82a66b1f3d5701caa8a9b3698e
If it makes sense here, I will create a PR as well. Many thanks! (Two failed test cases found. I will fix them if this solution is accepted.)
FAILED tests/mobly/controllers/android_device_lib/jsonrpc_client_base_test.py::JsonRpcClientBaseTest::test_clear_host_port_positive FAILED tests/mobly/controllers/android_device_lib/snippet_client_test.py::SnippetClientTest::test_snippet_stop_app_raises - Assertio
Failed test cases are fixed in below commit: https://github.com/johnklee/mobly/commit/382d4542e51678183bde6c8f93e4def0a9fde561
There are a lot of bug fixes in the sl4a client in the AOSP repo. The plan is to update the client here with that one, instead of doing small fixes here.
Understood. Thanks for the update.
Hi @xpconanfan , Is there any update from AOSP repo to fix this issue? Our automation is suffering from it and I am thinking if it is ok for us to have a quick fix for it and then I will work on it?
We have decided to deprecate sl4a support as Mobly snippets can now be used in AOSP repo to gain the same level of access without all the legacy problems of sl4a
I can follow Mobly101 to execute
$ python hello_world_test.py -c sample_config.yml
without issue. But when I updatedhello_world_test.py
to register SL4J service as below:I will get below error:
May need some time to dig in to collect more information. Thanks!