1#!/bin/bash -f
2#----------------------------------------------------------------------------
3# Project:  Horizon
4# File:     log_analyze.sh
5#
6# Copyright (C)2009-2011 Nintendo Co., Ltd.  All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law.  They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14# $Rev: 38282 $
15#----------------------------------------------------------------------------
16PATH=/usr/local/bin:/usr/bin:/bin
17ROOT=`cygpath -m ${HORIZON_ROOT}`
18ROOT_TESTS=${ROOT}/images/tests
19
20TEST_SUCCESS='^CU_TEST_EXIT:SUCCESS'
21TEST_FAILUE='^((CU_TEST_EXIT:FAIL)|(nn::svc::Break\(\d+\) called)|(KernelPanic))|(Exception =+$)'
22
23
24function xmlcutter(){
25    sed -e '/^<!-- begin:/, /^<!-- end:/d'
26}
27
28function taillog(){
29    file=$1
30    cat ${file} | xmlcutter | tail -10 | sed -e 's/^/> /g'; echo
31}
32
33function analyze_log(){
34    file=$1
35    gawk -f - ${file} << EOS || taillog ${file}
36BEGIN{
37    found = 0
38}
39/${TEST_SUCCESS}/ {
40    printf "[SUCCESS] %s\n", FILENAME
41    found = 1
42    nextfile
43}
44/${TEST_FAILUE}/ {
45    printf "\033[31m[FAILUE]\033[0m  %s\n", FILENAME
46    found = -1
47    nextfile
48}
49END{
50    if (found == 0) {
51        printf "\033[33m[UNKNOWN]\033[0m %s\n", FILENAME
52        found = -1
53    }
54
55    if (found == -1) {
56        exit 1
57    }
58}
59EOS
60}
61
62function analyze_logs(){
63    for logfile in $*
64    do
65        if [ -r "${logfile}" ]; then
66            analyze_log "${logfile}"
67        fi
68    done
69}
70
71if [ -z $1 ]; then
72    LOGS=`find ${ROOT_TESTS} -name '*.log' -print`
73else
74    LOGS=$*
75    echo ${LOGS}
76fi
77
78analyze_logs ${LOGS}
79