Skip to content

Rebaselineable minimal runtime code size test - #10478

Merged
juj merged 15 commits into
emscripten-core:masterfrom
juj:rebaselineable_minimal_runtime_code_size_test
Feb 23, 2020
Merged

juj merged 15 commits into
emscripten-core:masterfrom
juj:rebaselineable_minimal_runtime_code_size_test

Conversation

@juj

@juj juj commented Feb 16, 2020

Copy link
Copy Markdown
Collaborator

This adds EMTEST_REBASELINE=1 support to test other.test_minimal_runtime_code_size.

Also adds a new code size test that stresses printf(), different random number generation functions, and SINGLE_FILE=1 support.

Comment thread tests/test_other.py Outdated
print('Total output size gzipped=' + str(total_output_size_gz) + ' bytes, expected total size gzipped=' + str(total_expected_size_gz) + ', delta=' + str(total_output_size_gz - total_expected_size_gz) + print_percent(total_output_size_gz, total_expected_size_gz))

if os.environ.get('EMTEST_REBASELINE'):
open(results_file, 'w').write(json.dumps(obtained_results))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you call call self.assertFileContents(results_file, obtained_results) rather then duplicating the logic?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you format the JSON nicely the fails will be reported pretty clearly via the output of the diff I think.. so you can remove the check below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would cause the code to verify both gzip compressed and non-compressed sizes, but I do not want to test gzip compressed sizes, just print them, since strictly optimizing for gzip compressed sizes is not productive. (also there is no guarantee that different systems will produce identical gzip compressed output)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think why you can replace lines 9739 through 9747 with

expected = json.dumps(obtained_results, indent=2) + '\n'
self.assertFileContents(results_file, expected)

If you want to print something and not compare it then isn't the best way simply not to include it in the expected string. (Otherwise you will get cases where the tests pass by EMTEST_REBASELINE still produces a diff.. which is a little confusing I think).

The side effect of doing it this way is that the tests will "fail fast", but I actually prefer this over the method of storing the failure on the side and delaying reporting until later. Plus EMTEST_REBASELINE makes it easy to run through all them effectively skipping over the failures.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise you will get cases where the tests pass by EMTEST_REBASELINE still produces a diff.. which is a little confusing I think).

The .gz sizes are included so that the effect on their size changes can be easily tracked when doing changes locally. We have not tracked them before, and it would be informative to know how they change, we'd lose that if so.

Also using assertFileContents would mean dropping the current allowance for slop that we have now. Neither compiler produces identical results across OSes and systems, for unknown reasons. That would probably require first fixing up all sources of nondeterminism in the compiler backends first.

@juj
juj force-pushed the rebaselineable_minimal_runtime_code_size_test branch from 28083ad to 4f49de8 Compare February 19, 2020 10:43
@sbc100

sbc100 commented Feb 19, 2020

Copy link
Copy Markdown
Collaborator

I also recently landed a change to make the assertFileContents output message even more readable.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sounds good.

Can you now remove the "success" variable and just self.assertEqual(total_output_size, total_expected_size)?

The current failure mode of AssertionError: False is not true is rather confusing, and I think all the benefit of continuing after a failure can be had by just adding EMTEST_REBASELINE and re-running.

"a.html.gz": 8602,
"total": 20613,
"total_gz": 8602
} No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newlines to EOF.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are programmatically generated. Could add an explicit + '\n' to the write, but why? It is not as if these files are #included anywhere that we'd need to care about concatenation rules...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please just add the '\n' when you write the file.

For consistency I think all text files (especially those under source control) should end in a newline. Tools like vim and github's UI hightlight the lack of newlines and I tend to agree with them.

@juj
juj force-pushed the rebaselineable_minimal_runtime_code_size_test branch from 30ce80b to 73e16c3 Compare February 21, 2020 09:45
@juj

juj commented Feb 21, 2020

Copy link
Copy Markdown
Collaborator Author

This rebaselining approach is a bit tricky with nondeterministic output. Fortunately it looks like that only fastcomp backend has nondeterminism, so I adjusted this to only allow slop for fastcomp, and loosened the slop amount so that it passes on the CI.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-determinism is worrying, but this change lgtm.

@juj
juj force-pushed the rebaselineable_minimal_runtime_code_size_test branch from 7fc2d5b to b7d53f8 Compare February 22, 2020 11:23
@juj
juj merged commit 5d5e296 into emscripten-core:master Feb 23, 2020
@juj

juj commented Feb 23, 2020

Copy link
Copy Markdown
Collaborator Author

Unfortunately it looks like there is nondeterminism in wasm backend as well, although I believe the nondeterminism comes closure. Posted #10546 about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants