aboutsummaryrefslogtreecommitdiff
path: root/tests/runner.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/runner.py')
-rw-r--r--tests/runner.py194
1 files changed, 194 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 25995c5c..4a738c66 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2078,6 +2078,200 @@ if 'benchmark' not in sys.argv:
src = open(path_from_root('tests', 'files.cpp'), 'r').read()
self.do_test(src, 'size: 7\ndata: 100,-56,50,25,10,77,123\ninput:hi there!\ntexto\ntexte\n5 : 10,30,20,11,88\nother=some data.\nseeked=me da.\nseeked=ata.\nseeked=ta.\nfscanfed: 10 - hello\n', post_build=post)
+ def test_folders(self):
+ def addPreRun(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '''
+ FS.createFolder('/', 'test', true, false);
+ FS.createPath('/', 'test/hello/world/', true, false);
+ FS.createPath('/test', 'goodbye/world/', true, false);
+ FS.createPath('/test/goodbye', 'noentry', false, false);
+ FS.createDataFile('/test', 'freeforall.ext', 'abc', true, true);
+ FS.createDataFile('/test', 'restricted.ext', 'def', false, false);
+ '''
+ )
+ open(filename, 'w').write(src)
+
+ src = r'''
+ #include <stdio.h>
+ #include <dirent.h>
+ #include <errno.h>
+
+ int main() {
+ struct dirent *e;
+
+ // Basic correct behaviour.
+ DIR* d = opendir("/test");
+ printf("--E: %d\n", errno);
+ while ((e = readdir(d))) puts(e->d_name);
+ printf("--E: %d\n", errno);
+
+ // Empty folder; tell/seek.
+ puts("****");
+ d = opendir("/test/hello/world/");
+ e = readdir(d);
+ puts(e->d_name);
+ int pos = telldir(d);
+ e = readdir(d);
+ puts(e->d_name);
+ seekdir(d, pos);
+ e = readdir(d);
+ puts(e->d_name);
+
+ // Errors.
+ puts("****");
+ printf("--E: %d\n", errno);
+ d = opendir("/test/goodbye/noentry");
+ printf("--E: %d, D: %d\n", errno, d);
+ d = opendir("/i/dont/exist");
+ printf("--E: %d, D: %d\n", errno, d);
+ d = opendir("/test/freeforall.ext");
+ printf("--E: %d, D: %d\n", errno, d);
+ while ((e = readdir(d))) puts(e->d_name);
+ printf("--E: %d\n", errno);
+
+ return 0;
+ }
+ '''
+ expected = '''
+ --E: 0
+ .
+ ..
+ hello
+ goodbye
+ freeforall.ext
+ restricted.ext
+ --E: 0
+ ****
+ .
+ ..
+ ..
+ ****
+ --E: 0
+ --E: 13, D: 0
+ --E: 2, D: 0
+ --E: 20, D: 0
+ --E: 9
+ '''
+ self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected), post_build=addPreRun)
+
+ def test_stat(self):
+ def addPreRun(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '''
+ var f1 = FS.createFolder('/', 'test', true, true);
+ var f2 = FS.createDataFile(f1, 'file', 'abcdef', true, true);
+ var f3 = FS.createLink(f1, 'link', 'file', true, true);
+ var f4 = FS.createDevice(f1, 'device', function(){}, function(){});
+ f1.timestamp = f2.timestamp = f3.timestamp = f4.timestamp = new Date(1200000000000);
+ '''
+ )
+ open(filename, 'w').write(src)
+ src = open(path_from_root('tests', 'stat', 'src.c'), 'r').read()
+ expected = open(path_from_root('tests', 'stat', 'output.txt'), 'r').read()
+ self.do_test(src, expected, post_build=addPreRun)
+
+ def test_libgen(self):
+ src = r'''
+ #include <stdio.h>
+ #include <libgen.h>
+
+ int main() {
+ char p1[16] = "/usr/lib", p1x[16] = "/usr/lib";
+ printf("%s -> ", p1);
+ printf("%s : %s\n", dirname(p1x), basename(p1));
+
+ char p2[16] = "/usr", p2x[16] = "/usr";
+ printf("%s -> ", p2);
+ printf("%s : %s\n", dirname(p2x), basename(p2));
+
+ char p3[16] = "/usr/", p3x[16] = "/usr/";
+ printf("%s -> ", p3);
+ printf("%s : %s\n", dirname(p3x), basename(p3));
+
+ char p4[16] = "/usr/lib///", p4x[16] = "/usr/lib///";
+ printf("%s -> ", p4);
+ printf("%s : %s\n", dirname(p4x), basename(p4));
+
+ char p5[16] = "/", p5x[16] = "/";
+ printf("%s -> ", p5);
+ printf("%s : %s\n", dirname(p5x), basename(p5));
+
+ char p6[16] = "///", p6x[16] = "///";
+ printf("%s -> ", p6);
+ printf("%s : %s\n", dirname(p6x), basename(p6));
+
+ char p7[16] = "/usr/../lib/..", p7x[16] = "/usr/../lib/..";
+ printf("%s -> ", p7);
+ printf("%s : %s\n", dirname(p7x), basename(p7));
+
+ char p8[16] = "", p8x[16] = "";
+ printf("(empty) -> %s : %s\n", dirname(p8x), basename(p8));
+
+ printf("(null) -> %s : %s\n", dirname(0), basename(0));
+
+ return 0;
+ }
+ '''
+ expected = '''
+ /usr/lib -> /usr : lib
+ /usr -> / : usr
+ /usr/ -> / : usr
+ /usr/lib/// -> /usr : lib
+ / -> / : /
+ /// -> / : /
+ /usr/../lib/.. -> /usr/../lib : ..
+ (empty) -> . : .
+ (null) -> . : .
+ '''
+ self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected))
+
+ def test_utime(self):
+ def addPreRunAndChecks(filename):
+ src = open(filename, 'r').read().replace(
+ '// {{PRE_RUN_ADDITIONS}}',
+ '''
+ var TEST_F1 = FS.createFolder('/', 'writeable', true, true);
+ var TEST_F2 = FS.createFolder('/', 'unwriteable', true, false);
+ '''
+ ).replace(
+ '// {{POST_RUN_ADDITIONS}}',
+ '''
+ print('first changed: ' + (TEST_F1.timestamp.getTime() == 1200000000000));
+ print('second changed: ' + (TEST_F2.timestamp.getTime() == 1200000000000));
+ '''
+ )
+ open(filename, 'w').write(src)
+
+ src = r'''
+ #include <stdio.h>
+ #include <errno.h>
+ #include <utime.h>
+
+ int main() {
+ struct utimbuf t = {1000000000, 1200000000};
+ char* writeable = "/writeable";
+ char* unwriteable = "/unwriteable";
+
+ utime(writeable, &t);
+ printf("writeable errno: %d\n", errno);
+
+ utime(unwriteable, &t);
+ printf("unwriteable errno: %d\n", errno);
+
+ return 0;
+ }
+ '''
+ expected = '''
+ writeable errno: 0
+ unwriteable errno: 1
+ first changed: true
+ second changed: false
+ '''
+ self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected), post_build=addPreRunAndChecks)
+
### 'Big' tests
def test_fannkuch(self):