Skip to content

Commit c251025

Browse files
committed
Move function a bit to minimize Git diff
1 parent 88bfef1 commit c251025

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

test/test_other.py

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9246,76 +9246,6 @@ def build(args):
92469246
# adding --metrics should not affect code size
92479247
self.assertEqual(base_size, os.path.getsize('a.out.wasm'))
92489248

9249-
def check_output_sizes(self, *outputs: str, **metadata):
9250-
test_name = self.id().split('.')[-1]
9251-
results_file = test_file('code_size', test_name + '.json')
9252-
9253-
expected_results: dict = {}
9254-
try:
9255-
expected_results = json.loads(read_file(results_file))
9256-
except Exception:
9257-
if not common.EMTEST_REBASELINE:
9258-
raise
9259-
9260-
obtained_results = {}
9261-
9262-
total_output_size = 0
9263-
total_expected_size = 0
9264-
total_output_size_gz = 0
9265-
total_expected_size_gz = 0
9266-
for f in outputs:
9267-
f_gz = f + '.gz'
9268-
expected_size = expected_results.get(f, inf)
9269-
expected_size_gz = expected_results.get(f_gz, inf)
9270-
contents = read_binary(f)
9271-
size = len(contents)
9272-
size_gz = len(gzip.compress(contents))
9273-
9274-
obtained_results[f] = size
9275-
obtained_results[f_gz] = size_gz
9276-
9277-
if not common.EMTEST_REBASELINE and size != expected_size and (f.endswith(('.js', '.html'))):
9278-
print('Contents of ' + f + ': ')
9279-
print(contents.decode('utf-8', errors='replace'))
9280-
9281-
def print_diff(title, actual, expected):
9282-
diff = actual - expected
9283-
s = f'{title}={actual}, expected {expected}'
9284-
if diff > 0:
9285-
s += f', delta={diff} ({diff * 100.0 / expected:+.2f}%)'
9286-
print(s)
9287-
9288-
print_diff(f'size of {f}', size, expected_size)
9289-
print_diff(f'size of {f_gz}', size_gz, expected_size_gz)
9290-
9291-
# N.B. even though the test code above prints out gzip compressed sizes, regression testing is done against uncompressed sizes
9292-
# this is because optimizing for compressed sizes can be unpredictable and sometimes counterproductive
9293-
total_output_size += size
9294-
total_expected_size += expected_size
9295-
9296-
total_output_size_gz += size_gz
9297-
total_expected_size_gz += expected_size_gz
9298-
9299-
if len(outputs) > 1:
9300-
obtained_results['total'] = total_output_size
9301-
obtained_results['total_gz'] = total_output_size_gz
9302-
9303-
print_diff('Total output size', total_output_size, total_expected_size)
9304-
print_diff('Total output size gzipped', total_output_size_gz, total_expected_size_gz)
9305-
9306-
obtained_results.update(metadata)
9307-
9308-
if common.EMTEST_REBASELINE:
9309-
create_file(results_file, json.dumps(obtained_results, indent=2) + '\n', absolute=True)
9310-
else:
9311-
if total_output_size > total_expected_size:
9312-
print(f'Oops, overall generated code size regressed by {total_output_size - total_expected_size} bytes!')
9313-
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
9314-
if total_output_size < total_expected_size:
9315-
print(f'Hey amazing, overall generated code size was improved by {total_expected_size - total_output_size} bytes!')
9316-
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
9317-
self.assertDictEqual(obtained_results, expected_results)
9318-
93199249
@crossplatform
93209250
def test_unoptimized_code_size(self):
93219251
# We don't care too about unoptimized code size but we would like to keep it
@@ -11962,6 +11892,76 @@ def test_minimal_runtime_code_size(self, test_name, wasm2js, compare_js_output=F
1196211892

1196311893
self.check_output_sizes(*outputs)
1196411894

11895+
def check_output_sizes(self, *outputs: str, **metadata):
11896+
test_name = self.id().split('.')[-1]
11897+
results_file = test_file('code_size', test_name + '.json')
11898+
11899+
expected_results: dict = {}
11900+
try:
11901+
expected_results = json.loads(read_file(results_file))
11902+
except Exception:
11903+
if not common.EMTEST_REBASELINE:
11904+
raise
11905+
11906+
obtained_results = {}
11907+
11908+
total_output_size = 0
11909+
total_expected_size = 0
11910+
total_output_size_gz = 0
11911+
total_expected_size_gz = 0
11912+
for f in outputs:
11913+
f_gz = f + '.gz'
11914+
expected_size = expected_results.get(f, inf)
11915+
expected_size_gz = expected_results.get(f_gz, inf)
11916+
contents = read_binary(f)
11917+
size = len(contents)
11918+
size_gz = len(gzip.compress(contents))
11919+
11920+
obtained_results[f] = size
11921+
obtained_results[f_gz] = size_gz
11922+
11923+
if not common.EMTEST_REBASELINE and size != expected_size and (f.endswith(('.js', '.html'))):
11924+
print('Contents of ' + f + ': ')
11925+
print(contents.decode('utf-8', errors='replace'))
11926+
11927+
def print_diff(title, actual, expected):
11928+
diff = actual - expected
11929+
s = f'{title}={actual}, expected {expected}'
11930+
if diff > 0:
11931+
s += f', delta={diff} ({diff * 100.0 / expected:+.2f}%)'
11932+
print(s)
11933+
11934+
print_diff(f'size of {f}', size, expected_size)
11935+
print_diff(f'size of {f_gz}', size_gz, expected_size_gz)
11936+
11937+
# N.B. even though the test code above prints out gzip compressed sizes, regression testing is done against uncompressed sizes
11938+
# this is because optimizing for compressed sizes can be unpredictable and sometimes counterproductive
11939+
total_output_size += size
11940+
total_expected_size += expected_size
11941+
11942+
total_output_size_gz += size_gz
11943+
total_expected_size_gz += expected_size_gz
11944+
11945+
if len(outputs) > 1:
11946+
obtained_results['total'] = total_output_size
11947+
obtained_results['total_gz'] = total_output_size_gz
11948+
11949+
print_diff('Total output size', total_output_size, total_expected_size)
11950+
print_diff('Total output size gzipped', total_output_size_gz, total_expected_size_gz)
11951+
11952+
obtained_results.update(metadata)
11953+
11954+
if common.EMTEST_REBASELINE:
11955+
create_file(results_file, json.dumps(obtained_results, indent=2) + '\n', absolute=True)
11956+
else:
11957+
if total_output_size > total_expected_size:
11958+
print(f'Oops, overall generated code size regressed by {total_output_size - total_expected_size} bytes!')
11959+
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
11960+
if total_output_size < total_expected_size:
11961+
print(f'Hey amazing, overall generated code size was improved by {total_expected_size - total_output_size} bytes!')
11962+
print('If this is expected, rerun the test with --rebaseline to update the expected sizes')
11963+
self.assertDictEqual(obtained_results, expected_results)
11964+
1196511965
# Tests the library_c_preprocessor.js functionality.
1196611966
@crossplatform
1196711967
def test_c_preprocessor(self):

0 commit comments

Comments
 (0)