Skip to content

Commit bad8f04

Browse files
committed
Tweak to test function
1 parent be3f065 commit bad8f04

1 file changed

Lines changed: 40 additions & 17 deletions

File tree

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
//
22
// See: https://github.com/gpujs/gpu.js/issues/31
33
//
4-
function nestedVarDeclare( mode ) {
5-
var gpu = new GPU();
6-
var f = gpu.createKernel(function() {
7-
var ret = 0.0;
8-
9-
// outer loop limit is effectively skipped in CPU
10-
for(var i=0; i<10; ++i) {
11-
// inner loop limit should be higher, to avoid infinite loops
12-
for(var i=0; i<20; ++i) {
13-
ret += 1;
14-
}
4+
function nestedVarDeclareFunction() {
5+
var ret = 0.0;
6+
7+
// outer loop limit is effectively skipped in CPU
8+
for(var i=0; i<10; ++i) {
9+
// inner loop limit should be higher, to avoid infinite loops
10+
for(var i=0; i<20; ++i) {
11+
ret += 1;
1512
}
16-
17-
return ret;
18-
}, {
13+
}
14+
15+
return ret;
16+
}
17+
18+
function nestedVarDeclareTest( mode ) {
19+
var gpu = new GPU();
20+
var f = gpu.createKernel(nestedVarDeclareFunction, {
1921
dimensions : [1],
2022
mode : mode
2123
});
@@ -25,13 +27,34 @@ function nestedVarDeclare( mode ) {
2527
}
2628

2729
QUnit.test( "Issue #31 - nestedVarDeclare (auto)", function() {
28-
nestedVarDeclare(null);
30+
nestedVarDeclareTest(null);
2931
});
3032

3133
QUnit.test( "Issue #31 - nestedVarDeclare (GPU)", function() {
32-
nestedVarDeclare("gpu");
34+
nestedVarDeclareTest("gpu");
3335
});
3436

3537
QUnit.test( "Issue #31 - nestedVarDeclare (CPU)", function() {
36-
nestedVarDeclare("cpu");
38+
nestedVarDeclareTest("cpu");
39+
});
40+
41+
QUnit.test( "Issue #31 - nestedVarDeclare : AST handling", function() {
42+
var builder = new functionBuilder();
43+
builder.addFunction(null, nestedVarDeclareFunction);
44+
45+
QUnit.equal(
46+
builder.webglString_fromFunctionNames(["nestedVarDeclareFunction"]).replace(new RegExp("\n", "g"), ""),
47+
"float nestedVarDeclareFunction() {"+
48+
"float user_ret=0.0;"+
49+
";"+
50+
""+
51+
"for (float user_i=0.0;(user_i<10.0);++user_i){"+
52+
"for (user_i=0.0;(user_i<20.0);++user_i){"+
53+
"user_ret+=1.0;"+
54+
"}"+
55+
"}"+
56+
""+
57+
"return user_ret;"+
58+
"}"
59+
);
3760
});

0 commit comments

Comments
 (0)