aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/filesystem/src.js1
-rwxr-xr-xtests/runner.py32
-rw-r--r--tests/stat/test_chmod.c24
-rw-r--r--tests/stat/test_mknod.c5
-rw-r--r--tests/stat/test_stat.c3
-rw-r--r--tests/stdio/test_rename.c107
6 files changed, 110 insertions, 62 deletions
diff --git a/tests/filesystem/src.js b/tests/filesystem/src.js
index 801b45d6..ceea348d 100644
--- a/tests/filesystem/src.js
+++ b/tests/filesystem/src.js
@@ -8,6 +8,7 @@ FS.createDevice('/def', 'deviceB', function() {}, function() {});
FS.createLink('/abc', 'localLink', '123', true, true);
FS.createLink('/abc', 'rootLink', '/', true, true);
FS.createLink('/abc', 'relativeLink', '../def', true, true);
+FS.ignorePermissions = false;
function explore(path) {
Module.print(path);
diff --git a/tests/runner.py b/tests/runner.py
index fbeec03c..46096213 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3591,33 +3591,8 @@ Exiting setjmp function, level: 0, prev_jmp: -1
self.do_run(src, 'z:1*', force_c=True)
def test_rename(self):
- src = '''
- #include <stdio.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <assert.h>
-
- int main() {
- int err;
- FILE* fid;
-
- err = mkdir("/foo", 0777);
- err = mkdir("/bar", 0777);
- fid = fopen("/foo/bar", "w+");
- fclose(fid);
-
- err = rename("/foo/bar", "/foo/bar2");
- printf("%d\\n", err);
-
- err = rename("/foo", "/foo/foo");
- printf("%d\\n", err);
-
- err = rename("/foo", "/bar/foo");
- printf("%d\\n", err);
- return 0;
- }
- '''
- self.do_run(src, '0\n-1\n0\n', force_c=True)
+ src = open(path_from_root('tests', 'stdio', 'test_rename.c'), 'r').read()
+ self.do_run(src, 'success', force_c=True)
def test_alloca_stack(self):
if self.emcc_args is None: return # too slow in other modes
@@ -7244,17 +7219,14 @@ def process(filename):
self.do_run(src, 'success', force_c=True)
def test_stat(self):
- Building.COMPILER_TEST_OPTS += ['-DUSE_OLD_FS='+str(Settings.USE_OLD_FS)]
src = open(path_from_root('tests', 'stat', 'test_stat.c'), 'r').read()
self.do_run(src, 'success', force_c=True)
def test_stat_chmod(self):
- Building.COMPILER_TEST_OPTS += ['-DUSE_OLD_FS='+str(Settings.USE_OLD_FS)]
src = open(path_from_root('tests', 'stat', 'test_chmod.c'), 'r').read()
self.do_run(src, 'success', force_c=True)
def test_stat_mknod(self):
- Building.COMPILER_TEST_OPTS += ['-DUSE_OLD_FS='+str(Settings.USE_OLD_FS)]
src = open(path_from_root('tests', 'stat', 'test_mknod.c'), 'r').read()
self.do_run(src, 'success', force_c=True)
diff --git a/tests/stat/test_chmod.c b/tests/stat/test_chmod.c
index bf0e2cbe..3574760b 100644
--- a/tests/stat/test_chmod.c
+++ b/tests/stat/test_chmod.c
@@ -56,11 +56,7 @@ void test() {
memset(&s, 0, sizeof s);
stat("file", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0222 | S_IFREG));
-#else
assert(s.st_mode == (0200 | S_IFREG));
-#endif
assert(s.st_ctime != lastctime);
//
@@ -74,11 +70,7 @@ void test() {
memset(&s, 0, sizeof s);
stat("file", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0000 | S_IFREG));
-#else
assert(s.st_mode == (0100 | S_IFREG));
-#endif
assert(s.st_ctime != lastctime);
//
@@ -95,11 +87,7 @@ void test() {
assert(!err);
memset(&s, 0, sizeof s);
stat("folder", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0222 | S_IFDIR));
-#else
assert(s.st_mode == (0300 | S_IFDIR));
-#endif
assert(s.st_ctime != lastctime);
//
@@ -110,11 +98,7 @@ void test() {
// make sure the file it references changed
stat("file-link", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0555 | S_IFREG));
-#else
assert(s.st_mode == (0400 | S_IFREG));
-#endif
// but the link didn't
lstat("file-link", &s);
@@ -128,19 +112,11 @@ void test() {
// make sure the file it references didn't change
stat("file-link", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0555 | S_IFREG));
-#else
assert(s.st_mode == (0400 | S_IFREG));
-#endif
// but the link did
lstat("file-link", &s);
-#if USE_OLD_FS
- assert(s.st_mode == (0555 | S_IFLNK));
-#else
assert(s.st_mode == (0500 | S_IFLNK));
-#endif
puts("success");
}
diff --git a/tests/stat/test_mknod.c b/tests/stat/test_mknod.c
index 2b8f650d..361b2315 100644
--- a/tests/stat/test_mknod.c
+++ b/tests/stat/test_mknod.c
@@ -53,15 +53,10 @@ void test() {
// mknod a character device
err = mknod("mknod-device", S_IFCHR | 0777, 123);
-#if USE_OLD_FS
- assert(err);
- assert(errno == EPERM);
-#else
assert(!err);
memset(&s, 0, sizeof s);
stat("mknod-device", &s);
assert(S_ISCHR(s.st_mode));
-#endif
#endif
diff --git a/tests/stat/test_stat.c b/tests/stat/test_stat.c
index 2c2bf53d..f59fb3c3 100644
--- a/tests/stat/test_stat.c
+++ b/tests/stat/test_stat.c
@@ -104,13 +104,10 @@ void test() {
assert(s.st_ino);
assert(S_ISCHR(s.st_mode));
assert(s.st_nlink);
-#if !USE_OLD_FS
- // old FS doesn't store proper device ids
#ifndef __APPLE__
// mac uses makedev(3, 2) for /dev/null
assert(s.st_rdev == makedev(1, 3));
#endif
-#endif
assert(!s.st_size);
assert(s.st_atime);
assert(s.st_mtime);
diff --git a/tests/stdio/test_rename.c b/tests/stdio/test_rename.c
new file mode 100644
index 00000000..20ffb513
--- /dev/null
+++ b/tests/stdio/test_rename.c
@@ -0,0 +1,107 @@
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+void create_file(const char *path, const char *buffer, int mode) {
+ int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
+ assert(fd >= 0);
+
+ int err = write(fd, buffer, sizeof(char) * strlen(buffer));
+ assert(err == (sizeof(char) * strlen(buffer)));
+
+ close(fd);
+}
+
+void setup() {
+ create_file("file", "abcdef", 0777);
+ mkdir("dir", 0777);
+ create_file("dir/file", "abcdef", 0777);
+ mkdir("dir/subdir", 0777);
+ mkdir("dir-readonly", 0555);
+ mkdir("dir-nonempty", 0777);
+ create_file("dir-nonempty/file", "abcdef", 0777);
+}
+
+void cleanup() {
+ // we're hulk-smashing and removing original + renamed files to
+ // make sure we get it all regardless of anything failing
+ unlink("file");
+ unlink("dir/file");
+ unlink("dir/file1");
+ unlink("dir/file2");
+ rmdir("dir/subdir");
+ rmdir("dir/subdir1");
+ rmdir("dir/subdir2");
+ rmdir("dir");
+ rmdir("dir-readonly");
+ unlink("dir-nonempty/file");
+ rmdir("dir-nonempty");
+}
+
+void test() {
+ int err;
+
+ // can't rename something that doesn't exist
+ err = rename("noexist", "dir");
+ assert(err == -1);
+ assert(errno == ENOENT);
+
+ // can't overwrite a folder with a file
+ err = rename("file", "dir");
+ assert(err == -1);
+ assert(errno == EISDIR);
+
+ // can't overwrite a file with a folder
+ err = rename("dir", "file");
+ assert(err == -1);
+ assert(errno == ENOTDIR);
+
+ // can't overwrite a non-empty folder
+ err = rename("dir", "dir-nonempty");
+ assert(err == -1);
+ assert(errno == ENOTEMPTY);
+
+ // can't create anything in a read-only directory
+ err = rename("dir", "dir-readonly/dir");
+ assert(err == -1);
+ assert(errno == EACCES);
+
+ // source should not be ancestor of target
+ err = rename("dir", "dir/somename");
+ assert(err == -1);
+ assert(errno == EINVAL);
+
+ // target should not be an ancestor of source
+ err = rename("dir/subdir", "dir");
+ assert(err == -1);
+ assert(errno == ENOTEMPTY);
+
+ // do some valid renaming
+ err = rename("dir/file", "dir/file1");
+ assert(!err);
+ err = rename("dir/file1", "dir/file2");
+ assert(!err);
+ err = access("dir/file2", F_OK);
+ assert(!err);
+ err = rename("dir/subdir", "dir/subdir1");
+ assert(!err);
+ err = rename("dir/subdir1", "dir/subdir2");
+ assert(!err);
+ err = access("dir/subdir2", F_OK);
+ assert(!err);
+
+ puts("success");
+}
+
+int main() {
+ atexit(cleanup);
+ signal(SIGABRT, cleanup);
+ setup();
+ test();
+ return EXIT_SUCCESS;
+} \ No newline at end of file