/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #define TEST(cmd, exp_value) ({ \ int st = (cmd); \ if (st < 0) \ st = errno; \ printf("%s: got=%d expected=%d status=%s\n", #cmd, st, (exp_value), st == (exp_value) ? "OK" : "FAILURE"); \ }); #define ASSERT(expr) ({ \ printf("assert(%s) status=%s\n", #expr, (expr) ? "OK" : "FAILURE"); \ }); int main() { struct stat statbuf; time_t mtime; /* demonter et monter procfs */ printf("unmount and mount procfs\n"); TEST(stat("/proc/filesystems", &statbuf), 0); TEST(umount("/proc"), 0); TEST(umount("/proc"), EINVAL); TEST(mount(NULL, "/proc", "procfs", 0, NULL), 0); TEST(stat("/proc/filesystems", &statbuf), 0); printf("\n"); /* quelques cas d'erreur */ printf("a couple of error cases\n"); TEST(mount("bla", "/floppy/empty", "vfat", 0, NULL), ENOENT); TEST(mount("/dev/fd", NULL, "vfat", 0, NULL), EFAULT); TEST(mount("/dev/fd", "bla", "vfat", 0, NULL), ENOENT); TEST(mount("/dev/fd", "/floppy/empty", NULL, 0, NULL), EFAULT); TEST(mount("/dev/fd", "/floppy/empty", "bla", 0, NULL), ENODEV); TEST(mount("/dev/fd", "/floppy/", "vfat", 0, NULL), EBUSY); TEST(mount(NULL, "/floppy/empty", "vfat", 0, NULL), ENOTBLK); TEST(mount("/dev/null", "/floppy/empty", "vfat", 0, NULL), ENOTBLK); TEST(mount("/floppy/empty", "/floppy/empty", "vfat", 0, NULL), ENOTBLK); TEST(mount("/dev/fd", "/dev/fd", "vfat", 0, NULL), ENOTDIR); printf("\n"); /* monter et demonter rootfs plusieurs fois */ printf("mount and unmount rootfs several times\n"); TEST(stat("/floppy/empty/bin", &statbuf), ENOENT); TEST(mount(NULL, "/floppy/empty", "rootfs", 0, NULL), 0); TEST(stat("/floppy/empty/bin", &statbuf), 0); sleep(1); TEST(stat("/floppy/full/bin", &statbuf), ENOENT); TEST(mount("/dev/fd", "/floppy/full", "rootfs", 0, NULL), 0); TEST(stat("/floppy/full/bin", &statbuf), 0); system("cat /proc/mounts"); TEST(stat("/floppy/empty", &statbuf), 0); mtime = statbuf.st_mtime; TEST(stat("/floppy/full", &statbuf), 0); ASSERT(statbuf.st_mtime == mtime); TEST(umount("/floppy/empty"), 0); TEST(stat("/floppy/empty/bin", &statbuf), ENOENT); TEST(stat("/floppy/full/bin", &statbuf), 0); TEST(umount("/floppy/full"), 0); TEST(stat("/floppy/full/bin", &statbuf), ENOENT); printf("\n"); /* monter et demonter devfs plusieurs fois */ printf("mount and unmount devfs several times\n"); TEST(stat("/floppy/empty/null", &statbuf), ENOENT); TEST(mount(NULL, "/floppy/empty", "devfs", 0, NULL), 0); TEST(stat("/floppy/empty/null", &statbuf), 0); sleep(1); TEST(stat("/floppy/full/null", &statbuf), ENOENT); TEST(mount(NULL, "/floppy/full", "devfs", 0, NULL), 0); TEST(stat("/floppy/full/null", &statbuf), 0); system("cat /proc/mounts"); TEST(stat("/floppy/empty", &statbuf), 0); mtime = statbuf.st_mtime; TEST(stat("/floppy/full", &statbuf), 0); ASSERT(statbuf.st_mtime == mtime); TEST(umount("/floppy/empty"), 0); TEST(stat("/floppy/empty/null", &statbuf), ENOENT); TEST(stat("/floppy/full/null", &statbuf), 0); TEST(umount("/floppy/full"), 0); TEST(stat("/floppy/full/null", &statbuf), ENOENT); printf("\n"); /* monter et demonter procfs plusieurs fois */ printf("mount and unmount procfs several times\n"); TEST(stat("/floppy/empty/filesystems", &statbuf), ENOENT); TEST(mount(NULL, "/floppy/empty", "procfs", 0, NULL), 0); TEST(stat("/floppy/empty/filesystems", &statbuf), 0); sleep(1); TEST(stat("/floppy/full/filesystems", &statbuf), ENOENT); TEST(mount(NULL, "/floppy/full", "procfs", 0, NULL), 0); TEST(stat("/floppy/full/filesystems", &statbuf), 0); system("cat /proc/mounts"); TEST(stat("/floppy/empty", &statbuf), 0); mtime = statbuf.st_mtime; TEST(stat("/floppy/full", &statbuf), 0); ASSERT(statbuf.st_mtime == mtime); TEST(umount("/floppy/empty"), 0); TEST(stat("/floppy/empty/filesystems", &statbuf), ENOENT); TEST(stat("/floppy/full/filesystems", &statbuf), 0); TEST(umount("/floppy/full"), 0); TEST(stat("/floppy/full/filesystems", &statbuf), ENOENT); printf("\n"); /* monter et demonter vfat plusieurs fois */ printf("mount and unmount vfat several times\n"); TEST(stat("/floppy/empty/empty", &statbuf), ENOENT); TEST(mount("/dev/fd", "/floppy/empty", "vfat", 0, NULL), 0); TEST(stat("/floppy/empty/empty", &statbuf), 0); TEST(stat("/floppy/full/empty", &statbuf), ENOENT); TEST(mount("/dev/fd", "/floppy/full", "vfat", 0, NULL), 0); TEST(stat("/floppy/full/empty", &statbuf), 0); system("cat /proc/mounts"); TEST(mkdir("/floppy/empty/test1", 0), 0); TEST(mkdir("/floppy/full/test2", 0), 0); TEST(stat("/floppy/empty/test1", &statbuf), 0); TEST(stat("/floppy/empty/test2", &statbuf), 0); TEST(stat("/floppy/full/test1", &statbuf), 0); TEST(stat("/floppy/full/test2", &statbuf), 0); TEST(umount("/floppy/empty"), 0); TEST(stat("/floppy/empty/empty", &statbuf), ENOENT); TEST(stat("/floppy/full/empty", &statbuf), 0); TEST(umount("/floppy/full"), 0); TEST(stat("/floppy/full/empty", &statbuf), ENOENT); TEST(rmdir("/floppy/test1"), 0); TEST(rmdir("/floppy/test2"), 0); TEST(rmdir("/floppy/test1"), ENOENT); printf("\n"); /* monter et demonter ramfs plusieurs fois */ printf("mount and unmount ramfs several times\n"); TEST(mount(NULL, "/floppy/empty", "ramfs", 0, NULL), 0); TEST(mount(NULL, "/floppy/full", "ramfs", 0, NULL), 0); system("cat /proc/mounts"); TEST(mkdir("/floppy/empty/test1", 0), 0); TEST(mkdir("/floppy/full/test2", 0), 0); TEST(stat("/floppy/empty/test1", &statbuf), 0); TEST(stat("/floppy/empty/test2", &statbuf), ENOENT); TEST(stat("/floppy/full/test1", &statbuf), ENOENT); TEST(stat("/floppy/full/test2", &statbuf), 0); TEST(umount("/floppy/empty"), 0); TEST(stat("/floppy/empty/test1", &statbuf), ENOENT); TEST(stat("/floppy/full/test2", &statbuf), 0); TEST(umount("/floppy/full"), 0); TEST(stat("/floppy/full/empty", &statbuf), ENOENT); printf("\n"); return EXIT_SUCCESS; }