Skip to content

Commit bcc0bb4

Browse files
committed
test: add --interactive tests to test_emrun
Signed-off-by: Kohei Tokunaga <[email protected]>
1 parent 4792683 commit bcc0bb4

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/test_browser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5659,6 +5659,7 @@ def test_program_arg_separator(self):
56595659

56605660
def test_emrun(self):
56615661
self.emcc('test_emrun.c', ['--emrun', '-o', 'test_emrun.html'])
5662+
self.emcc('test_interactive_emrun.c', ['--emrun', '-pthread', '-sPROXY_TO_PTHREAD', '-sEXIT_RUNTIME', '-o', 'test_interactive_emrun.html'])
56625663
if not has_browser():
56635664
self.skipTest('need a browser')
56645665

@@ -5697,6 +5698,7 @@ def test_emrun(self):
56975698
['--private_browsing', '--port', '6941'],
56985699
['--dump_out_directory', 'other dir/multiple', '--port', '6942'],
56995700
['--dump_out_directory=foo_bar', '--port', '6942'],
5701+
['--interactive'],
57005702
]:
57015703
args = args_base + args + [self.in_dir('test_emrun.html'), '--', '1', '2', '--3', 'escaped space', 'with_underscore']
57025704
print(shlex.join(args))
@@ -5721,6 +5723,11 @@ def test_emrun(self):
57215723
self.assertContained('Testing char sequences: %20%21 &auml;', stdout)
57225724
self.assertContained('hello, error stream!', stderr)
57235725

5726+
args = args_base + ['--interactive', self.in_dir('test_interactive_emrun.html')]
5727+
print(shlex.join(args))
5728+
proc = self.run_process(args, check=False, input="hello")
5729+
self.assertEqual(proc.returncode, 100)
5730+
self.assertContained('hello', stdout)
57245731

57255732
class browser64(browser):
57265733
def setUp(self):

test/test_interactive_emrun.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <assert.h>
9+
#include <stdio.h>
10+
#include <unistd.h>
11+
#include <sys/select.h>
12+
#include <stdlib.h>
13+
14+
int main(int argc, char **argv) {
15+
fd_set readfds;
16+
char buf[124];
17+
ssize_t n;
18+
int nr = 0;
19+
20+
while (nr < sizeof(buf)) {
21+
FD_ZERO(&readfds);
22+
FD_SET(STDIN_FILENO, &readfds);
23+
assert(select(STDIN_FILENO + 1, &readfds, NULL, NULL, NULL) == 1);
24+
assert(FD_ISSET(STDIN_FILENO, &readfds));
25+
n = read(STDIN_FILENO, &(buf[nr]), sizeof(buf) - nr);
26+
assert(n >= 0);
27+
if (n == 0) break;
28+
nr += n;
29+
}
30+
31+
printf("%s\n", buf);
32+
33+
exit(0);
34+
}

0 commit comments

Comments
 (0)