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 package com.android.compatibility.common.tradefed.build;
17 
18 import com.android.tradefed.build.IBuildInfo;
19 import com.android.tradefed.log.LogUtil.CLog;
20 import com.android.tradefed.testtype.suite.TestSuiteInfo;
21 
22 import java.io.File;
23 import java.io.FileNotFoundException;
24 
25 /**
26  * A simple helper that stores and retrieves information from a {@link IBuildInfo}.
27  */
28 public class VtsCompatibilityInvocationHelper {
29     private File mTestCasesDir = null;
30 
31     /**
32      * Get test case binaries directory
33      */
getTestsDir()34     public File getTestsDir() throws FileNotFoundException {
35         if (mTestCasesDir == null) {
36             String suiteName = TestSuiteInfo.getInstance().getName();
37             String testCasesRootDirPath;
38             testCasesRootDirPath =
39                     System.getenv(String.format("%s_TESTCASES", suiteName.replace('-', '_')));
40             File testCaseDir;
41             if (testCasesRootDirPath != null && !testCasesRootDirPath.trim().equals("")) {
42                 testCaseDir = new File(testCasesRootDirPath);
43             } else {
44                 String rootDirPath;
45                 rootDirPath =
46                         System.getProperty(String.format("%s_ROOT", suiteName.replace('-', '_')));
47                 if (rootDirPath == null || rootDirPath.trim().equals("")) {
48                     throw new IllegalArgumentException(String.format(
49                             "Missing install path property %s_ROOT", suiteName.replace('-', '_')));
50                 }
51                 testCaseDir = new File(rootDirPath,
52                         String.format("android-%s/testcases", suiteName.toLowerCase()));
53             }
54             if (!testCaseDir.exists()) {
55                 throw new FileNotFoundException(String.format(
56                         "Root directory doesn't exist %s", testCaseDir.getAbsolutePath()));
57             }
58             mTestCasesDir = testCaseDir.getAbsoluteFile();
59             CLog.d(String.format("%s TEST CASES DIR: %s", suiteName, mTestCasesDir));
60         }
61 
62         return mTestCasesDir;
63     }
64 }
65