go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/changepoints/inputbuffer/test_util.go (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package inputbuffer 16 17 import ( 18 "time" 19 ) 20 21 func Verdicts(positions, total, hasUnexpected []int) []PositionVerdict { 22 retried := make([]int, len(total)) 23 unexpectedAfterRetry := make([]int, len(total)) 24 return VerdictsWithRetries(positions, total, hasUnexpected, retried, unexpectedAfterRetry) 25 } 26 27 func VerdictsWithRetries(positions, total, hasUnexpected, retried, unexpectedAfterRetry []int) []PositionVerdict { 28 if len(total) != len(hasUnexpected) { 29 panic("length mismatch between total and hasUnexpected") 30 } 31 if len(total) != len(retried) { 32 panic("length mismatch between total and retried") 33 } 34 if len(total) != len(unexpectedAfterRetry) { 35 panic("length mismatch between total and unexpectedAfterRetry") 36 } 37 result := make([]PositionVerdict, 0, len(total)) 38 for i := range total { 39 // From top to bottom, these are increasingly restrictive. 40 totalCount := total[i] // Total number of test runs in this verdict. 41 hasUnexpectedCount := hasUnexpected[i] // How many of those test runs had at least one unexpected result. 42 retriedCount := retried[i] // As above, plus at least two results in total. 43 unexpectedAfterRetry := unexpectedAfterRetry[i] // As above, plus all test runs have only unexpected results. 44 45 verdict := PositionVerdict{ 46 CommitPosition: positions[i], 47 Hour: time.Unix(int64(3600*(positions[i])), 0), 48 } 49 if hasUnexpectedCount == 0 && totalCount == 1 { 50 verdict.IsSimpleExpectedPass = true 51 } else { 52 verdict.Details = VerdictDetails{ 53 Runs: []Run{}, 54 } 55 for i := 0; i < totalCount; i++ { 56 if i < unexpectedAfterRetry { 57 verdict.Details.Runs = append(verdict.Details.Runs, Run{ 58 Unexpected: ResultCounts{ 59 FailCount: 1, 60 CrashCount: 1, 61 }, 62 }) 63 } else if i < retriedCount { 64 verdict.Details.Runs = append(verdict.Details.Runs, Run{ 65 Expected: ResultCounts{ 66 PassCount: 1, 67 }, 68 Unexpected: ResultCounts{ 69 FailCount: 1, 70 }, 71 }) 72 } else if i < hasUnexpectedCount { 73 verdict.Details.Runs = append(verdict.Details.Runs, Run{ 74 Unexpected: ResultCounts{ 75 FailCount: 1, 76 }, 77 }) 78 } else { 79 verdict.Details.Runs = append(verdict.Details.Runs, Run{ 80 Expected: ResultCounts{ 81 PassCount: 1, 82 }, 83 }) 84 } 85 } 86 } 87 result = append(result, verdict) 88 } 89 return result 90 }