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

CI: spectests in CI #95

Merged
merged 1 commit into from
Nov 22, 2023
Merged

CI: spectests in CI #95

merged 1 commit into from
Nov 22, 2023

Conversation

MCJOHN974
Copy link

@MCJOHN974 MCJOHN974 commented Nov 21, 2023

Added script to generate .csv with spectest results and asserting commited result corresponds actual results in CI

Fixes #84

@MCJOHN974
Copy link
Author

Am I right that ci/run-tests.sh runs test_zkasm::tests::run_spectests?

@nagisa
Copy link
Collaborator

nagisa commented Nov 22, 2023

#bash ./ci/run-tests.sh --locked | grep test_zkasm
<snip>
test test_zkasm::tests::run_spectests ... ok
<snip>

@nagisa
Copy link
Collaborator

nagisa commented Nov 22, 2023

I’ll defer this to @Akashin since it was their request. I personally think it would be easier on the eyes if this file was post-processed with columns -t -s',' -o',' but I can see why we might not want to do that either (e.g. test additions will potentially cause the entire table to be reformatted which can then be hard to diff.)

@MCJOHN974
Copy link
Author

@nagisa can you take a look please, why it fails? As prints show python script goes to sys.exit(0) but fails... Locally whole pipe exits with 0. Pipe return status of last command so problem should be around python script..

@aborg-dev
Copy link

I’ll defer this to @Akashin since it was their request. I think it would be easier on the eyes if this file was post-processed with columns -t -s',' -o',' but I can see why we might not want to do that either (e.g. test additions will potentially cause the entire table to be reformatted which can then be hard to diff.)

I do agree that we would benefit from making this output easily readable by humans to make it easier to study this data. I think CSV is fine for the first version, but we should iterate on it in the future PR.

@@ -50,6 +50,19 @@ jobs:
- run: npm ci --prefix tests/zkasm
- run: ./ci/test-zkasm.sh

spectest_zkasm:

Choose a reason for hiding this comment

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

I suggest we merge this with the previous test_zkasm job:

  • They are semantically in the same category
  • We will likely have more of these tests (for each of spec test files) and we wouldn't want a new job for each one of them
  • This will make sure we reuse NPM cache between jobs and save execution time as that is the dominating step for this job

Am I missing any reasons to split these into separate jobs?

if file.endswith('.wat'):
test_name = os.path.splitext(file)[0]
zkasm_file = f'{test_name}.zkasm'
status_map[test_name] = 'compilation success' if zkasm_file in os.listdir(generated_dir) else 'compilation failed'

Choose a reason for hiding this comment

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

You can do os.path.exists(os.path.join(generated_dir, zkasm_file)) to be more specific

def check_compilation_status():
status_map = {}
for file in os.listdir(tests_dir):
if file.endswith('.wat'):

Choose a reason for hiding this comment

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

General idea to reduce code nesting, use continue:

if not file.endswith('.wat'):
  continue

# Code below becomes less nested.
...


def update_status_from_stdin(status_map):
for line in sys.stdin:
if "--> fail" in line or "--> pass" in line:

Choose a reason for hiding this comment

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

That's the reason I originally suggested doing this in run-tests-zkasm.js where we have the information about test status programmatically and don't have to parse strings.

I'm fine with keeping this in Python for now, but if you agree moving this to JS will simplify code, feel free to do this.

Copy link
Author

@MCJOHN974 MCJOHN974 Nov 22, 2023

Choose a reason for hiding this comment

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

This parsing takes just a few lines, and I found that wasmtime repo already contains some python files, so it won't be a big deviation from style of the repo, so I decided proceed with more convenient for me language

csvwriter = csv.writer(csvfile)
csvwriter.writerow(['Test', 'Status'])
status_list = sorted(list(map(lambda x: (x, status_map[x]), status_map)))
for (test, status) in status_list:

Choose a reason for hiding this comment

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

You can also do csvwriter.writerows(status_list)

with open(state_csv_path, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['Test', 'Status'])
status_list = sorted(list(map(lambda x: (x, status_map[x]), status_map)))

Choose a reason for hiding this comment

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

You can simplify this to sorted(status_map.items())

for line in sys.stdin:
if "--> fail" in line or "--> pass" in line:
_, _, test_path = line.partition(' ')
test_name = os.path.basename(test_path).split('.')[0]

Choose a reason for hiding this comment

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

The canonical way to do this is:

filename, file_extension = os.path.splitext(os.path.basename('/path/to/somefile.ext'))
# filename == "somefile"

print("assert foo")
with open(state_csv_path, newline='') as csvfile:
csvreader = csv.reader(csvfile)
print("csvreader ok")

Choose a reason for hiding this comment

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

Leaving a comment not to forget to remove debug statements before submitting the PR.

print('a')
for row in csvreader:
print('b')
if row[0] == "Test" or row[0] == "Total Passed" or row[0] == "Amount of Tests":

Choose a reason for hiding this comment

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

A way to simplify: if row[0] in ["Test", "Total Passed", "Amount of Tests"]:

@aborg-dev
Copy link

@nagisa can you take a look please, why it fails? As prints show python script goes to sys.exit(0) but fails... Locally whole pipe exits with 0. Pipe return status of last command so problem should be around python script..

I suspect this is because we have pipefail set and the first command npm test --prefix tests/zkasm ../../cranelift/zkasm_data/spectest/i64/generated fails

See https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425#set--o-pipefail

Copy link

@aborg-dev aborg-dev left a comment

Choose a reason for hiding this comment

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

Let's ship it!

@MCJOHN974
Copy link
Author

Thanks for review, Andrei!

@MCJOHN974 MCJOHN974 added this pull request to the merge queue Nov 22, 2023
Merged via the queue into main with commit 4e7366b Nov 22, 2023
21 checks passed
@MCJOHN974 MCJOHN974 deleted the viktar/spectests branch November 22, 2023 14:56
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.

Import i64 testcases from WASM Spec test
3 participants