Home | History | Annotate | Download | only in testforward
      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 
     17 package com.android.rs.testforward;
     18 
     19 import com.android.rs.unittest.UnitTest;
     20 
     21 import android.content.Context;
     22 import android.support.test.InstrumentationRegistry;
     23 import android.support.test.filters.MediumTest;
     24 import android.util.Log;
     25 
     26 import org.junit.Assert;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.junit.runners.Parameterized;
     30 import org.junit.runners.Parameterized.Parameter;
     31 import org.junit.runners.Parameterized.Parameters;
     32 
     33 import java.util.ArrayList;
     34 import java.util.List;
     35 
     36 /**
     37  * RSTestForward, functional test for platform RenderScript APIs.
     38  * To run the test, please use command
     39  *
     40  * adb shell am instrument -w com.android.rs.testforward/android.support.test.runner.AndroidJUnitRunner
     41  */
     42 @RunWith(Parameterized.class)
     43 public class RSForwardCompatibilityTests {
     44     private static final String TAG = RSForwardCompatibilityTests.class.getSimpleName();
     45 
     46     /**
     47      * Returns the list of subclasses of UnitTest to run.
     48      */
     49     @Parameters(name = "ForwardVersion" + RSForwardVersion.VERSION + ":{0}")
     50     public static Iterable<?> getParams() throws Exception {
     51         Context ctx = InstrumentationRegistry.getTargetContext();
     52 
     53         List<UnitTest> validUnitTests = new ArrayList<>();
     54 
     55         Iterable<Class<? extends UnitTest>> testClasses =
     56                 UnitTest.getProperSubclasses(ctx);
     57         for (Class<? extends UnitTest> testClass : testClasses) {
     58             UnitTest test = testClass.getDeclaredConstructor(Context.class).newInstance(ctx);
     59             validUnitTests.add(test);
     60         }
     61 
     62         UnitTest.checkDuplicateNames(validUnitTests);
     63 
     64         return validUnitTests;
     65     }
     66 
     67     @Parameter(0)
     68     public UnitTest mTest;
     69 
     70     @Test
     71     @MediumTest
     72     public void testRSUnitTest() throws Exception {
     73         mTest.logStart(TAG, "RenderScript Forward Compatibility Testing");
     74         mTest.runTest();
     75         mTest.logEnd(TAG);
     76         Assert.assertTrue(mTest.getSuccess());
     77     }
     78 }
     79