mochitest_options.py 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. from abc import ABCMeta, abstractmethod, abstractproperty
  5. from argparse import ArgumentParser, SUPPRESS
  6. from distutils.util import strtobool
  7. from urlparse import urlparse
  8. import json
  9. import os
  10. import tempfile
  11. from mozdevice import DroidADB, DroidSUT
  12. from mozprofile import DEFAULT_PORTS
  13. import mozinfo
  14. import mozlog
  15. import moznetwork
  16. here = os.path.abspath(os.path.dirname(__file__))
  17. try:
  18. from mozbuild.base import (
  19. MozbuildObject,
  20. MachCommandConditions as conditions,
  21. )
  22. build_obj = MozbuildObject.from_environment(cwd=here)
  23. except ImportError:
  24. build_obj = None
  25. conditions = None
  26. def get_default_valgrind_suppression_files():
  27. # We are trying to locate files in the source tree. So if we
  28. # don't know where the source tree is, we must give up.
  29. #
  30. # When this is being run by |mach mochitest --valgrind ...|, it is
  31. # expected that |build_obj| is not None, and so the logic below will
  32. # select the correct suppression files.
  33. #
  34. # When this is run from mozharness, |build_obj| is None, and we expect
  35. # that testing/mozharness/configs/unittests/linux_unittests.py will
  36. # select the correct suppression files (and paths to them) and
  37. # will specify them using the --valgrind-supp-files= flag. Hence this
  38. # function will not get called when running from mozharness.
  39. #
  40. # Note: keep these Valgrind .sup file names consistent with those
  41. # in testing/mozharness/configs/unittests/linux_unittest.py.
  42. if build_obj is None or build_obj.topsrcdir is None:
  43. return []
  44. supps_path = os.path.join(build_obj.topsrcdir, "build", "valgrind")
  45. rv = []
  46. if mozinfo.os == "linux":
  47. if mozinfo.processor == "x86_64":
  48. rv.append(os.path.join(supps_path, "x86_64-redhat-linux-gnu.sup"))
  49. rv.append(os.path.join(supps_path, "cross-architecture.sup"))
  50. elif mozinfo.processor == "x86":
  51. rv.append(os.path.join(supps_path, "i386-redhat-linux-gnu.sup"))
  52. rv.append(os.path.join(supps_path, "cross-architecture.sup"))
  53. return rv
  54. class ArgumentContainer():
  55. __metaclass__ = ABCMeta
  56. @abstractproperty
  57. def args(self):
  58. pass
  59. @abstractproperty
  60. def defaults(self):
  61. pass
  62. @abstractmethod
  63. def validate(self, parser, args, context):
  64. pass
  65. def get_full_path(self, path, cwd):
  66. """Get an absolute path relative to cwd."""
  67. return os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
  68. class MochitestArguments(ArgumentContainer):
  69. """General mochitest arguments."""
  70. FLAVORS = ('a11y', 'browser', 'chrome', 'jetpack-addon', 'jetpack-package', 'plain')
  71. LOG_LEVELS = ("DEBUG", "INFO", "WARNING", "ERROR", "FATAL")
  72. args = [
  73. [["test_paths"],
  74. {"nargs": "*",
  75. "metavar": "TEST",
  76. "default": [],
  77. "help": "Test to run. Can be a single test file or a directory of tests "
  78. "(to run recursively). If omitted, the entire suite is run.",
  79. }],
  80. [["-f", "--flavor"],
  81. {"default": "plain",
  82. "choices": FLAVORS,
  83. "help": "Mochitest flavor to run, one of {}. Defaults to 'plain'.".format(FLAVORS),
  84. "suppress": build_obj is not None,
  85. }],
  86. [["--keep-open"],
  87. {"nargs": "?",
  88. "type": strtobool,
  89. "const": "true",
  90. "default": None,
  91. "help": "Always keep the browser open after tests complete. Or always close the "
  92. "browser with --keep-open=false",
  93. }],
  94. [["--appname"],
  95. {"dest": "app",
  96. "default": None,
  97. "help": "Override the default binary used to run tests with the path provided, e.g "
  98. "/usr/bin/firefox. If you have run ./mach package beforehand, you can "
  99. "specify 'dist' to run tests against the distribution bundle's binary.",
  100. }],
  101. [["--utility-path"],
  102. {"dest": "utilityPath",
  103. "default": build_obj.bindir if build_obj is not None else None,
  104. "help": "absolute path to directory containing utility programs "
  105. "(xpcshell, ssltunnel, certutil)",
  106. "suppress": True,
  107. }],
  108. [["--certificate-path"],
  109. {"dest": "certPath",
  110. "default": None,
  111. "help": "absolute path to directory containing certificate store to use testing profile",
  112. "suppress": True,
  113. }],
  114. [["--no-autorun"],
  115. {"action": "store_false",
  116. "dest": "autorun",
  117. "default": True,
  118. "help": "Do not start running tests automatically.",
  119. }],
  120. [["--timeout"],
  121. {"type": int,
  122. "default": None,
  123. "help": "The per-test timeout in seconds (default: 60 seconds).",
  124. }],
  125. [["--max-timeouts"],
  126. {"type": int,
  127. "dest": "maxTimeouts",
  128. "default": None,
  129. "help": "The maximum number of timeouts permitted before halting testing.",
  130. }],
  131. [["--total-chunks"],
  132. {"type": int,
  133. "dest": "totalChunks",
  134. "help": "Total number of chunks to split tests into.",
  135. "default": None,
  136. }],
  137. [["--this-chunk"],
  138. {"type": int,
  139. "dest": "thisChunk",
  140. "help": "If running tests by chunks, the chunk number to run.",
  141. "default": None,
  142. }],
  143. [["--chunk-by-runtime"],
  144. {"action": "store_true",
  145. "dest": "chunkByRuntime",
  146. "help": "Group tests such that each chunk has roughly the same runtime.",
  147. "default": False,
  148. }],
  149. [["--chunk-by-dir"],
  150. {"type": int,
  151. "dest": "chunkByDir",
  152. "help": "Group tests together in the same chunk that are in the same top "
  153. "chunkByDir directories.",
  154. "default": 0,
  155. }],
  156. [["--run-by-dir"],
  157. {"action": "store_true",
  158. "dest": "runByDir",
  159. "help": "Run each directory in a single browser instance with a fresh profile.",
  160. "default": False,
  161. }],
  162. [["--shuffle"],
  163. {"action": "store_true",
  164. "help": "Shuffle execution order of tests.",
  165. "default": False,
  166. }],
  167. [["--console-level"],
  168. {"dest": "consoleLevel",
  169. "choices": LOG_LEVELS,
  170. "default": "INFO",
  171. "help": "One of {} to determine the level of console logging.".format(
  172. ', '.join(LOG_LEVELS)),
  173. "suppress": True,
  174. }],
  175. [["--bisect-chunk"],
  176. {"dest": "bisectChunk",
  177. "default": None,
  178. "help": "Specify the failing test name to find the previous tests that may be "
  179. "causing the failure.",
  180. }],
  181. [["--start-at"],
  182. {"dest": "startAt",
  183. "default": "",
  184. "help": "Start running the test sequence at this test.",
  185. }],
  186. [["--end-at"],
  187. {"dest": "endAt",
  188. "default": "",
  189. "help": "Stop running the test sequence at this test.",
  190. }],
  191. [["--subsuite"],
  192. {"default": None,
  193. "help": "Subsuite of tests to run. Unlike tags, subsuites also remove tests from "
  194. "the default set. Only one can be specified at once.",
  195. }],
  196. [["--setenv"],
  197. {"action": "append",
  198. "dest": "environment",
  199. "metavar": "NAME=VALUE",
  200. "default": [],
  201. "help": "Sets the given variable in the application's environment.",
  202. }],
  203. [["--exclude-extension"],
  204. {"action": "append",
  205. "dest": "extensionsToExclude",
  206. "default": [],
  207. "help": "Excludes the given extension from being installed in the test profile.",
  208. "suppress": True,
  209. }],
  210. [["--browser-arg"],
  211. {"action": "append",
  212. "dest": "browserArgs",
  213. "default": [],
  214. "help": "Provides an argument to the test application (e.g Firefox).",
  215. "suppress": True,
  216. }],
  217. [["--leak-threshold"],
  218. {"type": int,
  219. "dest": "defaultLeakThreshold",
  220. "default": 0,
  221. "help": "Fail if the number of bytes leaked in default processes through "
  222. "refcounted objects (or bytes in classes with MOZ_COUNT_CTOR and "
  223. "MOZ_COUNT_DTOR) is greater than the given number.",
  224. "suppress": True,
  225. }],
  226. [["--fatal-assertions"],
  227. {"action": "store_true",
  228. "dest": "fatalAssertions",
  229. "default": False,
  230. "help": "Abort testing whenever an assertion is hit (requires a debug build to "
  231. "be effective).",
  232. "suppress": True,
  233. }],
  234. [["--extra-profile-file"],
  235. {"action": "append",
  236. "dest": "extraProfileFiles",
  237. "default": [],
  238. "help": "Copy specified files/dirs to testing profile. Can be specified more "
  239. "than once.",
  240. "suppress": True,
  241. }],
  242. [["--install-extension"],
  243. {"action": "append",
  244. "dest": "extensionsToInstall",
  245. "default": [],
  246. "help": "Install the specified extension in the testing profile. Can be a path "
  247. "to a .xpi file.",
  248. }],
  249. [["--profile-path"],
  250. {"dest": "profilePath",
  251. "default": None,
  252. "help": "Directory where the profile will be stored. This directory will be "
  253. "deleted after the tests are finished.",
  254. "suppress": True,
  255. }],
  256. [["--testing-modules-dir"],
  257. {"dest": "testingModulesDir",
  258. "default": None,
  259. "help": "Directory where testing-only JS modules are located.",
  260. "suppress": True,
  261. }],
  262. [["--repeat"],
  263. {"type": int,
  264. "default": 0,
  265. "help": "Repeat the tests the given number of times.",
  266. }],
  267. [["--run-until-failure"],
  268. {"action": "store_true",
  269. "dest": "runUntilFailure",
  270. "default": False,
  271. "help": "Run tests repeatedly but stop the first time a test fails. Default cap "
  272. "is 30 runs, which can be overridden with the --repeat parameter.",
  273. }],
  274. [["--manifest"],
  275. {"dest": "manifestFile",
  276. "default": None,
  277. "help": "Path to a manifestparser (.ini formatted) manifest of tests to run.",
  278. "suppress": True,
  279. }],
  280. [["--extra-mozinfo-json"],
  281. {"dest": "extra_mozinfo_json",
  282. "default": None,
  283. "help": "Filter tests based on a given mozinfo file.",
  284. "suppress": True,
  285. }],
  286. [["--testrun-manifest-file"],
  287. {"dest": "testRunManifestFile",
  288. "default": 'tests.json',
  289. "help": "Overrides the default filename of the tests.json manifest file that is "
  290. "generated by the harness and used by SimpleTest. Only useful when running "
  291. "multiple test runs simulatenously on the same machine.",
  292. "suppress": True,
  293. }],
  294. [["--dump-tests"],
  295. {"dest": "dump_tests",
  296. "default": None,
  297. "help": "Specify path to a filename to dump all the tests that will be run",
  298. "suppress": True,
  299. }],
  300. [["--failure-file"],
  301. {"dest": "failureFile",
  302. "default": None,
  303. "help": "Filename of the output file where we can store a .json list of failures "
  304. "to be run in the future with --run-only-tests.",
  305. "suppress": True,
  306. }],
  307. [["--run-slower"],
  308. {"action": "store_true",
  309. "dest": "runSlower",
  310. "default": False,
  311. "help": "Delay execution between tests.",
  312. }],
  313. [["--metro-immersive"],
  314. {"action": "store_true",
  315. "dest": "immersiveMode",
  316. "default": False,
  317. "help": "Launches tests in an immersive browser.",
  318. "suppress": True,
  319. }],
  320. [["--httpd-path"],
  321. {"dest": "httpdPath",
  322. "default": None,
  323. "help": "Path to the httpd.js file.",
  324. "suppress": True,
  325. }],
  326. [["--setpref"],
  327. {"action": "append",
  328. "metavar": "PREF=VALUE",
  329. "default": [],
  330. "dest": "extraPrefs",
  331. "help": "Defines an extra user preference.",
  332. }],
  333. [["--jsdebugger"],
  334. {"action": "store_true",
  335. "default": False,
  336. "help": "Start the browser JS debugger before running the test. Implies --no-autorun.",
  337. }],
  338. [["--debug-on-failure"],
  339. {"action": "store_true",
  340. "default": False,
  341. "dest": "debugOnFailure",
  342. "help": "Breaks execution and enters the JS debugger on a test failure. Should "
  343. "be used together with --jsdebugger."
  344. }],
  345. [["--disable-e10s"],
  346. {"action": "store_false",
  347. "default": True,
  348. "dest": "e10s",
  349. "help": "Run tests with electrolysis preferences and test filtering disabled.",
  350. }],
  351. [["--store-chrome-manifest"],
  352. {"action": "store",
  353. "help": "Destination path to write a copy of any chrome manifest "
  354. "written by the harness.",
  355. "default": None,
  356. "suppress": True,
  357. }],
  358. [["--jscov-dir-prefix"],
  359. {"action": "store",
  360. "help": "Directory to store per-test line coverage data as json "
  361. "(browser-chrome only). To emit lcov formatted data, set "
  362. "JS_CODE_COVERAGE_OUTPUT_DIR in the environment.",
  363. "default": None,
  364. "suppress": True,
  365. }],
  366. [["--strict-content-sandbox"],
  367. {"action": "store_true",
  368. "default": False,
  369. "dest": "strictContentSandbox",
  370. "help": "Run tests with a more strict content sandbox (Windows only).",
  371. "suppress": not mozinfo.isWin,
  372. }],
  373. [["--nested_oop"],
  374. {"action": "store_true",
  375. "default": False,
  376. "help": "Run tests with nested_oop preferences and test filtering enabled.",
  377. }],
  378. [["--dmd"],
  379. {"action": "store_true",
  380. "default": False,
  381. "help": "Run tests with DMD active.",
  382. }],
  383. [["--dmd-path"],
  384. {"default": None,
  385. "dest": "dmdPath",
  386. "help": "Specifies the path to the directory containing the shared library for DMD.",
  387. "suppress": True,
  388. }],
  389. [["--dump-output-directory"],
  390. {"default": None,
  391. "dest": "dumpOutputDirectory",
  392. "help": "Specifies the directory in which to place dumped memory reports.",
  393. }],
  394. [["--dump-about-memory-after-test"],
  395. {"action": "store_true",
  396. "default": False,
  397. "dest": "dumpAboutMemoryAfterTest",
  398. "help": "Dump an about:memory log after each test in the directory specified "
  399. "by --dump-output-directory.",
  400. }],
  401. [["--dump-dmd-after-test"],
  402. {"action": "store_true",
  403. "default": False,
  404. "dest": "dumpDMDAfterTest",
  405. "help": "Dump a DMD log after each test in the directory specified "
  406. "by --dump-output-directory.",
  407. }],
  408. [["--slowscript"],
  409. {"action": "store_true",
  410. "default": False,
  411. "help": "Do not set the JS_DISABLE_SLOW_SCRIPT_SIGNALS env variable; "
  412. "when not set, recoverable but misleading SIGSEGV instances "
  413. "may occur in Ion/Odin JIT code.",
  414. }],
  415. [["--screenshot-on-fail"],
  416. {"action": "store_true",
  417. "default": False,
  418. "dest": "screenshotOnFail",
  419. "help": "Take screenshots on all test failures. Set $MOZ_UPLOAD_DIR to a directory "
  420. "for storing the screenshots."
  421. }],
  422. [["--quiet"],
  423. {"action": "store_true",
  424. "dest": "quiet",
  425. "default": False,
  426. "help": "Do not print test log lines unless a failure occurs.",
  427. }],
  428. [["--pidfile"],
  429. {"dest": "pidFile",
  430. "default": "",
  431. "help": "Name of the pidfile to generate.",
  432. "suppress": True,
  433. }],
  434. [["--use-test-media-devices"],
  435. {"action": "store_true",
  436. "default": False,
  437. "dest": "useTestMediaDevices",
  438. "help": "Use test media device drivers for media testing.",
  439. }],
  440. [["--gmp-path"],
  441. {"default": None,
  442. "help": "Path to fake GMP plugin. Will be deduced from the binary if not passed.",
  443. "suppress": True,
  444. }],
  445. [["--xre-path"],
  446. {"dest": "xrePath",
  447. "default": None, # individual scripts will set a sane default
  448. "help": "Absolute path to directory containing XRE (probably xulrunner).",
  449. "suppress": True,
  450. }],
  451. [["--symbols-path"],
  452. {"dest": "symbolsPath",
  453. "default": None,
  454. "help": "Absolute path to directory containing breakpad symbols, or the URL of a "
  455. "zip file containing symbols",
  456. "suppress": True,
  457. }],
  458. [["--debugger"],
  459. {"default": None,
  460. "help": "Debugger binary to run tests in. Program name or path.",
  461. }],
  462. [["--debugger-args"],
  463. {"dest": "debuggerArgs",
  464. "default": None,
  465. "help": "Arguments to pass to the debugger.",
  466. }],
  467. [["--valgrind"],
  468. {"default": None,
  469. "help": "Valgrind binary to run tests with. Program name or path.",
  470. }],
  471. [["--valgrind-args"],
  472. {"dest": "valgrindArgs",
  473. "default": None,
  474. "help": "Comma-separated list of extra arguments to pass to Valgrind.",
  475. }],
  476. [["--valgrind-supp-files"],
  477. {"dest": "valgrindSuppFiles",
  478. "default": None,
  479. "help": "Comma-separated list of suppression files to pass to Valgrind.",
  480. }],
  481. [["--debugger-interactive"],
  482. {"action": "store_true",
  483. "dest": "debuggerInteractive",
  484. "default": None,
  485. "help": "Prevents the test harness from redirecting stdout and stderr for "
  486. "interactive debuggers.",
  487. "suppress": True,
  488. }],
  489. [["--tag"],
  490. {"action": "append",
  491. "dest": "test_tags",
  492. "default": None,
  493. "help": "Filter out tests that don't have the given tag. Can be used multiple "
  494. "times in which case the test must contain at least one of the given tags.",
  495. }],
  496. [["--enable-cpow-warnings"],
  497. {"action": "store_true",
  498. "dest": "enableCPOWWarnings",
  499. "help": "Enable logging of unsafe CPOW usage, which is disabled by default for tests",
  500. "suppress": True,
  501. }],
  502. [["--marionette"],
  503. {"default": None,
  504. "help": "host:port to use when connecting to Marionette",
  505. }],
  506. [["--marionette-port-timeout"],
  507. {"default": None,
  508. "help": "Timeout while waiting for the marionette port to open.",
  509. "suppress": True,
  510. }],
  511. [["--marionette-socket-timeout"],
  512. {"default": None,
  513. "help": "Timeout while waiting to receive a message from the marionette server.",
  514. "suppress": True,
  515. }],
  516. [["--marionette-startup-timeout"],
  517. {"default": None,
  518. "help": "Timeout while waiting for marionette server startup.",
  519. "suppress": True,
  520. }],
  521. [["--cleanup-crashes"],
  522. {"action": "store_true",
  523. "dest": "cleanupCrashes",
  524. "default": False,
  525. "help": "Delete pending crash reports before running tests.",
  526. "suppress": True,
  527. }],
  528. [["--websocket-process-bridge-port"],
  529. {"default": "8191",
  530. "dest": "websocket_process_bridge_port",
  531. "help": "Port for websocket/process bridge. Default 8191.",
  532. }],
  533. ]
  534. defaults = {
  535. # Bug 1065098 - The geckomediaplugin process fails to produce a leak
  536. # log for some reason.
  537. 'ignoreMissingLeaks': ["geckomediaplugin"],
  538. 'extensionsToExclude': ['specialpowers'],
  539. # Set server information on the args object
  540. 'webServer': '127.0.0.1',
  541. 'httpPort': DEFAULT_PORTS['http'],
  542. 'sslPort': DEFAULT_PORTS['https'],
  543. 'webSocketPort': '9988',
  544. # The default websocket port is incorrect in mozprofile; it is
  545. # set to the SSL proxy setting. See:
  546. # see https://bugzilla.mozilla.org/show_bug.cgi?id=916517
  547. # args.webSocketPort = DEFAULT_PORTS['ws']
  548. }
  549. def validate(self, parser, options, context):
  550. """Validate generic options."""
  551. # for test manifest parsing.
  552. mozinfo.update({"strictContentSandbox": options.strictContentSandbox})
  553. # for test manifest parsing.
  554. mozinfo.update({"nested_oop": options.nested_oop})
  555. # and android doesn't use 'app' the same way, so skip validation
  556. if parser.app != 'android':
  557. if options.app is None:
  558. if build_obj:
  559. options.app = build_obj.get_binary_path()
  560. else:
  561. parser.error(
  562. "could not find the application path, --appname must be specified")
  563. elif options.app == "dist" and build_obj:
  564. options.app = build_obj.get_binary_path(where='staged-package')
  565. options.app = self.get_full_path(options.app, parser.oldcwd)
  566. if not os.path.exists(options.app):
  567. parser.error("Error: Path {} doesn't exist. Are you executing "
  568. "$objdir/_tests/testing/mochitest/runtests.py?".format(
  569. options.app))
  570. if options.gmp_path is None and options.app and build_obj:
  571. # Need to fix the location of gmp_fake which might not be shipped in the binary
  572. gmp_modules = (
  573. ('gmp-fake', '1.0'),
  574. ('gmp-clearkey', '0.1'),
  575. ('gmp-fakeopenh264', '1.0')
  576. )
  577. options.gmp_path = os.pathsep.join(
  578. os.path.join(build_obj.bindir, *p) for p in gmp_modules)
  579. if options.totalChunks is not None and options.thisChunk is None:
  580. parser.error(
  581. "thisChunk must be specified when totalChunks is specified")
  582. if options.extra_mozinfo_json:
  583. if not os.path.isfile(options.extra_mozinfo_json):
  584. parser.error("Error: couldn't find mozinfo.json at '%s'."
  585. % options.extra_mozinfo_json)
  586. options.extra_mozinfo_json = json.load(open(options.extra_mozinfo_json))
  587. if options.totalChunks:
  588. if not 1 <= options.thisChunk <= options.totalChunks:
  589. parser.error("thisChunk must be between 1 and totalChunks")
  590. if options.chunkByDir and options.chunkByRuntime:
  591. parser.error(
  592. "can only use one of --chunk-by-dir or --chunk-by-runtime")
  593. if options.xrePath is None:
  594. # default xrePath to the app path if not provided
  595. # but only if an app path was explicitly provided
  596. if options.app != parser.get_default('app'):
  597. options.xrePath = os.path.dirname(options.app)
  598. if mozinfo.isMac:
  599. options.xrePath = os.path.join(
  600. os.path.dirname(
  601. options.xrePath),
  602. "Resources")
  603. elif build_obj is not None:
  604. # otherwise default to dist/bin
  605. options.xrePath = build_obj.bindir
  606. else:
  607. parser.error(
  608. "could not find xre directory, --xre-path must be specified")
  609. # allow relative paths
  610. if options.xrePath:
  611. options.xrePath = self.get_full_path(options.xrePath, parser.oldcwd)
  612. if options.profilePath:
  613. options.profilePath = self.get_full_path(options.profilePath, parser.oldcwd)
  614. if options.dmdPath:
  615. options.dmdPath = self.get_full_path(options.dmdPath, parser.oldcwd)
  616. if options.dmd and not options.dmdPath:
  617. if build_obj:
  618. options.dmdPath = build_obj.bindir
  619. else:
  620. parser.error(
  621. "could not find dmd libraries, specify them with --dmd-path")
  622. if options.utilityPath:
  623. options.utilityPath = self.get_full_path(options.utilityPath, parser.oldcwd)
  624. if options.certPath:
  625. options.certPath = self.get_full_path(options.certPath, parser.oldcwd)
  626. elif build_obj:
  627. options.certPath = os.path.join(build_obj.topsrcdir, 'build', 'pgo', 'certs')
  628. if options.symbolsPath and len(urlparse(options.symbolsPath).scheme) < 2:
  629. options.symbolsPath = self.get_full_path(options.symbolsPath, parser.oldcwd)
  630. elif not options.symbolsPath and build_obj:
  631. options.symbolsPath = os.path.join(build_obj.distdir, 'crashreporter-symbols')
  632. if options.jsdebugger:
  633. options.extraPrefs += [
  634. "devtools.debugger.remote-enabled=true",
  635. "devtools.chrome.enabled=true",
  636. "devtools.debugger.prompt-connection=false"
  637. ]
  638. options.autorun = False
  639. if options.debugOnFailure and not options.jsdebugger:
  640. parser.error(
  641. "--debug-on-failure requires --jsdebugger.")
  642. if options.debuggerArgs and not options.debugger:
  643. parser.error(
  644. "--debugger-args requires --debugger.")
  645. if options.valgrind or options.debugger:
  646. # valgrind and some debuggers may cause Gecko to start slowly. Make sure
  647. # marionette waits long enough to connect.
  648. options.marionette_port_timeout = 900
  649. options.marionette_socket_timeout = 540
  650. if options.store_chrome_manifest:
  651. options.store_chrome_manifest = os.path.abspath(options.store_chrome_manifest)
  652. if not os.path.isdir(os.path.dirname(options.store_chrome_manifest)):
  653. parser.error(
  654. "directory for %s does not exist as a destination to copy a "
  655. "chrome manifest." % options.store_chrome_manifest)
  656. if options.jscov_dir_prefix:
  657. options.jscov_dir_prefix = os.path.abspath(options.jscov_dir_prefix)
  658. if not os.path.isdir(options.jscov_dir_prefix):
  659. parser.error(
  660. "directory %s does not exist as a destination for coverage "
  661. "data." % options.jscov_dir_prefix)
  662. if options.testingModulesDir is None:
  663. if build_obj:
  664. options.testingModulesDir = os.path.join(
  665. build_obj.topobjdir, '_tests', 'modules')
  666. else:
  667. # Try to guess the testing modules directory.
  668. # This somewhat grotesque hack allows the buildbot machines to find the
  669. # modules directory without having to configure the buildbot hosts. This
  670. # code should never be executed in local runs because the build system
  671. # should always set the flag that populates this variable. If buildbot ever
  672. # passes this argument, this code can be deleted.
  673. possible = os.path.join(here, os.path.pardir, 'modules')
  674. if os.path.isdir(possible):
  675. options.testingModulesDir = possible
  676. if build_obj:
  677. plugins_dir = os.path.join(build_obj.distdir, 'plugins')
  678. if plugins_dir not in options.extraProfileFiles:
  679. options.extraProfileFiles.append(plugins_dir)
  680. # Even if buildbot is updated, we still want this, as the path we pass in
  681. # to the app must be absolute and have proper slashes.
  682. if options.testingModulesDir is not None:
  683. options.testingModulesDir = os.path.normpath(
  684. options.testingModulesDir)
  685. if not os.path.isabs(options.testingModulesDir):
  686. options.testingModulesDir = os.path.abspath(
  687. options.testingModulesDir)
  688. if not os.path.isdir(options.testingModulesDir):
  689. parser.error('--testing-modules-dir not a directory: %s' %
  690. options.testingModulesDir)
  691. options.testingModulesDir = options.testingModulesDir.replace(
  692. '\\',
  693. '/')
  694. if options.testingModulesDir[-1] != '/':
  695. options.testingModulesDir += '/'
  696. if options.immersiveMode:
  697. if not mozinfo.isWin:
  698. parser.error("immersive is only supported on Windows 8 and up.")
  699. options.immersiveHelperPath = os.path.join(
  700. options.utilityPath, "metrotestharness.exe")
  701. if not os.path.exists(options.immersiveHelperPath):
  702. parser.error("%s not found, cannot launch immersive tests." %
  703. options.immersiveHelperPath)
  704. if options.runUntilFailure:
  705. if not options.repeat:
  706. options.repeat = 29
  707. if options.dumpOutputDirectory is None:
  708. options.dumpOutputDirectory = tempfile.gettempdir()
  709. if options.dumpAboutMemoryAfterTest or options.dumpDMDAfterTest:
  710. if not os.path.isdir(options.dumpOutputDirectory):
  711. parser.error('--dump-output-directory not a directory: %s' %
  712. options.dumpOutputDirectory)
  713. if options.useTestMediaDevices:
  714. if not mozinfo.isLinux:
  715. parser.error(
  716. '--use-test-media-devices is only supported on Linux currently')
  717. for f in ['/usr/bin/gst-launch-0.10', '/usr/bin/pactl']:
  718. if not os.path.isfile(f):
  719. parser.error(
  720. 'Missing binary %s required for '
  721. '--use-test-media-devices' % f)
  722. if options.nested_oop:
  723. options.e10s = True
  724. options.leakThresholds = {
  725. "default": options.defaultLeakThreshold,
  726. "tab": 10000, # See dependencies of bug 1051230.
  727. # GMP rarely gets a log, but when it does, it leaks a little.
  728. "geckomediaplugin": 20000,
  729. }
  730. # XXX We can't normalize test_paths in the non build_obj case here,
  731. # because testRoot depends on the flavor, which is determined by the
  732. # mach command and therefore not finalized yet. Conversely, test paths
  733. # need to be normalized here for the mach case.
  734. if options.test_paths and build_obj:
  735. # Normalize test paths so they are relative to test root
  736. options.test_paths = [build_obj._wrap_path_argument(p).relpath()
  737. for p in options.test_paths]
  738. return options
  739. class AndroidArguments(ArgumentContainer):
  740. """Android specific arguments."""
  741. args = [
  742. [["--remote-app-path"],
  743. {"dest": "remoteAppPath",
  744. "help": "Path to remote executable relative to device root using \
  745. only forward slashes. Either this or app must be specified \
  746. but not both.",
  747. "default": None,
  748. }],
  749. [["--deviceIP"],
  750. {"dest": "deviceIP",
  751. "help": "ip address of remote device to test",
  752. "default": None,
  753. }],
  754. [["--deviceSerial"],
  755. {"dest": "deviceSerial",
  756. "help": "ip address of remote device to test",
  757. "default": None,
  758. }],
  759. [["--dm_trans"],
  760. {"choices": ["adb", "sut"],
  761. "default": "adb",
  762. "help": "The transport to use for communication with the device [default: adb].",
  763. "suppress": True,
  764. }],
  765. [["--adbpath"],
  766. {"dest": "adbPath",
  767. "default": None,
  768. "help": "Path to adb binary.",
  769. "suppress": True,
  770. }],
  771. [["--devicePort"],
  772. {"dest": "devicePort",
  773. "type": int,
  774. "default": 20701,
  775. "help": "port of remote device to test",
  776. }],
  777. [["--remote-product-name"],
  778. {"dest": "remoteProductName",
  779. "default": "fennec",
  780. "help": "The executable's name of remote product to test - either \
  781. fennec or firefox, defaults to fennec",
  782. "suppress": True,
  783. }],
  784. [["--remote-logfile"],
  785. {"dest": "remoteLogFile",
  786. "default": None,
  787. "help": "Name of log file on the device relative to the device \
  788. root. PLEASE ONLY USE A FILENAME.",
  789. }],
  790. [["--remote-webserver"],
  791. {"dest": "remoteWebServer",
  792. "default": None,
  793. "help": "ip address where the remote web server is hosted at",
  794. }],
  795. [["--http-port"],
  796. {"dest": "httpPort",
  797. "default": DEFAULT_PORTS['http'],
  798. "help": "http port of the remote web server",
  799. "suppress": True,
  800. }],
  801. [["--ssl-port"],
  802. {"dest": "sslPort",
  803. "default": DEFAULT_PORTS['https'],
  804. "help": "ssl port of the remote web server",
  805. "suppress": True,
  806. }],
  807. [["--robocop-ini"],
  808. {"dest": "robocopIni",
  809. "default": "",
  810. "help": "name of the .ini file containing the list of tests to run",
  811. }],
  812. [["--robocop-apk"],
  813. {"dest": "robocopApk",
  814. "default": "",
  815. "help": "name of the Robocop APK to use for ADB test running",
  816. }],
  817. [["--remoteTestRoot"],
  818. {"dest": "remoteTestRoot",
  819. "default": None,
  820. "help": "remote directory to use as test root \
  821. (eg. /mnt/sdcard/tests or /data/local/tests)",
  822. "suppress": True,
  823. }],
  824. ]
  825. defaults = {
  826. 'dm': None,
  827. # we don't want to exclude specialpowers on android just yet
  828. 'extensionsToExclude': [],
  829. # mochijar doesn't get installed via marionette on android
  830. 'extensionsToInstall': [os.path.join(here, 'mochijar')],
  831. 'logFile': 'mochitest.log',
  832. 'utilityPath': None,
  833. }
  834. def validate(self, parser, options, context):
  835. """Validate android options."""
  836. if build_obj:
  837. options.log_mach = '-'
  838. device_args = {'deviceRoot': options.remoteTestRoot}
  839. if options.dm_trans == "adb":
  840. device_args['adbPath'] = options.adbPath
  841. if options.deviceIP:
  842. device_args['host'] = options.deviceIP
  843. device_args['port'] = options.devicePort
  844. elif options.deviceSerial:
  845. device_args['deviceSerial'] = options.deviceSerial
  846. options.dm = DroidADB(**device_args)
  847. elif options.dm_trans == 'sut':
  848. if options.deviceIP is None:
  849. parser.error(
  850. "If --dm_trans = sut, you must provide a device IP")
  851. device_args['host'] = options.deviceIP
  852. device_args['port'] = options.devicePort
  853. options.dm = DroidSUT(**device_args)
  854. if not options.remoteTestRoot:
  855. options.remoteTestRoot = options.dm.deviceRoot
  856. if options.remoteWebServer is None:
  857. if os.name != "nt":
  858. options.remoteWebServer = moznetwork.get_ip()
  859. else:
  860. parser.error(
  861. "you must specify a --remote-webserver=<ip address>")
  862. options.webServer = options.remoteWebServer
  863. if options.remoteLogFile is None:
  864. options.remoteLogFile = options.remoteTestRoot + \
  865. '/logs/mochitest.log'
  866. if options.remoteLogFile.count('/') < 1:
  867. options.remoteLogFile = options.remoteTestRoot + \
  868. '/' + options.remoteLogFile
  869. if options.remoteAppPath and options.app:
  870. parser.error(
  871. "You cannot specify both the remoteAppPath and the app setting")
  872. elif options.remoteAppPath:
  873. options.app = options.remoteTestRoot + "/" + options.remoteAppPath
  874. elif options.app is None:
  875. if build_obj:
  876. options.app = build_obj.substs['ANDROID_PACKAGE_NAME']
  877. else:
  878. # Neither remoteAppPath nor app are set -- error
  879. parser.error("You must specify either appPath or app")
  880. if build_obj and 'MOZ_HOST_BIN' in os.environ:
  881. options.xrePath = os.environ['MOZ_HOST_BIN']
  882. # Only reset the xrePath if it wasn't provided
  883. if options.xrePath is None:
  884. options.xrePath = options.utilityPath
  885. if options.pidFile != "":
  886. f = open(options.pidFile, 'w')
  887. f.write("%s" % os.getpid())
  888. f.close()
  889. # Robocop specific options
  890. if options.robocopIni != "":
  891. if not os.path.exists(options.robocopIni):
  892. parser.error(
  893. "Unable to find specified robocop .ini manifest '%s'" %
  894. options.robocopIni)
  895. options.robocopIni = os.path.abspath(options.robocopIni)
  896. if not options.robocopApk and build_obj:
  897. options.robocopApk = os.path.join(build_obj.topobjdir, 'mobile', 'android',
  898. 'tests', 'browser',
  899. 'robocop', 'robocop-debug.apk')
  900. if options.robocopApk != "":
  901. if not os.path.exists(options.robocopApk):
  902. parser.error(
  903. "Unable to find robocop APK '%s'" %
  904. options.robocopApk)
  905. options.robocopApk = os.path.abspath(options.robocopApk)
  906. # Disable e10s by default on Android because we don't run Android
  907. # e10s jobs anywhere yet.
  908. options.e10s = False
  909. mozinfo.update({'e10s': options.e10s})
  910. # allow us to keep original application around for cleanup while
  911. # running robocop via 'am'
  912. options.remoteappname = options.app
  913. return options
  914. container_map = {
  915. 'generic': [MochitestArguments],
  916. 'android': [MochitestArguments, AndroidArguments],
  917. }
  918. class MochitestArgumentParser(ArgumentParser):
  919. """%(prog)s [options] [test paths]"""
  920. _containers = None
  921. context = {}
  922. def __init__(self, app=None, **kwargs):
  923. ArgumentParser.__init__(self, usage=self.__doc__, conflict_handler='resolve', **kwargs)
  924. self.oldcwd = os.getcwd()
  925. self.app = app
  926. if not self.app and build_obj:
  927. if conditions.is_android(build_obj):
  928. self.app = 'android'
  929. if not self.app:
  930. # platform can't be determined and app wasn't specified explicitly,
  931. # so just use generic arguments and hope for the best
  932. self.app = 'generic'
  933. if self.app not in container_map:
  934. self.error("Unrecognized app '{}'! Must be one of: {}".format(
  935. self.app, ', '.join(container_map.keys())))
  936. defaults = {}
  937. for container in self.containers:
  938. defaults.update(container.defaults)
  939. group = self.add_argument_group(container.__class__.__name__, container.__doc__)
  940. for cli, kwargs in container.args:
  941. # Allocate new lists so references to original don't get mutated.
  942. # allowing multiple uses within a single process.
  943. if "default" in kwargs and isinstance(kwargs['default'], list):
  944. kwargs["default"] = []
  945. if 'suppress' in kwargs:
  946. if kwargs['suppress']:
  947. kwargs['help'] = SUPPRESS
  948. del kwargs['suppress']
  949. group.add_argument(*cli, **kwargs)
  950. self.set_defaults(**defaults)
  951. mozlog.commandline.add_logging_group(self)
  952. @property
  953. def containers(self):
  954. if self._containers:
  955. return self._containers
  956. containers = container_map[self.app]
  957. self._containers = [c() for c in containers]
  958. return self._containers
  959. def validate(self, args):
  960. for container in self.containers:
  961. args = container.validate(self, args, self.context)
  962. return args