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

test_cmd.sh: Correct test for are-images-different #1902

Conversation

wantehchang
Copy link
Collaborator

are_images_equal exits with status 1 when the images are different, and exits with status 2 when there is an error, such as file not found.

When we want to test if the images are different, we should test specifically for status 1 rather than any nonzero (failure) status.

are_images_equal exits with status 1 when the images are different, and
exits with status 2 when there is an error, such as file not found.

When we want to test if the images are different, we should test
specifically for status 1 rather than any nonzero (failure) status.
"${ARE_IMAGES_EQUAL}" "${INPUT_UTF8_Y4M}" "${DECODED_UTF8_FILE}" 0 || RET=$?
if [ ${RET} -ne 1 ]; then
exit 1
fi
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Line 73 probably should receive the same treatment.

I discovered this issue when I tested test_cmd.sh with a Windows are_images_equal executable that didn't support UTF-8. test_cmd.sh still passed because exit status 2 (for "file not found") was treated as "images are different".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not directly

    if [ $("${ARE_IMAGES_EQUAL}" "${INPUT_UTF8_Y4M}" "${DECODED_UTF8_FILE}" 0) -ne 1 ]; then
      exit 1
    fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also tried that, but found that $(command) is the standard output of the command, not its exit status.

Because this script does "set -x" and this command is expected to fail, the script needs to test this command, otherwise the command's failure will cause the script to exit. This is why I use the awkward command || RET=$? solution. (I found it in a Stack Overflow article.) I hope there is a cleaner solution.

"${ARE_IMAGES_EQUAL}" "${INPUT_UTF8_Y4M}" "${DECODED_UTF8_FILE}" 0 || RET=$?
if [ ${RET} -ne 1 ]; then
exit 1
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not directly

    if [ $("${ARE_IMAGES_EQUAL}" "${INPUT_UTF8_Y4M}" "${DECODED_UTF8_FILE}" 0) -ne 1 ]; then
      exit 1
    fi

@wantehchang wantehchang merged commit a9709d3 into AOMediaCodec:main Dec 23, 2023
20 checks passed
@wantehchang wantehchang deleted the test-cmd-sh-are-images-equal-exit-code branch December 23, 2023 19:10
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