Add RsList implementation to RSTest.
Run subtests in their own thread / RS context. Created UnitTest framework using message passing for RS. Add color status reporting to device output. Fix some typos in RsList. Change-Id: I251d632b9550a1c117d677f011741a796b561e59
This commit is contained in:
@@ -54,7 +54,7 @@ public class RsList extends Activity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onResume();
|
||||
mView.onResume();
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class RsList extends Activity {
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
// to take appropriate action when the activity loses focus
|
||||
super.onPause();
|
||||
mView.onPause();
|
||||
}
|
||||
|
||||
@@ -19,10 +19,13 @@ package com.android.rs.test;
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
import android.util.Log;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
|
||||
public class RSTestCore {
|
||||
public static final int PART_COUNT = 50000;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
||||
public RSTestCore() {
|
||||
}
|
||||
@@ -30,31 +33,85 @@ public class RSTestCore {
|
||||
private Resources mRes;
|
||||
private RenderScriptGL mRS;
|
||||
|
||||
private ScriptC_test_root mRootScript;
|
||||
private Font mFont;
|
||||
ScriptField_ListAllocs_s mListAllocs;
|
||||
int mLastX;
|
||||
int mLastY;
|
||||
private ScriptC_rslist mScript;
|
||||
|
||||
private boolean fp_mad() {
|
||||
ScriptC_fp_mad s = new ScriptC_fp_mad(mRS, mRes, R.raw.fp_mad, true);
|
||||
s.invoke_doTest(0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean rs_primitives_test() {
|
||||
ScriptC_primitives s = new ScriptC_primitives(mRS, mRes, R.raw.primitives, true);
|
||||
s.invoke_rs_primitives_test(0, 0);
|
||||
return true;
|
||||
}
|
||||
private ArrayList<UnitTest> unitTests;
|
||||
|
||||
public void init(RenderScriptGL rs, Resources res, int width, int height) {
|
||||
mRS = rs;
|
||||
mRes = res;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
|
||||
mRootScript = new ScriptC_test_root(mRS, mRes, R.raw.test_root, true);
|
||||
mScript = new ScriptC_rslist(mRS, mRes, R.raw.rslist, true);
|
||||
|
||||
rs_primitives_test();
|
||||
fp_mad();
|
||||
unitTests = new ArrayList<UnitTest>();
|
||||
|
||||
unitTests.add(new UT_primitives(mRes));
|
||||
unitTests.add(new UT_fp_mad(mRes));
|
||||
/*
|
||||
unitTests.add(new UnitTest("<Pass>", 1));
|
||||
unitTests.add(new UnitTest());
|
||||
unitTests.add(new UnitTest("<Fail>", -1));
|
||||
*/
|
||||
|
||||
UnitTest [] uta = new UnitTest[unitTests.size()];
|
||||
uta = unitTests.toArray(uta);
|
||||
|
||||
/* Run the actual unit tests */
|
||||
ListIterator<UnitTest> test_iter = unitTests.listIterator();
|
||||
while (test_iter.hasNext()) {
|
||||
UnitTest t = test_iter.next();
|
||||
t.start();
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
mListAllocs = new ScriptField_ListAllocs_s(mRS, uta.length);
|
||||
for (int i = 0; i < uta.length; i++) {
|
||||
ScriptField_ListAllocs_s.Item listElem = new ScriptField_ListAllocs_s.Item();
|
||||
listElem.text = Allocation.createFromString(mRS, uta[i].name);
|
||||
listElem.result = uta[i].result;
|
||||
mListAllocs.set(listElem, i, false);
|
||||
}
|
||||
|
||||
mListAllocs.copyAll();
|
||||
|
||||
mScript.bind_gList(mListAllocs);
|
||||
|
||||
mFont = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8);
|
||||
mScript.set_gFont(mFont);
|
||||
|
||||
mRS.contextBindRootScript(mScript);
|
||||
mRS.finish();
|
||||
}
|
||||
|
||||
public void newTouchPosition(float x, float y, float pressure, int id) {
|
||||
}
|
||||
|
||||
public void onActionDown(int x, int y) {
|
||||
mScript.set_gDY(0.0f);
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
|
||||
public void onActionMove(int x, int y) {
|
||||
int dx = mLastX - x;
|
||||
int dy = mLastY - y;
|
||||
|
||||
if (Math.abs(dy) <= 2) {
|
||||
dy = 0;
|
||||
}
|
||||
|
||||
mScript.set_gDY(dy);
|
||||
|
||||
mLastX = x;
|
||||
mLastY = y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,40 +67,28 @@ public class RSTestView extends RSSurfaceView {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev)
|
||||
{
|
||||
int act = ev.getActionMasked();
|
||||
if (act == ev.ACTION_UP) {
|
||||
mRender.newTouchPosition(0, 0, 0, ev.getPointerId(0));
|
||||
return false;
|
||||
} else if (act == MotionEvent.ACTION_POINTER_UP) {
|
||||
// only one pointer going up, we can get the index like this
|
||||
int pointerIndex = ev.getActionIndex();
|
||||
int pointerId = ev.getPointerId(pointerIndex);
|
||||
mRender.newTouchPosition(0, 0, 0, pointerId);
|
||||
boolean ret = false;
|
||||
int act = ev.getAction();
|
||||
if (act == ev.ACTION_DOWN) {
|
||||
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
}
|
||||
int count = ev.getHistorySize();
|
||||
int pcount = ev.getPointerCount();
|
||||
|
||||
for (int p=0; p < pcount; p++) {
|
||||
int id = ev.getPointerId(p);
|
||||
mRender.newTouchPosition(ev.getX(p),
|
||||
ev.getY(p),
|
||||
ev.getPressure(p),
|
||||
id);
|
||||
|
||||
for (int i=0; i < count; i++) {
|
||||
mRender.newTouchPosition(ev.getHistoricalX(p, i),
|
||||
ev.getHistoricalY(p, i),
|
||||
ev.getHistoricalPressure(p, i),
|
||||
id);
|
||||
}
|
||||
else if (act == ev.ACTION_MOVE) {
|
||||
mRender.onActionMove((int)ev.getX(), (int)ev.getY());
|
||||
ret = true;
|
||||
}
|
||||
return true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
39
libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
Normal file
39
libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.rs.test;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class UT_fp_mad extends UnitTest {
|
||||
private Resources mRes;
|
||||
|
||||
protected UT_fp_mad(Resources res) {
|
||||
super("Fp_Mad");
|
||||
mRes = res;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
RenderScript pRS = RenderScript.create();
|
||||
ScriptC_fp_mad s = new ScriptC_fp_mad(pRS, mRes, R.raw.fp_mad, true);
|
||||
pRS.mMessageCallback = mRsMessage;
|
||||
s.invoke_fp_mad_test(0, 0);
|
||||
pRS.finish();
|
||||
pRS.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.rs.test;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.renderscript.*;
|
||||
|
||||
public class UT_primitives extends UnitTest {
|
||||
private Resources mRes;
|
||||
|
||||
protected UT_primitives(Resources res) {
|
||||
super("Primitives");
|
||||
mRes = res;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
RenderScript pRS = RenderScript.create();
|
||||
ScriptC_primitives s = new ScriptC_primitives(pRS, mRes, R.raw.primitives, true);
|
||||
pRS.mMessageCallback = mRsMessage;
|
||||
s.invoke_primitives_test(0, 0);
|
||||
pRS.finish();
|
||||
//android.util.Log.v("UT", "After pRS.finish");
|
||||
|
||||
pRS.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
61
libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
Normal file
61
libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.rs.test;
|
||||
import android.renderscript.RenderScript.RSMessage;
|
||||
|
||||
public class UnitTest extends Thread {
|
||||
public String name;
|
||||
public int result;
|
||||
|
||||
/* These constants must match those in shared.rsh */
|
||||
public static final int RS_MSG_TEST_PASSED = 100;
|
||||
public static final int RS_MSG_TEST_FAILED = 101;
|
||||
|
||||
protected UnitTest(String n, int initResult) {
|
||||
super();
|
||||
name = n;
|
||||
result = initResult;
|
||||
}
|
||||
|
||||
protected UnitTest(String n) {
|
||||
this(n, 0);
|
||||
}
|
||||
|
||||
protected UnitTest() {
|
||||
this ("<Unknown>");
|
||||
}
|
||||
|
||||
protected RSMessage mRsMessage = new RSMessage() {
|
||||
public void run() {
|
||||
switch (mID) {
|
||||
case RS_MSG_TEST_PASSED:
|
||||
result = 1;
|
||||
break;
|
||||
case RS_MSG_TEST_FAILED:
|
||||
result = -1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void run() {
|
||||
/* This method needs to be implemented for each subclass */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
const int TEST_COUNT = 1;
|
||||
|
||||
#pragma rs export_var(g_results)
|
||||
#pragma rs export_func(doTest)
|
||||
|
||||
#pragma rs export_func(fp_mad_test)
|
||||
|
||||
static float data_f1[1025];
|
||||
static float4 data_f4[1025];
|
||||
@@ -143,7 +142,7 @@ static void test_clamp4(uint32_t index) {
|
||||
rsDebug("fp_clamp4 M ops", 100.f / time);
|
||||
}
|
||||
|
||||
void doTest(uint32_t index, int test_num) {
|
||||
void fp_mad_test(uint32_t index, int test_num) {
|
||||
for (int x=0; x < 1025; x++) {
|
||||
data_f1[x] = (x & 0xf) * 0.1f;
|
||||
data_f4[x].x = (x & 0xf) * 0.1f;
|
||||
@@ -168,6 +167,10 @@ void doTest(uint32_t index, int test_num) {
|
||||
test_sincos(index);
|
||||
test_clamp4(index);
|
||||
test_clamp(index);
|
||||
|
||||
// TODO Actually verify test result accuracy
|
||||
rsDebug("fp_mad_test PASSED", 0);
|
||||
rsSendToClient(RS_MSG_TEST_PASSED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#include "shared.rsh"
|
||||
|
||||
#pragma rs export_func(rs_primitives_test)
|
||||
#pragma rs export_func(primitives_test)
|
||||
|
||||
// Testing primitive types
|
||||
#pragma rs export_var(floatTest)
|
||||
#pragma rs export_var(doubleTest)
|
||||
static float floatTest = 1.99f;
|
||||
static double doubleTest = 2.05;
|
||||
static char charTest = -8;
|
||||
@@ -14,7 +12,7 @@ static uchar ucharTest = 8;
|
||||
static ushort ushortTest = 16;
|
||||
static uint uintTest = 32;
|
||||
|
||||
static void test_primitive_types(uint32_t index) {
|
||||
static bool test_primitive_types(uint32_t index) {
|
||||
bool failed = false;
|
||||
start();
|
||||
|
||||
@@ -28,17 +26,26 @@ static void test_primitive_types(uint32_t index) {
|
||||
_RS_ASSERT(uintTest == 32);
|
||||
|
||||
float time = end(index);
|
||||
|
||||
if (failed) {
|
||||
rsDebug("test_primitives FAILED ", time);
|
||||
rsDebug("test_primitives FAILED", time);
|
||||
}
|
||||
else {
|
||||
rsDebug("test_primitives PASSED ", time);
|
||||
rsDebug("test_primitives PASSED", time);
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
void primitives_test(uint32_t index, int test_num) {
|
||||
bool failed = false;
|
||||
failed |= test_primitive_types(index);
|
||||
|
||||
if (failed) {
|
||||
rsSendToClient(RS_MSG_TEST_FAILED);
|
||||
}
|
||||
else {
|
||||
rsSendToClient(RS_MSG_TEST_PASSED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void rs_primitives_test(uint32_t index, int test_num) {
|
||||
test_primitive_types(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
86
libs/rs/java/tests/src/com/android/rs/test/rslist.rs
Normal file
86
libs/rs/java/tests/src/com/android/rs/test/rslist.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright (C) 2009 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma version(1)
|
||||
|
||||
#pragma rs java_package_name(com.android.rs.test)
|
||||
|
||||
#include "rs_graphics.rsh"
|
||||
|
||||
float gDY;
|
||||
|
||||
rs_font gFont;
|
||||
|
||||
typedef struct ListAllocs_s {
|
||||
rs_allocation text;
|
||||
int result;
|
||||
} ListAllocs;
|
||||
|
||||
ListAllocs *gList;
|
||||
|
||||
#pragma rs export_var(gDY, gFont, gList)
|
||||
|
||||
void init() {
|
||||
gDY = 0.0f;
|
||||
}
|
||||
|
||||
int textPos = 0;
|
||||
|
||||
int root(int launchID) {
|
||||
|
||||
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
rsgClearDepth(1.0f);
|
||||
|
||||
textPos -= (int)gDY*2;
|
||||
gDY *= 0.95;
|
||||
|
||||
rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
|
||||
rsgBindFont(gFont);
|
||||
color(0.2, 0.2, 0.2, 0);
|
||||
|
||||
rs_allocation listAlloc = rsGetAllocation(gList);
|
||||
int allocSize = rsAllocationGetDimX(listAlloc);
|
||||
|
||||
int width = rsgGetWidth();
|
||||
int height = rsgGetHeight();
|
||||
|
||||
int itemHeight = 80;
|
||||
int currentYPos = itemHeight + textPos;
|
||||
|
||||
for(int i = 0; i < allocSize; i ++) {
|
||||
if(currentYPos - itemHeight > height) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(currentYPos > 0) {
|
||||
switch(gList[i].result) {
|
||||
case 1: /* Passed */
|
||||
rsgFontColor(0.5f, 0.9f, 0.5f, 1.0f);
|
||||
break;
|
||||
case -1: /* Failed */
|
||||
rsgFontColor(0.9f, 0.5f, 0.5f, 1.0f);
|
||||
break;
|
||||
case 0: /* Unknown */
|
||||
default:
|
||||
rsgFontColor(0.9f, 0.9f, 0.9f, 1.0f);
|
||||
break;
|
||||
}
|
||||
rsgDrawRect(0, currentYPos - 1, width, currentYPos, 0);
|
||||
rsgDrawText(gList[i].text, 30, currentYPos - 32);
|
||||
}
|
||||
currentYPos += itemHeight;
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
||||
@@ -25,7 +25,6 @@ static float end(uint32_t idx) {
|
||||
|
||||
#define _RS_ASSERT(b) \
|
||||
do { \
|
||||
rsDebug("Checking " #b, ((int) (b))); \
|
||||
if (!(b)) { \
|
||||
failed = true; \
|
||||
rsDebug(#b " FAILED", 0); \
|
||||
@@ -33,3 +32,7 @@ do { \
|
||||
\
|
||||
} while (0)
|
||||
|
||||
/* These constants must match those in UnitTest.java */
|
||||
static const int RS_MSG_TEST_PASSED = 100;
|
||||
static const int RS_MSG_TEST_FAILED = 101;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user