Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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.dumprendertree2; |
| 18 | |
| 19 | import android.os.Environment; |
| 20 | import android.os.Message; |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 21 | import java.io.File; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.LinkedList; |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 24 | import java.util.List; |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * A Thread that is responsible for generating a lists of tests to run. |
| 28 | */ |
| 29 | public class TestsListPreloaderThread extends Thread { |
| 30 | |
| 31 | private static final String LOG_TAG = "TestsListPreloaderThread"; |
| 32 | |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 33 | /** A list containing relative paths of tests to run */ |
| 34 | private ArrayList<String> mTestsList = new ArrayList<String>(); |
| 35 | |
| 36 | private FileFilter mFileFilter; |
| 37 | |
| 38 | /** |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 39 | * A relative path to the directory with the tests we want to run or particular test. |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 40 | * Used up to and including preloadTests(). |
| 41 | */ |
| 42 | private String mRelativePath; |
| 43 | |
| 44 | private Message mDoneMsg; |
| 45 | |
| 46 | /** |
| 47 | * The given path must be relative to the root dir. |
| 48 | * |
| 49 | * @param path |
| 50 | * @param doneMsg |
| 51 | */ |
| 52 | public TestsListPreloaderThread(String path, Message doneMsg) { |
Steve Block | 34c6891 | 2010-09-13 15:50:12 +0100 | [diff] [blame] | 53 | mFileFilter = new FileFilter(); |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 54 | mRelativePath = path; |
| 55 | mDoneMsg = doneMsg; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void run() { |
Maksymilian Osowski | c6a341d | 2010-08-23 16:57:27 +0100 | [diff] [blame] | 60 | if (FileFilter.isTestFile(mRelativePath)) { |
| 61 | mTestsList.add(mRelativePath); |
Maksymilian Osowski | a0a586c | 2010-08-11 12:42:57 +0100 | [diff] [blame] | 62 | } else { |
Maksymilian Osowski | c6a341d | 2010-08-23 16:57:27 +0100 | [diff] [blame] | 63 | loadTestsFromUrl(mRelativePath); |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 66 | mDoneMsg.obj = mTestsList; |
| 67 | mDoneMsg.sendToTarget(); |
| 68 | } |
| 69 | |
| 70 | /** |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 71 | * Loads all the tests from the given directories and all the subdirectories |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 72 | * into mTestsList. |
| 73 | * |
| 74 | * @param dirRelativePath |
| 75 | */ |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 76 | private void loadTestsFromUrl(String rootRelativePath) { |
| 77 | LinkedList<String> directoriesList = new LinkedList<String>(); |
| 78 | directoriesList.add(rootRelativePath); |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 79 | |
| 80 | String relativePath; |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 81 | String itemName; |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 82 | while (!directoriesList.isEmpty()) { |
| 83 | relativePath = directoriesList.removeFirst(); |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 84 | |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 85 | List<String> dirRelativePaths = FsUtils.getLayoutTestsDirContents(relativePath, false, true); |
| 86 | if (dirRelativePaths != null) { |
| 87 | for (String dirRelativePath : dirRelativePaths) { |
| 88 | itemName = new File(dirRelativePath).getName(); |
| 89 | if (FileFilter.isTestDir(itemName)) { |
| 90 | directoriesList.add(dirRelativePath); |
| 91 | } |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 92 | } |
Maksymilian Osowski | c6a341d | 2010-08-23 16:57:27 +0100 | [diff] [blame] | 93 | } |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 94 | |
Steve Block | cb98a3e | 2010-09-28 12:13:40 +0100 | [diff] [blame] | 95 | List<String> testRelativePaths = FsUtils.getLayoutTestsDirContents(relativePath, false, false); |
| 96 | if (testRelativePaths != null) { |
| 97 | for (String testRelativePath : testRelativePaths) { |
| 98 | itemName = new File(testRelativePath).getName(); |
| 99 | if (FileFilter.isTestFile(itemName)) { |
| 100 | /** We choose to skip all the tests that are expected to crash. */ |
| 101 | if (!mFileFilter.isCrash(testRelativePath)) { |
| 102 | mTestsList.add(testRelativePath); |
| 103 | } else { |
| 104 | /** |
| 105 | * TODO: Summarizer is now in service - figure out how to send the info. |
| 106 | * Previously: mSummarizer.addSkippedTest(relativePath); |
| 107 | */ |
| 108 | } |
Maksymilian Osowski | 5f0ccd7 | 2010-07-23 17:15:26 +0100 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
Steve Block | 34c6891 | 2010-09-13 15:50:12 +0100 | [diff] [blame] | 114 | } |