aboutsummaryrefslogtreecommitdiff
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
parent47d35839b54bedb65427bcac153f112e33cea478 (diff)
updated unistd and fs_base tests to use new FS APIs
-rw-r--r--tests/filesystem/src.js22
-rw-r--r--tests/test_core.py57
-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
13 files changed, 103 insertions, 131 deletions
diff --git a/tests/filesystem/src.js b/tests/filesystem/src.js
index dbdd4bed..91337f5b 100644
--- a/tests/filesystem/src.js
+++ b/tests/filesystem/src.js
@@ -1,16 +1,18 @@
var dummy_device = FS.makedev(64, 0);
FS.registerDevice(dummy_device, {});
-FS.createFolder('/', 'forbidden', false, false);
-FS.createFolder('/forbidden', 'test', true, true);
-FS.createPath('/', 'abc/123', true, true);
-FS.createPath('/', 'abc/456', true, true);
-FS.createPath('/', 'def/789', true, true);
-FS.mkdev('/abc/deviceA', 0666, dummy_device);
-FS.mkdev('/def/deviceB', 0666, dummy_device);
-FS.createLink('/abc', 'localLink', '123', true, true);
-FS.createLink('/abc', 'rootLink', '/', true, true);
-FS.createLink('/abc', 'relativeLink', '../def', true, true);
+FS.mkdir('/forbidden', 0000);
+FS.mkdir('/forbidden/test');
+FS.mkdir('/abc');
+FS.mkdir('/abc/123');
+FS.mkdir('/abc/456');
+FS.mkdir('/def');
+FS.mkdir('/def/789');
+FS.mkdev('/abc/deviceA', dummy_device);
+FS.mkdev('/def/deviceB', dummy_device);
+FS.symlink('123', '/abc/localLink');
+FS.symlink('/', '/abc/rootLink');
+FS.symlink('../def', '/abc/relativeLink');
FS.ignorePermissions = false;
function explore(path) {
diff --git a/tests/test_core.py b/tests/test_core.py
index 6bb5ccb6..05d96914 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -7222,7 +7222,7 @@ def process(filename):
FS.registerDevice(dummy_device, {});
FS.createDataFile('/', 'file', 'abcdef', true, true);
- FS.mkdev('/device', 0666, dummy_device);
+ FS.mkdev('/device', dummy_device);
\'\'\'
)
open(filename, 'w').write(src)
@@ -7480,32 +7480,14 @@ def process(filename):
Settings.INCLUDE_FULL_LIBRARY = 0
def test_unistd_access(self):
- add_pre_run = '''
-def process(filename):
- import tools.shared as shared
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- open(shared.path_from_root('tests', 'unistd', 'access.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'access.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'access.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, expected)
def test_unistd_curdir(self):
- add_pre_run = '''
-def process(filename):
- import tools.shared as shared
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- open(shared.path_from_root('tests', 'unistd', 'curdir.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'curdir.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'curdir.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, expected)
def test_unistd_close(self):
src = open(path_from_root('tests', 'unistd', 'close.c'), 'r').read()
@@ -7532,18 +7514,9 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_truncate(self):
- add_pre_run = '''
-def process(filename):
- import tools.shared as shared
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- open(shared.path_from_root('tests', 'unistd', 'truncate.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'truncate.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'truncate.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, expected)
def test_unistd_swab(self):
src = open(path_from_root('tests', 'unistd', 'swab.c'), 'r').read()
@@ -7569,18 +7542,9 @@ def process(filename):
self.do_run(src, 'success', force_c=True)
def test_unistd_links(self):
- add_pre_run = '''
-def process(filename):
- import tools.shared as shared
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- open(shared.path_from_root('tests', 'unistd', 'links.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'links.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'links.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, expected)
def test_unistd_sleep(self):
src = open(path_from_root('tests', 'unistd', 'sleep.c'), 'r').read()
@@ -7588,18 +7552,9 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_io(self):
- add_pre_run = '''
-def process(filename):
- import tools.shared as shared
- src = open(filename, 'r').read().replace(
- '// {{PRE_RUN_ADDITIONS}}',
- open(shared.path_from_root('tests', 'unistd', 'io.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'io.c'), 'r').read()
expected = open(path_from_root('tests', 'unistd', 'io.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, expected)
def test_unistd_misc(self):
src = open(path_from_root('tests', 'unistd', 'misc.c'), 'r').read()
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);