platform_build_soong/ui/status/kati_test.go

176 lines
4.1 KiB
Go
Raw Normal View History

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
2018-05-18 01:37:09 +02:00
// 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 lastOutput struct {
counterOutput
action *Action
result ActionResult
msgLevel MsgLevel
msg string
}
func (l *lastOutput) StartAction(a *Action, c Counts) {
l.action = a
l.counterOutput.StartAction(a, c)
}
func (l *lastOutput) FinishAction(r ActionResult, c Counts) {
l.result = r
l.counterOutput.FinishAction(r, c)
}
func (l *lastOutput) Message(level MsgLevel, msg string) {
l.msgLevel = level
l.msg = msg
}
func (l *lastOutput) Flush() {}
func TestKatiNormalCase(t *testing.T) {
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
parser := &katiOutputParser{
st: status.StartTool(),
}
msg := "*kati*: verbose msg"
parser.parseLine(msg)
output.Expect(t, Counts{})
if output.msgLevel != VerboseLvl {
t.Errorf("Expected verbose message, but got %d", output.msgLevel)
}
if output.msg != msg {
t.Errorf("unexpected message contents:\nwant: %q\n got: %q\n", msg, output.msg)
}
parser.parseLine("out/build-aosp_arm.ninja is missing, regenerating...")
output.Expect(t, Counts{})
parser.parseLine("[1/1] initializing build system ...")
output.Expect(t, Counts{
TotalActions: 1,
RunningActions: 1,
StartedActions: 1,
FinishedActions: 0,
})
parser.parseLine("[2/5] including out/soong/Android-aosp_arm.mk ...")
output.Expect(t, Counts{
TotalActions: 5,
RunningActions: 1,
StartedActions: 2,
FinishedActions: 1,
})
parser.parseLine("[3/5] including a ...")
msg = "a random message"
parser.parseLine(msg)
// Start the next line to flush the previous result
parser.parseLine("[4/5] finishing build rules ...")
msg += "\n"
if output.result.Output != msg {
t.Errorf("output for action did not match:\nwant: %q\n got: %q\n", msg, output.result.Output)
}
parser.parseLine("[5/5] writing build rules ...")
parser.parseLine("*kati*: verbose msg")
parser.flushAction()
if output.result.Output != "" {
t.Errorf("expected no output for last action, but got %q", output.result.Output)
}
output.Expect(t, Counts{
TotalActions: 5,
RunningActions: 0,
StartedActions: 5,
FinishedActions: 5,
})
}
func TestKatiExtraIncludes(t *testing.T) {
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
parser := &katiOutputParser{
st: status.StartTool(),
}
parser.parseLine("[1/1] initializing build system ...")
parser.parseLine("[2/5] including out/soong/Android-aosp_arm.mk ...")
output.Expect(t, Counts{
TotalActions: 5,
RunningActions: 1,
StartedActions: 2,
FinishedActions: 1,
})
parser.parseLine("including a ...")
output.Expect(t, Counts{
TotalActions: 6,
RunningActions: 1,
StartedActions: 3,
FinishedActions: 2,
})
parser.parseLine("including b ...")
output.Expect(t, Counts{
TotalActions: 7,
RunningActions: 1,
StartedActions: 4,
FinishedActions: 3,
})
parser.parseLine("[3/5] finishing build rules ...")
output.Expect(t, Counts{
TotalActions: 7,
RunningActions: 1,
StartedActions: 5,
FinishedActions: 4,
})
}
func TestKatiFailOnError(t *testing.T) {
status := &Status{}
output := &lastOutput{}
status.AddOutput(output)
parser := &katiOutputParser{
st: status.StartTool(),
}
parser.parseLine("[1/1] initializing build system ...")
parser.parseLine("[2/5] inclduing out/soong/Android-aosp_arm.mk ...")
parser.parseLine("build/make/tools/Android.mk:19: error: testing")
parser.flushAction()
if output.result.Error == nil {
t.Errorf("Expected the last action to be marked as an error")
}
}