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

eofparse: Return number of errors #873

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/eofparse/eofparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{
try
{
int num_errors = 0;
for (std::string line; std::getline(std::cin, line);)
{
if (line.empty() || line.starts_with('#'))
Expand All @@ -48,6 +49,7 @@
if (!o)
{
std::cout << "err: invalid hex\n";
++num_errors;
continue;
}

Expand All @@ -56,6 +58,7 @@
if (err != evmone::EOFValidationError::success)
{
std::cout << "err: " << evmone::get_error_message(err) << "\n";
++num_errors;
continue;
}

Expand All @@ -69,11 +72,11 @@
}
std::cout << "\n";
}
return 0;
return num_errors;
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << "\n";
return 1;
return -1;

Check warning on line 80 in test/eofparse/eofparse.cpp

View check run for this annotation

Codecov / codecov/patch

test/eofparse/eofparse.cpp#L80

Added line #L80 was not covered by tests
}
}
1 change: 1 addition & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DUP1,4

endif()

add_subdirectory(eofparse)
add_subdirectory(statetest)
add_subdirectory(t8n)

Expand Down
25 changes: 25 additions & 0 deletions test/integration/eofparse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2024 The evmone Authors.
# SPDX-License-Identifier: Apache-2.0

set(PREFIX ${PROJECT_NAME}/integration/eofparse)

string(REPLACE ";" " " CROSSCOMPILING_EMULATOR "${CMAKE_CROSSCOMPILING_EMULATOR}")

add_test(NAME ${PREFIX}/minimal_eof COMMAND sh -c "echo EF0001.010004 0200010001 040000 00,00800000 FE | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
set_tests_properties(${PREFIX}/minimal_eof PROPERTIES PASS_REGULAR_EXPRESSION "OK fe")

add_test(NAME ${PREFIX}/two_code_sections COMMAND sh -c "echo EF0001 010008 02000200030001 040000 00 00800000,00800000 E50001,00 | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
set_tests_properties(${PREFIX}/two_code_sections PROPERTIES PASS_REGULAR_EXPRESSION "OK e50001,00")

add_test(NAME ${PREFIX}/eof_version_unknown COMMAND sh -c "echo EF00.FF | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
set_tests_properties(${PREFIX}/eof_version_unknown PROPERTIES PASS_REGULAR_EXPRESSION "err: eof_version_unknown")

add_test(NAME ${PREFIX}/invalid_hex COMMAND sh -c "echo gaga | ${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

to test the new behavior, would a command like echo <code1> \n <invalid_code2> \n <invalid_code3> | eofparse || echo $? and then assert that 2 got printed in the end work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I didn't know how to test the exit code...

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 Maybe something like <eofparse> > /dev/null; echo $? would be more robust, just assert result is exactly 2.

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 did exactly this. Hopefully, there will be no issues with shell on different OSes.

set_tests_properties(${PREFIX}/invalid_hex PROPERTIES PASS_REGULAR_EXPRESSION "err: invalid hex")

add_test(NAME ${PREFIX}/example_input_file COMMAND sh -c "${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse> <${CMAKE_CURRENT_SOURCE_DIR}/two_errors.txt")
set_tests_properties(${PREFIX}/example_input_file PROPERTIES PASS_REGULAR_EXPRESSION "OK 00\nerr: type_section_missing\nerr: no_terminating_instruction")

add_test(NAME ${PREFIX}/exit_code COMMAND sh -c "${CROSSCOMPILING_EMULATOR} $<TARGET_FILE:evmone-eofparse> <${CMAKE_CURRENT_SOURCE_DIR}/two_errors.txt >/dev/null; echo $?")
set_tests_properties(${PREFIX}/exit_code PROPERTIES PASS_REGULAR_EXPRESSION "2")
10 changes: 10 additions & 0 deletions test/integration/eofparse/two_errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Example input file to eofparse tool. Two of the following lines contain EOF validation errors.

# Minimal valid EOF container.
EF0001 010004 0200010001 040000 00 00800000 00

# Mandatory sections missing
EF0001 00

# Code section not terminated
EF0001 010004 0200010001 040000 00 00800000 5b