aboutsummaryrefslogtreecommitdiff
path: root/tests/unistd
diff options
context:
space:
mode:
authorAnthony Pesch <inolen@gmail.com>2013-09-02 22:32:55 -0700
committerAnthony Pesch <inolen@gmail.com>2013-09-03 22:00:02 -0700
commit9ba95541831fcddf3e99554cd3a11c87cb935d3b (patch)
tree875433d8010bf80c6c90231fd3617cfb6391209e /tests/unistd
parent47d35839b54bedb65427bcac153f112e33cea478 (diff)
updated unistd and fs_base tests to use new FS APIs
Diffstat (limited to 'tests/unistd')
-rw-r--r--tests/unistd/access.c8
-rw-r--r--tests/unistd/access.js4
-rw-r--r--tests/unistd/access.out4
-rw-r--r--tests/unistd/curdir.c11
-rw-r--r--tests/unistd/curdir.js7
-rw-r--r--tests/unistd/io.c50
-rw-r--r--tests/unistd/io.js52
-rw-r--r--tests/unistd/links.c7
-rw-r--r--tests/unistd/links.js3
-rw-r--r--tests/unistd/truncate.c7
-rw-r--r--tests/unistd/truncate.js2
11 files changed, 85 insertions, 70 deletions
diff --git a/tests/unistd/access.c b/tests/unistd/access.c
index 89428610..4d5ba08e 100644
--- a/tests/unistd/access.c
+++ b/tests/unistd/access.c
@@ -1,8 +1,16 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
+#include <emscripten.h>
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);
+ );
+
char* files[] = {"/readable", "/writeable",
"/allaccess", "/forbidden", "/nonexistent"};
for (int i = 0; i < sizeof files / sizeof files[0]; i++) {
diff --git a/tests/unistd/access.js b/tests/unistd/access.js
deleted file mode 100644
index ea9e6359..00000000
--- a/tests/unistd/access.js
+++ /dev/null
@@ -1,4 +0,0 @@
-FS.createDataFile('/', 'forbidden', '', false, false);
-FS.createDataFile('/', 'readable', '', true, false);
-FS.createDataFile('/', 'writeable', '', false, true);
-FS.createDataFile('/', 'allaccess', '', true, true);
diff --git a/tests/unistd/access.out b/tests/unistd/access.out
index dffe0b9e..d462e5a5 100644
--- a/tests/unistd/access.out
+++ b/tests/unistd/access.out
@@ -2,8 +2,8 @@ F_OK(/readable): 0
errno: 0
R_OK(/readable): 0
errno: 0
-X_OK(/readable): 0
-errno: 0
+X_OK(/readable): -1
+errno: 13
W_OK(/readable): -1
errno: 13
diff --git a/tests/unistd/curdir.c b/tests/unistd/curdir.c
index 63b9c7fe..b9f22dd7 100644
--- a/tests/unistd/curdir.c
+++ b/tests/unistd/curdir.c
@@ -2,8 +2,19 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <emscripten.h>
int main() {
+ EM_ASM(
+ var dummy_device = FS.makedev(64, 0);
+ FS.registerDevice(dummy_device, {});
+ FS.mkdev('/device', dummy_device);
+
+ FS.mkdir('/folder');
+ FS.symlink('/folder', '/link');
+ FS.writeFile('/file', '', { mode: 0777 });
+ );
+
char buffer[256];
printf("getwd: %s\n", getwd(buffer));
printf("errno: %d\n", errno);
diff --git a/tests/unistd/curdir.js b/tests/unistd/curdir.js
deleted file mode 100644
index 75a1d2ce..00000000
--- a/tests/unistd/curdir.js
+++ /dev/null
@@ -1,7 +0,0 @@
-var dummy_device = FS.makedev(64, 0);
-FS.registerDevice(dummy_device, {});
-
-FS.createDataFile('/', 'file', '', true, true);
-FS.createFolder('/', 'folder', true, true);
-FS.mkdev('/device', 0666, dummy_device);
-FS.createLink('/', 'link', 'folder', true, true);
diff --git a/tests/unistd/io.c b/tests/unistd/io.c
index a96290ef..0ff5f4fb 100644
--- a/tests/unistd/io.c
+++ b/tests/unistd/io.c
@@ -3,8 +3,58 @@
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
+#include <emscripten.h>
int main() {
+ EM_ASM(
+ var major = 80;
+
+ var device = FS.makedev(major++, 0);
+ FS.registerDevice(device, {
+ open: function(stream) {
+ stream.payload = [65, 66, 67, 68];
+ },
+ read: function(stream, buffer, offset, length, pos) {
+ var bytesRead = 0;
+ for (var i = 0; i < length; i++) {
+ if (stream.payload.length) {
+ bytesRead++;
+ buffer[offset+i] = stream.payload.shift();
+ } else {
+ break;
+ }
+ }
+ return bytesRead;
+ },
+ write: function(stream, buffer, offset, length, pos) {
+ for (var i = 0; i < length; i++) {
+ Module.print('TO DEVICE: ' + buffer[offset+i]);
+ }
+ return i;
+ }
+ });
+ FS.mkdev('/device', device);
+
+ var broken_device = FS.makedev(major++, 0);
+ FS.registerDevice(broken_device, {
+ read: function(stream, buffer, offset, length, pos) {
+ throw new FS.ErrnoError(ERRNO_CODES.EIO);
+ },
+ write: function(stream, buffer, offset, length, pos) {
+ throw new FS.ErrnoError(ERRNO_CODES.EIO);
+ }
+ });
+ FS.mkdev('/broken-device', broken_device);
+
+ // NB: These are meant to test FS.createDevice specifically,
+ // and as such do not use registerDevice/mkdev
+ FS.createDevice('/', 'createDevice-read-only', function() {});
+ FS.createDevice('/', 'createDevice-write-only', null, function() {});
+
+ FS.mkdir('/folder', 0777);
+ FS.writeFile('/file', '1234567890');
+ );
+
char readBuffer[256] = {0};
char writeBuffer[] = "writeme";
diff --git a/tests/unistd/io.js b/tests/unistd/io.js
deleted file mode 100644
index 11c0da79..00000000
--- a/tests/unistd/io.js
+++ /dev/null
@@ -1,52 +0,0 @@
-(function() {
- var major = 80;
-
- var device = FS.makedev(major++, 0);
- var device_ops = {
- open: function(stream) {
- stream.payload = [65, 66, 67, 68];
- },
- read: function(stream, buffer, offset, length, pos) {
- var bytesRead = 0;
- for (var i = 0; i < length; i++) {
- if (stream.payload.length) {
- bytesRead++;
- buffer[offset+i] = stream.payload.shift();
- } else {
- break;
- }
- }
- return bytesRead;
- },
- write: function(stream, buffer, offset, length, pos) {
- for (var i = 0; i < length; i++) {
- Module.print("TO DEVICE: " + buffer[offset+i]);
- }
- return i;
- }
- };
- FS.registerDevice(device, device_ops);
-
- FS.mkdev('/device', 0666, device);
-
- var broken_device = FS.makedev(major++, 0);
- var broken_device_ops = {
- read: function(stream, buffer, offset, length, pos) {
- throw new FS.ErrnoError(ERRNO_CODES.EIO);
- },
- write: function(stream, buffer, offset, length, pos) {
- throw new FS.ErrnoError(ERRNO_CODES.EIO);
- }
- };
- FS.registerDevice(broken_device, broken_device_ops);
-
- FS.mkdev('/broken-device', 0666, broken_device);
-
- // NB: These are meant to test FS.createDevice specifically,
- // and as such do not use registerDevice/mkdev
- FS.createDevice('/', 'createDevice-read-only', function() {});
- FS.createDevice('/', 'createDevice-write-only', null, function() {});
-
- FS.createDataFile('/', 'file', '1234567890', true, true);
- FS.createFolder('/', 'folder', true, true);
-})();
diff --git a/tests/unistd/links.c b/tests/unistd/links.c
index c6da83b9..5b403c1f 100644
--- a/tests/unistd/links.c
+++ b/tests/unistd/links.c
@@ -1,8 +1,15 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
+#include <emscripten.h>
int main() {
+ EM_ASM(
+ FS.symlink('../test/../there!', '/link');
+ FS.writeFile('/file', 'test');
+ FS.mkdir('/folder');
+ );
+
char* files[] = {"/link", "/file", "/folder"};
char buffer[256] = {0};
diff --git a/tests/unistd/links.js b/tests/unistd/links.js
deleted file mode 100644
index 5e58a729..00000000
--- a/tests/unistd/links.js
+++ /dev/null
@@ -1,3 +0,0 @@
-FS.createLink('/', 'link', '../test/../there!', true, true);
-FS.createDataFile('/', 'file', 'test', true, true);
-FS.createFolder('/', 'folder', true, true);
diff --git a/tests/unistd/truncate.c b/tests/unistd/truncate.c
index 18920976..b1d9fc96 100644
--- a/tests/unistd/truncate.c
+++ b/tests/unistd/truncate.c
@@ -4,8 +4,15 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
+#include <emscripten.h>
int main() {
+ EM_ASM(
+ 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);
diff --git a/tests/unistd/truncate.js b/tests/unistd/truncate.js
deleted file mode 100644
index 6a4c6868..00000000
--- a/tests/unistd/truncate.js
+++ /dev/null
@@ -1,2 +0,0 @@
-FS.createDataFile('/', 'towrite', 'abcdef', true, true);
-FS.createDataFile('/', 'toread', 'abcdef', true, false);