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

Tracking Modifications and Findings During Test Suite Porting #15

Open
Yaxuan-w opened this issue Sep 18, 2024 · 0 comments
Open

Tracking Modifications and Findings During Test Suite Porting #15

Yaxuan-w opened this issue Sep 18, 2024 · 0 comments
Assignees

Comments

@Yaxuan-w
Copy link
Member

Yaxuan-w commented Sep 18, 2024

Description:

This issue is to document all the changes and discoveries made while porting the test suite from RustPOSIX to RawPOSIX. Below are the current modifications and fixes identified:

chmod

  1. Modify behaviors: cannot setting 0o777 so set to 0o755 instead
  2. Modify behaviors: The extra bits are special permission bits in native linux

close

  1. Fix bug in fdtable array

mmap

  1. Fix error return
  2. Test fix: Native linux may default to treating the combination as one or the other.
  3. Test fix: Native linux will return EINVAL when offset is negative or not in range.
  4. Test fix: Native linux can mmap character device.
  5. Test fix: Native linux require specific flags to open a dir.
  6. Test fix: Native linux will return ENODEV when mapping a dir.
  7. Test fix: The previous test cases created directories but did not remove them. Consequently, when subsequent test cases attempted to create directories with the same names, an error was thrown because the directories already existed. This fix ensures that the directories are properly removed after each test case, preventing these conflicts.
  8. Modification: The test now checks for the generic error code (-1) before matching against EINVAL for invalid flag combinations.
  9. Test fix: When handling memory-mapped files and syscalls like getdents_syscall that deal with directory entries stored in packed structures, accessing fields like d_off and d_reclen directly can result in alignment issues on architectures that enforce strict memory alignment. To prevent runtime errors, the fields from packed structures are copied into local variables before they are used. This approach avoids accessing misaligned memory directly, ensuring the program remains stable across different platforms.

chdir

  1. Fix bug that we should first check if desired path exists in native

fchdir

  1. Test fix: Native linux require specific flags to open a dir.
  2. Fix bug that we should also updated the lind cwd (calling libc::cwd and then extract the working directory) after calling fchdir.

open

  1. Fix the condition when opening large number of files
  2. Fix the issue related to writing to directories:
    • Test fix: Ensure that when attempting to write to a directory with O_WRONLY, it returns EISDIR as expected.
    • Test fix: Ensure that opening a directory with O_RDONLY returns a valid file descriptor, and attempting to write to it results in EBADF.
    • Added cleanup to remove the directory after each test to prevent conflicts with subsequent tests.
  3. Fix for handling st_nlink and st_size values in directory tests:
    • Test fix: The st_nlink value in ut_lind_fs_simple was adjusted to account for multiple subdirectories under /, ensuring accurate hard link counts.
    • Test fix: The st_size value for directories is now validated to be greater than or equal to the filesystem's block size (commonly 4096 bytes), instead of assuming a size of 0.

getdents_syscall

  1. Test Fix: When calling getdents_syscall with a buffer size smaller than CLIPPED_DIRENT_SIZE, the test should ensure that the appropriate error (EINVAL) is returned. The current behavior was returning an incorrect file descriptor error (EBADF) due to opening the directory with incorrect flags.
  2. Modification: Changed the directory open flags from O_RDWR to O_RDONLY in the ut_lind_fs_getdents_bufsize_too_small test case, ensuring that the directory opens correctly and allows testing for the proper error behavior.

dup

  1. Fix to handle bad file descriptor condition

dup2

  1. Fix bug that might be caused by below. Soln: reserving STDIN / STDOUT / STDERR in lindrustinit by redirecting fd=0/1/2 to /dev/null
Sometimes the `ut_lind_fs_dup2` can succeed sometimes cannot, so I suspect the error caused by following:

Daemon Processes: Daemon processes or services that explicitly close standard file descriptors to run in the background may result in open returning 0
  1. Fix to handle bad file descriptor condition

fcntl

  1. Test fix: Use FD_CLOEXEC when setting and checking file descriptor flags with F_SETFD and F_GETFD.
  2. Test fix: Change to use & to check if flag has been set, and O_RDONLY should be checked by using O_ACCMODE
  3. Test fix: Fixed getdents_syscall handling when the file descriptor is out of range.
Set the file status flags to the value specified by arg.
              File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file
              creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC)
              in arg are ignored.  On Linux, this operation can change
              only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and
              O_NONBLOCK flags
  1. Test fix: F_SETFD, F_SETFL with negative value args will not cause fcntl return error.
  2. Fix bug that op is F_DUPFD and arg is negative or is greater than the maximum allowable value.
  3. Fix bug that op is F_DUPFD and the per-process limit on the number of open file descriptors has been reached.
  4. Fix bug that
Duplicate the file descriptor fd using the lowest-numbered
              available file descriptor greater than or equal to arg.
              This is different from dup2(2), which uses exactly the
              file descriptor specified
  1. Test fix: We should do lseek first to put file position at beginning, because in native linux when we read from the end of the file it will return 0
EOF (End of File): This indicates that the end of the file has been reached. If reading from a regular file, this means there is no more data left to read.

ioctl

  1. Test fix (exclusive): change ioctl_union to libc::ioctl
  2. Test fix (exclusice): Those invalid argument(FIONBIO) will success in native linux (ArchLinux)
    [https://stackoverflow.com/a/1151077/22572322]
    ...but these behaved inconsistently between systems, and even within the same system...
  3. Test fix: I suspect that The ioctl call first checks whether the file descriptor type supports the operation associated with the request code. If the file descriptor is of a type that does not handle the requested operation (such as a socket not supporting a terminal command), ENOTTY is returned.

link

  1. Test fix (exclusive): because in rawposix we'll transfer relative path into absolute path, native linux will always return EPERM instead of ENOENT when passing null value.

unlink

  1. Test fix (exclusive): because in rawposix we'll transfer relative path into absolute path, native linux will alway
    s return EISDIR instead of ENOENT when passing null value.

rmdir

  1. Test fix (exclusive): because in rawposix we'll transfer relative path into absolute path, native linux will alway
    s return ENOTEMPTY instead of ENOENT when passing null value.

  2. Test fix: In the condition: calling rmdir_syscall()on the child directory should return Directory does not allow write permission error because the directory cannot be removed if its parent directory does not allow write permission. Native linux will return EACCES instead of EPERM.

  3. Test fix: changing all directory name into test-specific, because native mkdir will return error when directory has been created before.

  4. Test fix: rmdir can succeed even if the directory has restrictive permissions because rmdir doesn't require write permissions on the directory itself; it requires write and execute permissions on the parent directory of the target directory.

  5. Test fix: bug related to mkdir in rustposix but not in native linux, so changing test to correct version.

mkdir

  1. Fix for handling empty path: Modified mkdir_syscall to return ENOENT for an empty path, ensuring compliance with expected behavior when no directory name is provided. Previously, this scenario returned an incorrect error code.
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

No branches or pull requests

2 participants