public boolean processLine()

in tools/device_broker/java/com/google/android/apps/common/testing/broker/InstrumentationTestRunnerProcessor.java [77:191]


  public boolean processLine(String line) {
    if (null == currentTest) {
      currentTest = ExecutedTest.builder();
    }
    if ((isInStack || isInStatusStream || isInResultsStream) &&
        line.startsWith(INSTRUMENTATION_PREFIX)) {
      if (isInStack) {
        isInStack = false;
      }
      if (isInStatusStream) {
        isInStatusStream = false;
      }
      if (isInResultsStream) {
        isInResultsStream = false;
      }
    }

    if (line.startsWith(STATUS_ID)) {
      currentTest.setId(line.replace(STATUS_ID, ""));
      currentTest.appendAllLines(line);
      return true;
    }

    currentTest.appendAllLines(line);

    if (isInStack || line.startsWith(STATUS_STACK)) {
      currentTest.appendStackTrace(line.replace(STATUS_STACK, ""));
      isInStack = true;
      return true;
    }

    if (isInStatusStream || line.startsWith(STATUS_STREAM)) {
      currentTest.appendStatusStream(line.replace(STATUS_STREAM, ""));
      isInStatusStream = true;
      return true;
    }

    if (isInResultsStream || line.startsWith(RESULT_STREAM)) {
      currentTest.appendResultStream(line.replace(RESULT_STREAM, ""));
      isInResultsStream = true;
      return true;
    }

    if (line.startsWith(INSTRUMENTATION_RESULT)) {
      currentTest.appendResultStream(line.replace(INSTRUMENTATION_RESULT, ""));
      return true;
    }

    if (line.startsWith(STATUS_CODE)) {
      String statusCode = line.replace(STATUS_CODE, "").trim();
      int statusInt = Integer.parseInt(statusCode);

      try {
        switch (statusInt) {
          case 1:
            currentTest.setStatus(Status.STARTED);
            onTestStart(currentTest.build());
            break;
          case 0:
            currentTest.setStatus(Status.PASSED);
            break;
          case -1:
            currentTest.setStatus(Status.ERROR);
            break;
          case -2:
            currentTest.setStatus(Status.FAILED);
            break;
          case -4:
            currentTest.setStatus(Status.ASSUMPTION_FAILURE);
            break;
          default:
            throw new IllegalArgumentException(
                String.format("Illegal test instrumentation code: \"%s\"", statusCode));
        }
      } finally {
        onTestFinished(currentTest.build());
        currentTest = null;
      }

      return true;
    }

    if (line.startsWith(STATUS_NUMTESTS)) {
      currentTest.setNumTests(line.replace(STATUS_NUMTESTS, ""));
      return true;
    }

    if (line.startsWith(STATUS_CLASS)) {
      currentTest.setTestClass(line.replace(STATUS_CLASS, ""));
      return true;
    }

    if (line.startsWith(STATUS_CURRENT)) {
      currentTest.setCurrentTest(line.replace(STATUS_CURRENT, ""));
      return true;
    }

    if (line.startsWith(STATUS_TEST)) {
      currentTest.setTestMethod(line.replace(STATUS_TEST, ""));
      return true;
    }

    if (line.startsWith(INSTRUMENTATION_CODE)) {
      return true;
    }

    if (line.contains("Killed")) {
      // shh: b/73514868
      // We kill the shell executor to ensure that it doesn't end up hanging in atexit.
      return true;
    }
    logger.severe("Line not handled by the parser:\n" + line);

    return true;
  }