1#!/bin/bash -f
2#----------------------------------------------------------------------------
3# Project:  Horizon
4# File:     log_analyze.sh
5#
6# Copyright 2009 Nintendo.  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# $Date:: 2009-09-28#$
15# $Rev: 5402 $
16# $Author: adachi_hiroaki $
17#----------------------------------------------------------------------------
18PATH=/usr/local/bin:/usr/bin:/bin
19ROOT=`cygpath -m ${HORIZON_ROOT}`
20ROOT_TESTS=${ROOT}/images/tests
21
22TEST_SUCCESS='^CU_TEST_EXIT:SUCCESS'
23TEST_FAILUE='^((CU_TEST_EXIT:FAIL)|(nn::svc::Break\(\d+\) called)|(KernelPanic))|(Exception =+$)'
24
25
26function xmlcutter(){
27    sed -e '/^<!-- begin:/, /^<!-- end:/d'
28}
29
30function taillog(){
31    file=$1
32    cat ${file} | xmlcutter | tail -10 | sed -e 's/^/> /g'; echo
33}
34
35function analyze_log(){
36    file=$1
37    gawk -f - ${file} << EOS || taillog ${file}
38BEGIN{
39    found = 0
40}
41/${TEST_SUCCESS}/ {
42    printf "[SUCCESS] %s\n", FILENAME
43    found = 1
44    nextfile
45}
46/${TEST_FAILUE}/ {
47    printf "\033[31m[FAILUE]\033[0m  %s\n", FILENAME
48    found = -1
49    nextfile
50}
51END{
52    if (found == 0) {
53        printf "\033[33m[UNKNOWN]\033[0m %s\n", FILENAME
54        found = -1
55    }
56
57    if (found == -1) {
58        exit 1
59    }
60}
61EOS
62}
63
64function analyze_logs(){
65    for logfile in $*
66    do
67        if [ -r "${logfile}" ]; then
68            analyze_log "${logfile}"
69        fi
70    done
71}
72
73if [ -z $1 ]; then
74    LOGS=`find ${ROOT_TESTS} -name '*.log' -print`
75else
76    LOGS=$*
77    echo ${LOGS}
78fi
79
80analyze_logs ${LOGS}
81