diff options
author | Ranger Harke <ranger.harke@autodesk.com> | 2013-08-28 14:06:44 -0400 |
---|---|---|
committer | Ranger Harke <ranger.harke@autodesk.com> | 2013-08-28 16:11:13 -0400 |
commit | 2ce6e7948422d85456aa494ecc7920ee545e258f (patch) | |
tree | 61d1bf250fd0c537d82f3885452006ff54d956cb | |
parent | 05b1fe0a482da02f4c913d675b9e054527d4ad27 (diff) |
Update test_unistd_io to use registerDevice/mkdev
-rw-r--r-- | tests/unistd/io.js | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/tests/unistd/io.js b/tests/unistd/io.js index cf66a438..11c0da79 100644 --- a/tests/unistd/io.js +++ b/tests/unistd/io.js @@ -1,21 +1,52 @@ (function() { - var devicePayload = [65, 66, 67, 68]; - FS.createDevice('/', 'device', function() { - if (devicePayload.length) { - return devicePayload.shift(); - } else { - return null; + 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; } - }, function(arg) { - Module.print("TO DEVICE: " + arg); - }); - FS.createDevice('/', 'broken-device', function() { - throw new Error('Broken device input.'); - }, function(arg) { - throw new Error('Broken device output.'); - }); + }; + 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); })(); |