Skip to content

Commit 3737863

Browse files
authored
Parameterize test_webgl_timer_query. NFC (#20085)
Also, convert it from C++ to C.
1 parent ba30089 commit 3737863

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

test/test_browser.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4558,17 +4558,16 @@ def test_webgl_sample_query(self):
45584558
self.btest_exit('webgl_sample_query.cpp', args=cmd)
45594559

45604560
@requires_graphics_hardware
4561-
def test_webgl_timer_query(self):
4562-
for args in [
4563-
# EXT query entrypoints on WebGL 1.0
4564-
['-sMAX_WEBGL_VERSION'],
4565-
# builtin query entrypoints on WebGL 2.0
4566-
['-sMAX_WEBGL_VERSION=2', '-DTEST_WEBGL2'],
4567-
# EXT query entrypoints on a WebGL 1.0 context while built for WebGL 2.0
4568-
['-sMAX_WEBGL_VERSION=2'],
4569-
]:
4570-
cmd = args + ['-lGL']
4571-
self.btest_exit('webgl_timer_query.cpp', args=cmd)
4561+
@parameterized({
4562+
# EXT query entrypoints on WebGL 1.0
4563+
'': (['-sMAX_WEBGL_VERSION'],),
4564+
# EXT query entrypoints on a WebGL 1.0 context while built for WebGL 2.0
4565+
'v2': (['-sMAX_WEBGL_VERSION=2'],),
4566+
# builtin query entrypoints on WebGL 2.0
4567+
'v2api': (['-sMAX_WEBGL_VERSION=2', '-DTEST_WEBGL2'],),
4568+
})
4569+
def test_webgl_timer_query(self, args):
4570+
self.btest_exit('webgl_timer_query.c', args=args + ['-lGL'])
45724571

45734572
# Tests that -sOFFSCREEN_FRAMEBUFFER rendering works.
45744573
@requires_graphics_hardware

test/webgl_timer_query.cpp renamed to test/webgl_timer_query.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
// University of Illinois/NCSA Open Source License. Both these licenses can be
44
// found in the LICENSE file.
55

6-
#include <cassert>
7-
#include <cstdlib>
8-
#include <cstdio>
9-
#include <cstring>
6+
#include <assert.h>
7+
#include <stdlib.h>
8+
#include <stdbool.h>
9+
#include <stdio.h>
10+
#include <string.h>
1011
#include <emscripten.h>
1112
#include <emscripten/html5.h>
1213

@@ -22,18 +23,17 @@
2223
int result = 0;
2324
GLuint timerQuery = 0;
2425

25-
#define GL_CALL( x ) \
26-
{ \
27-
x; \
28-
GLenum error = glGetError(); \
29-
if( error != GL_NO_ERROR ) { \
30-
printf( "GL ERROR: %d, %s\n", (int)error, #x ); \
31-
result = 1; \
32-
} \
33-
} \
34-
35-
void getQueryResult()
36-
{
26+
#define GL_CALL(x) \
27+
{ \
28+
x; \
29+
GLenum error = glGetError(); \
30+
if (error != GL_NO_ERROR) { \
31+
printf("GL ERROR: %d, %s\n", (int)error, #x); \
32+
result = 1; \
33+
} \
34+
}
35+
36+
void getQueryResult() {
3737
/* Get the result. It should be nonzero. */
3838
GLuint64 time = 0;
3939
#ifdef TEST_WEBGL2
@@ -42,7 +42,7 @@ void getQueryResult()
4242
GL_CALL(glGetQueryObjectui64vEXT(timerQuery, GL_QUERY_RESULT_EXT, &time));
4343
#endif
4444

45-
if(!time) return;
45+
if (!time) return;
4646

4747
printf("queried time: %llu\n", time);
4848
emscripten_cancel_main_loop();
@@ -56,8 +56,7 @@ void getQueryResult()
5656
exit(result);
5757
}
5858

59-
int main()
60-
{
59+
int main() {
6160
EmscriptenWebGLContextAttributes attrs;
6261
emscripten_webgl_init_context_attributes(&attrs);
6362

@@ -78,8 +77,7 @@ int main()
7877
/* Skip WebGL 2 tests if not supported */
7978
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( "#canvas", &attrs );
8079
#ifdef TEST_WEBGL2
81-
if (!context)
82-
{
80+
if (!context) {
8381
printf("Skipped: WebGL 2 is not supported.\n");
8482
return 0;
8583
}
@@ -88,8 +86,7 @@ int main()
8886

8987
/* Check if the extension is actually supported. Firefox reports
9088
EXT_disjoint_timer_query on WebGL 2 as well. */
91-
if (!std::strstr(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)), "EXT_disjoint_timer_query"))
92-
{
89+
if (!strstr(glGetString(GL_EXTENSIONS), "EXT_disjoint_timer_query")) {
9390
printf("EXT_disjoint_timer_query[_webgl2] not supported\n");
9491
return 0;
9592
}

0 commit comments

Comments
 (0)