1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--
Copyright (c) 2019 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.
-->
<link rel="stylesheet" type="text/css" href="../unit.css" />
<script type="application/javascript" src="../unit.js"></script>
<script type="application/javascript" src="../util.js"></script>
<script type="application/javascript">
Tests.autorun = false;
Tests.message = "This will fuzz the API with random inputs for a [long] while."
function randomCall(testProgress, gl, m, arities) {
doTestNotify(m);
var argcs = {};
var foundArity = false;
if (arities == null) {
testProgress.textContent += " 500 random arity calls on " + m + "\n";
for (var i=0; i<50; i++) {
for (var j=0; j<10; j++) {
var args = generateRandomArgs(j);
// doTestNotify(m + ": " + args.toSource());
try {
gl[m].apply(gl, args);
argcs[j] = true;
foundArity = true;
} catch (e) {
}
}
}
for (var j in argcs) {
testProgress.textContent += "200 arity " + j + " calls on " + m + "\n";
for (var i=0; i<200; i++) {
var args = generateRandomArgs(j);
// doTestNotify(m + ": " + args.toSource());
try {
gl[m].apply(gl, args);
argcs[j] = true;
} catch (e) {
}
}
}
} else {
for (var k=0; k<arities.length; k++) {
var j = arities[k];
testProgress.textContent += "500 arity " + j + " calls on " + m + "\n";
for (var i=0; i<500; i++) {
var args = generateRandomArgs(j);
// doTestNotify(m + ": " + args.toSource());
try {
gl[m].apply(gl, args);
} catch (e) {
}
}
}
}
// doTestNotify(m+"--OK");
}
Tests.testGetGLWeb20 = function() {
var testProgress = document.getElementById('testProgress');
var funcnames = document.getElementById('funcnames').value.split(",");
var canvas = document.getElementById('glweb20');
var gl;
assertOk(function(){gl = getGLContext(canvas);});
var funcs = [];
for (var i=0; i<funcnames.length; i++) {
var fn = funcnames[i];
fn = fn.replace(/^\s+|\s+$/g, '');
if (fn.length > 0)
funcs.push(fn);
}
if (funcs.length == 0) {
for (var m in gl)
try{if (typeof gl[m] == 'function')
funcs.push(m);}catch(e){}
}
var idx = 0;
var count = 0;
var limit = 1000;
var iv1;
var iv2;
iv1 = setInterval(function(){
if (idx >= funcs.length) {
iv2 = setInterval(function(){
if (count >= limit) {
clearInterval(iv2);
return false;
}
count++;
var f = Math.floor(Math.random() * funcs.length);
randomCall(testProgress, gl, funcs[f]);
}, 50);
clearInterval(iv1);
return false;
}
randomCall(testProgress, gl, funcs[idx]);
idx++;
}, 50);
}
</script>
<style>canvas{ position:absolute; }</style>
</head><body>
<canvas id="glweb20" width="16" height="16"></canvas>
<p>Optional: Enter a comma-separated list of functions to fuzz (leave blank for full API)</p>
<input type="text" size="40" id="funcnames" value="">
<pre id="testProgress"></pre>
</body></html>
|