Skip to content

Commit

Permalink
[test] Remove (broken) EMTEST_BROWSER_PORT test setting (#23113)
Browse files Browse the repository at this point in the history
The `browser_reporting.js` file (which does most of the reporting these
days) was not honoring it anyway. I've never found the need to configure
this in all the years I've been working on emscripten so hopefully we
don't need to bring it back.
  • Loading branch information
sbc100 authored Dec 10, 2024
1 parent d87c1ac commit d5c419f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ Instructions

.. include:: ../../../../../test/test_browser.py
:literal:
:start-after: create_file('main.html',
:end-before: """ % (worker_filename, self.port))
:start-after: create_file('main.html', '''
:end-before: ''' % self.PORT)
:code: html
30 changes: 13 additions & 17 deletions test/browser_reporting.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
var hasModule = typeof Module === 'object' && Module;

/**
* @param {number=} port
*/
function reportResultToServer(result, port) {
port = port || 8888;
var reportingURL = 'http://localhost:8888/';

function reportResultToServer(result) {
if (reportResultToServer.reported) {
// Only report one result per test, even if the test misbehaves and tries to report more.
reportErrorToServer(`excessive reported results, sending ${result}, test will fail`);
Expand All @@ -14,7 +12,7 @@ function reportResultToServer(result, port) {
out(`RESULT: ${result}`);
} else {
let doFetch = typeof origFetch != 'undefined' ? origFetch : fetch;
doFetch(`http://localhost:${port}/report_result?${encodeURIComponent(result)}`).then(() => {
doFetch(`${reportingURL}/report_result?${encodeURIComponent(result)}`).then(() => {
if (typeof window === 'object' && window && hasModule && !Module['pageThrewException']) {
/* for easy debugging, don't close window on failure */
window.close();
Expand All @@ -24,26 +22,24 @@ function reportResultToServer(result, port) {
}

function sendFileToServer(filename, contents) {
fetch(`http://localhost:8888/?file=${encodeURIComponent(filename)}`, {method: "POST", body: contents});
fetch(`${reportingURL}/?file=${encodeURIComponent(filename)}`, {method: "POST", body: contents});
}

/**
* @param {number=} port
*/
function maybeReportResultToServer(result, port) {
if (reportResultToServer.reported) return;
reportResultToServer(result, port);
function maybeReportResultToServer(result) {
if (!reportResultToServer.reported) {
reportResultToServer(result);
}
}

function reportErrorToServer(message) {
if (typeof ENVIRONMENT_IS_NODE !== 'undefined' && ENVIRONMENT_IS_NODE) {
err(message);
} else {
fetch(`http://localhost:8888?stderr=${encodeURIComponent(message)}`);
fetch(`${reportingURL}?stderr=${encodeURIComponent(message)}`);
}
}

function report_error(e) {
function reportTopLevelError(e) {
// MINIMAL_RUNTIME doesn't handle exit or call the below onExit handler
// so we detect the exit by parsing the uncaught exception message.
var message = e.message || e;
Expand All @@ -68,9 +64,9 @@ function report_error(e) {

if (typeof window === 'object' && window) {
window.addEventListener('error', event => {
report_error(event.error || event)
reportTopLevelError(event.error || event)
});
window.addEventListener('unhandledrejection', event => report_error(event.reason));
window.addEventListener('unhandledrejection', event => reportTopLevelError(event.reason));
}

if (hasModule) {
Expand Down
17 changes: 8 additions & 9 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,9 @@ class BrowserCore(RunnerCore):
# suite early, as otherwise we will wait for the timeout on every
# single test (hundreds of minutes)
MAX_UNRESPONSIVE_TESTS = 10
PORT = 8888
HARNESS_URL = 'http://localhost:%s/run_harness' % PORT
BROWSER_TIMEOUT = 60

unresponsive_tests = 0

Expand All @@ -2091,7 +2094,7 @@ def browser_restart(cls):
logger.info('Browser did not respond to `terminate`. Using `kill`')
cls.browser_proc.kill()
cls.browser_proc.wait()
cls.browser_open(cls.harness_url)
cls.browser_open(cls.HARNESS_URL)

@classmethod
def browser_open(cls, url):
Expand All @@ -2106,17 +2109,14 @@ def browser_open(cls, url):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.port = int(os.getenv('EMTEST_BROWSER_PORT', '8888'))
if not has_browser() or EMTEST_BROWSER == 'node':
return
cls.browser_timeout = 60
cls.harness_in_queue = multiprocessing.Queue()
cls.harness_out_queue = multiprocessing.Queue()
cls.harness_server = multiprocessing.Process(target=harness_server_func, args=(cls.harness_in_queue, cls.harness_out_queue, cls.port))
cls.harness_server = multiprocessing.Process(target=harness_server_func, args=(cls.harness_in_queue, cls.harness_out_queue, cls.PORT))
cls.harness_server.start()
print('[Browser harness server on process %d]' % cls.harness_server.pid)
cls.harness_url = 'http://localhost:%s/run_harness' % cls.port
cls.browser_open(cls.harness_url)
cls.browser_open(cls.HARNESS_URL)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -2158,11 +2158,11 @@ def run_browser(self, html_file, expected=None, message=None, timeout=None, extr
if expected is not None:
try:
self.harness_in_queue.put((
'http://localhost:%s/%s' % (self.port, html_file),
'http://localhost:%s/%s' % (self.PORT, html_file),
self.get_dir()
))
if timeout is None:
timeout = self.browser_timeout
timeout = self.BROWSER_TIMEOUT
try:
output = self.harness_out_queue.get(block=True, timeout=timeout)
except queue.Empty:
Expand Down Expand Up @@ -2213,7 +2213,6 @@ def compile_btest(self, filename, args, reporting=Reporting.FULL):
# If C reporting (i.e. the REPORT_RESULT macro) is required we
# also include report_result.c and force-include report_result.h
self.run_process([EMCC, '-c', '-I' + TEST_ROOT,
'-DEMTEST_PORT_NUMBER=%d' % self.port,
test_file('report_result.c')] + self.get_emcc_args(compile_only=True) + (['-fPIC'] if '-fPIC' in args else []))
args += ['report_result.o', '-include', test_file('report_result.h')]
if EMTEST_BROWSER == 'node':
Expand Down
11 changes: 2 additions & 9 deletions test/report_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ extern "C" {
#endif

#if defined __EMSCRIPTEN__ && !defined EMTEST_NODE
#ifndef EMTEST_PORT_NUMBER
#error "EMTEST_PORT_NUMBER not defined"
#endif

void EMSCRIPTEN_KEEPALIVE _ReportResult(int result) {
EM_ASM({
reportResultToServer($0, $1);
}, result, EMTEST_PORT_NUMBER);
EM_ASM(reportResultToServer($0), result);
}

void EMSCRIPTEN_KEEPALIVE _MaybeReportResult(int result) {
EM_ASM({
maybeReportResultToServer($0, $1);
}, result, EMTEST_PORT_NUMBER);
EM_ASM(maybeReportResultToServer($0), result);
}

#else
Expand Down
10 changes: 5 additions & 5 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ def test_hello_world_worker(self, file_data):
</script>
</body>
</html>
''' % self.port)
''' % self.PORT)

cmd = [EMCC, test_file('hello_world_worker.c'), '-o', 'worker.js'] + self.get_emcc_args()
if file_data:
Expand Down Expand Up @@ -1671,7 +1671,7 @@ def test_chunked_synchronous_xhr(self):
</script>
</body>
</html>
""" % (worker_filename, self.port))
""" % (worker_filename, self.PORT))

create_file('worker_prejs.js', r"""
Module.arguments = ["/bigfile"];
Expand All @@ -1688,7 +1688,7 @@ def test_chunked_synchronous_xhr(self):
data = os.urandom(10 * chunkSize + 1) # 10 full chunks and one 1 byte chunk
checksum = zlib.adler32(data) & 0xffffffff # Python 2 compatibility: force bigint

server = multiprocessing.Process(target=test_chunked_synchronous_xhr_server, args=(True, chunkSize, data, checksum, self.port))
server = multiprocessing.Process(target=test_chunked_synchronous_xhr_server, args=(True, chunkSize, data, checksum, self.PORT))
server.start()

# block until the server is actually ready
Expand Down Expand Up @@ -2422,7 +2422,7 @@ def test_runtime_misuse(self):
doCwrapCall(200);
doDirectCall(300);
}
''' % self.port
''' % self.PORT

create_file('pre_runtime.js', r'''
Module.onRuntimeInitialized = myJSCallback;
Expand Down Expand Up @@ -2569,7 +2569,7 @@ def test_html5_core(self, opts):
window.disableErrorReporting = true;
window.addEventListener('error', (event) => {
if (!event.message.includes('exception:fullscreen error')) {
report_error(event);
reportTopLevelError(event);
}
});
''')
Expand Down

0 comments on commit d5c419f

Please sign in to comment.