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

compel/test: Fix success condition check in fdspy #2192

Merged
merged 1 commit into from
Jun 17, 2023

Conversation

ancientmodern
Copy link
Contributor

@ancientmodern ancientmodern commented Jun 14, 2023

Found this bug when working on adding riscv64 support to compel #1702 :) Specifically, the bug appeared when the p_err pipe became broken after resuming, causing check_pipe_ends() to hit either these branches:

if (write(wfd, "1", 2) != 2) {
	fprintf(stderr, "write to pipe failed\n");
	return -1;
}
if (read(rfd, aux, sizeof(aux)) != sizeof(aux)) {
	fprintf(stderr, "read from pipe failed\n");
	return -1;
}

The -1 return value was not correctly handled in the final check:

pass = check_pipe_ends(stolen_fd, p_err[0]);

if (pass)
	printf("All OK\n");
else
	printf("Something went WRONG\n");

This pull request modified the condition to pass == 1, ensuring that "All OK" is printed only when check_pipe_ends() returns 1 (indicating a successful case), and any other value will correctly result in "Something went WRONG" being printed.

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2023

Codecov Report

Patch coverage: 25.00% and project coverage change: +0.02 🎉

Comparison is base (4d137b8) 70.74% compared to head (581d7f6) 70.77%.

❗ Current head 581d7f6 differs from pull request most recent head 8e68170. Consider uploading reports for the commit 8e68170 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           criu-dev    #2192      +/-   ##
============================================
+ Coverage     70.74%   70.77%   +0.02%     
============================================
  Files           133      133              
  Lines         33244    33233      -11     
============================================
+ Hits          23518    23520       +2     
+ Misses         9726     9713      -13     
Impacted Files Coverage Δ
criu/cgroup.c 74.53% <0.00%> (ø)
criu/include/restorer.h 100.00% <ø> (ø)
criu/include/rst_info.h 100.00% <ø> (ø)
criu/mem.c 86.30% <ø> (+0.95%) ⬆️
criu/memfd.c 81.81% <20.00%> (-1.26%) ⬇️
criu/cr-restore.c 67.19% <100.00%> (-0.19%) ⬇️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mihalicyn
Copy link
Member

Hi @ancientmodern !

Thanks for looking into it.

Speaking about RISC-V support, Yixue (@felicitia) working on that closely. Are your really working on that too? I think you need to contact Yixue then.

Now about your fix. As far as I understand this inconsistency appeared after this commit 5364ca3
IMHO, it's better to always return 0 in case of error (then you don't need to change if condition).

@rst0git
Copy link
Member

rst0git commented Jun 15, 2023

As far as I understand this inconsistency appeared after this commit 5364ca3
IMHO, it's better to always return 0 in case of error (then you don't need to change if condition).

Thanks for pointing this out Alex! I agree, check_pipe_ends() should return 0 in the case of an error to be consistent with the other conditions in that function.

@ancientmodern
Copy link
Contributor Author

ancientmodern commented Jun 15, 2023

Hi @ancientmodern !

Thanks for looking into it.

Speaking about RISC-V support, Yixue (@felicitia) working on that closely. Are your really working on that too? I think you need to contact Yixue then.

Now about your fix. As far as I understand this inconsistency appeared after this commit 5364ca3 IMHO, it's better to always return 0 in case of error (then you don't need to change if condition).

Thank you for the feedback Alex! Yeah I've contacted Yixue and we are working together on RISC-V support. As per Yixue's recent update in #1702, we've successfully enabled most of compel to function on RISC-V, and we are actively addressing a few remaining bugs :)

I agree it's better to consistently return 0 in case of error and will make the changes. As this is a fix to a previous commit, do I need to follow the guideline about "fix tags" mentioned here?

Edit: I've updated my commit. Please let me know if there is any issue I need to resolve :)

This commit revises the error handling in the fdspy test. Previously,
a failure case could have been incorrectly reported as successful because
of a specific check `pass != 0`, leading to potential false positives
when `check_pipe_ends()` returned `-1` due to a read/write pipe error.

To improve this, we've adjusted the error handling to return `0` in case
of any error. As such, the final success condition remains unchanged. This
approach will help accurately differentiate between successful and failed
cases, ensuring the output "All OK" is printed for success, and "Something
went WRONG" for any failure.

Fixes: 5364ca3 ("compel/test: Fix warn_unused_result")

Signed-off-by: Haorong Lu <ancientmodern4@gmail.com>
Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@avagin avagin merged commit 9e2e560 into checkpoint-restore:criu-dev Jun 17, 2023
33 of 38 checks passed
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.

None yet

5 participants