Skip to content

Commit 18af894

Browse files
committed
Update to latest emrun.py with argparse and javascript.options.shared_memory retained for testing purposes (emrun is a test harness driver)
1 parent 7d4596e commit 18af894

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

emrun.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# See emrun --help for more information
66

77
from __future__ import print_function
8-
import os, platform, optparse, logging, re, pprint, atexit, subprocess, sys, time, struct, socket, cgi, tempfile, stat, shutil, json, uuid, shlex
8+
import os, platform, argparse, logging, re, pprint, atexit, subprocess, sys, time, struct, socket, cgi, tempfile, stat, shutil, json, uuid, shlex
99
from operator import itemgetter
1010
from threading import Thread, RLock
1111

@@ -285,6 +285,8 @@ def create_emrun_safe_firefox_profile():
285285
user_pref("extensions.getAddons.cache.enabled", false);
286286
// Enable wasm
287287
user_pref("javascript.options.wasm", true);
288+
// Enable SharedArrayBuffer (this profile is for a testing environment, so Spectre/Meltdown don't apply)
289+
user_pref("javascript.options.shared_memory", true);
288290
''')
289291
f.close()
290292
logv('create_emrun_safe_firefox_profile: Created new Firefox profile "' + temp_firefox_profile_dir + '"')
@@ -1231,84 +1233,86 @@ def get_system_info(format_json):
12311233

12321234
def run():
12331235
global browser_process, browser_exe, processname_killed_atexit, emrun_options, emrun_not_enabled_nag_printed, ADB
1234-
usage_str = "usage: emrun [emrun_options] filename.html [html_cmdline_options]\n\n where emrun_options specifies command line options for emrun itself, whereas\n html_cmdline_options specifies startup arguments to the program."
1235-
parser = optparse.OptionParser(usage=usage_str)
1236+
usage_str = "emrun [emrun_options] filename.html [html_cmdline_options]\n\n where emrun_options specifies command line options for emrun itself, whereas\n html_cmdline_options specifies startup arguments to the program."
1237+
parser = argparse.ArgumentParser(usage=usage_str)
12361238

1237-
parser.add_option('--kill_start', dest='kill_on_start', action='store_true', default=False,
1239+
parser.add_argument('--kill_start', dest='kill_on_start', action='store_true', default=False,
12381240
help='If true, any previously running instances of the target browser are killed before starting.')
12391241

1240-
parser.add_option('--kill_exit', dest='kill_on_exit', action='store_true', default=False,
1242+
parser.add_argument('--kill_exit', dest='kill_on_exit', action='store_true', default=False,
12411243
help='If true, the spawned browser process is forcibly killed when it calls exit(). Note: Using this option may require explicitly passing the option --browser=/path/to/browser, to avoid emrun being detached from the browser process it spawns.')
12421244

1243-
parser.add_option('--no_server', dest='no_server', action='store_true', default=False,
1245+
parser.add_argument('--no_server', dest='no_server', action='store_true', default=False,
12441246
help='If specified, a HTTP web server is not launched to host the page to run.')
12451247

1246-
parser.add_option('--no_browser', dest='no_browser', action='store_true', default=False,
1248+
parser.add_argument('--no_browser', dest='no_browser', action='store_true', default=False,
12471249
help='If specified, emrun will not launch a web browser to run the page.')
12481250

1249-
parser.add_option('--no_emrun_detect', dest='no_emrun_detect', action='store_true', default=False,
1251+
parser.add_argument('--no_emrun_detect', dest='no_emrun_detect', action='store_true', default=False,
12501252
help='If specified, skips printing the warning message if html page is detected to not have been built with --emrun linker flag.')
12511253

1252-
parser.add_option('--serve_after_close', dest='serve_after_close', action='store_true', default=False,
1254+
parser.add_argument('--serve_after_close', dest='serve_after_close', action='store_true', default=False,
12531255
help='If true, serves the web page even after the application quits by user closing the web page.')
12541256

1255-
parser.add_option('--serve_after_exit', dest='serve_after_exit', action='store_true', default=False,
1257+
parser.add_argument('--serve_after_exit', dest='serve_after_exit', action='store_true', default=False,
12561258
help='If true, serves the web page even after the application quits by a call to exit().')
12571259

1258-
parser.add_option('--serve_root', dest='serve_root', default='',
1260+
parser.add_argument('--serve_root', dest='serve_root', default='',
12591261
help='If set, specifies the root path that the emrun web server serves. If not specified, the directory where the target .html page lives in is served.')
12601262

1261-
parser.add_option('--verbose', dest='verbose', action='store_true', default=False,
1263+
parser.add_argument('--verbose', dest='verbose', action='store_true', default=False,
12621264
help='Enable verbose logging from emrun internal operation.')
12631265

1264-
parser.add_option('--hostname', dest='hostname', default=default_webserver_hostname,
1266+
parser.add_argument('--hostname', dest='hostname', default=default_webserver_hostname,
12651267
help='Specifies the hostname the server runs in.')
12661268

1267-
parser.add_option('--port', dest='port', default=default_webserver_port, type="int",
1269+
parser.add_argument('--port', dest='port', default=default_webserver_port, type=int,
12681270
help='Specifies the port the server runs in.')
12691271

1270-
parser.add_option('--log_stdout', dest='log_stdout', default='',
1272+
parser.add_argument('--log_stdout', dest='log_stdout', default='',
12711273
help='Specifies a log filename where the browser process stdout data will be appended to.')
12721274

1273-
parser.add_option('--log_stderr', dest='log_stderr', default='',
1275+
parser.add_argument('--log_stderr', dest='log_stderr', default='',
12741276
help='Specifies a log filename where the browser process stderr data will be appended to.')
12751277

1276-
parser.add_option('--silence_timeout', dest='silence_timeout', type="int", default=0,
1278+
parser.add_argument('--silence_timeout', dest='silence_timeout', type=int, default=0,
12771279
help='If no activity is received in this many seconds, the browser process is assumed to be hung, and the web server is shut down and the target browser killed. Disabled by default.')
12781280

1279-
parser.add_option('--timeout', dest='timeout', type="int", default=0,
1281+
parser.add_argument('--timeout', dest='timeout', type=int, default=0,
12801282
help='If the browser process does not quit or the page exit() in this many seconds, the browser is assumed to be hung, and the web server is shut down and the target browser killed. Disabled by default.')
12811283

1282-
parser.add_option('--timeout_returncode', dest='timeout_returncode', type="int", default=99999,
1284+
parser.add_argument('--timeout_returncode', dest='timeout_returncode', type=int, default=99999,
12831285
help='Sets the exit code that emrun reports back to caller in the case that a page timeout occurs. Default: 99999.')
12841286

1285-
parser.add_option('--list_browsers', dest='list_browsers', action='store_true',
1287+
parser.add_argument('--list_browsers', dest='list_browsers', action='store_true',
12861288
help='Prints out all detected browser that emrun is able to use with the --browser command and exits.')
12871289

1288-
parser.add_option('--browser', dest='browser', default='',
1290+
parser.add_argument('--browser', dest='browser', default='',
12891291
help='Specifies the browser executable to run the web page in.')
12901292

1291-
parser.add_option('--browser_args', dest='browser_args', default='',
1293+
parser.add_argument('--browser_args', dest='browser_args', default='',
12921294
help='Specifies the arguments to the browser executable.')
12931295

1294-
parser.add_option('--android', dest='android', action='store_true', default=False,
1296+
parser.add_argument('--android', dest='android', action='store_true', default=False,
12951297
help='Launches the page in a browser of an Android device connected to an USB on the local system. (via adb)')
12961298

1297-
parser.add_option('--system_info', dest='system_info', action='store_true',
1299+
parser.add_argument('--system_info', dest='system_info', action='store_true',
12981300
help='Prints information about the current system at startup.')
12991301

1300-
parser.add_option('--browser_info', dest='browser_info', action='store_true',
1302+
parser.add_argument('--browser_info', dest='browser_info', action='store_true',
13011303
help='Prints information about the target browser to launch at startup.')
13021304

1303-
parser.add_option('--json', dest='json', action='store_true',
1305+
parser.add_argument('--json', dest='json', action='store_true',
13041306
help='If specified, --system_info and --browser_info are outputted in JSON format.')
13051307

1306-
parser.add_option('--safe_firefox_profile', dest='safe_firefox_profile', action='store_true',
1308+
parser.add_argument('--safe_firefox_profile', dest='safe_firefox_profile', action='store_true',
13071309
help='If true, the browser is launched into a new clean Firefox profile that is suitable for unattended automated runs. (If target browser != Firefox, this parameter is ignored)')
13081310

1309-
parser.add_option('--log_html', dest='log_html', action='store_true',
1311+
parser.add_argument('--log_html', dest='log_html', action='store_true',
13101312
help='If set, information lines are printed out an HTML-friendly format.')
13111313

1314+
parser.add_argument('serve', nargs='*')
1315+
13121316
opts_with_param = ['--browser', '--timeout_returncode', '--timeout', '--silence_timeout', '--log_stderr', '--log_stdout', '--hostname', '--port', '--serve_root']
13131317

13141318
cmdlineparams = []
@@ -1324,7 +1328,8 @@ def run():
13241328
break
13251329
i += 1
13261330

1327-
(options, args) = parser.parse_args(sys.argv)
1331+
options = parser.parse_args(sys.argv[1:])
1332+
args = options.serve
13281333
emrun_options = options
13291334

13301335
if options.android:
@@ -1350,10 +1355,10 @@ def run():
13501355
list_pc_browsers()
13511356
return
13521357

1353-
if len(args) < 2 and (options.system_info or options.browser_info):
1358+
if len(args) < 1 and (options.system_info or options.browser_info):
13541359
options.no_server = options.no_browser = True # Don't run if only --system_info or --browser_info was passed.
13551360

1356-
if len(args) < 2 and not (options.no_server == True and options.no_browser == True):
1361+
if len(args) < 1 and not (options.no_server == True and options.no_browser == True):
13571362
logi(usage_str)
13581363
logi('')
13591364
logi('Type emrun --help for a detailed list of available options.')

0 commit comments

Comments
 (0)