-
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
Arkadiusz kozlowski/opendir tests #278
Conversation
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've left some improvements and I've indicated some lacks in the coverage of requirements. However the existent code looks clean, and I like its structure.
libc/Makefile
Outdated
@@ -23,3 +23,4 @@ $(eval $(call add_test_libc,misc)) | |||
$(eval $(call add_test_libc,stdio)) | |||
$(eval $(call add_test_libc,stdlib)) | |||
$(eval $(call add_test_libc,string)) | |||
$(eval $(call add_test_libc,dirent)) |
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.
Please always add newline at the end of file. Unless you do it, there will be this red sign.
libc/dirent/main.c
Outdated
* Copyright 2021, 2022 Phoenix Systems | ||
* Author: Marek Bialowas, Damian Loewnau |
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.
You can assume that you are the only author in this case. Moreover please correct the date.
libc/dirent/opendir.c
Outdated
} | ||
|
||
|
||
TEST(opendir, opening_not_empty_directory) |
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 case is not called.
libc/dirent/opendir.c
Outdated
TEST_GROUP(opendir); | ||
|
||
|
||
TEST_SETUP(opendir) |
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 would opt for leaving only the things necessary for all the cases in setup/tear_down functions as they are called before/after every test case.
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.
Applies to the rest of tests.
libc/dirent/opendir.c
Outdated
} | ||
|
||
|
||
TEST(opendir, opening_not_empty_directory) |
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.
Creating case, where empty directory is checked will be a good idea.
libc/dirent/readdir.c
Outdated
TEST_GROUP_RUNNER(readdir) | ||
{ | ||
RUN_TEST_CASE(readdir, basic_listing_count); | ||
RUN_TEST_CASE(readdir, correct_dirent_names); |
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 about testing errnos in this test? I am not sure about EOVERFLOW (maybe if d_name was too long) and ENOENT (don't have idea for reproducing it for now), but EBADF seems to be simple to check. Please leave a comment if some requirement is not possilble to test using our current testing environment.
libc/dirent/opendir.c
Outdated
RUN_TEST_CASE(opendir, not_a_directory); | ||
RUN_TEST_CASE(opendir, direct_symlink); | ||
RUN_TEST_CASE(opendir, too_long_path); | ||
RUN_TEST_CASE(opendir, open_n_directories); |
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.
You can also add a case, where you:
- open directory with some initial content
- read the whole content and assert it's proper
- close the directory
- create some additional files within mentioned dir
- open it for a second time
- check whether the content has been updated
It shall also cause the directory stream to refer to the current state of the corresponding directory, as a call to opendir()would have done
- rewinddir docs. So you can also add the analogical case in rewinddir tests.
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'm not sure how I would read the whole content from no. 2, in opendir at most I can check if I have access to newly created files, even if the dir isn't opened.
libc/dirent/rewinddir.c
Outdated
TEST_GROUP_RUNNER(rewinddir) | ||
{ | ||
|
||
RUN_TEST_CASE(rewinddir, reset_dirstream_position); |
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.
After a call to the fork() function, either the parent or child (but not both) may continue processing the directory stream using rewinddir(),
- please try to call rewinddir in a child.
libc/dirent/rewinddir.c
Outdated
while (readdir(dp)) | ||
counter3++; | ||
|
||
TEST_ASSERT_NOT_EQUAL(counter1, counter3); |
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'd opt for asserting the exact value, so in this case counter3 to be 3.
libc/dirent/closedir.c
Outdated
} | ||
} | ||
|
||
kill(childID, SIGKILL); |
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.
SIGKILL
also kills the parent - that's why it won't work. I am not sure whether this requirement is valid on our system and possible to test - to be discussed. Notice that it's not strictly required on POSIX as word may
is used: The closedir() function may fail if:
. For now you can leave those cases commented out.
c3e930a
to
74bd017
Compare
46c7ebf
to
e1207ea
Compare
bd78a18
to
c0f421a
Compare
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment