-
Notifications
You must be signed in to change notification settings - Fork 18
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
Adamdebek/exit test #208
Conversation
140aa06
to
b99df3c
Compare
b34af1c
to
42153c6
Compare
42153c6
to
a4736b2
Compare
b1ab1d4
to
91f4107
Compare
There was a problem hiding this 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 onfork
exit has no effect and is used in many testcases- variable declaration in the middle of the code
TEST_ASSERT
s infork
-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 viaif
clause and pass failure information as exit status of that process.- Please add description to PR
exit/test_exit.c
Outdated
int val[3]; | ||
val[0] = 0x1 << 8; | ||
val[1] = (0x1 << 16) + 1; | ||
val[2] = (0x1 << 24) + 2; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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)); |
There was a problem hiding this comment.
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 + 1of
fun1and assert only
atexitMax` invocations?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
f149842
to
9c1506a
Compare
9c1506a
to
6717dc1
Compare
exit/test_exit.c
Outdated
pid_t old_ppid, new_ppid; | ||
int status; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
phoenix-rtos-tests/socket/test_socket.c
Lines 623 to 670 in 4334a5c
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; | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
6717dc1
to
5411388
Compare
exit/test_exit.c
Outdated
atexit(test_fun1); | ||
atexit(test_fun1); |
There was a problem hiding this comment.
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
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this 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:
Please leave a comment what was not covered and why (when it's impossible).
However, the code is really clean and understandable.
5411388
to
bfc9968
Compare
bfc9968
to
d6c771f
Compare
d6c771f
to
cbebc7e
Compare
There was a problem hiding this 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_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 | ||
*/ | ||
|
There was a problem hiding this comment.
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 functionthe full value shall be available from waitid()
- temporary not possible to check, due to lack of waitid() func - please leave a comment about it.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | ||
*/ | ||
|
There was a problem hiding this comment.
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
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 | ||
*/ | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cbebc7e
to
25b68f3
Compare
25b68f3
to
926247c
Compare
There was a problem hiding this 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
926247c
to
ad0ad38
Compare
ad0ad38
to
63bda5b
Compare
exit/test-exit.c
Outdated
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"); | ||
} |
There was a problem hiding this comment.
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?
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"); | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
} | ||
|
||
|
||
TEST(unistd_exit, status_vals) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It potentially may change.
There was a problem hiding this comment.
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.
37e48a7
to
e39c937
Compare
e39c937
to
41222c3
Compare
a641473
to
9ffd0d3
Compare
8f6ea7e
to
cf9ebf5
Compare
cf9ebf5
to
f24a1c6
Compare
JIRA: CI-209
f24a1c6
to
2cd4b47
Compare
There was a problem hiding this 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
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment