// Copyright 2014 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.runtime; import com.google.devtools.build.lib.analysis.test.TestResult; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.exec.ExecutionOptions; import com.google.devtools.build.lib.exec.TestLogHelper; import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat; import com.google.devtools.build.lib.exec.TestStrategy.TestSummaryFormat; import com.google.devtools.build.lib.util.StringUtil; import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter; import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionDocumentationCategory; import com.google.devtools.common.options.OptionEffectTag; import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsProvider; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** * Prints the test results to a terminal. */ public class TerminalTestResultNotifier implements TestResultNotifier { private static class TestResultStats { int numberOfTargets; int passCount; int failedToBuildCount; int failedCount; int failedRemotelyCount; int failedLocallyCount; int noStatusCount; int numberOfExecutedTargets; boolean wasUnreportedWrongSize; } /** * Flags specific to test summary reporting. */ public static class TestSummaryOptions extends OptionsBase { @Option( name = "verbose_test_summary", defaultValue = "true", documentationCategory = OptionDocumentationCategory.LOGGING, effectTags = {OptionEffectTag.AFFECTS_OUTPUTS}, help = "If true, print additional information (timing, number of failed runs, etc) in the" + " test summary." ) public boolean verboseSummary; @Option( name = "test_verbose_timeout_warnings", defaultValue = "false", documentationCategory = OptionDocumentationCategory.LOGGING, effectTags = {OptionEffectTag.AFFECTS_OUTPUTS}, help = "If true, print additional warnings when the actual test execution time does not " + "match the timeout defined by the test (whether implied or explicit)." ) public boolean testVerboseTimeoutWarnings; } private final AnsiTerminalPrinter printer; private final OptionsProvider options; private final TestSummaryOptions summaryOptions; /** * @param printer The terminal to print to */ public TerminalTestResultNotifier(AnsiTerminalPrinter printer, OptionsProvider options) { this.printer = printer; this.options = options; this.summaryOptions = options.getOptions(TestSummaryOptions.class); } /** * Decide if two tests with the same label are contained in the set of test summaries */ private boolean duplicateLabels(Set summaries) { Set