Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Refactor scripts/ASTImportTest.sh. #13576

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

aarlt
Copy link
Member

@aarlt aarlt commented Sep 28, 2022

Refactors script/ASTImportTests.sh to make #12834 more readable.

Fixes #8185

scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
@cameel cameel requested a review from r0qs September 28, 2022 11:27
@aarlt aarlt added the refactor label Sep 28, 2022
Copy link
Member

@r0qs r0qs left a comment

Choose a reason for hiding this comment

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

Hey, I took a look at the PR, and it looks good, I just made some comments ;)

scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
printError "❌ ERROR: AST reimport failed for ${sol_file}"
if [[ $ABORT_ON_ERROR == 1 ]]
then
printError "You can find the files used for this test here: $(pwd)"
Copy link
Member Author

Choose a reason for hiding this comment

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

I think something like that is useful. It allows to investigate the resulting json files and gives information what was actually done in these tests. so this should allow an easy reproduction.

scripts/common.sh Show resolved Hide resolved
@aarlt aarlt force-pushed the import-export-script-refactoring branch 2 times, most recently from 0c2ee2a to 73b5b88 Compare October 5, 2022 19:39
@aarlt
Copy link
Member Author

aarlt commented Oct 5, 2022

@cameel @r0qs I'm somehow not sure what to do with #8185. I guess that issue was created, when the script was different. However, right now the only place where we redirect potential errors to /dev/null is where we test a specific source for its compilability. We have especially in test/libsolidity/syntaxTests sources, that are not compilable. So to introduce a mechanism to show these errors would not make much sense from my point of view. For the other steps - e.g. export and import, we will show the compilation errors (compiler's stderr & stdout). Also if there is a mismatch between expected- and obtained output we show the diff. However, I introduced also --exit-on-error, that will stop on the first mismatch and show exactly what commands where used to allow further investigation of potential problems.

@aarlt aarlt force-pushed the import-export-script-refactoring branch from 73b5b88 to c13aa5b Compare October 5, 2022 19:50
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
scripts/common.sh Outdated Show resolved Hide resolved
@aarlt aarlt force-pushed the import-export-script-refactoring branch from c13aa5b to 8597351 Compare October 5, 2022 20:33
@cameel
Copy link
Member

cameel commented Oct 5, 2022

I'm somehow not sure what to do with #8185. I guess that issue was created, when the script was different. However, right now the only place where we redirect potential errors to /dev/null is where we test a specific source for its compilability.

It wasn't really that much different. In the last revision before the issue was reported I see that only solc output was being sent to /dev/null so basically as it is now.

We have especially in test/libsolidity/syntaxTests sources, that are not compilable. So to introduce a mechanism to show these errors would not make much sense from my point of view.

I think it would still be worthwhile to check why it's not compilable. If it's a compilation error, ignore. But if it's an ICE or a segfault, I'd print the error and exit.

But to detect that, it would be best to compile via Standard JSON since then we can check if we got valid JSON on output. I wouldn't do this in this PR though because it's a bit unrelated. So just post a comment about it in the issue and leave it open.

For the other steps - e.g. export and import, we will show the compilation errors (compiler's stderr & stdout). Also if there is a mismatch between expected- and obtained output we show the diff. However, I introduced also --exit-on-error, that will stop on the first mismatch and show exactly what commands where used to allow further investigation of potential problems.

This is nice and I think it solves part of that issue. I'd still keep it open as I said above though.

@aarlt
Copy link
Member Author

aarlt commented Oct 18, 2022

I think it would still be worthwhile to check why it's not compilable. If it's a compilation error, ignore. But if it's an ICE or a segfault, I'd print the error and exit.

Hmm.. interesting idea.. I think we should change return codes in solc/main.cpp so that we get 0 on success, 1 on normal failures but 2 on exceptions.

See #13633

Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Looks fine overall, but still needs some small corrections.

scripts/common.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
@aarlt
Copy link
Member Author

aarlt commented Nov 1, 2022

I think it would still be worthwhile to check why it's not compilable. If it's a compilation error, ignore. But if it's an ICE or a segfault, I'd print the error and exit.

Hmm.. interesting idea.. I think we should change return codes in solc/main.cpp so that we get 0 on success, 1 on normal failures but 2 on exceptions.

See #13633

After #13633 got merged, I change the script accordingly. However, the script will ignore all UnimplementedFeatureError exceptions.

# compare expected and obtained ast's
if diff_files expected.json obtained.json
then
echo -n "✅"
Copy link
Member Author

Choose a reason for hiding this comment

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

After staring on these nice unicode checkmarks for some hours today, I think they should not be used ;)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could ignore the print in case of success and only print an error if they are not equivalent?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just remove the unicode checkmark. However, I think that CircleCI will terminate jobs that are not generating any output for a specific time. So I will let it still print normal dots.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the normal dots are fine in my opinion. I was thinking of removing only the checkmarks as you mentioned. And keep the error in case the ast's are not equivalent.

