Add NTFS test to test suite

This commit is contained in:
Thomas Veerman 2012-11-15 17:38:16 +00:00
parent 9903b9fb96
commit d67db9b39c
3 changed files with 127 additions and 3 deletions

View file

@ -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

View file

@ -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`

123
test/test65.c Normal file
View file

@ -0,0 +1,123 @@
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#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 */
}