21
21
from tools .shared import EXPECTED_LLVM_VERSION , Cache
22
22
from tools import shared , system_libs , utils
23
23
24
- SANITY_FILE = shared .Cache .get_path ('sanity.txt' , root = True )
24
+ SANITY_FILE = shared .Cache .get_path ('sanity.txt' )
25
25
commands = [[EMCC ], [PYTHON , path_from_root ('tests' , 'runner.py' ), 'blahblah' ]]
26
26
27
27
@@ -415,31 +415,29 @@ def ensure_cache(self):
415
415
self .do ([EMCC , '-O2' , path_from_root ('tests' , 'hello_world.c' )])
416
416
417
417
def test_emcc_caching (self ):
418
- BUILDING_MESSAGE = 'generating system library: X '
418
+ BUILDING_MESSAGE = 'generating system library: %s '
419
419
420
420
restore_and_set_up ()
421
421
self .erase_cache ()
422
422
423
423
# Building a file that *does* need something *should* trigger cache
424
424
# generation, but only the first time
425
- libname = 'libc++'
425
+ libname = Cache . get_lib_name ( 'libc++.a' )
426
426
for i in range (3 ):
427
427
print (i )
428
428
self .clear ()
429
429
output = self .do ([EMCC , '-O' + str (i ), path_from_root ('tests' , 'hello_libcxx.cpp' ), '-s' , 'DISABLE_EXCEPTION_CATCHING=0' ])
430
430
print ('\n \n \n ' , output )
431
- self .assertContainedIf (BUILDING_MESSAGE . replace ( 'X' , libname ) , output , i == 0 )
431
+ self .assertContainedIf (BUILDING_MESSAGE % libname , output , i == 0 )
432
432
self .assertContained ('hello, world!' , self .run_js ('a.out.js' ))
433
433
self .assertExists (Cache .dirname )
434
- full_libname = libname + '.bc' if libname != 'libc++' else libname + '.a'
435
- self .assertExists (os .path .join (Cache .dirname , full_libname ))
434
+ self .assertExists (os .path .join (Cache .dirname , libname ))
436
435
437
436
def test_cache_clearing_manual (self ):
438
437
# Manual cache clearing
439
438
restore_and_set_up ()
440
439
self .ensure_cache ()
441
440
self .assertTrue (os .path .exists (Cache .dirname ))
442
- self .assertTrue (os .path .exists (Cache .root_dirname ))
443
441
output = self .do ([EMCC , '--clear-cache' ])
444
442
self .assertIn ('clearing cache' , output )
445
443
self .assertIn (SANITY_MESSAGE , output )
@@ -463,12 +461,10 @@ def test_FROZEN_CACHE(self):
463
461
self .erase_cache ()
464
462
self .ensure_cache ()
465
463
self .assertTrue (os .path .exists (Cache .dirname ))
466
- self .assertTrue (os .path .exists (Cache .root_dirname ))
467
464
# changing config file should not clear cache
468
465
add_to_config ('FROZEN_CACHE = True' )
469
466
self .do ([EMCC ])
470
467
self .assertTrue (os .path .exists (Cache .dirname ))
471
- self .assertTrue (os .path .exists (Cache .root_dirname ))
472
468
# building libraries is disallowed
473
469
output = self .do ([EMBUILDER , 'build' , 'libemmalloc' ])
474
470
self .assertIn ('FROZEN_CACHE disallows building system libs' , output )
@@ -487,6 +483,7 @@ def test_emcc_multiprocess_cache_access(self):
487
483
}
488
484
''' )
489
485
cache_dir_name = self .in_dir ('test_cache' )
486
+ libname = Cache .get_lib_name ('libc.a' )
490
487
with env_modify ({'EM_CACHE' : cache_dir_name }):
491
488
tasks = []
492
489
num_times_libc_was_built = 0
@@ -495,13 +492,13 @@ def test_emcc_multiprocess_cache_access(self):
495
492
tasks += [p ]
496
493
for p in tasks :
497
494
print ('stdout:\n ' , p .stdout )
498
- if 'generating system library: libc' in p .stdout :
495
+ if 'generating system library: ' + libname in p .stdout :
499
496
num_times_libc_was_built += 1
500
497
501
498
# The cache directory must exist after the build
502
499
self .assertTrue (os .path .exists (cache_dir_name ))
503
500
# The cache directory must contain a built libc
504
- self .assertTrue (os .path .exists (os .path .join (cache_dir_name , 'wasm' , 'libc.a' )))
501
+ self .assertTrue (os .path .exists (os .path .join (cache_dir_name , libname )))
505
502
# Exactly one child process should have triggered libc build!
506
503
self .assertEqual (num_times_libc_was_built , 1 )
507
504
@@ -535,12 +532,11 @@ def test_emcc_ports(self):
535
532
restore_and_set_up ()
536
533
537
534
# listing ports
538
-
539
535
out = self .do ([EMCC , '--show-ports' ])
540
- assert 'Available ports:' in out , out
541
- assert 'SDL2' in out , out
542
- assert 'SDL2_image' in out , out
543
- assert 'SDL2_net' in out , out
536
+ self . assertContained ( 'Available ports:' , out )
537
+ self . assertContained ( 'SDL2' , out )
538
+ self . assertContained ( 'SDL2_image' , out )
539
+ self . assertContained ( 'SDL2_net' , out )
544
540
545
541
# using ports
546
542
RETRIEVING_MESSAGE = 'retrieving port'
@@ -555,27 +551,27 @@ def test_emcc_ports(self):
555
551
try_delete (PORTS_DIR )
556
552
else :
557
553
self .do ([EMCC , '--clear-ports' ])
558
- assert not os . path . exists (PORTS_DIR )
554
+ self . assertNotExists (PORTS_DIR )
559
555
560
556
# Building a file that doesn't need ports should not trigger anything
561
557
output = self .do ([EMCC , path_from_root ('tests' , 'hello_world_sdl.cpp' )])
562
558
assert RETRIEVING_MESSAGE not in output , output
563
559
assert BUILDING_MESSAGE not in output
564
560
print ('no' , output )
565
- assert not os . path . exists (PORTS_DIR )
561
+ self . assertNotExists (PORTS_DIR )
566
562
567
563
def first_use ():
568
564
output = self .do ([EMCC , path_from_root ('tests' , 'hello_world_sdl.cpp' ), '-s' , 'USE_SDL=2' ])
569
- assert RETRIEVING_MESSAGE in output , output
570
- assert BUILDING_MESSAGE in output , output
565
+ self . assertContained ( RETRIEVING_MESSAGE , output )
566
+ self . assertContained ( BUILDING_MESSAGE , output )
571
567
self .assertExists (PORTS_DIR )
572
568
print ('yes' , output )
573
569
574
570
def second_use ():
575
571
# Using it again avoids retrieve and build
576
572
output = self .do ([EMCC , path_from_root ('tests' , 'hello_world_sdl.cpp' ), '-s' , 'USE_SDL=2' ])
577
- assert RETRIEVING_MESSAGE not in output , output
578
- assert BUILDING_MESSAGE not in output , output
573
+ self . assertNotContained ( RETRIEVING_MESSAGE , output )
574
+ self . assertNotContained ( BUILDING_MESSAGE , output )
579
575
580
576
# Building a file that need a port does trigger stuff
581
577
first_use ()
@@ -699,10 +695,10 @@ def test_embuilder_wasm_backend(self):
699
695
# the --lto flag makes us build wasm-bc
700
696
self .do ([EMCC , '--clear-cache' ])
701
697
self .run_process ([EMBUILDER , 'build' , 'libemmalloc' ])
702
- self .assertExists (os .path .join (config .CACHE , 'wasm ' ))
698
+ self .assertExists (os .path .join (config .CACHE , 'sysroot' , 'lib' , 'wasm32-emscripten ' ))
703
699
self .do ([EMCC , '--clear-cache' ])
704
700
self .run_process ([EMBUILDER , 'build' , 'libemmalloc' , '--lto' ])
705
- self .assertExists (os .path .join (config .CACHE , 'wasm- lto' ))
701
+ self .assertExists (os .path .join (config .CACHE , 'sysroot' , 'lib' , 'wasm32-emscripten' , ' lto' ))
706
702
707
703
def test_binaryen_version (self ):
708
704
restore_and_set_up ()
0 commit comments