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