Skip to content

Commit 0b17115

Browse files
stephenhinesAndroid (Google) Code Review
authored andcommitted
Merge "RS char bug repro case" into jb-mr1-dev
2 parents c49c71a + d895d37 commit 0b17115

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-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
@@ -72,6 +72,7 @@ public void init(RenderScriptGL rs, Resources res, int width, int height) {
7272
unitTests.add(new UT_array_alloc(this, mRes, mCtx));
7373
unitTests.add(new UT_kernel(this, mRes, mCtx));
7474
unitTests.add(new UT_kernel_struct(this, mRes, mCtx));
75+
unitTests.add(new UT_bug_char(this, mRes, mCtx));
7576
unitTests.add(new UT_clamp(this, mRes, mCtx));
7677
unitTests.add(new UT_clamp_relaxed(this, mRes, mCtx));
7778
unitTests.add(new UT_convert(this, mRes, mCtx));
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
import java.util.Arrays;
24+
25+
public class UT_bug_char extends UnitTest {
26+
private Resources mRes;
27+
28+
protected UT_bug_char(RSTestCore rstc, Resources res, Context ctx) {
29+
super(rstc, "Bug Char", ctx);
30+
mRes = res;
31+
}
32+
33+
// packing functions
34+
private Byte2 pack_b2(byte[] val) {
35+
assert val.length == 2;
36+
Log.i("bug_char", "pack_b2 " + val[0] + " " + val[1]);
37+
return new Byte2(val[0], val[1]);
38+
}
39+
40+
private byte min(byte v1, byte v2) {
41+
return v1 < v2 ? v1 : v2;
42+
}
43+
private byte[] min(byte[] v1, byte[] v2) {
44+
assert v1.length == v2.length;
45+
byte[] rv = new byte[v1.length];
46+
for (int i = 0; i < v1.length; ++i)
47+
rv[i] = min(v1[i], v2[i]);
48+
return rv;
49+
}
50+
51+
private void initializeValues(ScriptC_bug_char s) {
52+
byte rand_sc1_0 = (byte)7;
53+
byte[] rand_sc2_0 = new byte[2];
54+
rand_sc2_0[0] = 11;
55+
rand_sc2_0[1] = 21;
56+
Log.i("bug_char", "Generated sc2_0 to " + Arrays.toString(rand_sc2_0));
57+
byte rand_sc1_1 = (byte)10;
58+
byte[] rand_sc2_1 = new byte[2];
59+
rand_sc2_1[0] = 13;
60+
rand_sc2_1[1] = 15;
61+
Log.i("bug_char", "Generated sc2_1 to " + Arrays.toString(rand_sc2_1));
62+
63+
s.set_rand_sc1_0(rand_sc1_0);
64+
s.set_rand_sc2_0(pack_b2(rand_sc2_0));
65+
s.set_rand_sc1_1(rand_sc1_1);
66+
s.set_rand_sc2_1(pack_b2(rand_sc2_1));
67+
// Set results for min
68+
s.set_min_rand_sc1_sc1(min(rand_sc1_0, rand_sc1_1));
69+
byte[] min_rand_sc2_raw = min(rand_sc2_0, rand_sc2_1);
70+
Log.i("bug_char", "Generating min_rand_sc2_sc2 to " +
71+
Arrays.toString(min_rand_sc2_raw));
72+
Byte2 min_rand_sc2 = pack_b2(min_rand_sc2_raw);
73+
Log.i("bug_char", "Setting min_rand_sc2_sc2 to [" + min_rand_sc2.x +
74+
", " + min_rand_sc2.y + "]");
75+
s.set_min_rand_sc2_sc2(min_rand_sc2);
76+
}
77+
78+
public void run() {
79+
RenderScript pRS = RenderScript.create(mCtx);
80+
ScriptC_bug_char s = new ScriptC_bug_char(pRS, mRes,
81+
R.raw.bug_char);
82+
pRS.setMessageHandler(mRsMessage);
83+
initializeValues(s);
84+
s.invoke_bug_char_test();
85+
pRS.finish();
86+
waitForMessage();
87+
pRS.destroy();
88+
}
89+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "shared.rsh"
2+
3+
char rand_sc1_0, rand_sc1_1;
4+
char2 rand_sc2_0, rand_sc2_1;
5+
6+
char min_rand_sc1_sc1;
7+
char2 min_rand_sc2_sc2;
8+
9+
static bool test_bug_char() {
10+
bool failed = false;
11+
12+
rsDebug("rand_sc2_0.x: ", rand_sc2_0.x);
13+
rsDebug("rand_sc2_0.y: ", rand_sc2_0.y);
14+
rsDebug("rand_sc2_1.x: ", rand_sc2_1.x);
15+
rsDebug("rand_sc2_1.y: ", rand_sc2_1.y);
16+
char temp_sc1;
17+
char2 temp_sc2;
18+
19+
temp_sc1 = min( rand_sc1_0, rand_sc1_1 );
20+
if (temp_sc1 != min_rand_sc1_sc1) {
21+
rsDebug("temp_sc1", temp_sc1);
22+
failed = true;
23+
}
24+
rsDebug("broken", 'y');
25+
26+
temp_sc2 = min( rand_sc2_0, rand_sc2_1 );
27+
if (temp_sc2.x != min_rand_sc2_sc2.x
28+
|| temp_sc2.y != min_rand_sc2_sc2.y) {
29+
failed = true;
30+
}
31+
32+
33+
return failed;
34+
}
35+
36+
void bug_char_test() {
37+
bool failed = false;
38+
failed |= test_bug_char();
39+
40+
if (failed) {
41+
rsSendToClientBlocking(RS_MSG_TEST_FAILED);
42+
}
43+
else {
44+
rsSendToClientBlocking(RS_MSG_TEST_PASSED);
45+
}
46+
}
47+

0 commit comments

Comments
 (0)