aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/initscripts/initscripts/luv-test-manager
blob: 84715470dfe0aaf675b0cfad7b11d50719648846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#
# Copyright 2014 Intel Corporation; author Matt Fleming
#

grep -q noluv /proc/cmdline
if [ $? -ne 1 ]; then
    exit 0
fi

FIFO="/mnt/.psplash/psplash_fifo"
psplash_write() {
    if [ -e $FIFO ]; then
	echo $1 > $FIFO
    fi
}

# Save test results to a disk. In order to reliable identify the
# correct partition, mount using the disk's UUID. If the partition
# cannot be mounted, test results are not saved.

LUV_SAVE_RAW_DIR=/dev/null
LUV_SAVE_PARSED_DIR=/dev/null
LUV_SAVE_RESULTS_DIR=/dev/null

LUV_STORAGE=/mnt/luv-storage/
LUV_PARTITION_UUID=05D6-1523
LUV_DISK_DEVICE=/dev/disk/by-uuid/${LUV_PARTITION_UUID}

mkdir -p ${LUV_STORAGE}
if [ $? -eq 0 ]; then
    mount ${LUV_DISK_DEVICE} ${LUV_STORAGE}
    if [ $? -eq 0 ]; then
        LUV_SAVE_RESULTS_DIR=${LUV_STORAGE}luv-results/

        mkdir -p ${LUV_SAVE_RESULTS_DIR}raw/
        [ $? -eq 0 ] && LUV_SAVE_RAW_DIR=${LUV_SAVE_RESULTS_DIR}raw/

        mkdir -p ${LUV_SAVE_RESULTS_DIR}parsed/
        [ $? -eq 0 ] && LUV_SAVE_PARSED_DIR=${LUV_SAVE_RESULTS_DIR}parsed
    fi
fi

LUV_EFI_UUID=423C-C2C8
LUV_EFI=/mnt/luv-efi/

mkdir -p ${LUV_EFI}
if [ $? -eq 0 ]; then
    mount /dev/disk/by-uuid/${LUV_EFI_UUID} ${LUV_EFI}
fi

psplash_write "MSG Running tests..."

luv_version=$(cut -d\\ -f1 /etc/issue)

cat <<EOF
Welcome to ${luv_version}

Running tests...
EOF

#
# Every test must create a runner script and place it in $LUV_TESTS_DIR.
# See meta-luv/classes/luv-test.bbclass for details.
#
# Most also want to provide a testsuite log parser that converts the
# testsuite-specific output into the log schema defined in
# luv-test-parser.
#
LUV_TESTS_DIR=/etc/luv/tests/
LUV_PARSER_DIR=/etc/luv/parsers/
LUV_LOG_DIR=/var/log/luv/

mkdir -p ${LUV_LOG_DIR}

#
# We can't get very accurate progress because we've no way of knowing
# how many unit tests each test suite includes. Use a coarse-grained
# progress step based on the number of test suites.
#
psplash_write "PROGRESS 0"

# Begin the results files by stating the version of luv
cat <<EOF | tee ${LUV_SAVE_RESULTS_DIR}/luv.results > /tmp/luv.results
$luv_version

Test results summary:

EOF

runner_list=`ls -A ${LUV_TESTS_DIR}`

progress_step="$((100/$(echo $runner_list | wc -w)))"
for r in $runner_list; do
    runner="${LUV_TESTS_DIR}$r"

    [ -f "$runner" ] || continue

    psplash_write "PROGRESS $progress_step"
    psplash_write "MSG Running $r"

    parser="${LUV_PARSER_DIR}/$r"
    [ -e ${parser} ] || {
        parser="/bin/cat"
    }

    $runner | tee ${LUV_LOG_DIR}/$r | tee ${LUV_SAVE_RAW_DIR}/$r | $parser | \
              tee ${LUV_SAVE_PARSED_DIR}/$r | ${LUV_PARSER_DIR}/test-manager | \
              tee /dev/console | \
              tee -a /tmp/luv.results | tee -a ${LUV_SAVE_RESULTS_DIR}/luv.results
    sync
done | awk '/      \[\+/ { units += 1 }
    /    \[\-/ { suites += 1 }
    /pass/ { passes += 1 }
    /fail/ { fails += $3 }
    /skip/ { skips += 1 }
    END {
	printf("\nRan %d testsuites and %d unittests, %d passes, %d fails, %d skipped.\n", suites, units, passes, fails, skips)
    }' | tee -a /tmp/luv.results | tee -a ${LUV_SAVE_RESULTS_DIR}/luv.results

mountpoint -q ${LUV_EFI}
if [ $? -eq 0 ]; then
    umount ${LUV_EFI}
fi

mountpoint -q ${LUV_STORAGE}
if [ $? -eq 0 ]; then
    umount ${LUV_STORAGE}
    SAVE_STATUS="Results were saved in your boot media. You may now turn off the system and remove it."
else
    SAVE_STATUS="Results were not saved in storage media."
fi

[ -e $FIFO ] && {
    echo "DONE" > $FIFO
    grep "Ran" /tmp/luv.results | awk '{printf "MSG %s\n%s\n", $0, "'"$SAVE_STATUS"'"}' > $FIFO

    umount -l /mnt/.psplash
}

grep -q luv.halt /proc/cmdline
if [ $? -ne 1 ]; then
    halt -p
fi

REBOOT_TIMEOUT=$((5*60))

timeout_file="/sys/firmware/efi/efivars/LuvTimeout-3b6bf55d-a6f6-45cf-9f7e-ebf3bdadf74e"
[ -e ${timeout_file} ] && {
    REBOOT_TIMEOUT=`hexdump -e '"%08u\n"' ${timeout_file} | tail -n1`
}

grep -q luv.noreboot /proc/cmdline
if [ $? -eq 1 ]; then
    # Put reboot task into background and drop to a shell
    $(sleep ${REBOOT_TIMEOUT} ; reboot)&
fi