@@ -3578,40 +3578,63 @@ def test_no_exit_runtime_warnings_flush(self):
3578
3578
# check we warn if there is unflushed info
3579
3579
create_file ('code.c' , r'''
3580
3580
#include <stdio.h>
3581
+ #include <emscripten/emscripten.h>
3581
3582
int main(int argc, char **argv) {
3582
3583
printf("hello\n");
3583
3584
printf("world"); // no newline, not flushed
3584
3585
#if FLUSH
3585
3586
printf("\n");
3586
3587
#endif
3588
+ #if KEEPALIVE
3589
+ emscripten_exit_with_live_runtime();
3590
+ #endif
3587
3591
}
3588
3592
''' )
3589
3593
create_file ('code.cpp' , r'''
3590
3594
#include <iostream>
3595
+ #include <emscripten/emscripten.h>
3591
3596
int main() {
3592
3597
using namespace std;
3593
3598
cout << "hello" << std::endl;
3594
3599
cout << "world"; // no newline, not flushed
3595
3600
#if FLUSH
3596
3601
std::cout << std::endl;
3597
3602
#endif
3603
+ #if KEEPALIVE
3604
+ emscripten_exit_with_live_runtime();
3605
+ #endif
3598
3606
}
3599
3607
''' )
3600
- for compiler , src in [(EMCC , 'code.c' ), (EMXX , 'code.cpp' )]:
3608
+ warning = 'stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1'
3609
+
3610
+ def test (cxx , no_exit , assertions , flush , keepalive ):
3611
+ if cxx :
3612
+ cmd = [EMXX , 'code.cpp' ]
3613
+ else :
3614
+ cmd = [EMCC , 'code.c' ]
3615
+ # TODO: also check FILESYSTEM=0 here. it never worked though, buffered output was not emitted at shutdown
3616
+ print ('%s: no_exit=%d assertions=%d flush=%d keepalive=%d' % (cmd [1 ], no_exit , assertions , flush , keepalive ))
3617
+ cmd += ['-sEXIT_RUNTIME=%d' % (1 - no_exit ), '-sASSERTIONS=%d' % assertions ]
3618
+ if flush :
3619
+ cmd += ['-DFLUSH' ]
3620
+ if keepalive :
3621
+ cmd += ['-DKEEPALIVE' ]
3622
+ self .run_process (cmd )
3623
+ output = self .run_js ('a.out.js' )
3624
+ exit = 1 - no_exit
3625
+ self .assertContained ('hello' , output )
3626
+ self .assertContainedIf ('world' , output , exit or flush )
3627
+ self .assertContainedIf (warning , output , no_exit and assertions and not flush and not keepalive )
3628
+
3629
+ # Run just one test with KEEPALIVE set. In this case we don't expect to see any kind
3630
+ # of warning becasue we are explictly requesting the runtime stay alive for later use.
3631
+ test (cxx = 0 , no_exit = 1 , assertions = 1 , flush = 0 , keepalive = 1 )
3632
+
3633
+ for cxx in [0 , 1 ]:
3601
3634
for no_exit in [0 , 1 ]:
3602
3635
for assertions in [0 , 1 ]:
3603
3636
for flush in [0 , 1 ]:
3604
- # TODO: also check FILESYSTEM=0 here. it never worked though, buffered output was not emitted at shutdown
3605
- print (src , no_exit , assertions , flush )
3606
- cmd = [compiler , src , '-sEXIT_RUNTIME=%d' % (1 - no_exit ), '-sASSERTIONS=%d' % assertions ]
3607
- if flush :
3608
- cmd += ['-DFLUSH' ]
3609
- self .run_process (cmd )
3610
- output = self .run_js ('a.out.js' )
3611
- exit = 1 - no_exit
3612
- self .assertContained ('hello' , output )
3613
- assert ('world' in output ) == (exit or flush ), 'unflushed content is shown only when exiting the runtime'
3614
- assert (no_exit and assertions and not flush ) == ('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1' in output ), 'warning should be shown'
3637
+ test (cxx , no_exit , assertions , flush , 0 )
3615
3638
3616
3639
def test_fs_after_main (self ):
3617
3640
for args in [[], ['-O1' ]]:
0 commit comments