diff options
author | Dan Willemsen <dwillemsen@google.com> | 2018-05-17 16:37:09 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2018-07-12 14:15:31 -0700 |
commit | b82471ad6dfec4790b2d86e49525dadc3fc06416 (patch) | |
tree | bca7e73da63c7506bbc3c967468034a351aaad94 /ui/status/status_test.go | |
parent | 5e48b1d183a8333528f529c7e677c4ab644f8caf (diff) | |
download | build_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.tar.gz build_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.tar.bz2 build_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.zip |
Add a unified status reporting UI
This adds a new status package that merges the running of "actions"
(ninja calls them edges) of multiple tools into one view of the current
state, and gives that to a number of different outputs.
For inputs:
Kati's output parser has been rewritten (and moved) to map onto the
StartAction/FinishAction API. A byproduct of this is that the build
servers should be able to extract errors from Kati better, since they
look like the errors that Ninja used to write.
Ninja is no longer directly connected to the terminal, but its output is
read via the protobuf frontend API, so it's just another tool whose
output becomes merged together.
multiproduct_kati loses its custom status routines, and uses the common
one instead.
For outputs:
The primary output is the ui/terminal.Status type, which along with
ui/terminal.Writer now controls everything about the terminal output.
Today, this doesn't really change any behaviors, but having all terminal
output going through here allows a more complicated (multi-line / full
window) status display in the future.
The tracer acts as an output of the status package, tracing all the
action start / finish events. This replaces reading the .ninja_log file,
so it now properly handles multiple output files from a single action.
A new rotated log file (out/error.log, or out/dist/logs/error.log) just
contains a description of all of the errors that happened during the
current build.
Another new compressed and rotated log file (out/verbose.log.gz, or
out/dist/logs/verbose.log.gz) contains the full verbose (showcommands)
log of every execution run by the build. Since this is now written on
every build, the showcommands argument is now ignored -- if you want to
get the commands run, look at the log file after the build.
Test: m
Test: <built-in tests>
Test: NINJA_ARGS="-t list" m
Test: check the build.trace.gz
Test: check the new log files
Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
Diffstat (limited to 'ui/status/status_test.go')
-rw-r--r-- | ui/status/status_test.go | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/ui/status/status_test.go b/ui/status/status_test.go new file mode 100644 index 00000000..e62785f4 --- /dev/null +++ b/ui/status/status_test.go @@ -0,0 +1,166 @@ +// Copyright 2018 Google Inc. 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 status + +import "testing" + +type counterOutput Counts + +func (c *counterOutput) StartAction(action *Action, counts Counts) { + *c = counterOutput(counts) +} +func (c *counterOutput) FinishAction(result ActionResult, counts Counts) { + *c = counterOutput(counts) +} +func (c counterOutput) Message(level MsgLevel, msg string) {} +func (c counterOutput) Flush() {} + +func (c counterOutput) Expect(t *testing.T, counts Counts) { + if Counts(c) == counts { + return + } + t.Helper() + + if c.TotalActions != counts.TotalActions { + t.Errorf("Expected %d total edges, but got %d", counts.TotalActions, c.TotalActions) + } + if c.RunningActions != counts.RunningActions { + t.Errorf("Expected %d running edges, but got %d", counts.RunningActions, c.RunningActions) + } + if c.StartedActions != counts.StartedActions { + t.Errorf("Expected %d started edges, but got %d", counts.StartedActions, c.StartedActions) + } + if c.FinishedActions != counts.FinishedActions { + t.Errorf("Expected %d finished edges, but got %d", counts.FinishedActions, c.FinishedActions) + } +} + +func TestBasicUse(t *testing.T) { + status := &Status{} + counts := &counterOutput{} + status.AddOutput(counts) + s := status.StartTool() + + s.SetTotalActions(2) + + a := &Action{} + s.StartAction(a) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 1, + StartedActions: 1, + FinishedActions: 0, + }) + + s.FinishAction(ActionResult{Action: a}) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 0, + StartedActions: 1, + FinishedActions: 1, + }) + + a = &Action{} + s.StartAction(a) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 1, + StartedActions: 2, + FinishedActions: 1, + }) + + s.FinishAction(ActionResult{Action: a}) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 0, + StartedActions: 2, + FinishedActions: 2, + }) +} + +// For when a tool claims to have 2 actions, but finishes after one. +func TestFinishEarly(t *testing.T) { + status := &Status{} + counts := &counterOutput{} + status.AddOutput(counts) + s := status.StartTool() + + s.SetTotalActions(2) + + a := &Action{} + s.StartAction(a) + s.FinishAction(ActionResult{Action: a}) + s.Finish() + + s = status.StartTool() + s.SetTotalActions(2) + + a = &Action{} + s.StartAction(a) + + counts.Expect(t, Counts{ + TotalActions: 3, + RunningActions: 1, + StartedActions: 2, + FinishedActions: 1, + }) +} + +// For when a tool claims to have 1 action, but starts two. +func TestExtraActions(t *testing.T) { + status := &Status{} + counts := &counterOutput{} + status.AddOutput(counts) + s := status.StartTool() + + s.SetTotalActions(1) + + s.StartAction(&Action{}) + s.StartAction(&Action{}) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 2, + StartedActions: 2, + FinishedActions: 0, + }) +} + +// When a tool calls Finish() with a running Action +func TestRunningWhenFinished(t *testing.T) { + status := &Status{} + counts := &counterOutput{} + status.AddOutput(counts) + + s := status.StartTool() + s.SetTotalActions(1) + s.StartAction(&Action{}) + s.Finish() + + s = status.StartTool() + s.SetTotalActions(1) + s.StartAction(&Action{}) + + counts.Expect(t, Counts{ + TotalActions: 2, + RunningActions: 2, + StartedActions: 2, + FinishedActions: 0, + }) +} |