aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/browser_harness.html25
-rw-r--r--tests/hello_world_gles_shell.html2
-rw-r--r--tests/htmltest.pngbin0 -> 743 bytes
-rwxr-xr-xtests/runner.py126
-rw-r--r--tests/sdl_audio.c2
5 files changed, 111 insertions, 44 deletions
diff --git a/tests/browser_harness.html b/tests/browser_harness.html
new file mode 100644
index 00000000..3fbe8646
--- /dev/null
+++ b/tests/browser_harness.html
@@ -0,0 +1,25 @@
+<html>
+<body>
+<div id="output"></div>
+<script>
+ var counter = 0;
+ function check() {
+ var request = new XMLHttpRequest();
+ request.open('GET', '/check', false);
+ try {
+ request.send(null);
+ if (request.responseText != 'False') {
+ document.getElementById('output').innerHTML += 'opening test window ' + (counter++) + '..<br>';
+ window.open(request.responseText);
+ }
+ setTimeout(check, 333);
+ } catch(e) {
+ document.write('Tests complete. View log in console.');
+ return;
+ }
+ }
+ check();
+</script>
+</body>
+</html>
+
diff --git a/tests/hello_world_gles_shell.html b/tests/hello_world_gles_shell.html
index d3429e3a..343ddb64 100644
--- a/tests/hello_world_gles_shell.html
+++ b/tests/hello_world_gles_shell.html
@@ -36,7 +36,7 @@
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8888/report_gl_result?' + result, true);
xhr.send();
- setTimeout(function() { _glutDisplayFunc = function(){} }, 2000); // Stop rendering after a while
+ setTimeout(function() { window.close() }, 1000);
}
function doTest() {
var firstImage = Module.canvas.toDataURL();
diff --git a/tests/htmltest.png b/tests/htmltest.png
new file mode 100644
index 00000000..980245ee
--- /dev/null
+++ b/tests/htmltest.png
Binary files differ
diff --git a/tests/runner.py b/tests/runner.py
index f29c7e0c..592f685c 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2639,6 +2639,8 @@ def process(filename):
# part 2: make sure we warn about mixing c and c++ calling conventions here
+ if not (self.emcc_args is None or self.emcc_args == []): return # Optimized code is missing the warning comments
+
header = r'''
struct point
{
@@ -2691,17 +2693,11 @@ def process(filename):
all_name = os.path.join(self.get_dir(), 'all.bc')
Building.link([supp_name + '.o', main_name + '.o'], all_name)
- try:
- # This will fail! See explanation near the warning we check for, in the compiler source code
- self.do_ll_run(all_name, 'pre: 54,2\ndump: 55,3\ndump: 55,3\npost: 54,2')
- except Exception, e:
- # Check for warning in the generated code
- generated = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read()
- if self.emcc_args is None or self.emcc_args == []: # Optimized code is missing the warning comments
- assert 'Casting a function pointer type to another with a different number of arguments.' in generated, 'Missing expected warning'
- assert 'void (i32, i32)* ==> void (%struct.point.0*)*' in generated, 'Missing expected warning details'
- return
- raise Exception('We should not have gotten to here!')
+ # This will fail! See explanation near the warning we check for, in the compiler source code
+ output = Popen(['python', EMCC, all_name], stderr=PIPE).communicate()
+ # Check for warning in the generated code
+ generated = open(os.path.join(self.get_dir(), 'src.cpp.o.js')).read()
+ assert 'Casting a function pointer type to another with a different number of arguments.' in output[1], 'Missing expected warning'
def test_stdlibs(self):
if Settings.USE_TYPED_ARRAYS == 2:
@@ -6624,19 +6620,70 @@ elif 'browser' in str(sys.argv):
# Browser tests.
class browser(RunnerCore):
+ def __init__(self, *args, **kwargs):
+ super(browser, self).__init__(*args, **kwargs)
+
+ if hasattr(browser, 'harness_server'): return
+
+ # Run a server and a web page. When a test runs, we tell the server about it,
+ # which tells the web page, which then opens a window with the test. Doing
+ # it this way then allows the page to close() itself when done.
+ def server_func(q):
+ class TestServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+ def do_GET(s):
+ s.send_response(200)
+ s.send_header("Content-type", "text/html")
+ s.end_headers()
+ if s.path == '/run_harness':
+ s.wfile.write(open(path_from_root('tests', 'browser_harness.html')).read())
+ else:
+ result = 'False'
+ if not q.empty():
+ result = q.get()
+ s.wfile.write(result)
+ s.wfile.close()
+ httpd = BaseHTTPServer.HTTPServer(('localhost', 9999), TestServerHandler)
+ httpd.serve_forever() # test runner will kill us
+ browser.harness_queue = multiprocessing.Queue()
+ browser.harness_server = multiprocessing.Process(target=server_func, args=(browser.harness_queue,))
+ browser.harness_server.start()
+ print '[Browser harness server on process %d]' % browser.harness_server.pid
+ webbrowser.open_new('http://localhost:9999/run_harness')
+
+ def __del__(self):
+ if not hasattr(browser, 'harness_server'): return
+
+ browser.harness_server.terminate()
+ delattr(browser, 'harness_server')
+ print '[Browser harness server terminated]'
+
def run_browser(self, html_file, message, expectedResult=None):
if expectedResult is not None:
try:
def server_func(q):
class TestServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
- q.put(s.path)
+ if 'report_' in s.path:
+ q.put(s.path)
+ else:
+ filename = s.path[1:]
+ if os.path.exists(filename):
+ s.send_response(200)
+ s.send_header("Content-type", "text/html")
+ s.end_headers()
+ s.wfile.write(open(filename).read())
+ s.wfile.close()
+ else:
+ s.send_response(500)
+ s.send_header("Content-type", "text/html")
+ s.end_headers()
+ os.chdir(self.get_dir())
httpd = BaseHTTPServer.HTTPServer(('localhost', 8888), TestServerHandler)
httpd.serve_forever() # test runner will kill us
queue = multiprocessing.Queue()
server = multiprocessing.Process(target=server_func, args=(queue,))
server.start()
- webbrowser.open_new(os.path.abspath(html_file))
+ browser.harness_queue.put('http://localhost:8888/' + html_file)
output = '[no http server activity]'
start = time.time()
while time.time() - start < 5:
@@ -6655,13 +6702,6 @@ elif 'browser' in str(sys.argv):
time.sleep(5)
print '(moving on..)'
- def test_html(self):
- # test HTML generation.
- output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.html'], stdout=PIPE, stderr=PIPE).communicate()
- assert len(output[0]) == 0, output[0]
- assert os.path.exists('something.html'), output
- self.run_browser('something.html', 'You should see "hello, world!" and a colored cube.')
-
def with_report_result(self, code):
return code.replace('REPORT_RESULT();', '''
char output[1000];
@@ -6670,6 +6710,7 @@ elif 'browser' in str(sys.argv):
"xhr.open('GET', 'http://localhost:8888/report_result?%d');"
"xhr.send();", result);
emscripten_run_script(output);
+ emscripten_run_script("setTimeout(function() { window.close() }, 1000)");
''')
def reftest(self, expected):
@@ -6714,6 +6755,7 @@ elif 'browser' in str(sys.argv):
xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8888/report_result?' + wrong);
xhr.send();
+ setTimeout(function() { window.close() }, 1000);
};
actualImage.src = actualUrl;
}
@@ -6725,6 +6767,12 @@ elif 'browser' in str(sys.argv):
};
''' % basename)
+ def test_html(self):
+ # test HTML generation.
+ self.reftest(path_from_root('tests', 'htmltest.png'))
+ output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_sdl.cpp'), '-o', 'something.html', '--pre-js', 'reftest.js']).communicate()
+ self.run_browser('something.html', 'You should see "hello, world!" and a colored cube.', '/report_result?0')
+
def test_compression(self):
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(self.with_report_result(r'''
#include <stdio.h>
@@ -6959,55 +7007,49 @@ elif 'browser' in str(sys.argv):
html_file.write('''
<html>
<body>
+ Worker Test
<script>
var worker = new Worker('worker.js');
worker.onmessage = function(event) {
- document.write("<hr>Called back by the worker: " + event.data + "<br><hr>");
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', 'http://localhost:8888/report_result?' + event.data);
+ xhr.send();
+ setTimeout(function() { window.close() }, 1000);
};
</script>
</body>
</html>
''')
html_file.close()
- self.run_browser('main.html', 'You should see that the worker was called, and said "hello from worker!"')
+ self.run_browser('main.html', 'You should see that the worker was called, and said "hello from worker!"', '/report_result?hello%20from%20worker!')
def test_glgears(self):
self.reftest(path_from_root('tests', 'gears.png'))
- output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
- '-DHAVE_BUILTIN_SINCOS', '--pre-js', 'reftest.js'],
- stdout=PIPE, stderr=PIPE).communicate()
- assert len(output[0]) == 0, output[0]
- assert os.path.exists('something.html'), output
+ Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
+ '-DHAVE_BUILTIN_SINCOS', '--pre-js', 'reftest.js']).communicate()
self.run_browser('something.html', 'You should see animating gears.', '/report_result?0')
def test_glgears_animation(self):
- output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
+ Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
'-DHAVE_BUILTIN_SINCOS',
- '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')],
- stdout=PIPE, stderr=PIPE).communicate()
- assert len(output[0]) == 0, output[0]
- assert os.path.exists('something.html'), output
+ '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')]).communicate()
self.run_browser('something.html', 'You should see animating gears.', '/report_gl_result?true')
def test_glgears_bad(self):
# Make sure that OpenGL ES is not available if typed arrays are not used
- output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
+ Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles.c'), '-o', 'something.html',
'-DHAVE_BUILTIN_SINCOS',
'-s', 'USE_TYPED_ARRAYS=0',
- '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')],
- stdout=PIPE, stderr=PIPE).communicate()
- assert len(output[0]) == 0, output[0]
- assert os.path.exists('something.html'), output
+ '--shell-file', path_from_root('tests', 'hello_world_gles_shell.html')]).communicate()
self.run_browser('something.html', 'You should not see animating gears.', '/report_gl_result?false')
def test_glgears_deriv(self):
self.reftest(path_from_root('tests', 'gears.png'))
- output = Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles_deriv.c'), '-o', 'something.html',
- '-DHAVE_BUILTIN_SINCOS', '--pre-js', 'reftest.js'],
- stdout=PIPE, stderr=PIPE).communicate()
- assert len(output[0]) == 0, output[0]
- assert os.path.exists('something.html'), output
+ Popen(['python', EMCC, path_from_root('tests', 'hello_world_gles_deriv.c'), '-o', 'something.html',
+ '-DHAVE_BUILTIN_SINCOS', '--pre-js', 'reftest.js']).communicate()
self.run_browser('something.html', 'You should see animating gears.', '/report_result?0')
+ src = open('something.html').read()
+ assert 'gl-matrix' not in src, 'Should not include glMatrix when not needed'
def test_glbook(self):
programs = self.get_library('glbook', [
diff --git a/tests/sdl_audio.c b/tests/sdl_audio.c
index 77c82b4e..4927d868 100644
--- a/tests/sdl_audio.c
+++ b/tests/sdl_audio.c
@@ -12,7 +12,7 @@ void play() {
int channel = Mix_PlayChannel(-1, sound, 1);
assert(channel >= 0);
- emscripten_run_script("setTimeout(Module['_play2'], 1000)");
+ emscripten_run_script("setTimeout(Module['_play2'], 500)");
}
void play2() {