Skip to content

Commit f9901ea

Browse files
authored
Merge pull request emscripten-core#8 from rstz/remove-bugfixes
Fix a bug in Unlink and add additional tests
2 parents e65dbc9 + a094223 commit f9901ea

File tree

6 files changed

+390
-14
lines changed

6 files changed

+390
-14
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2013 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <assert.h>
9+
#include <dirent.h>
10+
#include <errno.h>
11+
#include <fcntl.h>
12+
#include <signal.h>
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <string.h>
16+
#include <time.h>
17+
#include <unistd.h>
18+
#include <utime.h>
19+
#include <sys/stat.h>
20+
#include <sys/types.h>
21+
#include <sys/sysmacros.h>
22+
#include "pthreadfs.h"
23+
24+
void create_file(const char *path, const char *buffer, int mode) {
25+
int fd = open(path, O_CREAT | O_TRUNC | O_RDWR , mode);
26+
assert(fd >= 0);
27+
28+
int err = write(fd, buffer, sizeof(char) * strlen(buffer));
29+
assert(err == (sizeof(char) * strlen(buffer)));
30+
31+
close(fd);
32+
}
33+
34+
void setup() {
35+
// struct utimbuf t = {1200000000, 1200000000};
36+
37+
mkdir("pthreadfs/folder", 0777);
38+
create_file("pthreadfs/folder/file", "abcdef", 0777);
39+
//symlink("file", "folder/file-link");
40+
41+
//utime("folder/file", &t);
42+
//utime("folder", &t);
43+
44+
puts("success");
45+
}
46+
47+
void cleanup() {
48+
unlink("pthreadfs/folder/file");
49+
// unlink("folder/file-link");
50+
rmdir("pthreadfs/folder");
51+
}
52+
53+
void test() {
54+
create_file("pthreadfs/folder/file", "blubbbbb", 0777);
55+
}
56+
57+
int main() {
58+
emscripten_init_pthreadfs();
59+
setup();
60+
test();
61+
cleanup();
62+
return EXIT_SUCCESS;
63+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2013 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <assert.h>
9+
#include <dirent.h>
10+
#include <errno.h>
11+
#include <fcntl.h>
12+
#include <signal.h>
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <string.h>
16+
#include <time.h>
17+
#include <unistd.h>
18+
#include <utime.h>
19+
#include <sys/stat.h>
20+
#include <sys/types.h>
21+
#include <sys/sysmacros.h>
22+
#include "pthreadfs.h"
23+
24+
void create_file(const char *path, const char *buffer, int mode) {
25+
int fd = open(path, O_CREAT | O_TRUNC | O_RDWR, mode);
26+
assert(fd >= 0);
27+
28+
int err = write(fd, buffer, sizeof(char) * strlen(buffer));
29+
assert(err == (sizeof(char) * strlen(buffer)));
30+
31+
close(fd);
32+
}
33+
34+
void setup() {
35+
// struct utimbuf t = {1200000000, 1200000000};
36+
37+
mkdir("pthreadfs/folder", 0777);
38+
create_file("pthreadfs/folder/file", "abcdef", 0777);
39+
//symlink("file", "folder/file-link");
40+
41+
//utime("folder/file", &t);
42+
//utime("folder", &t);
43+
}
44+
45+
void cleanup() {
46+
unlink("pthreadfs/folder/file");
47+
// unlink("folder/file-link");
48+
rmdir("pthreadfs/folder");
49+
}
50+
51+
void test() {
52+
remove("pthreadfs/folder/file");
53+
remove("pthreadfs/folder");
54+
55+
56+
puts("success");
57+
}
58+
59+
int main() {
60+
emscripten_init_pthreadfs();
61+
// atexit(cleanup);
62+
//signal(SIGABRT, cleanup);
63+
setup();
64+
test();
65+
cleanup();
66+
return EXIT_SUCCESS;
67+
}
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* Copyright 2013 The Emscripten Authors. All rights reserved.
3+
* Emscripten is available under two separate licenses, the MIT license and the
4+
* University of Illinois/NCSA Open Source License. Both these licenses can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include <assert.h>
9+
#include <dirent.h>
10+
#include <errno.h>
11+
#include <fcntl.h>
12+
#include <signal.h>
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <string.h>
16+
#include <time.h>
17+
#include <unistd.h>
18+
#include <utime.h>
19+
#include <sys/stat.h>
20+
#include <sys/types.h>
21+
#include <sys/sysmacros.h>
22+
#include "pthreadfs.h"
23+
24+
void create_file(const char *path, const char *buffer, int mode) {
25+
int fd = open(path, O_CREAT | O_TRUNC | O_RDWR, mode);
26+
assert(fd >= 0);
27+
28+
int err = write(fd, buffer, sizeof(char) * strlen(buffer));
29+
assert(err == (sizeof(char) * strlen(buffer)));
30+
31+
close(fd);
32+
}
33+
34+
void setup() {
35+
// struct utimbuf t = {1200000000, 1200000000};
36+
37+
mkdir("pthreadfs/folder", 0777);
38+
create_file("pthreadfs/folder/file", "abcdef", 0777);
39+
//symlink("file", "folder/file-link");
40+
41+
//utime("folder/file", &t);
42+
//utime("folder", &t);
43+
}
44+
45+
void cleanup() {
46+
rmdir("pthreadfs/folder/subdir");
47+
unlink("pthreadfs/folder/file");
48+
// unlink("folder/file-link");
49+
rmdir("pthreadfs/folder");
50+
}
51+
52+
void test() {
53+
int err;
54+
struct stat s;
55+
// struct utimbuf t = {1200000000, 1200000000};
56+
57+
// non-existent
58+
err = stat("pthreadfs/does_not_exist", &s);
59+
assert(err == -1);
60+
assert(errno == ENOENT);
61+
62+
// stat a folder
63+
memset(&s, 0, sizeof(s));
64+
err = stat("pthreadfs/folder", &s);
65+
assert(!err);
66+
assert(s.st_dev);
67+
assert(s.st_ino);
68+
assert(S_ISDIR(s.st_mode));
69+
assert(s.st_nlink);
70+
assert(s.st_rdev == 0);
71+
assert(s.st_size);
72+
// assert(s.st_atime == 1200000000);
73+
// assert(s.st_mtime == 1200000000);
74+
// assert(s.st_ctime);
75+
#ifdef __EMSCRIPTEN__
76+
assert(s.st_blksize == 4096);
77+
assert(s.st_blocks == 1);
78+
#endif
79+
80+
// stat a file
81+
memset(&s, 0, sizeof(s));
82+
err = stat("pthreadfs/folder/file", &s);
83+
assert(!err);
84+
assert(s.st_dev);
85+
assert(s.st_ino);
86+
assert(S_ISREG(s.st_mode));
87+
assert(s.st_nlink);
88+
assert(s.st_rdev == 0);
89+
assert(s.st_size == 6);
90+
// assert(s.st_atime == 1200000000);
91+
// assert(s.st_mtime == 1200000000);
92+
// assert(s.st_ctime);
93+
#ifdef __EMSCRIPTEN__
94+
assert(s.st_blksize == 4096);
95+
assert(s.st_blocks == 1);
96+
#endif
97+
98+
// fstat a file (should match file stat from above)
99+
memset(&s, 0, sizeof(s));
100+
err = fstat(open("pthreadfs/folder/file", O_RDONLY), &s);
101+
assert(!err);
102+
assert(s.st_dev);
103+
assert(s.st_ino);
104+
assert(S_ISREG(s.st_mode));
105+
assert(s.st_nlink);
106+
assert(s.st_rdev == 0);
107+
assert(s.st_size == 6);
108+
// assert(s.st_atime == 1200000000);
109+
// assert(s.st_mtime == 1200000000);
110+
// assert(s.st_ctime);
111+
#ifdef __EMSCRIPTEN__
112+
assert(s.st_blksize == 4096);
113+
assert(s.st_blocks == 1);
114+
#endif
115+
116+
// stat a device
117+
memset(&s, 0, sizeof(s));
118+
err = stat("/dev/null", &s);
119+
assert(!err);
120+
assert(s.st_dev);
121+
assert(s.st_ino);
122+
assert(S_ISCHR(s.st_mode));
123+
assert(s.st_nlink);
124+
#ifndef __APPLE__
125+
// mac uses makedev(3, 2) for /dev/null
126+
assert(s.st_rdev == makedev(1, 3));
127+
#endif
128+
assert(!s.st_size);
129+
assert(s.st_atime);
130+
assert(s.st_mtime);
131+
assert(s.st_ctime);
132+
#ifdef __EMSCRIPTEN__
133+
assert(s.st_blksize == 4096);
134+
assert(s.st_blocks == 0);
135+
#endif
136+
137+
// stat a link (should match the file stat from above)
138+
// memset(&s, 0, sizeof(s));
139+
// err = stat("folder/file-link", &s);
140+
// assert(!err);
141+
// assert(s.st_dev);
142+
// assert(s.st_ino);
143+
// assert(S_ISREG(s.st_mode));
144+
// assert(s.st_nlink);
145+
// assert(s.st_rdev == 0);
146+
// assert(s.st_size == 6);
147+
// assert(s.st_atime == 1200000000);
148+
// assert(s.st_mtime == 1200000000);
149+
// assert(s.st_ctime);
150+
// #ifdef __EMSCRIPTEN__
151+
// assert(s.st_blksize == 4096);
152+
// assert(s.st_blocks == 1);
153+
// #endif
154+
155+
// lstat a link (should NOT match the file stat from above)
156+
// memset(&s, 0, sizeof(s));
157+
// err = lstat("folder/file-link", &s);
158+
// assert(!err);
159+
// assert(s.st_dev);
160+
// assert(s.st_ino);
161+
// assert(S_ISLNK(s.st_mode));
162+
// assert(s.st_nlink);
163+
// assert(s.st_rdev == 0);
164+
// assert(s.st_size == 4); // strlen("file")
165+
// assert(s.st_atime != 1200000000); // should NOT match the utime call we did for dir/file
166+
// assert(s.st_mtime != 1200000000);
167+
// assert(s.st_ctime);
168+
// #ifdef __EMSCRIPTEN__
169+
// assert(s.st_blksize == 4096);
170+
// assert(s.st_blocks == 1);
171+
// #endif
172+
173+
// create and unlink files inside a directory and check that mtime updates
174+
mkdir("pthreadfs/folder/subdir", 0777);
175+
// utime("pthreadfs/folder/subdir", &t);
176+
create_file("pthreadfs/folder/subdir/file", "abcdef", 0777);
177+
err = stat("pthreadfs/folder/subdir", &s);
178+
// assert(s.st_mtime != 1200000000);
179+
// utime("pthreadfs/folder/subdir", &t);
180+
unlink("pthreadfs/folder/subdir/file");
181+
err = stat("pthreadfs/folder/subdir", &s);
182+
// assert(s.st_mtime != 1200000000);
183+
184+
puts("success");
185+
}
186+
187+
int main() {
188+
emscripten_init_pthreadfs();
189+
// atexit(cleanup);
190+
//signal(SIGABRT, cleanup);
191+
setup();
192+
test();
193+
cleanup();
194+
return EXIT_SUCCESS;
195+
}

0 commit comments

Comments
 (0)