Skip to content

Commit b1ea64e

Browse files
committed
Test RS struct writing/reading.
BUG=5569561 Note that this only tests the issue described in the bug. It does not actually produce an error on any recent version of RS. Change-Id: I0194b13cb3f4ff01ce95d966e8e2dd74119a3946
1 parent e372593 commit b1ea64e

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-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
@@ -73,6 +73,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
7373
unitTests.add(new UT_refcount(this, mRes, mCtx));
7474
unitTests.add(new UT_foreach(this, mRes, mCtx));
7575
unitTests.add(new UT_atomic(this, mRes, mCtx));
76+
unitTests.add(new UT_struct(this, mRes, mCtx));
7677
unitTests.add(new UT_math(this, mRes, mCtx));
7778
unitTests.add(new UT_fp_mad(this, mRes, mCtx));
7879
/*
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
23+
public class UT_struct extends UnitTest {
24+
private Resources mRes;
25+
26+
protected UT_struct(RSTestCore rstc, Resources res, Context ctx) {
27+
super(rstc, "Struct", ctx);
28+
mRes = res;
29+
}
30+
31+
public void run() {
32+
RenderScript pRS = RenderScript.create(mCtx);
33+
ScriptC_struct s = new ScriptC_struct(pRS, mRes, R.raw.struct);
34+
pRS.setMessageHandler(mRsMessage);
35+
36+
ScriptField_Point2 p = new ScriptField_Point2(pRS, 1);
37+
ScriptField_Point2.Item i = new ScriptField_Point2.Item();
38+
int val = 100;
39+
i.x = val;
40+
i.y = val;
41+
p.set(i, 0, true);
42+
s.bind_point2(p);
43+
s.invoke_struct_test(val);
44+
pRS.finish();
45+
waitForMessage();
46+
47+
val = 200;
48+
p.set_x(0, val, true);
49+
p.set_y(0, val, true);
50+
s.invoke_struct_test(val);
51+
pRS.finish();
52+
waitForMessage();
53+
pRS.destroy();
54+
}
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "shared.rsh"
2+
3+
typedef struct Point2 {
4+
int x;
5+
int y;
6+
} Point_2;
7+
Point_2 *point2;
8+
9+
static bool test_Point_2(int expected) {
10+
bool failed = false;
11+
12+
rsDebug("Point: ", point2[0].x, point2[0].y);
13+
_RS_ASSERT(point2[0].x == expected);
14+
_RS_ASSERT(point2[0].y == expected);
15+
16+
if (failed) {
17+
rsDebug("test_Point_2 FAILED", 0);
18+
}
19+
else {
20+
rsDebug("test_Point_2 PASSED", 0);
21+
}
22+
23+
return failed;
24+
}
25+
26+
void struct_test(int expected) {
27+
bool failed = false;
28+
failed |= test_Point_2(expected);
29+
30+
if (failed) {
31+
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
32+
}
33+
else {
34+
rsSendToClientBlocking(RS_MSG_TEST_PASSED);
35+
}
36+
}
37+

0 commit comments

Comments
 (0)