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

Arkadiusz kozlowski/opendir tests #278

Closed
wants to merge 1 commit into from

Conversation

KArkadiusz
Copy link

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.

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.

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))
Copy link
Contributor

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.

Comment on lines 8 to 9
* Copyright 2021, 2022 Phoenix Systems
* Author: Marek Bialowas, Damian Loewnau
Copy link
Contributor

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.

}


TEST(opendir, opening_not_empty_directory)
Copy link
Contributor

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.

TEST_GROUP(opendir);


TEST_SETUP(opendir)
Copy link
Contributor

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.

Copy link
Contributor

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.

}


TEST(opendir, opening_not_empty_directory)
Copy link
Contributor

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.

TEST_GROUP_RUNNER(readdir)
{
RUN_TEST_CASE(readdir, basic_listing_count);
RUN_TEST_CASE(readdir, correct_dirent_names);
Copy link
Contributor

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.

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);
Copy link
Contributor

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:

  1. open directory with some initial content
  2. read the whole content and assert it's proper
  3. close the directory
  4. create some additional files within mentioned dir
  5. open it for a second time
  6. 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.

Copy link
Author

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.

TEST_GROUP_RUNNER(rewinddir)
{

RUN_TEST_CASE(rewinddir, reset_dirstream_position);
Copy link
Contributor

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.

while (readdir(dp))
counter3++;

TEST_ASSERT_NOT_EQUAL(counter1, counter3);
Copy link
Contributor

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.

}
}

kill(childID, SIGKILL);
Copy link
Contributor

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.

@KArkadiusz KArkadiusz force-pushed the ArkadiuszKozlowski/opendirTests branch from c3e930a to 74bd017 Compare October 24, 2023 11:53
@github-actions
Copy link

github-actions bot commented Oct 24, 2023

Unit Test Results

6 167 tests  +178   5 500 ✔️ +152   34m 17s ⏱️ + 4m 50s
   341 suites +    8      657 💤 +  16 
       1 files   ±    0        10 +  10 

For more details on these failures, see this check.

Results for commit c0f421a. ± Comparison against base commit 36b0b78.

♻️ This comment has been updated with latest results.

@KArkadiusz KArkadiusz requested a review from damianloew November 2, 2023 17:15
libc/dirent/opendir.c Outdated Show resolved Hide resolved
@KArkadiusz KArkadiusz force-pushed the ArkadiuszKozlowski/opendirTests branch from 46c7ebf to e1207ea Compare November 8, 2023 16:39
@damianloew damianloew requested a review from adamdebek November 10, 2023 11:00
@KArkadiusz KArkadiusz force-pushed the ArkadiuszKozlowski/opendirTests branch from bd78a18 to c0f421a Compare November 10, 2023 11:22
@KArkadiusz KArkadiusz closed this Nov 13, 2023
@KArkadiusz KArkadiusz deleted the ArkadiuszKozlowski/opendirTests branch November 13, 2023 16:41
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