1// This file is automatically generated from
2// frameworks/rs/tests/java_api/RSUnitTests/RSUnitTests.py
3/*
4 * Copyright (C) 2017 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package com.android.rs.unittest;
20
21import android.content.Context;
22import android.support.v8.renderscript.Allocation;
23import android.support.v8.renderscript.Element;
24import android.support.v8.renderscript.RenderScript;
25import android.util.Log;
26
27public class UT_copy_test extends UnitTest {
28    boolean pass = true;
29
30    public UT_copy_test(Context ctx) {
31        super("Copy", ctx);
32    }
33
34    void testFloat2(RenderScript rs, ScriptC_copy_test s) {
35        Allocation a1 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
36        Allocation a2 = Allocation.createSized(rs, Element.F32_2(rs), 1024);
37
38        float[] f1 = new float[1024 * 2];
39        float[] f2 = new float[1024 * 2];
40        for (int ct = 0; ct < f1.length; ct++) {
41            f1[ct] = (float) ct;
42        }
43        a1.copyFrom(f1);
44
45        s.forEach_copyFloat2(a1, a2);
46
47        a2.copyTo(f2);
48        for (int ct = 0; ct < f1.length; ct++) {
49            if (f1[ct] != f2[ct]) {
50                failTest();
51                Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
52            }
53        }
54        a1.destroy();
55        a2.destroy();
56    }
57
58    void testFloat3(RenderScript rs, ScriptC_copy_test s) {
59        Allocation a1 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
60        Allocation a2 = Allocation.createSized(rs, Element.F32_3(rs), 1024);
61
62        float[] f1 = new float[1024 * 4];
63        float[] f2 = new float[1024 * 4];
64        for (int ct = 0; ct < f1.length; ct++) {
65            f1[ct] = (float) ct;
66        }
67        a1.copyFrom(f1);
68
69        s.forEach_copyFloat3(a1, a2);
70
71        a2.copyTo(f2);
72        for (int ct = 0; ct < f1.length; ct++) {
73            if ((f1[ct] != f2[ct]) && ((ct & 3) != 3)) {
74                failTest();
75                Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
76            }
77        }
78        a1.destroy();
79        a2.destroy();
80    }
81
82    void testFloat4(RenderScript rs, ScriptC_copy_test s) {
83        Allocation a1 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
84        Allocation a2 = Allocation.createSized(rs, Element.F32_4(rs), 1024);
85
86        float[] f1 = new float[1024 * 4];
87        float[] f2 = new float[1024 * 4];
88        for (int ct = 0; ct < f1.length; ct++) {
89            f1[ct] = (float) ct;
90        }
91        a1.copyFrom(f1);
92
93        s.forEach_copyFloat4(a1, a2);
94
95        a2.copyTo(f2);
96        for (int ct = 0; ct < f1.length; ct++) {
97            if (f1[ct] != f2[ct]) {
98                failTest();
99                Log.v("RS Test", "Compare failed at " + ct + ", " + f1[ct] + ", " + f2[ct]);
100            }
101        }
102        a1.destroy();
103        a2.destroy();
104    }
105
106    public void run() {
107        RenderScript pRS = createRenderScript(true);
108        ScriptC_copy_test s = new ScriptC_copy_test(pRS);
109
110        testFloat2(pRS, s);
111        testFloat3(pRS, s);
112        testFloat4(pRS, s);
113        s.invoke_sendResult(true);
114
115        pRS.finish();
116        s.destroy();
117        pRS.destroy();
118    }
119}
120
121