aboutsummaryrefslogtreecommitdiff
path: root/tests/unistd
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-09-02 13:58:39 -0700
committerAnthony Pesch <inolen@gmail.com>2013-09-27 00:46:17 -0700
commit9eaadf56f58b35376469e9a89373632fd34cf08c (patch)
tree1604648b4e270f5af03c6efc75dc287b2199d649 /tests/unistd
parentc354b8316cefef8fde6402cf0139f7a64f9b3103 (diff)
- updated several unistd tests to test against NODEFS
Diffstat (limited to 'tests/unistd')
-rw-r--r--tests/unistd/access.c17
-rw-r--r--tests/unistd/access.out40
-rw-r--r--tests/unistd/io.c13
-rw-r--r--tests/unistd/links.c21
-rw-r--r--tests/unistd/links.out6
-rw-r--r--tests/unistd/misc.c24
-rw-r--r--tests/unistd/truncate.c23
-rw-r--r--tests/unistd/unlink.c12
8 files changed, 98 insertions, 58 deletions
diff --git a/tests/unistd/access.c b/tests/unistd/access.c
index 4d5ba08e..57d38f5c 100644
--- a/tests/unistd/access.c
+++ b/tests/unistd/access.c
@@ -5,14 +5,19 @@
int main() {
EM_ASM(
- FS.writeFile('/forbidden', ''); FS.chmod('/forbidden', 0000);
- FS.writeFile('/readable', ''); FS.chmod('/readable', 0444);
- FS.writeFile('/writeable', ''); FS.chmod('/writeable', 0222);
- FS.writeFile('/allaccess', ''); FS.chmod('/allaccess', 0777);
+ FS.mkdir('working');
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, 'working');
+#endif
+ FS.chdir('working');
+ FS.writeFile('forbidden', ''); FS.chmod('forbidden', 0000);
+ FS.writeFile('readable', ''); FS.chmod('readable', 0444);
+ FS.writeFile('writeable', ''); FS.chmod('writeable', 0222);
+ FS.writeFile('allaccess', ''); FS.chmod('allaccess', 0777);
);
- char* files[] = {"/readable", "/writeable",
- "/allaccess", "/forbidden", "/nonexistent"};
+ char* files[] = {"readable", "writeable",
+ "allaccess", "forbidden", "nonexistent"};
for (int i = 0; i < sizeof files / sizeof files[0]; i++) {
printf("F_OK(%s): %d\n", files[i], access(files[i], F_OK));
printf("errno: %d\n", errno);
diff --git a/tests/unistd/access.out b/tests/unistd/access.out
index d462e5a5..b5e4a541 100644
--- a/tests/unistd/access.out
+++ b/tests/unistd/access.out
@@ -1,45 +1,45 @@
-F_OK(/readable): 0
+F_OK(readable): 0
errno: 0
-R_OK(/readable): 0
+R_OK(readable): 0
errno: 0
-X_OK(/readable): -1
+X_OK(readable): -1
errno: 13
-W_OK(/readable): -1
+W_OK(readable): -1
errno: 13
-F_OK(/writeable): 0
+F_OK(writeable): 0
errno: 0
-R_OK(/writeable): -1
+R_OK(writeable): -1
errno: 13
-X_OK(/writeable): -1
+X_OK(writeable): -1
errno: 13
-W_OK(/writeable): 0
+W_OK(writeable): 0
errno: 0
-F_OK(/allaccess): 0
+F_OK(allaccess): 0
errno: 0
-R_OK(/allaccess): 0
+R_OK(allaccess): 0
errno: 0
-X_OK(/allaccess): 0
+X_OK(allaccess): 0
errno: 0
-W_OK(/allaccess): 0
+W_OK(allaccess): 0
errno: 0
-F_OK(/forbidden): 0
+F_OK(forbidden): 0
errno: 0
-R_OK(/forbidden): -1
+R_OK(forbidden): -1
errno: 13
-X_OK(/forbidden): -1
+X_OK(forbidden): -1
errno: 13
-W_OK(/forbidden): -1
+W_OK(forbidden): -1
errno: 13
-F_OK(/nonexistent): -1
+F_OK(nonexistent): -1
errno: 2
-R_OK(/nonexistent): -1
+R_OK(nonexistent): -1
errno: 2
-X_OK(/nonexistent): -1
+X_OK(nonexistent): -1
errno: 2
-W_OK(/nonexistent): -1
+W_OK(nonexistent): -1
errno: 2
diff --git a/tests/unistd/io.c b/tests/unistd/io.c
index 6bf22593..5dcdbbb6 100644
--- a/tests/unistd/io.c
+++ b/tests/unistd/io.c
@@ -7,6 +7,11 @@
int main() {
EM_ASM(
+ FS.mkdir('/working');
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, '/working');
+#endif
+
var major = 80;
var device = FS.makedev(major++, 0);
@@ -51,14 +56,14 @@ int main() {
FS.createDevice('/', 'createDevice-read-only', function() {});
FS.createDevice('/', 'createDevice-write-only', null, function() {});
- FS.mkdir('/folder', 0777);
- FS.writeFile('/file', '1234567890');
+ FS.mkdir('/working/folder');
+ FS.writeFile('/working/file', '1234567890');
);
char readBuffer[256] = {0};
char writeBuffer[] = "writeme";
- int fl = open("/folder", O_RDWR);
+ int fl = open("/working/folder", O_RDWR);
printf("read from folder: %d\n", read(fl, readBuffer, sizeof readBuffer));
printf("errno: %d\n", errno);
errno = 0;
@@ -97,7 +102,7 @@ int main() {
printf("open write-only device from createDevice for write, errno: %d\n\n", errno);
errno = 0;
- int f = open("/file", O_RDWR);
+ int f = open("/working/file", O_RDWR);
printf("read from file: %d\n", read(f, readBuffer, sizeof readBuffer));
printf("data: %s\n", readBuffer);
memset(readBuffer, 0, sizeof readBuffer);
diff --git a/tests/unistd/links.c b/tests/unistd/links.c
index 5b403c1f..c46c6294 100644
--- a/tests/unistd/links.c
+++ b/tests/unistd/links.c
@@ -5,12 +5,17 @@
int main() {
EM_ASM(
- FS.symlink('../test/../there!', '/link');
- FS.writeFile('/file', 'test');
- FS.mkdir('/folder');
+ FS.mkdir('working');
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, 'working');
+#endif
+ FS.chdir('working');
+ FS.symlink('../test/../there!', 'link');
+ FS.writeFile('file', 'test');
+ FS.mkdir('folder');
);
- char* files[] = {"/link", "/file", "/folder"};
+ char* files[] = {"link", "file", "folder"};
char buffer[256] = {0};
for (int i = 0; i < sizeof files / sizeof files[0]; i++) {
@@ -22,23 +27,23 @@ int main() {
}
printf("symlink/overwrite\n");
- printf("ret: %d\n", symlink("new-nonexistent-path", "/link"));
+ printf("ret: %d\n", symlink("new-nonexistent-path", "link"));
printf("errno: %d\n\n", errno);
errno = 0;
printf("symlink/normal\n");
- printf("ret: %d\n", symlink("new-nonexistent-path", "/folder/link"));
+ printf("ret: %d\n", symlink("new-nonexistent-path", "folder/link"));
printf("errno: %d\n", errno);
errno = 0;
printf("readlink(created link)\n");
- printf("ret: %d\n", readlink("/folder/link", buffer, 256));
+ printf("ret: %d\n", readlink("folder/link", buffer, 256));
printf("errno: %d\n", errno);
printf("result: %s\n\n", buffer);
errno = 0;
printf("readlink(short buffer)\n");
- printf("ret: %d\n", readlink("/link", buffer, 4));
+ printf("ret: %d\n", readlink("link", buffer, 4));
printf("errno: %d\n", errno);
printf("result: %s\n", buffer);
errno = 0;
diff --git a/tests/unistd/links.out b/tests/unistd/links.out
index 75e410cb..f2a7aed6 100644
--- a/tests/unistd/links.out
+++ b/tests/unistd/links.out
@@ -1,14 +1,14 @@
-readlink(/link)
+readlink(link)
ret: 17
errno: 0
result: ../test/../there!
-readlink(/file)
+readlink(file)
ret: -1
errno: 22
result: ../test/../there!
-readlink(/folder)
+readlink(folder)
ret: -1
errno: 22
result: ../test/../there!
diff --git a/tests/unistd/misc.c b/tests/unistd/misc.c
index 5b0d63d2..2ca5b390 100644
--- a/tests/unistd/misc.c
+++ b/tests/unistd/misc.c
@@ -2,9 +2,17 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <emscripten.h>
int main() {
- int f = open("/", O_RDONLY);
+ EM_ASM(
+ FS.mkdir('working');
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, 'working');
+#endif
+ );
+
+ int f = open("working", O_RDONLY);
sync();
@@ -36,7 +44,7 @@ int main() {
printf(", errno: %d\n", errno);
errno = 0;
- printf("link: %d", link("/here", "/there"));
+ printf("link: %d", link("working/here", "working/there"));
printf(", errno: %d\n", errno);
errno = 0;
@@ -65,10 +73,10 @@ int main() {
char* exec_argv[] = {"arg", 0};
char* exec_env[] = {"a=b", 0};
- printf("execl: %d", execl("/program", "arg", 0));
+ printf("execl: %d", execl("working/program", "arg", 0));
printf(", errno: %d\n", errno);
errno = 0;
- printf("execle: %d", execle("/program", "arg", 0, exec_env));
+ printf("execle: %d", execle("working/program", "arg", 0, exec_env));
printf(", errno: %d\n", errno);
errno = 0;
printf("execlp: %d", execlp("program", "arg", 0));
@@ -84,16 +92,16 @@ int main() {
printf(", errno: %d\n", errno);
errno = 0;
- printf("chown(good): %d", chown("/", 123, 456));
+ printf("chown(good): %d", chown("working", 123, 456));
printf(", errno: %d\n", errno);
errno = 0;
- printf("chown(bad): %d", chown("/noexist", 123, 456));
+ printf("chown(bad): %d", chown("working/noexist", 123, 456));
printf(", errno: %d\n", errno);
errno = 0;
- printf("lchown(good): %d", lchown("/", 123, 456));
+ printf("lchown(good): %d", lchown("working", 123, 456));
printf(", errno: %d\n", errno);
errno = 0;
- printf("lchown(bad): %d", lchown("/noexist", 123, 456));
+ printf("lchown(bad): %d", lchown("working/noexist", 123, 456));
printf(", errno: %d\n", errno);
errno = 0;
printf("fchown(good): %d", fchown(f, 123, 456));
diff --git a/tests/unistd/truncate.c b/tests/unistd/truncate.c
index b1d9fc96..e63a4c13 100644
--- a/tests/unistd/truncate.c
+++ b/tests/unistd/truncate.c
@@ -8,14 +8,19 @@
int main() {
EM_ASM(
- FS.writeFile('/towrite', 'abcdef');
- FS.writeFile('/toread', 'abcdef');
- FS.chmod('/toread', 0444);
+ FS.mkdir('working');
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, 'working');
+#endif
+ FS.chdir('working');
+ FS.writeFile('towrite', 'abcdef');
+ FS.writeFile('toread', 'abcdef');
+ FS.chmod('toread', 0444);
);
struct stat s;
- int f = open("/towrite", O_WRONLY);
- int f2 = open("/toread", O_RDONLY);
+ int f = open("towrite", O_WRONLY);
+ int f2 = open("toread", O_RDONLY);
printf("f2: %d\n", f2);
fstat(f, &s);
@@ -48,17 +53,17 @@ int main() {
errno = 0;
printf("\n");
- printf("truncate(2): %d\n", truncate("/towrite", 2));
+ printf("truncate(2): %d\n", truncate("towrite", 2));
printf("errno: %d\n", errno);
- stat("/towrite", &s);
+ stat("towrite", &s);
printf("st_size: %d\n", s.st_size);
memset(&s, 0, sizeof s);
errno = 0;
printf("\n");
- printf("truncate(readonly, 2): %d\n", truncate("/toread", 2));
+ printf("truncate(readonly, 2): %d\n", truncate("toread", 2));
printf("errno: %d\n", errno);
- stat("/toread", &s);
+ stat("toread", &s);
printf("st_size: %d\n", s.st_size);
memset(&s, 0, sizeof s);
errno = 0;
diff --git a/tests/unistd/unlink.c b/tests/unistd/unlink.c
index f0a8f4dd..9f532325 100644
--- a/tests/unistd/unlink.c
+++ b/tests/unistd/unlink.c
@@ -7,6 +7,9 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
+#if EMSCRIPTEN
+#include <emscripten.h>
+#endif
static void create_file(const char *path, const char *buffer, int mode) {
int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
@@ -19,6 +22,15 @@ static void create_file(const char *path, const char *buffer, int mode) {
}
void setup() {
+ mkdir("working", 0777);
+#if EMSCRIPTEN
+ EM_ASM(
+#if NODEFS
+ FS.mount(NODEFS, { root: '.' }, 'working');
+#endif
+ );
+#endif
+ chdir("working");
create_file("file", "test", 0777);
create_file("file1", "test", 0777);
symlink("file1", "file1-link");