Skip to content

Commit 5ca88a1

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "Add tests for pass-by-value kernels." into jb-mr1-dev
2 parents 95cd451 + 263459d commit 5ca88a1

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

tests/RenderScriptTests/tests/src/com/android/rs/test/RSTestCore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
7070
unitTests.add(new UT_unsigned(this, mRes, mCtx));
7171
unitTests.add(new UT_array_init(this, mRes, mCtx));
7272
unitTests.add(new UT_array_alloc(this, mRes, mCtx));
73+
unitTests.add(new UT_kernel(this, mRes, mCtx));
7374
unitTests.add(new UT_clamp(this, mRes, mCtx));
7475
unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx));
7576
unitTests.add(new UT_convert(this, mRes, mCtx));
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2012 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.rs.test;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.renderscript.*;
22+
import android.util.Log;
23+
24+
public class UT_kernel extends UnitTest {
25+
private Resources mRes;
26+
private Allocation A;
27+
private Allocation B;
28+
29+
protected UT_kernel(RSTestCore rstc, Resources res, Context ctx) {
30+
super(rstc, "Kernels (pass-by-value)", ctx);
31+
mRes = res;
32+
}
33+
34+
private void initializeGlobals(RenderScript RS, ScriptC_kernel s) {
35+
Type.Builder typeBuilder = new Type.Builder(RS, Element.I32(RS));
36+
int X = 5;
37+
s.set_dimX(X);
38+
typeBuilder.setX(X);
39+
A = Allocation.createTyped(RS, typeBuilder.create());
40+
s.bind_ain(A);
41+
B = Allocation.createTyped(RS, typeBuilder.create());
42+
s.bind_aout(B);
43+
44+
return;
45+
}
46+
47+
public void run() {
48+
RenderScript pRS = RenderScript.create(mCtx);
49+
ScriptC_kernel s = new ScriptC_kernel(pRS);
50+
pRS.setMessageHandler(mRsMessage);
51+
initializeGlobals(pRS, s);
52+
s.forEach_init_vars(A);
53+
s.forEach_root(A, B);
54+
s.invoke_verify_root();
55+
s.invoke_kernel_test();
56+
pRS.finish();
57+
waitForMessage();
58+
pRS.destroy();
59+
}
60+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "shared.rsh"
2+
3+
int *ain;
4+
int *aout;
5+
int dimX;
6+
static bool failed = false;
7+
8+
void init_vars(int *out) {
9+
*out = 7;
10+
}
11+
12+
13+
int __attribute__((kernel)) root(int ain, uint32_t x) {
14+
_RS_ASSERT(ain == 7);
15+
return ain + x;
16+
}
17+
18+
static bool test_root_output() {
19+
bool failed = false;
20+
int i;
21+
22+
for (i = 0; i < dimX; i++) {
23+
_RS_ASSERT(aout[i] == (i + ain[i]));
24+
}
25+
26+
if (failed) {
27+
rsDebug("test_root_output FAILED", 0);
28+
}
29+
else {
30+
rsDebug("test_root_output PASSED", 0);
31+
}
32+
33+
return failed;
34+
}
35+
36+
void verify_root() {
37+
failed |= test_root_output();
38+
}
39+
40+
void kernel_test() {
41+
if (failed) {
42+
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
43+
}
44+
else {
45+
rsSendToClientBlocking(RS_MSG_TEST_PASSED);
46+
}
47+
}

0 commit comments

Comments
 (0)