sort: add -x hex sort feature back
[minix.git] / test / test65.c
blob27347e93c0641a8e85b1318aec736f1a7ac23e73
1 #include <sys/mount.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <sys/wait.h>
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <unistd.h>
9 #define MAX_ERROR 0
10 #include "common.c"
12 #define TESTMNT "testmnt"
13 #define TESTFILE "test.txt"
14 #define TESTSTRING "foobar"
15 #define RAMDISK "/dev/ram5"
16 #define RAMDISK_SIZE "2048"
17 #define SILENT " > /dev/null 2>&1"
19 void basic_test(void);
20 void bomb(char const *msg);
21 void skip(char const *msg);
22 void create_partition(void);
23 void verify_tools(void);
25 void
26 basic_test(void)
28 /* Write a string to a file, read it back, and confirm it's identical */
29 int status;
30 char cmd_buf[1024];
31 char file_buf[sizeof(TESTSTRING)*10];
32 int fd;
34 subtest = 3;
36 /* Write test string to test file */
37 snprintf(cmd_buf, sizeof(cmd_buf), "echo -n %s > %s/%s\n",
38 TESTSTRING, TESTMNT, TESTFILE);
39 status = system(cmd_buf);
40 if (WEXITSTATUS(status) != 0)
41 bomb("Unable to echo string to file");
43 /* Flush to disk and unmount, remount */
44 system("sync");
45 system("umount " RAMDISK SILENT);
46 snprintf(cmd_buf, sizeof(cmd_buf), "mount -t ntfs-3g %s %s %s",
47 RAMDISK, TESTMNT, SILENT);
48 status = system(cmd_buf);
49 if (WEXITSTATUS(status != 0))
50 bomb("Unable to mount NTFS partition (1)");
52 /* Open file and verify contents */
53 if ((fd = open(TESTMNT "/" TESTFILE, O_RDONLY)) < 0) e(1);
54 if (read(fd, file_buf, sizeof(file_buf)) != strlen(TESTSTRING)) e(2);
55 (void) close(fd);
56 system("umount " RAMDISK SILENT);
57 if (strncmp(file_buf, TESTSTRING, strlen(TESTSTRING))) e(3);
60 void
61 skip(char const *msg)
63 system("umount " RAMDISK SILENT);
64 printf("%s\n", msg);
65 quit();
68 void
69 bomb(char const *msg)
71 system("umount " RAMDISK SILENT);
72 printf("%s\n", msg);
73 e(99);
74 quit();
77 void
78 create_partition(void)
80 int status;
81 char mntcmd[1024];
83 subtest = 1;
85 if (getuid() != 0 && setuid(0) != 0) e(1);
86 status = system("ramdisk " RAMDISK_SIZE " " RAMDISK SILENT);
87 if (WEXITSTATUS(status) != 0)
88 bomb("Unable to create ramdisk");
90 status = system("mkntfs " RAMDISK SILENT);
91 if (WEXITSTATUS(status) != 0)
92 bomb("Unable to create NTFS file system on " RAMDISK);
94 if (mkdir(TESTMNT, 0755) != 0)
95 bomb("Unable to create directory for mounting");
97 snprintf(mntcmd, sizeof(mntcmd), "mount -t ntfs-3g %s %s %s",
98 RAMDISK, TESTMNT, SILENT);
99 status = system(mntcmd);
100 if (WEXITSTATUS(status != 0))
101 bomb("Unable to mount NTFS partition (1)");
104 void
105 verify_tools(void)
107 int status;
109 subtest = 1;
110 status = system("which mkntfs > /dev/null 2>&1");
111 if (WEXITSTATUS(status) != 0) {
112 skip("mkntfs not found. Please install ntfsprogs (pkgin in "
113 "ntfsprogs)");
115 status = system("which ntfs-3g > /dev/null 2>&1");
116 if (WEXITSTATUS(status) != 0) {
117 skip("ntfs-3g not found. Please install fuse-ntfs-3g-1.1120 "
118 "(pkgin in fuse-ntfs-3g-1.1120)");
123 main(int argc, char *argv[])
125 start(65);
126 verify_tools();
127 create_partition();
128 basic_test();
129 quit();
130 return(-1); /* Unreachable */