From d67db9b39c41758d9bdbd447f574796be15666b3 Mon Sep 17 00:00:00 2001 From: Thomas Veerman Date: Thu, 15 Nov 2012 17:38:16 +0000 Subject: [PATCH] Add NTFS test to test suite --- test/Makefile | 5 +- test/run | 2 +- test/test65.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 test/test65.c diff --git a/test/Makefile b/test/Makefile index 28535f50b..805e71523 100644 --- a/test/Makefile +++ b/test/Makefile @@ -23,7 +23,7 @@ OBJS.test57=test57loop.o 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ -61 62 64 +61 62 64 65 PROG+= test$(t) .endfor @@ -46,7 +46,8 @@ PROG+= test63 mod # Some are suid-root all: - chmod 4755 test11 test33 test43 test44 test46 test56 test60 test61 + chmod 4755 test11 test33 test43 test44 test46 test56 test60 test61 \ + test65 clean: .PHONY .MAKE $(MAKE) -C select clean diff --git a/test/run b/test/run index 0802e15a8..67d847cbb 100755 --- a/test/run +++ b/test/run @@ -14,7 +14,7 @@ badones= # list of tests that failed tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ - 61 62 63 64 \ + 61 62 63 64 65 \ sh1.sh sh2.sh interp.sh" tests_no=`expr 0` diff --git a/test/test65.c b/test/test65.c new file mode 100644 index 000000000..ca9e70bd4 --- /dev/null +++ b/test/test65.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +#include +#include + +#define MAX_ERROR 0 +#include "common.c" + +#define TESTMNT "testmnt" +#define TESTFILE "test.txt" +#define TESTSTRING "foobar" +#define RAMDISK "/dev/ram5" +#define RAMDISK_SIZE "2048" +#define SILENT " > /dev/null 2>&1" + +void basic_test(void); +void bomb(char const *msg); +void create_partition(void); +void verify_tools(void); + +void +basic_test(void) +{ +/* Write a string to a file, read it back, and confirm it's identical */ + int status; + char cmd_buf[1024]; + char file_buf[sizeof(TESTSTRING)*10]; + int fd; + + subtest = 3; + + /* Write test string to test file */ + snprintf(cmd_buf, sizeof(cmd_buf), "echo -n %s > %s/%s\n", + TESTSTRING, TESTMNT, TESTFILE); + status = system(cmd_buf); + if (WEXITSTATUS(status) != 0) + bomb("Unable to echo string to file"); + + /* Flush to disk and unmount, remount */ + system("sync"); + system("umount " RAMDISK SILENT); + snprintf(cmd_buf, sizeof(cmd_buf), "mount -t ntfs-3g %s %s %s", + RAMDISK, TESTMNT, SILENT); + status = system(cmd_buf); + if (WEXITSTATUS(status != 0)) + bomb("Unable to mount NTFS partition (1)"); + + /* Open file and verify contents */ + if ((fd = open(TESTMNT "/" TESTFILE, O_RDONLY)) < 0) e(1); + if (read(fd, file_buf, sizeof(file_buf)) != strlen(TESTSTRING)) e(2); + (void) close(fd); + system("umount " RAMDISK SILENT); + if (strncmp(file_buf, TESTSTRING, strlen(TESTSTRING))) e(3); +} + +void +bomb(char const *msg) +{ + system("umount " RAMDISK SILENT); + printf("%s\n", msg); + e(99); + quit(); +} + +void +create_partition(void) +{ + int status; + char mntcmd[1024]; + + subtest = 1; + + if (getuid() != 0 && setuid(0) != 0) e(1); + status = system("ramdisk " RAMDISK_SIZE " " RAMDISK SILENT); + if (WEXITSTATUS(status) != 0) + bomb("Unable to create ramdisk"); + + status = system("mkntfs " RAMDISK SILENT); + if (WEXITSTATUS(status) != 0) + bomb("Unable to create NTFS file system on " RAMDISK); + + if (mkdir(TESTMNT, 0755) != 0) + bomb("Unable to create directory for mounting"); + + snprintf(mntcmd, sizeof(mntcmd), "mount -t ntfs-3g %s %s %s", + RAMDISK, TESTMNT, SILENT); + status = system(mntcmd); + if (WEXITSTATUS(status != 0)) + bomb("Unable to mount NTFS partition (1)"); +} + +void +verify_tools(void) +{ + int status; + + subtest = 1; + status = system("which mkntfs > /dev/null 2>&1"); + if (WEXITSTATUS(status) != 0) { + bomb("mkntfs not found. Please install ntfsprogs (pkgin in " + "ntfsprogs)"); + } + status = system("which ntfs-3g > /dev/null 2>&1"); + if (WEXITSTATUS(status) != 0) { + bomb("ntfs-3g not found. Please install fuse-ntfs-3g-1.1120 " + "(pkgin in fuse-ntfs-3g-1.1120)"); + } +} + +int +main(int argc, char *argv[]) +{ + start(65); + verify_tools(); + create_partition(); + basic_test(); + quit(); + return(-1); /* Unreachable */ +} + -- 2.44.0