Closed Bug 1016307 Opened 11 years ago Closed 6 years ago

[mozdevice] Allow setting device serial using ANDROID_SERIAL environment variable

Categories

(Testing :: Mozbase, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: davehunt, Assigned: gbrown)

Details

At the moment mozdevice allows targeting a specific device using deviceSerial in the instantiation of DeviceManagerADB. This means that any command-line tool that depends on mozdevice must provide a way for the user to specify the device serial when there are multiple devices attached. ADB itself support setting an ANDROID_SERIAL environment variable, which contains the serial number of the device to connect to unless the serial is provided on the command line. Does it make sense to extend the support for this command line argument to mozdevice? This way, anybody using mozdevice directly or indirectly can target a specific device by setting the environment variable.
The device serial is currently set here: http://hg.mozilla.org/mozilla-central/file/cbe4f69c2e9c/testing/mozbase/mozdevice/mozdevice/devicemanagerADB.py#l48 I'm suggesting changing this to something like: self._deviceSerial = os.getenv('ANDROID_SERIAL', deviceSerial)
Flags: needinfo?(wlachance)
Summary: [mozdevice] Allow setting device serial using ANDROID_DEVICE environment variable → [mozdevice] Allow setting device serial using ANDROID_SERIAL environment variable
Hmm, I am not sure if I want to process environment variables inside devicemanagerADB itself as that seems to violate the principle of separation of concerns... I might be persuadable, but let me suggest the alternate idea of exporting something like the dmcli's getDevice inside mozdevice, and using the environment variables there: http://hg.mozilla.org/mozilla-central/file/7618a104e29d/testing/mozbase/mozdevice/mozdevice/dmcli.py#l194 Then each test harness can just use that factory function to get their device object. Does that make sense?
Flags: needinfo?(wlachance)
We already have something similar to this in the Marionette B2G test runner: http://hg.mozilla.org/mozilla-central/file/46c3b9de467a/testing/marionette/client/marionette/runner/mixins/b2g.py#l10 I think exposing something like getDevice in mozdevice sounds good. I suspect however that we're more likely to just add command-line arguments to the various tools for passing the device serial ID.
(In reply to Dave Hunt (:davehunt) from comment #3) > We already have something similar to this in the Marionette B2G test runner: > http://hg.mozilla.org/mozilla-central/file/46c3b9de467a/testing/marionette/ > client/marionette/runner/mixins/b2g.py#l10 > > I think exposing something like getDevice in mozdevice sounds good. I > suspect however that we're more likely to just add command-line arguments to > the various tools for passing the device serial ID. To be clear, I'm fine with processing the environment variable inside this factory function, in fact I think it's a good idea (though I think we should prefer an explicitly set value on the command line to the environment variable, if it's present).
I guess I'm just a little uncertain about writing it myself without fully understanding the implications of SUT and some of the other arguments for getDevice.
(In reply to Dave Hunt (:davehunt) from comment #5) > I guess I'm just a little uncertain about writing it myself without fully > understanding the implications of SUT and some of the other arguments for > getDevice. Let me know if there's anything I can do to clean up the confusion. :) I think copying what you see in dmcli should get you 99% of the way there. Any other problems I should be able to catch in review.
adb.py has good support for device-serial.
Assignee: nobody → gbrown
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
Actually, I just tried this with raptor-test this morning with a physical device and emulator and it borked on me. Perhaps I did it wrong?
mochitest/reftest/robocop and other android harnesses support --deviceSerial, and that works fine, even with multiple devices attached. I don't see any support for --deviceSerial in raptor. $ mach mochitest testing/mochitest/tests/Harness_sanity --deviceSerial=emulator-5554
Right. We can add that to Raptor but I was just commenting about ANDROID_SERIAL. I was going to ask Edwin if he wanted to take that.
You need to log in before you can comment on or make changes to this bug.