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

fix: test case ut_lind_fs_getdents #74

Merged
merged 2 commits into from
Oct 25, 2024
Merged

Conversation

ChinmayShringi
Copy link
Contributor

Description

Fixes # (issue)

This pull request focuses on resolving alignment issues in the ut_lind_fs_getdents test and ensuring proper handling of directory entries when interacting with packed fields. The primary changes involve:

  • Ensuring Safe Access to Packed Fields: In the original test, direct access to packed fields in the ClippedDirent struct resulted in alignment issues, particularly for d_off and d_reclen. These fields have been safely accessed by copying them into local variables to ensure proper memory alignment.
  • Test Setup Cleanup: The test now ensures that the /getdents directory is properly cleaned up before the test is executed. If the directory already exists, it is removed to avoid conflicts. This ensures the test runs in a clean environment each time.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Dependencies

This change does not introduce new dependencies, but it ensures better integration with existing modules (e.g., native-client, lind-glibc, and lind-project). No updates are required in those modules for this change to be effective.

How Has This Been Tested?

  • cargo test ut_lind_fs_getdents

Checklist:

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been added to a pull request and/or merged in other modules (native-client, lind-glibc, lind-project)


unsafe {
let first_dirent = baseptr as *mut interface::ClippedDirent;
assert!((*first_dirent).d_off == 24);
let reclen_matched: bool = ((*first_dirent).d_reclen == 24);
// Copy packed fields into local variables to avoid alignment issues
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain more what this is doing? What alignment? Do you mean word, etc. alignment? Why is this needed?

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 a byte alignment issue, the fields in the packed structure (ClippedDirent) are tightly packed without the usual padding that would align them on word boundaries (like 4 or 8 bytes). Because of this, directly accessing these fields cause problems on some systems that expect memory to be accessed in larger chunks (like words).

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this in the comment in more detail? Once this happens, I'll approve

@@ -2540,6 +2552,7 @@ pub mod fs_tests {
assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS);
lindrustfinalize();
}

Copy link
Member

Choose a reason for hiding this comment

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

extra space add?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I added a new line between the 2 test functions

Copy link
Member

@Yaxuan-w Yaxuan-w left a comment

Choose a reason for hiding this comment

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

I worked with Qianxi on testing getdents before, and we encountered issues related to memory alignment and differences in the data structures between 32-bit and 64-bit layouts when checking the returned structure. I'm really glad to see that your test is comprehensive in addressing these concerns.

@Yaxuan-w Yaxuan-w merged commit 7512ada into main Oct 25, 2024
1 check failed
@Yaxuan-w Yaxuan-w deleted the fix-ut-lind-fs-getdents branch October 25, 2024 21:02
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