Skip to content

Commit 641c36f

Browse files
author
Jean-Baptiste Queru
committed
Merge into jb-mr1-dev
Change-Id: Iec56e4962bbc78309b20595352cce986fe62f68e
2 parents e83221c + 85d4955 commit 641c36f

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-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
@@ -76,6 +76,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
7676
unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx));
7777
unitTests.add(new UT_convert(this, mRes, mCtx));
7878
unitTests.add(new UT_convert_relaxed(this, mRes, mCtx));
79+
unitTests.add(new UT_copy_test(this, mRes, mCtx));
7980
unitTests.add(new UT_rsdebug(this, mRes, mCtx));
8081
unitTests.add(new UT_rstime(this, mRes, mCtx));
8182
unitTests.add(new UT_rstypes(this, mRes, mCtx));
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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_copy_test extends UnitTest {
25+
private Resources mRes;
26+
boolean pass = true;
27+
28+
protected UT_copy_test(RSTestCore rstc, Resources res, Context ctx) {
29+
super(rstc, "Copy", ctx);
30+
mRes = res;
31+
}
32+
33+
void testFloat2(RenderScript rs, ScriptC_copy_test s) {
34+
Allocation a1 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
35+
Allocation a2 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
36+
37+
float[] f1 = new float[1024 * 2];
38+
float[] f2 = new float[1024 * 2];
39+
for (int ct=0; ct < f1.length; ct++) {
40+
f1[ct] = (float)ct;
41+
}
42+
a1.copyFrom(f1);
43+
44+
s.forEach_copyFloat2(a1, a2);
45+
46+
a2.copyTo(f2);
47+
for (int ct=0; ct < f1.length; ct++) {
48+
if (f1[ct] != f2[ct]) {
49+
failTest();
50+
Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
51+
}
52+
}
53+
a1.destroy();
54+
a2.destroy();
55+
}
56+
57+
void testFloat3(RenderScript rs, ScriptC_copy_test s) {
58+
Allocation a1 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
59+
Allocation a2 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
60+
61+
float[] f1 = new float[1024 * 4];
62+
float[] f2 = new float[1024 * 4];
63+
for (int ct=0; ct < f1.length; ct++) {
64+
f1[ct] = (float)ct;
65+
}
66+
a1.copyFrom(f1);
67+
68+
s.forEach_copyFloat3(a1, a2);
69+
70+
a2.copyTo(f2);
71+
for (int ct=0; ct < f1.length; ct++) {
72+
if ((f1[ct] != f2[ct]) && ((ct&3) != 3)) {
73+
failTest();
74+
Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
75+
}
76+
}
77+
a1.destroy();
78+
a2.destroy();
79+
}
80+
81+
void testFloat4(RenderScript rs, ScriptC_copy_test s) {
82+
Allocation a1 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
83+
Allocation a2 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
84+
85+
float[] f1 = new float[1024 * 4];
86+
float[] f2 = new float[1024 * 4];
87+
for (int ct=0; ct < f1.length; ct++) {
88+
f1[ct] = (float)ct;
89+
}
90+
a1.copyFrom(f1);
91+
92+
s.forEach_copyFloat4(a1, a2);
93+
94+
a2.copyTo(f2);
95+
for (int ct=0; ct < f1.length; ct++) {
96+
if (f1[ct] != f2[ct]) {
97+
failTest();
98+
Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
99+
}
100+
}
101+
a1.destroy();
102+
a2.destroy();
103+
}
104+
105+
public void run() {
106+
RenderScript pRS = RenderScript.create(mCtx);
107+
ScriptC_copy_test s = new ScriptC_copy_test(pRS);
108+
pRS.setMessageHandler(mRsMessage);
109+
110+
testFloat2(pRS, s);
111+
testFloat3(pRS, s);
112+
testFloat4(pRS, s);
113+
s.invoke_sendResult(true);
114+
115+
pRS.finish();
116+
waitForMessage();
117+
pRS.destroy();
118+
}
119+
}
120+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#include "shared.rsh"
18+
19+
void sendResult(bool pass) {
20+
if (pass) {
21+
rsSendToClientBlocking(RS_MSG_TEST_PASSED);
22+
}
23+
else {
24+
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
25+
}
26+
}
27+
28+
29+
float2 __attribute((kernel)) copyFloat2(float2 i) {
30+
return i;
31+
}
32+
33+
float3 __attribute((kernel)) copyFloat3(float3 i) {
34+
return i;
35+
}
36+
37+
float4 __attribute((kernel)) copyFloat4(float4 i) {
38+
return i;
39+
}
40+
41+

0 commit comments

Comments
 (0)