10
10
#include < string.h>
11
11
#include < sys/stat.h>
12
12
#include < unistd.h>
13
+ #include < assert.h>
13
14
14
15
#ifdef WASMFS
15
16
#include " ../wasmfs/get_backend.h"
@@ -31,72 +32,42 @@ int main() {
31
32
32
33
// Create a file
33
34
int fd = open (filename, O_RDWR | O_CREAT, 0777 );
34
- if (fd == -1 ) {
35
- return 1 ;
36
- }
35
+ assert (fd != -1 );
37
36
// Check it exists
38
- if (access (filename, F_OK) != 0 ) {
39
- return 1 ;
40
- }
37
+ assert (access (filename, F_OK) == 0 );
41
38
// Delete the file
42
- if (unlinkat (AT_FDCWD, filename, 0 )) {
43
- return 1 ;
44
- }
39
+ assert (unlinkat (AT_FDCWD, filename, 0 ) == 0 );
45
40
// Check that it doesn't exist
46
- if (access (filename, F_OK) != -1 ) {
47
- return 1 ;
48
- }
41
+ assert (access (filename, F_OK) == -1 );
49
42
// Check that we can still write to it
50
- if (write (fd, " hello" , 5 ) != 5 ) {
51
- return 1 ;
52
- }
43
+ assert (write (fd, " hello" , 5 ) == 5 );
53
44
// And seek in it.
54
- if (lseek (fd, 0 , SEEK_SET) != 0 ) {
55
- return 1 ;
56
- }
45
+ assert (lseek (fd, 0 , SEEK_SET) == 0 );
57
46
// And read from it.
58
47
char buf[6 ] = {0 };
59
48
auto r = read (fd, buf, 5 );
60
- if (r != 5 ) {
61
- return 1 ;
62
- }
63
- if (strcmp (" hello" , buf) != 0 ) {
64
- return 1 ;
65
- }
66
- if (close (fd)) {
67
- return 1 ;
68
- }
49
+ assert (r==5 );
50
+ assert (strcmp (" hello" , buf) == 0 );
51
+ assert (close (fd)==0 );
69
52
70
53
// Create a directory
71
- if (mkdir (dirname, 0700 ) != 0 ) {
72
- return 1 ;
73
- }
54
+ assert (mkdir (dirname, 0700 ) == 0 );
74
55
// Open the directory
75
56
DIR* d = opendir (dirname);
76
- if (d == NULL ) {
77
- return 1 ;
78
- }
57
+ assert (d != NULL );
79
58
// Delete the directory
80
- if (unlinkat (AT_FDCWD, dirname, AT_REMOVEDIR)) {
81
- return 1 ;
82
- }
59
+ assert (unlinkat (AT_FDCWD, dirname, AT_REMOVEDIR) == 0 );
83
60
// Check that it doesn't exist
84
- if (access (dirname, F_OK) != -1 ) {
85
- return 1 ;
86
- }
61
+ assert (access (dirname, F_OK) == -1 );
87
62
88
63
// The rest of this test does not yet pass with the node backend!
89
64
#ifndef WASMFS_NODE_BACKEND
90
65
91
66
// Check that we can still read the directory, but that it is empty.
92
67
errno = 0 ;
93
- if (readdir (d) != NULL || errno != 0 ) {
94
- return 1 ;
95
- }
68
+ assert (readdir (d) == NULL && errno == 0 );
96
69
// Check that we *cannot* create a child.
97
- if (openat (dirfd (d), filename, O_CREAT | O_WRONLY, S_IRWXU) != -1 ) {
98
- return 1 ;
99
- }
70
+ assert (openat (dirfd (d), filename, O_CREAT | O_WRONLY, S_IRWXU) == -1 );
100
71
printf (" %s\n " , strerror (errno));
101
72
#ifdef __EMSCRIPTEN__
102
73
// Linux allows "." and ".." to be accessed on unlinked directories, but this
@@ -105,27 +76,19 @@ int main() {
105
76
// TODO: Consider supporting "." on unlinked files, if not ".."
106
77
107
78
// Check that we cannot still access "."
108
- if (openat (dirfd (d), " ." , O_DIRECTORY | O_RDONLY) != -1 ) {
109
- return 1 ;
110
- }
79
+ assert (openat (dirfd (d), " ." , O_DIRECTORY | O_RDONLY) == -1 );
111
80
#ifdef WASMFS
112
81
// Check that we cannot still access ".." on WasmFS.
113
- if (openat (dirfd (d), " .." , O_DIRECTORY | O_RDONLY) != -1 ) {
114
- return 1 ;
115
- }
82
+ assert (openat (dirfd (d), " .." , O_DIRECTORY | O_RDONLY) == -1 );
116
83
#endif
117
84
#else
118
85
// Check that we can still access "." on Linux.
119
86
int self = openat (dirfd (d), " ." , O_DIRECTORY | O_RDONLY);
120
- if (self == -1 ) {
121
- return 1 ;
122
- }
87
+ assert (self != -1 );
123
88
close (self);
124
89
// Check that we can still access ".." on Linux.
125
90
int parent = openat (dirfd (d), " .." , O_DIRECTORY | O_RDONLY);
126
- if (parent == -1 ) {
127
- return 1 ;
128
- }
91
+ assert (parent != -1 );
129
92
close (parent);
130
93
#endif
131
94
0 commit comments