Skip to content

Commit

Permalink
Shader source character set and preprocess validation test (KhronosGr…
Browse files Browse the repository at this point in the history
…oup#3124)

* Shader source character set and preprocess validation test

* fix style

* add invalid test
  • Loading branch information
shrekshao authored Jul 27, 2020
1 parent 3f6b053 commit c12e598
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk/tests/conformance/glsl/bugs/00_test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--min-version 1.0.3 array-of-struct-with-int-first-position.html
--min-version 1.0.4 assign-to-swizzled-twice-in-function.html
--min-version 1.0.4 bool-type-cast-bug-int-float.html
--min-version 1.0.4 character-set.html
--min-version 1.0.3 compare-loop-index-to-uniform.html
--min-version 1.0.3 complex-glsl-does-not-crash.html
--min-version 1.0.4 compound-assignment-type-combination.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
debug("");
debug("Checking shader compilation and linking.");

checkCompilation()
checkCompilation();
}

function checkCompilation() {
Expand Down
134 changes: 134 additions & 0 deletions sdk/tests/conformance/glsl/bugs/character-set.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!--
Copyright (c) 2020 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Character Set</title>
<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
<script src="../../../js/js-test-pre.js"></script>
<script src="../../../js/webgl-test-utils.js"></script>
<script src="../../../js/glsl-conformance-test.js"></script>
</head>
<body>

<script id="fs-invalid-0" type="x-shader/x-fragment">
precision mediump float;
$
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
</script>

<script id="fs-invalid-1" type="x-shader/x-fragment">
precision mediump float;
一些注释
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
</script>

<script id="fs-invalid-2" type="x-shader/x-fragment">
precision mediump float;
#if defined(NOT_DEFINED_FOO)
一些注释
#endif
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
</script>

<script id="fs-comment-valid" type="x-shader/x-fragment">
precision mediump float;
// some comment: asdf1234~!@#$%^&*()-=[];',./{}:"?><_+
// some comment: 一些注释 (╯‵□′)╯︵┻━┻
// some comment: \\\\\\\\\
// some comment: \n\\r\n
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
</script>

<script id="fs-cleared-by-preprocessing-valid" type="x-shader/x-fragment">
precision mediump float;
#if defined(GL_GOOGLE_cpp_style_line_directive)
#line 9 "foo.txt"
#endif
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
</script>

<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
"use strict";
// See http://crbug.com/1108588 for original failing case.
// Check "OpenGL Registry The OpenGL ES Shading Language"
// Section 3.2 Character Sets For more info
description("This test checks character set validation for glsl.");

debug("");
debug("Canvas.getContext");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas");
if (!gl) {
testFailed("context does not exist");
} else {
testPassed("context exists");

debug("");
debug("Checking shader character set validation and compilation");

runTest();
}

function runTest() {
GLSLConformanceTester.runTests([
{
fShaderId: 'fs-invalid-0',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'Unallowed characters detected'
},
{
fShaderId: 'fs-invalid-1',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'Unallowed characters detected'
},
{
fShaderId: 'fs-invalid-2',
fShaderSuccess: false,
linkSuccess: false,
passMsg: 'Non ASCII characters detected that would be cleared by preprocessing step is still invalid'
},
{
fShaderId: 'fs-comment-valid',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'Unallowed characters and UTF-8 characters in comment are valid'
},
{
fShaderId: 'fs-cleared-by-preprocessing-valid',
fShaderSuccess: true,
linkSuccess: true,
passMsg: 'Unsupported shader extensions (with invalid ASCII characters) cleared by preprocessing step is valid'
},
]);
}

debug("");
var successfullyParsed = true;

</script>
<script src="../../../js/js-test-post.js"></script>

</body>
</html>

0 comments on commit c12e598

Please sign in to comment.