1 /* 2 * Copyright (C) 2009 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.cts; 18 19 import java.io.IOException; 20 21 import junit.framework.TestResult; 22 23 /** 24 * Host side only test. 25 */ 26 public class HostSideOnlyTest extends Test { 27 private HostSideTestRunner mHostSideTestRunner; 28 29 public HostSideOnlyTest(final TestCase parentCase, final String name, 30 final String type, final String knownFailure, final int resCode) { 31 32 super(parentCase, name, type, knownFailure, resCode); 33 mHostSideTestRunner = null; 34 } 35 36 /** 37 * The Thread to be run host side unit test. 38 */ 39 class HostSideTestRunner extends Thread { 40 41 private HostSideOnlyTest mTest; 42 43 public HostSideTestRunner(final HostSideOnlyTest test) { 44 mTest = test; 45 } 46 47 @Override 48 public void run() { 49 HostUnitTestRunner runner = new HostUnitTestRunner(mTest); 50 TestController controller = mTest.getTestController(); 51 TestResult testResult = null; 52 try { 53 testResult = runner.runTest(controller.getJarPath(), 54 controller.getPackageName(), controller.getClassName(), 55 controller.getMethodName()); 56 } catch (IOException e) { 57 Log.e("IOException while running test from " + 58 controller.getJarPath(), e); 59 } catch (ClassNotFoundException e) { 60 Log.e("The host controller JAR (" + controller.getJarPath() + 61 ") file doesn't contain class: " 62 + controller.getPackageName() + "." 63 + controller.getClassName(), e); 64 } 65 66 synchronized (mTimeOutTimer) { 67 mResult.setResult(testResult); 68 69 if (!mTimeOutTimer.isTimeOut()) { 70 Log.d("HostSideTestRunnerThread() detects that it needs to " 71 + "cancel mTimeOutTimer"); 72 mTimeOutTimer.sendNotify(); 73 } 74 } 75 } 76 } 77 78 /** {@inheritDoc} */ 79 @Override 80 protected void runImpl() { 81 mHostSideTestRunner = new HostSideTestRunner(this); 82 mHostSideTestRunner.start(); 83 } 84 } 85