~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/skiboot/external/boot-tests/boot_test.sh

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# Lets try for /bin/sh but bashisms will sneak in.
 
3
 
 
4
# partial bash strict mode
 
5
set -uo pipefail
 
6
 
 
7
V=0;
 
8
target=""
 
9
 
 
10
if [ -f ~/.skiboot_boot_tests ]; then
 
11
        source ~/.skiboot_boot_tests
 
12
fi
 
13
 
 
14
# Utility functions
 
15
function error {
 
16
        unset SSHPASS
 
17
        if [ ! -z "$target" ]; then
 
18
                echo "$target: $*" >&2
 
19
        else
 
20
                echo "$0: $*" >&2
 
21
        fi
 
22
        
 
23
        exit 1
 
24
}
 
25
 
 
26
function msg {
 
27
        if [ $V -ne 0 ]; then
 
28
                if [ ! -z "$target" ]; then
 
29
                        echo "$target: $*"
 
30
                else
 
31
                        echo "$0: $*"
 
32
                fi
 
33
        fi
 
34
}
 
35
 
 
36
# Generic conf
 
37
BOOT_SLEEP_PERIOD=10
 
38
FUNCTIONS_NEEDED="sshpass ssh ipmitool md5sum rsync expect";
 
39
 
 
40
function linux_boot {
 
41
        if [ $STRIP_CONTROL -eq 1 ]; then
 
42
            STRIPCOMMAND="col -b -l 1"
 
43
        else
 
44
            STRIPCOMMAND="cat"
 
45
        fi
 
46
 
 
47
        #Everyone is going to forget to disconnect - force them off
 
48
        ipmiresult=$($IPMI_COMMAND sol deactivate 2>&1);
 
49
        retval=$?
 
50
        if [ $retval -ne 0 -a "$ipmiresult" != "Info: SOL payload already de-activated" ]; then
 
51
            msg "IPMI sol deactivate failed; IPMI may have stalled, may just be IPMI. Good luck."
 
52
        fi
 
53
 
 
54
        LINUXBOOT_LOG=$(mktemp --tmpdir builder-2.XXXXXX);
 
55
        cat <<EOF | expect > $LINUXBOOT_LOG
 
56
set timeout 300
 
57
spawn $IPMI_COMMAND sol activate
 
58
expect {
 
59
timeout { send_user "\nTimeout waiting for petitboot\n"; exit 1 }
 
60
eof { send_user "\nUnexpected EOF\n;" exit 1 }
 
61
"Welcome to Petitboot"
 
62
}
 
63
 
 
64
close
 
65
exit 0
 
66
EOF
 
67
        retval=$?
 
68
        $IPMI_COMMAND sol deactivate > /dev/null;
 
69
        if [ $retval -ne 0 ]; then
 
70
                msg "Waiting for linux has timed out"
 
71
                msg "Boot log follows:"
 
72
                cat $LINUXBOOT_LOG
 
73
                rm -f $LINUXBOOT_LOG
 
74
                return 1
 
75
        else
 
76
                rm -f $LINUXBOOT_LOG
 
77
                return 0
 
78
        fi
 
79
}
 
80
 
 
81
function boot_test {
 
82
        # The functions called (e.g. flash, boot) are from the *_support files
 
83
        if [ $bootonly -ne 1 ]; then
 
84
            msg "Flashing ${target}..."
 
85
            flash $@;
 
86
        fi
 
87
 
 
88
        msg "Booting $target..."
 
89
        boot_firmware;
 
90
        msg "firmware looks good, waiting for linux";
 
91
 
 
92
        linux_boot;
 
93
        if [ $? -ne 0 ] ; then
 
94
                error "Couldn't reach petitboot on $target";
 
95
        fi
 
96
        msg "$target has booted";
 
97
        unset SSHPASS;
 
98
}
 
99
 
 
100
function sanity_test {
 
101
    $SSHCMD true;
 
102
    if [ $? -ne 0 ]; then
 
103
        echo "$target: Failed to SSH to $target..."
 
104
        echo "$target: Command was: $SSHCMD true"
 
105
        error "Try connecting manually to diagnose the issue."
 
106
    fi
 
107
 
 
108
    $IPMI_COMMAND chassis power status > /dev/null;
 
109
    if [ $? -ne 0 ]; then
 
110
        echo "$target: Failed to connect to $target with IPMI..."
 
111
        echo "$target: Command was: $IPMI_COMMAND chassis power status"
 
112
        error "Try connecting manually to diagnose the issue."
 
113
    fi
 
114
 
 
115
    # do further machine-type specific tests
 
116
    machine_sanity_test
 
117
}
 
118
 
 
119
function usage {
 
120
    cat <<EOF
 
121
boot_test.sh tests the bootability of a given target, optionally after
 
122
  flashing new firmware onto the target.
 
123
 
 
124
There are three usage modes.
 
125
 
 
126
1) boot_test.sh -h
 
127
     Print this help
 
128
 
 
129
2) boot_test.sh [-vdp] -t target -B -b (fsp|bmc)
 
