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 14require_relative 'string_logger' 15require_relative 'base_test_reporter' 16 17module TestRunner 18 # LogTestReporter is reporter to console, default reporter 19 class LogTestReporter < BaseTestReporter 20 @@mutex = Mutex.new 21 22 def initialize(_root_dir, pa_file, _report_dir) 23 super() 24 @pa_file = pa_file 25 @logger = Reporters::StringLogger.new 26 end 27 28 def prologue 29 @logger.log 2 30 @logger.log 2, '----------------------------------------' 31 @logger.log 2 32 @logger.log 2, "Test file: #{@pa_file}" 33 end 34 35 def epilogue 36 output = @logger.string 37 unless output.empty? 38 @@mutex.synchronize do 39 puts output 40 end 41 end 42 @logger.close 43 end 44 45 def log_exclusion 46 @logger.log 2, "Skip excluded test #{@pa_file} by tag" 47 end 48 49 def log_skip_include 50 @logger.log 2, "Skip not included test #{@pa_file} by tag" 51 end 52 53 def log_skip_bugid 54 @logger.log 2, "Skip test #{@pa_file} since bug id do not match" 55 end 56 57 def log_skip_ignore 58 @logger.log 2, "Skip test #{@pa_file}, because 'runner_option: ignore' tag is defined" 59 end 60 61 def log_skip_only_ignore 62 @logger.log 2, "Skip test #{@pa_file}, because run only test with 'runner_option: ignore' tag" 63 end 64 65 def log_ignore_ignored 66 @logger.log 2, "Execute test #{@pa_file}, since 'runner_option: ignore' tag is ignored" 67 end 68 69 def log_start_command(cmd) 70 @logger.log 3, "Start: #{cmd}" 71 end 72 73 def log_failed_compilation(output) 74 @logger.log 1, "TEST FAILED: #{@pa_file}" 75 @logger.log 1, 'Compilation failed.' 76 @logger.log 1, output unless output.empty? 77 end 78 79 def log_failed_quickening(output) 80 @logger.log 1, "TEST FAILED: #{@pa_file}" 81 @logger.log 1, 'Quickening failed.' 82 @logger.log 1, output unless output.empty? 83 end 84 85 def log_negative_passed_compilation(output) 86 @logger.log 1, "TEST FAILED: #{@pa_file}" 87 @logger.log 1, 'Compilation succeeded, but compilation failure expected.' 88 @logger.log 1, output unless output.empty? 89 end 90 91 def log_failed_negative_compilation(output) 92 @logger.log 2, "TEST PASSED: #{@pa_file}" 93 @logger.log 2, 'Compilation failed, as expected.' 94 @logger.log 3, output unless output.empty? 95 end 96 97 def log_compilation_passed(output) 98 @logger.log 2, "TEST PASSED: #{@pa_file}" 99 @logger.log 2, 'Compilation-only test.' 100 @logger.log 3, output unless output.empty? 101 end 102 103 def log_run_negative_failure(output, status) 104 @logger.log 1, "TEST FAILED: #{@pa_file}" 105 @logger.log 1, "Ark exit code: #{status}, but expected ark failure." 106 @logger.log 1, output unless output.empty? 107 end 108 109 def log_verifier_negative_failure(output, status) 110 @logger.log 1, "TEST FAILED: #{@pa_file}" 111 @logger.log 1, "Verifier exit code: #{status}, but expected verifier failure." 112 @logger.log 1, output unless output.empty? 113 end 114 115 def log_run_failure(output, status, core) 116 @logger.log 1, "TEST FAILED: #{@pa_file}" 117 @logger.log 1, "Ark exit code: #{status}" 118 @logger.log 1, 'Core dump was created' if core 119 @logger.log 1, output unless output.empty? 120 end 121 122 def log_verifier_failure(output, status, core) 123 @logger.log 1, "TEST FAILED: #{@pa_file}" 124 @logger.log 1, "Verifier exit code: #{status}" 125 @logger.log 1, 'Core dump was created' if core 126 @logger.log 1, output unless output.empty? 127 end 128 129 def log_passed(output, status) 130 @logger.log 2, "TEST PASSED: #{@pa_file}" 131 @logger.log 2, "Ark exit code: #{status}" 132 @logger.log 3, output unless output.empty? 133 end 134 135 def log_excluded 136 @logger.log 3, "TEST EXCLUDED: #{@pa_file}" 137 end 138 139 def verbose_log(status) 140 @logger.log 3, status 141 end 142 143 def log_bugids(bugids) end 144 145 def log_repro_commands(cmds) 146 return unless cmds.length.positive? 147 148 @logger.log 1, 'Commands to reproduce:' 149 @logger.log 1, cmds 150 @logger.log 1, '' 151 end 152 end 153end 154