Closed Bug 1567341 Opened 5 years ago Closed 4 years ago

Run GeckoView xpcshell tests in Android service

Categories

(GeckoView :: General, enhancement, P1)

enhancement

Tracking

(firefox89 fixed)

RESOLVED FIXED
89 Branch
Tracking Status
firefox89 --- fixed

People

(Reporter: CuveeHsu, Assigned: agi)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [geckoview:m82][geckoview:m87][geckoview:m88])

Attachments

(24 files, 4 obsolete files)

(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details

bug 1567097 comment 0 (a)

FWIW, all */unit_ipc/xpcshell.ini disable android.

Junior, could you work on this when possible (P2)?

Assignee: nobody → juhsu
Priority: P3 → P2

The crash stack is:

mozilla::jni::GetEnvForThread() 
mozilla::ipc::AndroidProcessLauncher::DoLaunch()
mozilla::ipc::BaseProcessLauncher::PerformAsyncLaunch()

which is triggered by BaseProcessLauncher::Launch
and initial from the stack:

GeckoChildProcessHost::AsyncLaunch
mozilla::ipc::GeckoChildProcessHost::LaunchAndWaitForProcessHandle
mozilla::dom::ContentParent::LaunchSubprocessInternal
mozilla::dom::ContentParent::LaunchSubprocessSync
mozilla::dom::ContentParent::GetNewOrUsedBrowserProcess
GetOrCreateTestShellParent
XRE_SendTestShellCommand

whose root is javascript sendCommand in test https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/testing/xpcshell/head.js#1320

That is, we need to set the JNIEnv if we want to launch a child process.
Currently we set the environment only for native launch through GeckoStart for parent process or XRE_SetAndroidChildFds for child process.
https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/mozglue/android/APKOpen.cpp#370-386

But I'm not familiar with xpcshell-test setup in android.

Hello :snorp,
Do you (or someone else) know where might be the best place to set the JNIEnv for xpcshell-test?
Thanks!

Flags: needinfo?(snorp)

xpcshell doesn't have a Dalvik VM at all, so we'd need to change that in order to fix this bug. My suggestion would be to host the xpcshell in an Android Service. Probably a pretty decent amount of work.

Flags: needinfo?(snorp)

Thanks :snorp.
Looks like it won't happen in the near future.

Component: Networking → General
Priority: P2 → --
Product: Core → Firefox for Android
Summary: Find a way to setup content process for netwerk/test/unit_ipc/* → setup content process in xpcshell-test /*/unit_ipc/* for fenix
Whiteboard: [necko-triaged]

In bug 1567342 I'll probably need to run nodeJS in a separate Android service, so maybe we could merge these efforts.

Assignee: juhsu → nobody

Only giving this a P3 priority to get it off the Fennec Project Board.

Priority: -- → P3

Raising the priority because this now blocks a P2 bug to re-enable some networking tests for Fenix (a Tier-1 platform).

Priority: P3 → P2

The way forward here is to not run a bare executable on Android, but instead launch Gecko from a Service as we do for the JUnit tests. The steps are roughly:

  1. Create a new Service in org.mozilla.geckoview.test, XPCShellService perhaps?
  2. Make the service instantiate a GeckoRuntime that will somehow end up calling XRE_XPCShellMain(). We don't want xpcshell garbage in the public API, so one way to do this would be a hack that detects a special process name (like :xpcshell) and calls the different entry point. It's also possible that we don't even need a different entry point on Android, since we're already kinda headless.
  3. Fix up the mach to launch this new service instead of running the bare executables. Any arguments we would normally pass can be sent in the Intent to start the service.
Product: Firefox for Android → GeckoView
Flags: needinfo?(honzab.moz)

James (David Bolter doesn't accept ni?), I'm looking for an assignee here, as this blocks a (P2) work to re-enable now Tier-1/Fenix networking xpcshell tests. Can you advice please?

Other option is to give more detailed pointers where to start (a code to duplicate or use as an example perhaps; for the purpose stated in comment 9 by James) and someone from our team could work on this.

Thanks.

Flags: needinfo?(honzab.moz) → needinfo?(snorp)

It's going to be pretty hairy. I think we'll need to try to prioritize this on the GV team. We probably need Emily for that.

Flags: needinfo?(snorp) → needinfo?(etoop)
Flags: needinfo?(etoop)
Whiteboard: [geckoview:m76]

proposed for GV76 sprint

Whiteboard: [geckoview:m76]
Summary: setup content process in xpcshell-test /*/unit_ipc/* for fenix → Run GeckoView xpcshell tests in Android service

I changed the summary to reflect how we're really treating this bug -- we need to run the xpcshell tests in an Android service in order for e10s to work.

Whiteboard: [geckoview:m79]
Priority: P2 → P1
Whiteboard: [geckoview:m79]
Priority: P1 → P2
Whiteboard: [geckoview:m81]
Whiteboard: [geckoview:m81] → [geckoview:m82]
Blocks: 1350559
Whiteboard: [geckoview:m82] → [geckoview:m82][geckoview:m87]
Assignee: nobody → agi
Priority: P2 → P1
Whiteboard: [geckoview:m82][geckoview:m87] → [geckoview:m82][geckoview:m87][geckoview:m88]

We don't need to initialize SafeBrowsing immediately at startup and we can
wait until the InitLater stage.

This has the added benefit of not crashing xpcshell-test which doesn't have
SafeBrowsing support.

Sending arguments in one string breaks arguments that contain a space, e.g. in
xpcshell-test.

nsBaseAppShell already listens to xpcom-shutdown and calls |Exit| when it
receives it so we don't need to also listen for it in nsAppShell (which causes
two calls to xpcom-shutdown instead of one).

This is consistent to geckoview-junit and mochitest.

This commit adds a new command line option |-xpcshell| that, when passed, will
run an xpcshell instead of launching a full Gecko instance.

This command line option is restricted to org.mozilla.geckoview.test for now,
as it's really hard to use and not really a usecase outside mozilla. We can
revisit this if there's interest.

This service, based off of TestRunnerActivity, can be used to run an
xpcshell-test instance.

It supports up to 10 concurrent instances, although we can add more if we need
to.

Local testing indicates that with more than 4 concurrent instances there's not
gain in test running performance.

This also adds a new intent action
|org.mozilla.geckoview.test.XPCSHELL_TEST_MAIN| that can be used by the test
harness to start the main application and gain foreground priority without
starting Gecko (which would interfere with the xpcshell runner services).

This is done so that xpcshell-test runs with a Dalvik VM and has access to all
the java-implemented bits of GeckoView.

When getting the *-extension-installed messages we should always notify
GeckoViewWebExtension.

This currently works because we always install the test support extension which
causes us to initialize GeckoViewWebExtension. On xpcshel tests, however, there
is no support extension so we need to account for that in GeckoViewStartup.

There is a little Woodoo in this patch but here it is:

  • According to the Android docs, services that implement onStartService are
    not considered bound services and need to stop themselves. Since we do want
    our child processes to die after every client unbounds, we shouldn't implement
    it.
  • Sometimes processes don't die after |onDestroy| is called, this causes
    processes being reused on some esoteric edge case (multiple runtimes, mostly).
    To avoid these corner cases, we call System.exit in onDestroy. Note: chromium
    does this too.
  • We now don't need to kill the process on onBind anymore (this is mostly to
    align with chromium).
  • We make sure we don't get created multiple times, as that could cause really
    weird behavior which is hard to debug (especially on users' devices).

For tests, we want to be able to run multiple runtimes at the same time (each
runtime gets its own process).

This mostly work, except our process allocator does not currently check that it
owns a certain process and it will happily try to take control of a different
runtime's process (and fail).

To make this work we tag each content process with the parent process' UUID so
that we can check whether the process that we try to create is free or not.

This strategy is pretty rudimental and we can iteratively improve on it if we
decide to use multiple runtimes on actual apps (and not just tests).

Attached file Bug 1567341 - Improve bind error logging. (obsolete) (deleted) —

This error is sent to the native layer so we never log it (at least locally).

This also adds a "cause" exception to have the full stacktrace.

Comment on attachment 9208422 [details]
Bug 1567341 - Ensure GeckoServiceChildProcess is treated as a bound service.

Revision D108036 was moved to bug 1696460. Setting attachment 9208422 [details] to obsolete.

Attachment #9208422 - Attachment is obsolete: true

Comment on attachment 9208423 [details]
Bug 1567341 - Allow multiple runtimes to run at the same time.

Revision D108037 was moved to bug 1696460. Setting attachment 9208423 [details] to obsolete.

Attachment #9208423 - Attachment is obsolete: true

Comment on attachment 9208424 [details]
Bug 1567341 - Improve bind error logging.

Revision D108038 was moved to bug 1696460. Setting attachment 9208424 [details] to obsolete.

Attachment #9208424 - Attachment is obsolete: true
Attachment #9204984 - Attachment description: Bug 1567341 - Allow specifing cwd on Android via env variable → Bug 1567341 - Add _TEST_CWD to xpcshell's head.js file.
Attachment #9204978 - Attachment description: Bug 1567341 - Add -o outputfile parameter to xpcshell. → Bug 1567341 - Add outFile parameter to XREShellData.
Attachment #9204978 - Attachment description: Bug 1567341 - Add outFile parameter to XREShellData. → Bug 1567341 - Add outFile, errFile parameters to XREShellData.

On Android we kill the content process when receiving |MarkAsDead|. This means
that the shutdown sequence races with killing the content process, as sometimes
the content process is killed before it has a chance to complete the shutdown
sequence and notify the parent process.

To avoid test timeouts we remove the shutdown blockers instead.

The code as written does not remove the connection from both
mContentConnections and mNonStartedContentConnections since && short circuits.

Since the connection is always present in mContentConnections, we just check
that.

Blocks: 1700482
Attachment #9210428 - Attachment is obsolete: true
Pushed by asferro@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d72accc274ac Initialize SafeBrowsing in geckoview.js. r=esawin https://hg.mozilla.org/integration/autoland/rev/dcb1ae146475 Add outFile, errFile parameters to XREShellData. r=jmaher https://hg.mozilla.org/integration/autoland/rev/ea84b5749a27 Properly initialize GeckoView in xpcshell-test. r=jmaher https://hg.mozilla.org/integration/autoland/rev/5a839d5e3e33 Remove unused serviceManager argument. r=mccr8 https://hg.mozilla.org/integration/autoland/rev/1cdd95c43416 Release EventDispatcher listeners on xpcom-shutdown. r=esawin https://hg.mozilla.org/integration/autoland/rev/9fb892955a88 Wait for the AddonManager to start up in GeckoViewWebExtension. r=esawin https://hg.mozilla.org/integration/autoland/rev/55652f6af6ed Initialize GeckoViewWebExtensions when getting extension-installed. r=esawin https://hg.mozilla.org/integration/autoland/rev/1d93ba23f809 Add launch_service to adb.py. r=firefox-build-system-reviewers,gbrown,mhentges https://hg.mozilla.org/integration/autoland/rev/9d1f27796a97 Add _TEST_CWD to xpcshell's head.js file. r=jmaher https://hg.mozilla.org/integration/autoland/rev/e3df748ed62f Send arguments using array instead of one string in adb.py. r=firefox-build-system-reviewers,mhentges,owlish https://hg.mozilla.org/integration/autoland/rev/c422ca4207ea Don't listen to xpcom-shutdown twice in nsAppShell. r=esawin https://hg.mozilla.org/integration/autoland/rev/6c104f865540 Add --no-install to xpcshell-test for Android. r=firefox-build-system-reviewers,nalexander https://hg.mozilla.org/integration/autoland/rev/3dc62863a028 Allow geckoview.test to run xpcshell. r=esawin https://hg.mozilla.org/integration/autoland/rev/9e8ea542b51e Add XpcshellTestRunnerService. r=owlish https://hg.mozilla.org/integration/autoland/rev/ec25c2df380e Run xpcshell-test in a service on Android. r=firefox-build-system-reviewers,mhentges https://hg.mozilla.org/integration/autoland/rev/f9ba384bb407 Re enable netwerk/test/unit_ipc/xpcshell.ini on Android. r=necko-reviewers,valentin https://hg.mozilla.org/integration/autoland/rev/c34928580933 Re-enable antitracking xpcshell. r=baku https://hg.mozilla.org/integration/autoland/rev/9dca635e41d7 Kill child process when Gecko exits. r=aklotz https://hg.mozilla.org/integration/autoland/rev/0dc0bfedc042 Fix typo in removeContentConnection. r=aklotz https://hg.mozilla.org/integration/autoland/rev/b6eb111329f3 Generate content process ID randomly. r=aklotz https://hg.mozilla.org/integration/autoland/rev/73a4ae419261 Unbind with a busy connection before trying a new one. r=aklotz https://hg.mozilla.org/integration/autoland/rev/1185cabd94e0 Use UUID IDs for isolated processes. r=aklotz https://hg.mozilla.org/integration/autoland/rev/62d24a3e5e33 Disable failing tests in netwerk/test/unit. r=necko-reviewers,kershaw https://hg.mozilla.org/integration/autoland/rev/deb795c7d0ed Disable failing tests in extensions/test/xpcshell. r=robwu

Backed out 24 changesets (bug 1567341) for causing xpcshell failures in test_telemetry.js
Backout link: https://hg.mozilla.org/integration/autoland/rev/c83c94d1986637661ff52d0beb24b4c94a6cd887
Push with failures, failure log.

Flags: needinfo?(agi)
Pushed by asferro@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/efb6cf38264e Initialize SafeBrowsing in geckoview.js. r=esawin https://hg.mozilla.org/integration/autoland/rev/dbc4f44ee10a Add outFile, errFile parameters to XREShellData. r=jmaher https://hg.mozilla.org/integration/autoland/rev/e755ef39a0ee Properly initialize GeckoView in xpcshell-test. r=jmaher https://hg.mozilla.org/integration/autoland/rev/e50020363a1c Remove unused serviceManager argument. r=mccr8 https://hg.mozilla.org/integration/autoland/rev/b2b2eaa9a75f Release EventDispatcher listeners on xpcom-shutdown. r=esawin https://hg.mozilla.org/integration/autoland/rev/072597b667ec Wait for the AddonManager to start up in GeckoViewWebExtension. r=esawin https://hg.mozilla.org/integration/autoland/rev/303fda21f7c0 Initialize GeckoViewWebExtensions when getting extension-installed. r=esawin https://hg.mozilla.org/integration/autoland/rev/2e1e1ec91eb8 Add launch_service to adb.py. r=firefox-build-system-reviewers,gbrown,mhentges https://hg.mozilla.org/integration/autoland/rev/8980d58216bc Add _TEST_CWD to xpcshell's head.js file. r=jmaher https://hg.mozilla.org/integration/autoland/rev/0e4b4e8cdb69 Send arguments using array instead of one string in adb.py. r=firefox-build-system-reviewers,mhentges,owlish https://hg.mozilla.org/integration/autoland/rev/c2a0b0be6c7d Don't listen to xpcom-shutdown twice in nsAppShell. r=esawin https://hg.mozilla.org/integration/autoland/rev/9b55527ca451 Add --no-install to xpcshell-test for Android. r=firefox-build-system-reviewers,nalexander https://hg.mozilla.org/integration/autoland/rev/c347bab90951 Allow geckoview.test to run xpcshell. r=esawin https://hg.mozilla.org/integration/autoland/rev/848ba2ab270c Add XpcshellTestRunnerService. r=owlish https://hg.mozilla.org/integration/autoland/rev/0db615460866 Run xpcshell-test in a service on Android. r=firefox-build-system-reviewers,mhentges https://hg.mozilla.org/integration/autoland/rev/f2e031c40335 Re enable netwerk/test/unit_ipc/xpcshell.ini on Android. r=necko-reviewers,valentin https://hg.mozilla.org/integration/autoland/rev/1c8892fce160 Re-enable antitracking xpcshell. r=baku https://hg.mozilla.org/integration/autoland/rev/fc76a1768da4 Kill child process when Gecko exits. r=aklotz https://hg.mozilla.org/integration/autoland/rev/c4aa3900ca76 Fix typo in removeContentConnection. r=aklotz https://hg.mozilla.org/integration/autoland/rev/de0dc03a7073 Generate content process ID randomly. r=aklotz https://hg.mozilla.org/integration/autoland/rev/edb1af92004d Unbind with a busy connection before trying a new one. r=aklotz https://hg.mozilla.org/integration/autoland/rev/2bd1a86b219b Use UUID IDs for isolated processes. r=aklotz https://hg.mozilla.org/integration/autoland/rev/2bb57a8dd29f Disable failing tests in netwerk/test/unit. r=necko-reviewers,kershaw https://hg.mozilla.org/integration/autoland/rev/1b0d3c1d43c7 Disable failing tests in extensions/test/xpcshell. r=robwu

Thanks

Flags: needinfo?(agi)
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 89 Branch
Regressions: 1700775
Regressions: 1558103
Regressions: 1705486
Blocks: 1637975
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: