aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py24
-rw-r--r--tests/unistd/isatty.c38
-rw-r--r--tests/unistd/isatty.js5
-rw-r--r--tests/unistd/isatty.out10
-rw-r--r--tests/unistd/ttyname.c76
-rw-r--r--tests/unistd/ttyname.js1
-rw-r--r--tests/unistd/ttyname.out5
7 files changed, 55 insertions, 104 deletions
diff --git a/tests/runner.py b/tests/runner.py
index bc0c77a4..ea702689 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7150,18 +7150,8 @@ def process(filename):
self.do_run(src, expected, extra_emscripten_args=['-H', 'libc/unistd.h'])
def test_unistd_ttyname(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', 'ttyname.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'ttyname.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'ttyname.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, 'success', force_c=True)
def test_unistd_dup(self):
src = open(path_from_root('tests', 'unistd', 'dup.c'), 'r').read()
@@ -7193,18 +7183,8 @@ def process(filename):
self.do_run(src, expected)
def test_unistd_isatty(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', 'isatty.js'), 'r').read()
- )
- open(filename, 'w').write(src)
-'''
src = open(path_from_root('tests', 'unistd', 'isatty.c'), 'r').read()
- expected = open(path_from_root('tests', 'unistd', 'isatty.out'), 'r').read()
- self.do_run(src, expected, post_build=add_pre_run)
+ self.do_run(src, 'success', force_c=True)
def test_unistd_sysconf(self):
src = open(path_from_root('tests', 'unistd', 'sysconf.c'), 'r').read()
diff --git a/tests/unistd/isatty.c b/tests/unistd/isatty.c
index cc1ff641..191036e9 100644
--- a/tests/unistd/isatty.c
+++ b/tests/unistd/isatty.c
@@ -1,28 +1,28 @@
-#include <stdio.h>
+#include <assert.h>
#include <errno.h>
-#include <unistd.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
int main() {
- printf("read: %d\n", isatty(open("/read", O_RDONLY)));
- printf("errno: %d\n", errno);
- errno = 0;
+ int err;
+
+ err = isatty(-1);
+ assert(!err);
+ assert(errno == EBADF);
- printf("write: %d\n", isatty(open("/write", O_WRONLY)));
- printf("errno: %d\n", errno);
- errno = 0;
+ err = isatty(open("/dev/stdin", O_RDONLY));
+ assert(err == 1);
- printf("all: %d\n", isatty(open("/all", O_RDONLY)));
- printf("errno: %d\n", errno);
- errno = 0;
+ err = isatty(open("/dev/null", O_RDONLY));
+ assert(!err);
- printf("folder: %d\n", isatty(open("/folder", O_RDONLY)));
- printf("errno: %d\n", errno);
- errno = 0;
+ err = isatty(open("/dev", O_RDONLY));
+ assert(!err);
- printf("file: %d\n", isatty(open("/file", O_RDONLY)));
- printf("errno: %d\n", errno);
- errno = 0;
+ puts("success");
- return 0;
-}
+ return EXIT_SUCCESS;
+} \ No newline at end of file
diff --git a/tests/unistd/isatty.js b/tests/unistd/isatty.js
deleted file mode 100644
index d88bd2be..00000000
--- a/tests/unistd/isatty.js
+++ /dev/null
@@ -1,5 +0,0 @@
-FS.createDevice('/', 'read', function() {}, null);
-FS.createDevice('/', 'write', null, function() {});
-FS.createDevice('/', 'all', function() {}, function() {});
-FS.createFolder('/', 'folder', true, true);
-FS.createDataFile('/', 'file', 'test', true, true);
diff --git a/tests/unistd/isatty.out b/tests/unistd/isatty.out
deleted file mode 100644
index 6823c1f0..00000000
--- a/tests/unistd/isatty.out
+++ /dev/null
@@ -1,10 +0,0 @@
-read: 0
-errno: 25
-write: 0
-errno: 25
-all: 0
-errno: 25
-folder: 0
-errno: 25
-file: 0
-errno: 25
diff --git a/tests/unistd/ttyname.c b/tests/unistd/ttyname.c
index 7080be5d..b7cc27bd 100644
--- a/tests/unistd/ttyname.c
+++ b/tests/unistd/ttyname.c
@@ -1,51 +1,43 @@
-#include <stdio.h>
+#include <assert.h>
#include <errno.h>
-#include <unistd.h>
#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
int main() {
+ int err;
+ int stdin, null, dev;
char buffer[256];
- int d = open("/device", O_RDWR);
- int f = open("/", O_RDONLY);
char* result;
+ stdin = open("/dev/stdin", O_RDONLY);
+ null = open("/dev/null", O_RDONLY);
+ dev = open("/dev", O_RDONLY);
+
result = ctermid(buffer);
- if (result) {
- printf("ctermid: %s\n", result);
- } else {
- printf("ctermid errno: %d\n", errno);
- errno = 0;
- }
-
- if (ttyname_r(d, buffer, 256) == 0) {
- printf("ttyname_r(d, ..., 256): %s\n", buffer);
- } else {
- printf("ttyname_r(d, ..., 256) errno: %d\n", errno);
- errno = 0;
- }
-
- if (ttyname_r(d, buffer, 2) == 0) {
- printf("ttyname_r(d, ..., 2): %s\n", buffer);
- } else {
- printf("ttyname_r(d, ..., 2) errno: %d\n", errno);
- errno = 0;
- }
-
- result = ttyname(d);
- if (result) {
- printf("ttyname(d): %s\n", result);
- } else {
- printf("ttyname(d) errno: %d\n", errno);
- errno = 0;
- }
-
- result = ttyname(f);
- if (result) {
- printf("ttyname(f): %s\n", result);
- } else {
- printf("ttyname(f) errno: %d\n", errno);
- errno = 0;
- }
-
- return 0;
+ assert(!strcmp(result, "/dev/tty"));
+
+ // strstr instead of strcmp as native code may
+ // be using a virtual console (e.g. /dev/tty02)
+ err = ttyname_r(stdin, buffer, 256);
+ assert(!err);
+ assert(strstr(buffer, "/dev/tty"));
+
+ err = ttyname_r(stdin, buffer, 2);
+ assert(err == ERANGE);
+
+ result = ttyname(stdin);
+ assert(strstr(result, "/dev/tty"));
+
+ result = ttyname(null);
+ assert(!result);
+
+ result = ttyname(dev);
+ assert(!result);
+
+ puts("success");
+
+ return EXIT_SUCCESS;
}
diff --git a/tests/unistd/ttyname.js b/tests/unistd/ttyname.js
deleted file mode 100644
index a21f417f..00000000
--- a/tests/unistd/ttyname.js
+++ /dev/null
@@ -1 +0,0 @@
-FS.createDevice('/', 'device', function() {}, function() {});
diff --git a/tests/unistd/ttyname.out b/tests/unistd/ttyname.out
deleted file mode 100644
index b47cbf75..00000000
--- a/tests/unistd/ttyname.out
+++ /dev/null
@@ -1,5 +0,0 @@
-ctermid: /dev/tty
-ttyname_r(d, ..., 256): /device
-ttyname_r(d, ..., 2) errno: 34
-ttyname(d): /device
-ttyname(f) errno: 25