• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# APEI library: APEI specific functions
3#
4# Copyright (C) 2008, Intel Corp.
5#   Author: Huang Ying <ying.huang@intel.com>
6#           Zheng Jiajia <jiajia.zheng@intel.com>
7# This file is released under the GPLv2.
8#
9
10. $ROOT/lib/soft-inject.sh
11
12if [ -n "$this_case" ]; then
13    bcase=$(basename $this_case)
14fi
15mcelog_result=$RDIR/$this_case/mcelog
16klog=$RDIR/$this_case/klog
17
18apei_mce_reformat()
19{
20    local inf="$1"
21    local outf="$2"
22    local tmpf=$WDIR/mce_reformat_for_cmp
23    sed "s/0x//g" $inf | grep -v 'STATUS 0x0' | \
24        grep -v 'STATUS 0x800000000000000' | sort > "$tmpf"
25    awk '/^STATUS/ {print $2}' $tmpf | cut -b 1-3 > $outf
26    awk '/MCGSTATUS/ {if ($4=="") print $2; else print $4;}' $tmpf >> $outf
27}
28
29apei_mce_cmp()
30{
31    [ $# -eq 2 ] || die "missing parameter for mce_cmp"
32    local m1="$1"
33    local m2="$2"
34    local tmpf1=$WDIR/mce_cmp_1
35    local tmpf2=$WDIR/mce_cmp_2
36
37    apei_mce_reformat "$m1" $tmpf1
38    apei_mce_reformat "$m2" $tmpf2
39    diff $tmpf1 $tmpf2 > /dev/null
40}
41
42apei_inject_verify_mcelog()
43{
44    if [ -f $RDIR/$this_case/mcelog ]; then
45        mcelog_refer=$SDIR/refer/$bcase
46        mce-inject --dump $mcelog_refer > $RDIR/$this_case/mcelog_refer
47        if apei_mce_cmp $RDIR/$this_case/mcelog $RDIR/$this_case/mcelog_refer; then
48            echo "  Passed: MCE log is ok"
49        else
50            echo "  Failed: MCE log is different from input"
51        fi
52    else
53        echo "  Failed: no MCE log result"
54    fi
55}
56
57
58apei_inject_get_klog()
59{
60    soft_inject_get_klog
61}
62
63apei_inject_get_mcelog()
64{
65    soft_inject_get_mcelog
66}
67
68# verify return value
69apei_inject_verify_return_val()
70{
71    soft_inject_verify_return_val
72}
73
74apei_inject_verify_kill()
75{
76    soft_inject_verify_kill
77}
78
79apei_inject_enumerate()
80{
81    soft_inject_enumerate
82}
83
84apei_inject_trigger()
85{
86    check_debugfs
87    #APEI_IF should be defined after debugfs is mounted
88    APEI_IF=`mount | grep debugfs | cut -d ' ' -f3`/apei/einj
89
90    #if einj is a module, it is ensured to have been loaded
91    modinfo einj > /dev/null 2>&1
92    if [ $? -eq 0 ]; then
93	[ -d $APEI_IF ] || modprobe einj
94        [ $? -eq 0 ] || die "module einj isn't supported ?"
95    fi
96
97    mcelog &> /dev/null
98    TYPE=`awk '/^TYPE/{print $2}' $SDIR/data/$bcase`
99    echo $TYPE > $APEI_IF/error_type
100    killall simple_process
101    $TDIR/simple_process/simple_process > /dev/null &
102
103    page-types -p `pidof simple_process` -LN -b ano > $RDIR/$this_case/page
104
105    ADDR=`awk '$2 != "offset" {print "0x"$2"000"}' $RDIR/$this_case/page | sed -n -e '1p'`
106    echo $ADDR > $APEI_IF/param1
107
108    echo "1" > $APEI_IF/error_inject
109
110    ret=$?
111    echo $ret > $RDIR/$this_case/return
112    sleep 1
113}
114
115start_tracing()
116{
117    [ $# -eq 1 ] || die "missing parameter for get_panic_from_mcelog: please set filter for ftrace"
118    [ -d /sys/kernel/debug/tracing ] || die "no tracing"
119    echo "function_graph" > /sys/kernel/debug/tracing/current_tracer
120    echo $1 > /sys/kernel/debug/tracing/set_ftrace_filter
121    echo "1" > /sys/kernel/debug/tracing/tracing_enabled
122}
123
124stop_tracing()
125{
126    [ -d /sys/kernel/debug/tracing ] || die "no tracing"
127    echo "0" > /sys/kernel/debug/tracing/tracing_enabled
128    cp /sys/kernel/debug/tracing/trace $RDIR/$this_case/
129    echo "nop" > /sys/kernel/debug/tracing/current_tracer
130}
131
132apei_inject_verify_trace()
133{
134    [ $# -eq 1 ] || die "missing parameter for apei_inject_verify_trace"
135    if grep "$1" $RDIR/$this_case/trace; then
136       echo "Passed: trace is correct"
137    else
138       echo "Failed: Nothing is traced"
139    fi
140}
141
142apei_inject_verify_panic()
143{
144    local mce_panic="$1"
145    verify_panic_via_klog $klog "$mce_panic"
146}
147
148apei_inject_verify_exp()
149{
150    verify_exp_via_klog $klog "$@"
151}
152
153apei_inject_verify_fail()
154{
155    verify_fail_via_klog $klog "$@"
156}
157
158apei_inject_main()
159{
160    op="$1"
161    shift
162
163    case "$op" in
164	enumerate)
165	    enumerate
166	    ;;
167	trigger)
168	    trigger "$@"
169	    ;;
170	get_result)
171	    get_result
172	    ;;
173	verify)
174	    verify
175	    ;;
176	*)
177	    die "Usage: $0 enumerate|trigger|get_result|verify"
178    esac
179    exit 0
180}
181