Skip to content

Commit

Permalink
tryfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJOHN974 committed Nov 22, 2023
1 parent e92f42d commit 04a6ba1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
3 changes: 2 additions & 1 deletion ci/spectest-zkasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ if [ ! -d "tests/zkasm/node_modules" ]; then
fi
# Assert results of running tests commited
TEST_PATH=../../${1:-"cranelift/zkasm_data/spectest/i64/generated"}
npm test --prefix tests/zkasm $TEST_PATH | python3 ci/zkasm-result.py
# We don't expect all tests will pass so ignore if testing script exits with non zero code
(npm test --prefix tests/zkasm $TEST_PATH || true) | python3 ci/zkasm-result.py
44 changes: 16 additions & 28 deletions ci/zkasm-result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,65 @@
import csv
import sys

# Define the directories

tests_dir = 'cranelift/zkasm_data/spectest/i64'
generated_dir = 'cranelift/zkasm_data/spectest/i64/generated'
state_csv_path = 'cranelift/codegen/src/isa/zkasm/docs/state.csv'


def check_compilation_status():
status_map = {}
for file in os.listdir(tests_dir):
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'
if not file.endswith('.wat'):
continue
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'
return status_map


def update_status_from_stdin(status_map):
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]
test_name, _ = os.path.splitext(os.path.basename(test_path))
status_map[test_name] = 'pass' if 'pass' in line else 'runtime error'


def write_csv(status_map):
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)))
for (test, status) in status_list:
csvwriter.writerow([test, status])
status_list = sorted(status_map.items())
csvwriter.writerows(status_list)
csvwriter.writerow(['Total Passed', sum(1 for status in status_map.values() if status == 'pass')])
csvwriter.writerow(['Amount of Tests', len(status_map)])


def assert_with_csv(status_map):
print("assert foo")
with open(state_csv_path, newline='') as csvfile:
csvreader = csv.reader(csvfile)
print("csvreader ok")
next(csvreader) # Skip header row
csv_dict = {}
print('a')
for row in csvreader:
print('b')
if row[0] == "Test" or row[0] == "Total Passed" or row[0] == "Amount of Tests":
if row[0] in ["Test", "Total Passed", "Amount of Tests"]:
continue
print('c')
csv_dict[row[0]] = row[1]
print('d')
print('e')
if csv_dict != status_map:
print('f')
print(f"dict diff = {csv_dict ^ status_map}")
return 1
print('assertfoo ret 0')
return 0


def main():
# Main execution
print("print works")
status_map = check_compilation_status()
print(1)
update_status_from_stdin(status_map)
print(2)
if '--update' in sys.argv:
print("if branch")
write_csv(status_map)
else:
print("else branch")
if assert_with_csv(status_map) != 0:
sys.exit(1)
print('ret 0????')
print('before exit 0')
sys.exit(0)


if __name__ == "__main__":
main()

0 comments on commit 04a6ba1

Please sign in to comment.