130
     Boot test the target without flashing. Specify the type of machine
 
131
     (FSP or BMC) with the -b option.
 
132
 
 
133
3) boot_test.sh [-vdp] -b bmc -t target -P pnor
 
134
   boot_test.sh [-vdp] -b bmc -t target [-1 PAYLOAD] [-2 BOOTKERNEL]
 
135
   boot_test.sh [-vdp] -b fsp -t target [-1 lid1] [-2 lid2] [-3 lid3]
 
136
 
 
137
     Flash the given firmware before boot testing.
 
138
 
 
139
     For a BMC target, -P specifies a full PNOR.
 
140
 
 
141
     For a BMC target, -1/-2 specify the PAYLOAD and BOOTKERNEL PNOR partitions
 
142
     respectively. Only the given partitions will be flashed.
 
143
 
 
144
     For an FSP target, -1/-2/-3 specify lids. Any combination of lids is
 
145
     acceptable.
 
146
 
 
147
Common Options:
 
148
 
 
149
  -p powers off the machine if it is running. Without -p, a running machine
 
150
     will cause the script to error out.
 
151
 
 
152
  -v makes the script print some progress messages. Recommended.
 
153
 
 
154
  -d makes the script print lots of things (set -vx).
 
155
     Only use this for debugging the script: it's highly likely that
 
156
     successful booting into Petitboot will not be detected with this option.
 
157
 
 
158
  -b BMC type (bmc or fsp).
 
159
EOF
 
160
    exit 1;
 
161
}
 
162
 
 
163
## 'Main' script begins
 
164
 
 
165
# Check prereqs
 
166
for func in $FUNCTIONS_NEEDED ; do
 
167
        if ! command -v "$func" &> /dev/null ; then
 
168
                error "I require command $func but it is not in \$PATH ($PATH)";
 
169
        fi
 
170
done
 
171
 
 
172
# Parse options
 
173
V=0;
 
174
bootonly=0;
 
175
powerdown=0;
 
176
firmware_supplied=0;
 
177
target=""
 
178
method=""
 
179
PNOR=""
 
180
LID[0]=""
 
181
LID[1]=""
 
182
LID[2]=""
 
183
while getopts "hvdpB1:2:3:P:t:b:" OPT; do
 
184
    case "$OPT" in
 
185
        v)
 
186
            V=1;
 
187
            ;;
 
188
        h)
 
189
            usage;
 
190
            ;;
 
191
        d)
 
192
            set -vx;
 
193
            ;;
 
194
        B)
 
195
            bootonly=1;
 
196
            if [ $firmware_supplied -eq 1 ]; then
 
197
                usage
 
198
            fi
 
199
            ;;
 
200
        p)
 
201
            powerdown=1;
 
202
            ;;
 
203
        b)
 
204
            method=$OPTARG;
 
205
            ;;
 
206
        1|2|3)
 
207
            firmware_supplied=1;
 
208
            if [ ! -e "$OPTARG" ] ; then
 
209
                error "Couldn't stat $OPTARG";
 
210
            fi
 
211
            LID[$(expr ${OPT} - 1)]="$OPTARG"
 
212
            ;;
 
213
        P)
 
214
            firmware_supplied=1;
 
215
            if [ ! -e "$OPTARG" ] ; then
 
216
                error "Couldn't stat $OPTARG";
 
217
            fi
 
218
            PNOR="$OPTARG"
 
219
            ;;
 
220
        t)
 
221
            target=$OPTARG;
 
222
            ;;
 
223
        \?)
 
224
            usage;
 
225
            ;;
 
226
    esac
 
227
done
 
228
 
 
229
shift $(expr $OPTIND - 1);
 
230
 
 
231
# Pull out the target and test
 
232
if [ "$target" = "" ]; then
 
233
    usage;
 
234
fi
 
235
 
 
236
if ! ping -c 1 "$target" &> /dev/null ; then
 
237
        error "Couldn't ping $target";
 
238
fi
 
239
 
 
240
if [ "$#" -ne 0 ]; then
 
241
    usage
 
242
fi
 
243
 
 
244
 
 
245
# pull in the relevant config file and set things up
 
246
source $(dirname $(readlink -f $0))/${method}_support.sh
 
247
IPMI_COMMAND="ipmitool -I lanplus -H $target $IPMI_AUTH"
 
248
 
 
249
msg "Running sanity test"
 
250
sanity_test
 
251
msg "Passed."
 
252
 
 
253
# check the target is down
 
254
# (pulls in is_off from ${method}_support.sh)
 
255
if ! is_off; then
 
256
    if [ $powerdown -eq 1 ]; then
 
257
        poweroff
 
258
    else
 
259
        error "$target is not turned off";
 
260
    fi
 
261
fi
 
262
 
 
263
force_primary_side # ensure we're booting from side we flash.
 
264
 
 
265
# run the boot test
 
266
echo "$target: Boot testing $target";
 
267
begin_t=$(date +%s);
 
268
boot_test
 
269
 
 
270
echo "$target: Done in $(expr $(date +%s) - $begin_t ) seconds";