uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.56k stars 1.26k forks source link

df: test_type_option_with_file is failing on linux #6194

Open jadijadi opened 5 months ago

jadijadi commented 5 months ago

running cargo test --features "df" --no-default-features on my machine (Fedora 39) fails with:

test test_df::test_type_option ... ok
test test_df::test_type_option_with_file ... FAILED

failures:

---- test_df::test_type_option_with_file stdout ----
run: /home/jadi/w/coreutils/target/debug/coreutils df --output=fstype .
run: /home/jadi/w/coreutils/target/debug/coreutils df -t tmpfs .
run: /home/jadi/w/coreutils/target/debug/coreutils df -t nonexisting .
run: /home/jadi/w/coreutils/target/debug/coreutils df --output=fstype
run: /home/jadi/w/coreutils/target/debug/coreutils df -t ext4 .
---- test_df::test_type_option_with_file stderr ----
thread 'main' panicked at tests/by-util/test_df.rs:292:14:
Command was expected to fail.
stdout = Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/nvme0n1p1  51290592 10272556  38380212  22% /

 stderr =
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    test_df::test_type_option_with_file

test result: FAILED. 75 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.83s

On command line, running df -t ext4 . is successful with the following stdout:

df -t ext4 .
Filesystem        1K-blocks      Used Available Use% Mounted on
/dev/mapper/chome 873904196 722075412 107363172  88% /home

but the test expects a failure.

cakebaker commented 5 months ago

What's the output of df --output=fstype . and df --output=fstype?

Edit: I'm able to reproduce it on my machine. It seems to be related to tmpfs: running df -t ext4 . on a tmpfs file system fails with "no file systems processed", whereas with uutils df it doesn't fail.

jadijadi commented 5 months ago

here you are

df --output=fstype .
Type
ext4

df --output=fstype
Type
ext4
devtmpfs
tmpfs
efivarfs
tmpfs
tmpfs
vfat
ext4
tmpfs

target/debug/coreutils df --output=fstype .
Type
ext4

target/debug/coreutils df --output=fstype
Type
ext4
devtmpfs
tmpfs
efivarfs
tmpfs
tmpfs
vfat
ext4
tmpfs
kralo commented 2 months ago

Edit: I'm able to reproduce it on my machine. It seems to be related to tmpfs: running df -t ext4 . on a tmpfs file system fails with "no file systems processed", whereas with uutils df it doesn't fail.

This looks done? Test passes and manuel test is getting the expected result:

# target/release/coreutils df -T /dev/shm
Filesystem     Type  1K-blocks   Used Available Use% Mounted on
tmpfs          tmpfs   1879516 375292   1504224  20% /dev/shm
# target/release/coreutils df -t ext4 /dev/shm
df: no file systems processed

(second try)

# target/release/coreutils df -T /tmp
Filesystem     Type 1K-blocks    Used Available Use% Mounted on
/dev/nvme0n1p1 xfs    8376300 4247452   4128848  51% /
# target/release/coreutils df -t ext4 /tmp
df: no file systems processed
cakebaker commented 2 months ago

@kralo hm, I'm still able to reproduce it on my machine:

$ cargo run df -T /dev/shm
Filesystem     Type  1K-blocks  Used Available Use% Mounted on
tmpfs          tmpfs   4011708 85000   3926708   3% /dev/shm
$ cargo run df -t ext4 /dev/shm
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda8      458020024 415326384  19400868  96% /
kralo commented 2 months ago

I'm still able to reproduce it on my machine:

$ cargo run df -t ext4 /dev/shm
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda8      458020024 415326384  19400868  96% /

This second invocation looks very strange. Why does it report the mountpoint / when you asked about /dev/shm ?

Might we establish common test procedure? What about


cd /dev/shm
fallocate -l 6M testvol
mkfs.fat testvol
mkdir testmnt
sudo mount testvol testmnt
sudo touch testmnt/testfile

$ cargo run df -T /dev/shm/testmnt/
Filesystem     Type 1K-blocks  Used Available Use% Mounted on
/dev/loop6     vfat      6114     0      6114   0% /dev/shm/testmnt

$ cargo run df -t ext4 /dev/shm/testmnt/
df: no file systems processed

could you share complete df -T ?

cakebaker commented 2 months ago

Sure, here it is:

$ cargo run df -T /dev/shm/testmnt
Filesystem     Type 1K-blocks  Used Available Use% Mounted on
/dev/loop0     vfat      6114     0      6114   0% /dev/shm/testmnt
$ cargo run df -t ext4 /dev/shm/testmnt
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda8      458020024 414414544  20312708  96% /

$ df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
dev            devtmpfs   3980580         0   3980580   0% /dev
run            tmpfs      4011712      1516   4010196   1% /run
efivarfs       efivarfs        88        86         0 100% /sys/firmware/efi/efivars
/dev/sda8      ext4     458020024 414414608  20312644  96% /
tmpfs          tmpfs      4011712     72968   3938744   2% /dev/shm
tmpfs          tmpfs      4011712     16236   3995476   1% /tmp
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-journald.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-tmpfiles-setup-dev-early.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-udev-load-credentials.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-sysctl.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-sysusers.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-tmpfiles-setup-dev.service
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-vconsole-setup.service
/dev/sda2      vfat        262144    211604     50540  81% /boot
tmpfs          tmpfs         1024         0      1024   0% /run/credentials/systemd-tmpfiles-setup.service
tmpfs          tmpfs       802340        88    802252   1% /run/user/1000
/dev/loop0     vfat          6114         0      6114   0% /dev/shm/testmnt
kralo commented 2 months ago

aah, I can reproduce, if you choose the filesystem that is your /, for me, btrfs . That is a bug

$ cargo run df -t btrfs /dev/shm/testmnt/
   Compiling uu_df v0.0.26 (/opt/maxprogs/coreutils/src/uu/df)
   Compiling coreutils v0.0.26 (/opt/maxprogs/coreutils)
    Finished dev [unoptimized + debuginfo] target(s) in 2.87s
     Running `target/debug/coreutils df -t btrfs /dev/shm/testmnt/`
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda3      234431488 130969240 101320408  57% /