From a9dfc98c63c26f9445a69d6e1de7af88e178e1b7 Mon Sep 17 00:00:00 2001 From: Chen Chengjun Date: Wed, 10 Sep 2025 10:38:45 +0000 Subject: [PATCH] Add tests for mount bind --- test/src/apps/scripts/fs.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/src/apps/scripts/fs.sh b/test/src/apps/scripts/fs.sh index 5ca39262c..462c27bfd 100755 --- a/test/src/apps/scripts/fs.sh +++ b/test/src/apps/scripts/fs.sh @@ -53,6 +53,39 @@ test_fdatasync() { rm -f /exfat/test_fdatasync.txt } +test_mount_bind_file() { + local file_a="/file_a.txt" + local file_b="/file_b.txt" + local content_a="initial content for file A" + local content_b_new="new content written to file B" + + echo "$content_a" > "$file_a" + touch "$file_b" + + mount --bind "$file_a" "$file_b" + + # Read from file_b and check if it matches file_a's content + if [ "$(cat "$file_b")" != "$content_a" ]; then + echo "Error: Read from bind-mounted file failed. Content mismatch." + umount "$file_b" + rm -f "$file_a" "$file_b" + return 1 + fi + + echo "$content_b_new" > "$file_b" + + # Check if file_a's content is updated + if [ "$(cat "$file_a")" != "$content_b_new" ]; then + echo "Error: Write to bind-mounted file did not affect the source file." + umount "$file_b" + rm -f "$file_a" "$file_b" + return 1 + fi + + umount "$file_b" + rm -f "$file_a" "$file_b" +} + echo "Start ext2 fs test......" test_ext2 "/ext2" "test_file.txt" echo "All ext2 fs test passed." @@ -61,6 +94,10 @@ echo "Start fdatasync test......" test_fdatasync echo "All fdatasync test passed." +echo "Start mount bind file test......" +test_mount_bind_file +echo "All mount bind file test passed." + pipe/pipe_err pipe/short_rw epoll/epoll_err