1f08c3bdfSopenharmony_ci#
2f08c3bdfSopenharmony_ci# Software Inject library: Software inject specific functions
3f08c3bdfSopenharmony_ci#
4f08c3bdfSopenharmony_ci# Copyright (C) 2008, Intel Corp.
5f08c3bdfSopenharmony_ci#   Author: Huang Ying <ying.huang@intel.com>
6f08c3bdfSopenharmony_ci#
7f08c3bdfSopenharmony_ci# This file is released under the GPLv2.
8f08c3bdfSopenharmony_ci#
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ciif [ -n "$this_case" ]; then
11f08c3bdfSopenharmony_ci    bcase=$(basename $this_case)
12f08c3bdfSopenharmony_cifi
13f08c3bdfSopenharmony_cimcelog_result=$RDIR/$this_case/mcelog
14f08c3bdfSopenharmony_ciklog=$RDIR/$this_case/klog
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_cisoft_inject_verify_mcelog()
17f08c3bdfSopenharmony_ci{
18f08c3bdfSopenharmony_ci    # check mcelog
19f08c3bdfSopenharmony_ci    if [ -f $RDIR/$this_case/mcelog ]; then
20f08c3bdfSopenharmony_ci	if [ -f $SDIR/refer/$bcase ]; then
21f08c3bdfSopenharmony_ci	    mcelog_refer=$SDIR/refer/$bcase
22f08c3bdfSopenharmony_ci	else
23f08c3bdfSopenharmony_ci	    mcelog_refer=$SDIR/data/$bcase
24f08c3bdfSopenharmony_ci	fi
25f08c3bdfSopenharmony_ci	mce_reformat $mcelog_refer $RDIR/$this_case/mcelog_refer
26f08c3bdfSopenharmony_ci
27f08c3bdfSopenharmony_ci	if mce_cmp $RDIR/$this_case/mcelog $mcelog_refer "$removes"; then
28f08c3bdfSopenharmony_ci	    echo "  Passed: MCE log is ok"
29f08c3bdfSopenharmony_ci	else
30f08c3bdfSopenharmony_ci	    echo "  Failed: MCE log is different from input"
31f08c3bdfSopenharmony_ci	fi
32f08c3bdfSopenharmony_ci    else
33f08c3bdfSopenharmony_ci	echo "  Failed: no MCE log result"
34f08c3bdfSopenharmony_ci    fi
35f08c3bdfSopenharmony_ci}
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_cisoft_inject_get_klog()
38f08c3bdfSopenharmony_ci{
39f08c3bdfSopenharmony_ci    local klog=$RDIR/$this_case/klog
40f08c3bdfSopenharmony_ci    local orig_klog=$RDIR/$this_case/orig_klog
41f08c3bdfSopenharmony_ci
42f08c3bdfSopenharmony_ci    if [ -f $klog ]; then
43f08c3bdfSopenharmony_ci	cp $klog $orig_klog
44f08c3bdfSopenharmony_ci	filter_fake_panic $orig_klog $klog
45f08c3bdfSopenharmony_ci    fi
46f08c3bdfSopenharmony_ci}
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_cisoft_inject_get_mcelog()
49f08c3bdfSopenharmony_ci{
50f08c3bdfSopenharmony_ci    case "$driver" in
51f08c3bdfSopenharmony_ci	simple*)
52f08c3bdfSopenharmony_ci	    get_mcelog_from_dev $mcelog_result
53f08c3bdfSopenharmony_ci	    ;;
54f08c3bdfSopenharmony_ci	kdump*)
55f08c3bdfSopenharmony_ci	    get_mcelog_from_klog $klog $mcelog_result
56f08c3bdfSopenharmony_ci	    ;;
57f08c3bdfSopenharmony_ci	*)
58f08c3bdfSopenharmony_ci	    echo '!!! Unsupported driver !!!'
59f08c3bdfSopenharmony_ci    esac
60f08c3bdfSopenharmony_ci}
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ci# verify return value
63f08c3bdfSopenharmony_cisoft_inject_verify_return_val()
64f08c3bdfSopenharmony_ci{
65f08c3bdfSopenharmony_ci    if [ -f $RDIR/$this_case/return ] && \
66f08c3bdfSopenharmony_ci	[ $(cat $RDIR/$this_case/return) -eq 0 ]; then
67f08c3bdfSopenharmony_ci	echo "  Passed: inject process continue"
68f08c3bdfSopenharmony_ci    else
69f08c3bdfSopenharmony_ci	echo "  Failed: inject process killed"
70f08c3bdfSopenharmony_ci    fi
71f08c3bdfSopenharmony_ci}
72f08c3bdfSopenharmony_ci
73f08c3bdfSopenharmony_cisoft_inject_verify_kill()
74f08c3bdfSopenharmony_ci{
75f08c3bdfSopenharmony_ci    if [ -f $RDIR/$this_case/return ] && \
76f08c3bdfSopenharmony_ci	[ $(cat $RDIR/$this_case/return) -eq 139 ]; then
77f08c3bdfSopenharmony_ci	echo "  Passed: inject process killed!"
78f08c3bdfSopenharmony_ci    else
79f08c3bdfSopenharmony_ci	echo "  Failed: Not killed"
80f08c3bdfSopenharmony_ci    fi
81f08c3bdfSopenharmony_ci}
82f08c3bdfSopenharmony_ci
83f08c3bdfSopenharmony_cisoft_inject_enumerate()
84f08c3bdfSopenharmony_ci{
85f08c3bdfSopenharmony_ci    local base=$(relative_path ${CDIR} ${SDIR})
86f08c3bdfSopenharmony_ci    [ -z "$base" ] && die "BUG!!! Please contact your software vendor!"
87f08c3bdfSopenharmony_ci    for c in $(cd $SDIR/data; ls *[^~]); do
88f08c3bdfSopenharmony_ci	echo $base/$c
89f08c3bdfSopenharmony_ci    done
90f08c3bdfSopenharmony_ci}
91f08c3bdfSopenharmony_ci
92f08c3bdfSopenharmony_cisoft_inject_trigger()
93f08c3bdfSopenharmony_ci{
94f08c3bdfSopenharmony_ci    mcelog &> /dev/null
95f08c3bdfSopenharmony_ci    case "$driver" in
96f08c3bdfSopenharmony_ci	kdump*)
97f08c3bdfSopenharmony_ci	    mce-inject --no-random $SDIR/data/$bcase
98f08c3bdfSopenharmony_ci	    ;;
99f08c3bdfSopenharmony_ci	*)
100f08c3bdfSopenharmony_ci	    mce-inject $SDIR/data/$bcase
101f08c3bdfSopenharmony_ci	    ;;
102f08c3bdfSopenharmony_ci    esac
103f08c3bdfSopenharmony_ci    ret=$?
104f08c3bdfSopenharmony_ci    echo $ret > $RDIR/$this_case/return
105f08c3bdfSopenharmony_ci    sleep 1
106f08c3bdfSopenharmony_ci}
107f08c3bdfSopenharmony_ci
108f08c3bdfSopenharmony_cisoft_inject_verify_panic()
109f08c3bdfSopenharmony_ci{
110f08c3bdfSopenharmony_ci    local mce_panic="$1"
111f08c3bdfSopenharmony_ci    verify_panic_via_klog $klog "$mce_panic"
112f08c3bdfSopenharmony_ci}
113f08c3bdfSopenharmony_ci
114f08c3bdfSopenharmony_cisoft_inject_verify_timeout()
115f08c3bdfSopenharmony_ci{
116f08c3bdfSopenharmony_ci    verify_timeout_via_klog $klog
117f08c3bdfSopenharmony_ci}
118f08c3bdfSopenharmony_ci
119f08c3bdfSopenharmony_cisoft_inject_verify_exp()
120f08c3bdfSopenharmony_ci{
121f08c3bdfSopenharmony_ci    verify_exp_via_klog $klog "$@"
122f08c3bdfSopenharmony_ci}
123f08c3bdfSopenharmony_ci
124f08c3bdfSopenharmony_cisoft_inject_main()
125f08c3bdfSopenharmony_ci{
126f08c3bdfSopenharmony_ci    op="$1"
127f08c3bdfSopenharmony_ci    shift
128f08c3bdfSopenharmony_ci
129f08c3bdfSopenharmony_ci    case "$op" in
130f08c3bdfSopenharmony_ci	enumerate)
131f08c3bdfSopenharmony_ci	    enumerate
132f08c3bdfSopenharmony_ci	    ;;
133f08c3bdfSopenharmony_ci	trigger)
134f08c3bdfSopenharmony_ci	    trigger "$@"
135f08c3bdfSopenharmony_ci	    ;;
136f08c3bdfSopenharmony_ci	get_result)
137f08c3bdfSopenharmony_ci	    get_result
138f08c3bdfSopenharmony_ci	    ;;
139f08c3bdfSopenharmony_ci	verify)
140f08c3bdfSopenharmony_ci	    verify
141f08c3bdfSopenharmony_ci	    ;;
142f08c3bdfSopenharmony_ci	*)
143f08c3bdfSopenharmony_ci	    die "Usage: $0 enumerate|trigger|get_result|verify"
144f08c3bdfSopenharmony_ci    esac
145f08c3bdfSopenharmony_ci    exit 0
146f08c3bdfSopenharmony_ci}
147