1/*
2 * Copyright (C) 2017 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
17package com.android.rs.testbackward;
18
19import com.android.rs.unittest.*;
20
21import android.content.Context;
22import android.support.test.InstrumentationRegistry;
23import android.support.test.filters.MediumTest;
24import android.util.Log;
25
26import org.junit.Assert;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.junit.runners.Parameterized;
30import org.junit.runners.Parameterized.Parameter;
31import org.junit.runners.Parameterized.Parameters;
32
33import java.util.ArrayList;
34import java.util.List;
35
36/**
37 * RSTestBackward, functional test for platform RenderScript APIs.
38 * To run the test, please use command
39 *
40 * adb shell am instrument -w com.android.rs.testbackward/android.support.test.runner.AndroidJUnitRunner
41 */
42@RunWith(Parameterized.class)
43public class RSBackwardCompatibilityTests {
44    private static final String TAG = RSBackwardCompatibilityTests.class.getSimpleName();
45
46    /**
47     * Returns the list of subclasses of UnitTest to run.
48     */
49    @Parameters(name = "{0}")
50    public static Iterable<?> getParams() throws Exception {
51        int thisApiVersion = android.os.Build.VERSION.SDK_INT;
52
53        int minApiVersion = 21;
54        if (thisApiVersion < minApiVersion) {
55            Log.w(TAG,
56                String.format("API version is less than %d, no tests running", minApiVersion));
57        }
58
59        Context ctx = InstrumentationRegistry.getTargetContext();
60
61        List<UnitTest> validUnitTests = new ArrayList<>();
62
63        Iterable<Class<? extends UnitTest>> testClasses =
64            RSTests.getTestClassesForCurrentAPIVersion();
65        for (Class<? extends UnitTest> testClass : testClasses) {
66            UnitTest test = testClass.getDeclaredConstructor(Context.class).newInstance(ctx);
67            validUnitTests.add(test);
68        }
69
70        UnitTest.checkDuplicateNames(validUnitTests);
71
72        return validUnitTests;
73    }
74
75
76    @Parameter(0)
77    public UnitTest mTest;
78
79    @Test
80    @MediumTest
81    public void testRSUnitTest() throws Exception {
82        mTest.logStart(TAG, "RenderScript Backward Compatibility Testing");
83        mTest.runTest();
84        mTest.logEnd(TAG);
85        Assert.assertTrue(mTest.getSuccess());
86    }
87}
88