示例#1
0
  /** Run the telephony outgoing call stress test Collect results and post results to dash board */
  @Override
  public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
    CLog.d(
        "input options: mCallDuration(%s),mPauseTime(%s), mPhoneNumber(%s)," + "mRepeatCount(%s)",
        mCallDuration, mPauseTime, mPhoneNumber, mRepeatCount);

    Assert.assertNotNull(mTestDevice);
    Assert.assertNotNull(mPhoneNumber);
    mRadioHelper = new RadioHelper(mTestDevice);
    // wait for data connection
    if (!mRadioHelper.radioActivation() || !mRadioHelper.waitForDataSetup()) {
      mRadioHelper.getBugreport(listener);
      return;
    }

    IRemoteAndroidTestRunner runner =
        new RemoteAndroidTestRunner(TEST_PACKAGE_NAME, TEST_RUNNER_NAME, mTestDevice.getIDevice());
    runner.setClassName(TEST_CLASS_NAME);
    runner.setMethodName(TEST_CLASS_NAME, TEST_METHOD);

    runner.addInstrumentationArg("callduration", mCallDuration);
    runner.addInstrumentationArg("pausetime", mPauseTime);
    runner.addInstrumentationArg("phonenumber", mPhoneNumber);
    runner.setMaxtimeToOutputResponse(TEST_TIMER);

    // Add bugreport listener for failed test
    BugreportCollector bugListener = new BugreportCollector(listener, mTestDevice);
    bugListener.addPredicate(BugreportCollector.AFTER_FAILED_TESTCASES);
    bugListener.setDescriptiveName(mTestName);

    CollectingTestListener collectListener = new CollectingTestListener();
    int remainingCalls = Integer.parseInt(mRepeatCount);

    while (remainingCalls > 0) {
      CLog.d("remaining calls: %s", remainingCalls);
      runner.addInstrumentationArg("repeatcount", String.valueOf(remainingCalls));
      mTestDevice.runInstrumentationTests(runner, bugListener, collectListener);
      if (collectListener.hasFailedTests()) {
        // the test failed
        int numCalls = logOutputFile(bugListener);
        remainingCalls -= numCalls;
        cleanOutputFiles();
      } else {
        // the test passed
        remainingCalls = 0;
      }
    }
    reportMetrics(mMetricsName, bugListener);
  }
 /**
  * Helper method for iterating through popular_urls.txt and reporting back how many pages fail to
  * load.
  *
  * @param runner The {@link IRemoteAndroidTestRunner} for instrumentation
  * @param listener The {@link CollectingTestListener} of test results
  * @return Number of pages that failed to load
  */
 private int runStabilityTest(IRemoteAndroidTestRunner runner, CollectingTestListener listener)
     throws DeviceNotAvailableException {
   boolean exitConditionMet = false;
   int failureCounter = 0;
   while (!exitConditionMet) {
     mTestDevice.runInstrumentationTests(runner, listener);
     // if the status file exists, then the previous instrumentation has crashed
     if (!mTestDevice.doesFileExist(mStatusFilePath)) {
       exitConditionMet = true;
     } else {
       ++failureCounter;
     }
   }
   return failureCounter;
 }
  @Override
  public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
    Assert.assertNotNull(mTestDevice);
    setupTests();

    if (mLogBtsnoop) {
      if (!enableBtsnoopLogging()) {
        CLog.e("Unable to enable btsnoop trace logging");
        throw new DeviceNotAvailableException();
      }
    }

    IRemoteAndroidTestRunner runner =
        new RemoteAndroidTestRunner(mTestPackageName, TEST_RUNNER_NAME, mTestDevice.getIDevice());
    runner.setClassName(mTestClassName);
    runner.setMaxTimeToOutputResponse(mTestTimeout, TimeUnit.MILLISECONDS);
    BugreportCollector bugListener = new BugreportCollector(listener, mTestDevice);
    bugListener.addPredicate(BugreportCollector.AFTER_FAILED_TESTCASES);

    for (TestInfo test : mTestCases) {
      String testName = test.mTestName;
      TestInfo t = test;

      if (t.mIterCount != null && t.mIterCount <= 0) {
        CLog.i("Cancelled '%s' test case with iter count %s", testName, t.mIterCount);
        continue;
      }

      // For semi-manual tests, print instructions and wait for user to continue.
      if (t.mInstructions != null) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("========================================");
        System.out.println(t.mInstructions);
        System.out.println("========================================");
        try {
          br.readLine();
        } catch (IOException e) {
          CLog.e("Continuing after IOException while waiting for confirmation: %s", e.getMessage());
        }
      }

      // Run the test
      cleanOutputFile();
      if (mLogHcidump) {
        mHcidumpCommand = new HcidumpCommand();
        mHcidumpCommand.startHcidump();
      }

      if (t.mIterKey != null && t.mIterCount != null) {
        runner.addInstrumentationArg(t.mIterKey, t.mIterCount.toString());
      }
      if (t.mRemoteAddress != null) {
        runner.addInstrumentationArg("device_address", t.mRemoteAddress);
        if (t.mPairPasskey != null) {
          runner.addInstrumentationArg("device_pair_passkey", t.mPairPasskey);
        }
        if (t.mPairPin != null) {
          runner.addInstrumentationArg("device_pair_pin", t.mPairPin);
        }
      }
      runner.setMethodName(mTestClassName, t.mTestMethod);
      bugListener.setDescriptiveName(testName);
      mTestDevice.runInstrumentationTests(runner, bugListener);
      if (t.mIterKey != null && t.mIterCount != null) {
        runner.removeInstrumentationArg(t.mIterKey);
      }
      if (t.mRemoteAddress != null) {
        runner.removeInstrumentationArg("device_address");
        if (t.mPairPasskey != null) {
          runner.removeInstrumentationArg("device_pair_passkey");
        }
        if (t.mPairPin != null) {
          runner.removeInstrumentationArg("device_pair_pin");
        }
      }

      // Log the output file
      logOutputFile(t, listener);
      if (mLogBtsnoop) {
        File logFile = null;
        InputStreamSource logSource = null;
        try {
          logFile = mTestDevice.pullFileFromExternal(BTSNOOP_LOG_FILE);
          if (logFile != null) {
            CLog.d("Sending %d byte file %s into the logosphere!", logFile.length(), logFile);
            logSource = new SnapshotInputStreamSource(new FileInputStream(logFile));
            listener.testLog(
                String.format("%s_btsnoop", t.mTestName), LogDataType.UNKNOWN, logSource);
          }
        } catch (IOException e) {
          CLog.e("Got an IO Exception: %s", e);
        } finally {
          if (logFile != null) {
            logFile.delete();
          }
          if (logSource != null) {
            logSource.cancel();
          }
        }
      }
      if (mLogHcidump) {
        listener.testLog(
            String.format("%s_hcidump", t.mTestName),
            LogDataType.TEXT,
            mHcidumpCommand.getHcidump());
        mHcidumpCommand.stopHcidump();
        mHcidumpCommand = null;
      }
      cleanOutputFile();
    }
  }