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

Adamdebek/exit test #208

Merged
merged 1 commit into from
Oct 16, 2023
Merged

Adamdebek/exit test #208

merged 1 commit into from
Oct 16, 2023

Conversation

adamdebek
Copy link
Contributor

@adamdebek adamdebek commented May 23, 2023

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@adamdebek adamdebek marked this pull request as draft May 23, 2023 11:27
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from 140aa06 to b99df3c Compare May 23, 2023 17:12
libc/exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 2 times, most recently from b34af1c to 42153c6 Compare May 29, 2023 13:49
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from 42153c6 to a4736b2 Compare June 12, 2023 13:05
@adamdebek adamdebek marked this pull request as ready for review June 13, 2023 11:17
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 2 times, most recently from b1ab1d4 to 91f4107 Compare June 22, 2023 13:42
Copy link
Contributor

@niewim19 niewim19 left a comment

Choose a reason for hiding this comment

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

General, repeating remarks:

  • if clause on fork exit has no effect and is used in many testcases
  • variable declaration in the middle of the code
  • TEST_ASSERTs in fork-ed processes may produce strange unity behavior and give unclear output in test runner. If you need to assert something in child process then do it via if clause and pass failure information as exit status of that process.
  • Please add description to PR

exit/test_exit.c Outdated
Comment on lines 86 to 239
int val[3];
val[0] = 0x1 << 8;
val[1] = (0x1 << 16) + 1;
val[2] = (0x1 << 24) + 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

The same name as global variable val. Please describe logic that stands behind these values calculations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done because only the least significant 8 bits shall be available to a waiting parent process. 3 most significant bytes should be cut off so returning val[0] should resolve to returning 0, val[1] to 1 and val[2] to 2.

exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated
Comment on lines 474 to 478
for (i = 0; i < atexit_max - 1; i++) {
TEST_ASSERT_EQUAL_INT(0, atexit(fun1));
}
TEST_ASSERT_EQUAL_INT(0, atexit(fun2));
TEST_ASSERT_EQUAL_INT(0, atexit(fun1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is fun2 used? Cant we try to register atexitMax + 1offun1and assert onlyatexitMax` invocations?

Copy link
Contributor Author

@adamdebek adamdebek Jul 5, 2023

Choose a reason for hiding this comment

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

Last registered function is invoked first, so I created fun2 to make distinguish between function calls and ensure they are called in proper order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this order asserted somewhere?

exit/test_exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 2 times, most recently from f149842 to 9c1506a Compare July 5, 2023 15:39
exit/test_exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from 9c1506a to 6717dc1 Compare July 5, 2023 20:20
@adamdebek adamdebek requested a review from niewim19 July 6, 2023 09:56
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated
Comment on lines 299 to 315
pid_t old_ppid, new_ppid;
int status;
Copy link
Contributor

Choose a reason for hiding this comment

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

variable declaration deep in test body, not in the beginning. Also names do not follow coding convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this approach is more readable and was used in other files in the past:

int fd[2];
pid_t pid;
size_t sfdcnt, rfdcnt;
sfdcnt = rand() % (MAX_FD_CNT + 1);
if (socketpair(AF_UNIX, type, 0, fd) < 0)
FAIL("socketpair");
if ((pid = fork()) < 0)
FAIL("fork");
if (pid) {
int sfd[MAX_FD_CNT];
ssize_t n;
int status;
if (open_files(sfd, sfdcnt) < 0)
FAIL("open_files");
if (write_files(sfd, sfdcnt) < 0)
FAIL("write_files");
n = unix_msg_send(fd[0], data, 1, sfd, sfdcnt);
TEST_ASSERT(n == 1);
if (close_files(sfd, sfdcnt) < 0)
FAIL("close_files");
if (waitpid(pid, &status, 0) < 0)
FAIL("waitpid");
TEST_ASSERT(WIFEXITED(status));
TEST_ASSERT(WEXITSTATUS(status) == 0);
if (stat_files(sfd, sfdcnt, 0) < 0)
FAIL("stat_files");
if (unlink_files(sfdcnt) < 0)
FAIL("unlink_files");
close(fd[0]);
close(fd[1]);
}
else {
int rfd[MAX_FD_CNT];
ssize_t n;

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this was used in the past. This code is pushed now and it should conform to current coding convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nalajcie Could you give your opinion on that?

Copy link
Contributor

Choose a reason for hiding this comment

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

@adamdebek still the variable names are not correct, please use camelCase.

@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from 6717dc1 to 5411388 Compare July 14, 2023 14:59
@adamdebek adamdebek requested review from damianloew and niewim19 July 17, 2023 10:07
exit/test_exit.c Outdated
Comment on lines 427 to 564
atexit(test_fun1);
atexit(test_fun1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is calling it 2 times intentional? If so, please leave a comment.

exit/test_exit.c Outdated
Comment on lines 474 to 478
for (i = 0; i < atexit_max - 1; i++) {
TEST_ASSERT_EQUAL_INT(0, atexit(fun1));
}
TEST_ASSERT_EQUAL_INT(0, atexit(fun2));
TEST_ASSERT_EQUAL_INT(0, atexit(fun1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this order asserted somewhere?

Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

For now looked through _exit() tests and a lot of requirements from the documentation are not covered. I understand that 100% coverage is not possible, though there is certainly a lot of test cases to create. I recommend you some method for verifying what is already covered, for example:
Screenshot from 2023-08-10 18-56-18

Please leave a comment what was not covered and why (when it's impossible).

However, the code is really clean and understandable.

exit/Makefile Outdated Show resolved Hide resolved
exit/test.yaml Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Unit Test Results

5 884 tests  +150   5 233 ✔️ +117   29m 10s ⏱️ +34s
   316 suites +    5      651 💤 +  33 
       1 files   ±    0          0 ±    0 

Results for commit 2cd4b47. ± Comparison against base commit dfa5bde.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

EDIT: As you mentioned - XSI requirements are not required in POSIX

exit/test.yaml Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated
process group is stopped, then a SIGHUP signal followed by a SIGCONT signal shall be sent to each process in
the newly-orphaned process group -> https://github.com/phoenix-rtos/phoenix-rtos-project/issues/809
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

the full value shall be available from waitid() and in the siginfo_t passed to a signal handler for SIGCHLD. - not covered.

From what I see

  • ...in the siginfo_t passed to a signal handler for SIGCHLD - it's possible to check - you probably can get siginfo_t in the handler function
  • the full value shall be available from waitid() - temporary not possible to check, due to lack of waitid() func - please leave a comment about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

siginfo_t can be accessed only when SA_SIGINFO flag is set, but it is not present in PHOENIX-RTOS right now.

Copy link
Contributor Author

@adamdebek adamdebek Sep 19, 2023

Choose a reason for hiding this comment

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

Yes, waitid() not implemented.

exit/test_exit.c Outdated
process group is stopped, then a SIGHUP signal followed by a SIGCONT signal shall be sent to each process in
the newly-orphaned process group -> https://github.com/phoenix-rtos/phoenix-rtos-project/issues/809
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

  • The _Exit() and _exit() functions shall be functionally equivalent. - also not covered - please add at least one twin case with _Exit call instead of _exit().

exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated
process group is stopped, then a SIGHUP signal followed by a SIGCONT signal shall be sent to each process in
the newly-orphaned process group -> https://github.com/phoenix-rtos/phoenix-rtos-project/issues/809
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

  • directory streams, conversion descriptors, and message catalog descriptors open in the calling process shall be closed - I think director streams (*DIR) may be asserted, I am not sure about conversion descriptors, and message catalog descriptors - to be checked. If sth is not possible please leave a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK it is not possible to check closure of directory stream.

exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated
process group is stopped, then a SIGHUP signal followed by a SIGCONT signal shall be sent to each process in
the newly-orphaned process group -> https://github.com/phoenix-rtos/phoenix-rtos-project/issues/809
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

And the rest of points - I haven't verified the rest yet.
Screenshot from 2023-09-18 18-32-06

Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

Some ideas for more cases + suggested information about not covered requirements

exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test_exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated
Comment on lines 377 to 408
if (argsThr2.retWaitThr == -1 && argsThr2.errnoThr == ECHILD) {
TEST_PASS();
}
else if (argsThr2.retWaitThr != 0 && argsThr2.errnoThr == 0) {
TEST_FAIL_MESSAGE("Error: More than 1 thread unblocked");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if different errno happened?

Suggested change
if (argsThr2.retWaitThr == -1 && argsThr2.errnoThr == ECHILD) {
TEST_PASS();
}
else if (argsThr2.retWaitThr != 0 && argsThr2.errnoThr == 0) {
TEST_FAIL_MESSAGE("Error: More than 1 thread unblocked");
}
if (argsThr2.retWaitThr == -1) {
if (argsThr2.errnoThr == ECHILD) {
TEST_PASS();
} else {
TEST_FAIL_MESSAGE("Error: wait() failed with an invalid errno: %d" argsThr2.errnoThr);
}
}
else if (argsThr2.retWaitThr != -1 && argsThr2.errnoThr == 0) {
TEST_FAIL_MESSAGE("Error: More than 1 thread unblocked");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is only 1 more errno value, which is EINTR but that is impossible to happen.

Copy link
Contributor

@damianloew damianloew Oct 12, 2023

Choose a reason for hiding this comment

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

Even if it's hardly possible I'd like to handle it (the potentially may be some issue with a system).

exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated
}


TEST(unistd_exit, status_vals)
Copy link
Contributor

Choose a reason for hiding this comment

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

such case missing for stdlib exit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stdlib exit calls _exit() from unistd.

Copy link
Contributor

Choose a reason for hiding this comment

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

It potentially may change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will not change, these function are designed to be called in this manner.

exit/test-exit.c Outdated Show resolved Hide resolved
exit/test-exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 5 times, most recently from 37e48a7 to e39c937 Compare October 4, 2023 14:42
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from e39c937 to 41222c3 Compare October 11, 2023 14:37
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 3 times, most recently from a641473 to 9ffd0d3 Compare October 11, 2023 14:55
@adamdebek adamdebek requested a review from damianloew October 11, 2023 15:11
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch 2 times, most recently from 8f6ea7e to cf9ebf5 Compare October 12, 2023 14:06
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
libc/exit/exit.c Outdated Show resolved Hide resolved
@adamdebek adamdebek force-pushed the adamdebek/exit_test branch from f24a1c6 to 2cd4b47 Compare October 13, 2023 14:55
Copy link
Contributor

@damianloew damianloew left a comment

Choose a reason for hiding this comment

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

Thanks for all the corrections, LGTM

@adamdebek adamdebek merged commit de54a95 into master Oct 16, 2023
@adamdebek adamdebek deleted the adamdebek/exit_test branch October 16, 2023 05:11
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.

3 participants