blob: 0e7d47a76f7a37835002bfc0a265e020ce0c3a70 [file] [log] [blame]
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +01001/*
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
17package com.android.dumprendertree2;
18
19import android.os.Environment;
20import android.os.Message;
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010021import java.io.File;
22import java.util.ArrayList;
23import java.util.LinkedList;
Steve Blockcb98a3e2010-09-28 12:13:40 +010024import java.util.List;
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010025
26/**
27 * A Thread that is responsible for generating a lists of tests to run.
28 */
29public class TestsListPreloaderThread extends Thread {
30
31 private static final String LOG_TAG = "TestsListPreloaderThread";
32
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010033 /** 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 Blockcb98a3e2010-09-28 12:13:40 +010039 * A relative path to the directory with the tests we want to run or particular test.
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010040 * 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 Block34c68912010-09-13 15:50:12 +010053 mFileFilter = new FileFilter();
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010054 mRelativePath = path;
55 mDoneMsg = doneMsg;
56 }
57
58 @Override
59 public void run() {
Maksymilian Osowskic6a341d2010-08-23 16:57:27 +010060 if (FileFilter.isTestFile(mRelativePath)) {
61 mTestsList.add(mRelativePath);
Maksymilian Osowskia0a586c2010-08-11 12:42:57 +010062 } else {
Maksymilian Osowskic6a341d2010-08-23 16:57:27 +010063 loadTestsFromUrl(mRelativePath);
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010064 }
65
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010066 mDoneMsg.obj = mTestsList;
67 mDoneMsg.sendToTarget();
68 }
69
70 /**
Steve Blockcb98a3e2010-09-28 12:13:40 +010071 * Loads all the tests from the given directories and all the subdirectories
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010072 * into mTestsList.
73 *
74 * @param dirRelativePath
75 */
Steve Blockcb98a3e2010-09-28 12:13:40 +010076 private void loadTestsFromUrl(String rootRelativePath) {
77 LinkedList<String> directoriesList = new LinkedList<String>();
78 directoriesList.add(rootRelativePath);
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010079
80 String relativePath;
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010081 String itemName;
Steve Blockcb98a3e2010-09-28 12:13:40 +010082 while (!directoriesList.isEmpty()) {
83 relativePath = directoriesList.removeFirst();
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010084
Steve Blockcb98a3e2010-09-28 12:13:40 +010085 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 Osowski5f0ccd72010-07-23 17:15:26 +010092 }
Maksymilian Osowskic6a341d2010-08-23 16:57:27 +010093 }
Maksymilian Osowski5f0ccd72010-07-23 17:15:26 +010094
Steve Blockcb98a3e2010-09-28 12:13:40 +010095 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 Osowski5f0ccd72010-07-23 17:15:26 +0100109 }
110 }
111 }
112 }
113 }
Steve Block34c68912010-09-13 15:50:12 +0100114}