1 /* 2 * Copyright (C) 2018 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 package com.android.tradefed.presubmit; 17 18 import static org.junit.Assert.assertTrue; 19 import static org.junit.Assert.fail; 20 21 import com.android.tradefed.config.ConfigurationDescriptor; 22 import com.android.tradefed.config.ConfigurationException; 23 import com.android.tradefed.config.ConfigurationFactory; 24 import com.android.tradefed.config.IConfiguration; 25 import com.android.tradefed.testtype.IRemoteTest; 26 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.junit.runners.JUnit4; 30 31 import java.io.File; 32 import java.io.FilenameFilter; 33 import java.util.Arrays; 34 import java.util.HashSet; 35 import java.util.Set; 36 37 /** 38 * Test that configuration in VTS10 can load and have expected properties. 39 */ 40 @RunWith(JUnit4.class) 41 public class VtsConfigLoadingTest { 42 /** 43 * List of the officially supported runners in VTS10. 44 */ 45 private static final Set<String> SUPPORTED_VTS_TEST_TYPE = new HashSet<>(Arrays.asList( 46 "com.android.compatibility.common.tradefed.testtype.JarHostTest", 47 "com.android.tradefed.testtype.AndroidJUnitTest", 48 "com.android.tradefed.testtype.GTest", 49 "com.android.tradefed.testtype.VtsMultiDeviceTest")); 50 51 /** 52 * Test that configuration shipped in Tradefed can be parsed. 53 */ 54 @Test testConfigurationLoad()55 public void testConfigurationLoad() throws Exception { 56 String vtsRoot = System.getProperty("VTS10_ROOT"); 57 File testcases = new File(vtsRoot, "/android-vts10/testcases/"); 58 if (!testcases.exists()) { 59 fail(String.format("%s does not exists", testcases)); 60 return; 61 } 62 File[] listVtsConfig = testcases.listFiles(new FilenameFilter() { 63 @Override 64 public boolean accept(File dir, String name) { 65 // Only check the VTS test config 66 if (name.startsWith("Vts") && name.endsWith(".config")) { 67 return true; 68 } 69 return false; 70 } 71 }); 72 assertTrue(listVtsConfig.length > 0); 73 for (File config : listVtsConfig) { 74 IConfiguration c = ConfigurationFactory.getInstance().createConfigurationFromArgs( 75 new String[] {config.getAbsolutePath()}); 76 for (IRemoteTest test : c.getTests()) { 77 // Check that all the tests runners are well supported. 78 if (!SUPPORTED_VTS_TEST_TYPE.contains(test.getClass().getCanonicalName())) { 79 throw new ConfigurationException( 80 String.format("testtype %s is not officially supported by VTS10.", 81 test.getClass().getCanonicalName())); 82 } 83 } 84 } 85 } 86 } 87