1# Copyright (c) 2021-2022 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14module TestRunner 15 16 class Result 17 # Class-level mutex and test execution statistics 18 @@mutex = Mutex.new 19 @@stats = { passed: { cnt: 0, files: [] }, 20 failed: { cnt: 0, files: [] }, 21 core: { cnt: 0, files: [] }, 22 compilation_error: { cnt: 0, files: [] }, 23 quickening_error: { cnt: 0, files: [] }, 24 excluded: { cnt: 0, files: [] }} 25 def initialize(reporter) 26 @reporter = reporter 27 end 28 29 def update_failed_compilation(output, file) 30 @@mutex.synchronize do 31 @@stats[:compilation_error][:cnt] += 1 32 @@stats[:compilation_error][:files] << file 33 end 34 @reporter.log_failed_compilation output 35 end 36 37 def update_failed_quickening(output, file) 38 @@mutex.synchronize do 39 @@stats[:quickening_error][:cnt] += 1 40 @@stats[:quickening_error][:files] << file 41 end 42 @reporter.log_failed_quickening output 43 end 44 45 def update_negative_passed_compilation(output, file) 46 @@mutex.synchronize do 47 @@stats[:compilation_error][:cnt] += 1 48 @@stats[:compilation_error][:files] << file 49 end 50 @reporter.log_negative_passed_compilation output 51 end 52 53 def update_failed_negative_compilation(output, file) 54 @@mutex.synchronize do 55 @@stats[:passed][:cnt] += 1 56 @@stats[:passed][:files] << file 57 end 58 @reporter.log_failed_negative_compilation output 59 end 60 61 def update_compilation_passed(output, file) 62 @@mutex.synchronize do 63 @@stats[:passed][:cnt] += 1 64 @@stats[:passed][:files] << file 65 end 66 @reporter.log_compilation_passed output 67 end 68 69 def update_run_negative_failure(output, status, file) 70 @@mutex.synchronize do 71 @@stats[:failed][:cnt] += 1 72 @@stats[:failed][:files] << file 73 end 74 @reporter.log_run_negative_failure output, status 75 end 76 77 def update_verifier_negative_failure(output, status, file) 78 @@mutex.synchronize do 79 @@stats[:failed][:cnt] += 1 80 @@stats[:failed][:files] << file 81 end 82 @reporter.log_verifier_negative_failure output, status 83 end 84 85 def update_run_failure(output, status, file, core) 86 @@mutex.synchronize do 87 @@stats[:failed][:cnt] += 1 88 @@stats[:failed][:files] << file 89 @@stats[:core][:cnt] += 1 if core 90 @@stats[:core][:files] << file if core 91 end 92 @reporter.log_run_failure output, status, core 93 end 94 95 def update_verifier_failure(output, status, file, core) 96 @@mutex.synchronize do 97 @@stats[:failed][:cnt] += 1 98 @@stats[:failed][:files] << file 99 @@stats[:core][:cnt] += 1 if core 100 @@stats[:core][:files] << file if core 101 end 102 @reporter.log_verifier_failure output, status, core 103 end 104 105 def update_passed(output, status, file) 106 @@mutex.synchronize do 107 @@stats[:passed][:cnt] += 1 108 @@stats[:passed][:files] << file 109 end 110 @reporter.log_passed output, status 111 end 112 113 def update_excluded(file) 114 @@mutex.synchronize do 115 @@stats[:excluded][:cnt] += 1 116 @@stats[:excluded][:files] << file 117 end 118 @reporter.log_excluded 119 end 120 121 def self.write_report 122 TestRunner::log 3, @@stats.to_yaml 123 TestRunner::log 2, "Passed: #{@@stats[:passed][:files].sort.to_yaml}" 124 TestRunner::log 1, 'Failed:' 125 TestRunner::log 1, "#{@@stats[:failed][:files].sort.to_yaml}" 126 TestRunner::log 1, 'Failed (coredump):' 127 TestRunner::log 1, "#{@@stats[:core][:files].sort.to_yaml}" 128 TestRunner::log 1, 'Compilation error:' 129 TestRunner::log 1, "#{@@stats[:compilation_error][:files].sort.to_yaml}" 130 TestRunner::log 2, '----------------------------------------' 131 TestRunner::log 1, "Run all: #{$run_all}" 132 TestRunner::log 1, "Run only ignored: #{$run_ignore}" 133 TestRunner::log 1, "Passed: #{@@stats[:passed][:cnt]}" 134 TestRunner::log 1, "Failed: #{@@stats[:failed][:cnt]}" 135 TestRunner::log 1, "Compilation error: #{@@stats[:compilation_error][:cnt]}" 136 TestRunner::log 1, "Excluded: #{@@stats[:excluded][:cnt]}" 137 end 138 139 def self.failed? 140 (@@stats[:failed][:cnt] + @@stats[:compilation_error][:cnt]) > 0 141 end #def 142 end #class 143end #module 144