Example #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);
  }
  /** {@inheritDoc} */
  @Override
  public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
    int failCounter = 0;
    Map<String, String> finalMetrics = new HashMap<String, String>();

    preTestSetup();

    // Create and config runner for instrumentation test
    IRemoteAndroidTestRunner runner =
        new RemoteAndroidTestRunner(mTestPackage, TEST_RUNNER_NAME, mTestDevice.getIDevice());
    runner.setClassName(mTestClass);
    runner.setMethodName(mTestClass, mTestMethod);
    // max timeout is the smaller of: 8 hrs or 1 minute per site
    runner.setMaxtimeToOutputResponse(Math.min(MAX_TIMEOUT_MS, 60 * 1000 * mTotalSites));

    CollectingTestListener collectingTestListener = new CollectingTestListener();
    failCounter = runStabilityTest(runner, collectingTestListener);
    finalMetrics.put(mSchemaKey, Integer.toString(mTotalSites - failCounter));

    reportMetrics(listener, mMetricsName, finalMetrics);
  }
  @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();
    }
  }