@r0qs
Copy link
Member

r0qs commented Nov 2, 2022

Running the branch locally, I got the following result:

SUCCESS: 1103 tests passed, 0 failed, 1883 could not be compiled (2986 sources total).

Is it expected that 1883 cannot be compiled?

@aarlt
Copy link
Member Author

aarlt commented Nov 3, 2022

Running the branch locally, I got the following result:

SUCCESS: 1103 tests passed, 0 failed, 1883 could not be compiled (2986 sources total).

Is it expected that 1883 cannot be compiled?

Ah yes! The reason for that the syntax tests. Many of these syntax tests consists of errors to be able to check for specific behaviour of the parser. Maybe we should change that to only use the semantic test cases. But in general the high amount of not compilable tests are expected.

@cameel
Copy link
Member

cameel commented Nov 7, 2022

Maybe we should change that to only use the semantic test cases.

I think that syntax tests are actually more important for this feature than semantic tests. At least with regard to AST import/export - because they generally use more varied syntax so I'd expect them to cover more corner cases of the AST. For assembly import/export it might actually be the opposite though so ideally we'd have both.

for PARAM in "$@"
do
case "$PARAM" in
ast) IMPORT_TEST_TYPE="ast" ;;
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be accepted only once. It's less of a problem when there's one possible value but later this approach will allow things like scripts/ASTImportTest.sh --exit-on-error evm-assembly ast, which is very misleading because it looks as if it would run both sets of tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a simple function check_import_test_type_unset that is called before setting IMPORT_TEST_TYPE. This should solve the problem mentioned here.

scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
@aarlt aarlt force-pushed the import-export-script-refactoring branch from 7e82fc1 to 357d81c Compare November 9, 2022 21:50
@aarlt
Copy link
Member Author

aarlt commented Nov 9, 2022

Running the branch locally, I got the following result:

SUCCESS: 1103 tests passed, 0 failed, 1883 could not be compiled (2986 sources total).

Is it expected that 1883 cannot be compiled?

Ah yes! The reason for that the syntax tests. Many of these syntax tests consists of errors to be able to check for specific behaviour of the parser. Maybe we should change that to only use the semantic test cases. But in general the high amount of not compilable tests are expected.

@r0qs @cameel The original script did not invoke the code generator. This was changed in this PR. Thats why many of the syntax tests were treated as non-compilable. See #13576 (comment). I corrected this now.

cameel
cameel previously approved these changes Nov 10, 2022
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

I still have some suggestions but they're all cosmetic so tentatively approving.

scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
@aarlt
Copy link
Member Author

aarlt commented Nov 11, 2022

I also added now another change in scripts/common.sh. I noticed that the printStackTrace function was not working correctly under macOS. The cut command there is not the gnu version (similar to readlink). This version does not support e.g. --delimiter. However, on macOS it will now use gcut instead of cut.

@aarlt aarlt force-pushed the import-export-script-refactoring branch 2 times, most recently from deaddec to dcfc59e Compare November 11, 2022 03:32
@aarlt aarlt requested review from r0qs and cameel November 12, 2022 00:29
scripts/common.sh Outdated Show resolved Hide resolved
@aarlt aarlt force-pushed the import-export-script-refactoring branch from dcfc59e to ab706e3 Compare November 23, 2022 13:08
cameel
cameel previously approved these changes Nov 23, 2022
scripts/ASTImportTest.sh Outdated Show resolved Hide resolved
@cameel cameel dismissed r0qs’s stale review November 23, 2022 19:05

All requested changes were applied.

r0qs
r0qs previously approved these changes Nov 24, 2022
Copy link
Member

@r0qs r0qs left a comment

Choose a reason for hiding this comment

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

Please, fix this: #13576 (comment) and we are good to go :)

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
@NunoFilipeSantos NunoFilipeSantos dismissed stale reviews from r0qs and cameel via 17cfdb1 November 24, 2022 10:51
@NunoFilipeSantos
Copy link
Contributor

NunoFilipeSantos commented Nov 24, 2022

Please, fix this: #13576 (comment) and we are good to go :)

I just applied it. 😛 Didn't see the need to wait.
Now waiting for the tests to pass.

@r0qs r0qs self-requested a review November 24, 2022 12:52
@cameel cameel merged commit fe68200 into develop Nov 24, 2022
@cameel cameel deleted the import-export-script-refactoring branch November 24, 2022 15:16
javierSande pushed a commit to javierSande/solidity that referenced this pull request Feb 23, 2023
* [tests] Refactor scripts/ASTImportTest.sh.

Co-authored-by: Nuno Santos <nuno.santos@ethereum.org>
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
Ruko97 pushed a commit to Ruko97/solidity that referenced this pull request Apr 7, 2024
* [tests] Refactor scripts/ASTImportTest.sh.

Co-authored-by: Nuno Santos <nuno.santos@ethereum.org>
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Display errors when ASTImportTest.sh is not run by CI
4 participants