blob: 1c324f34ad8399fc7e939b966a79d9fe9ef71742 [file] [log] [blame]
Yegor Timoshenkoc2e49412018-10-07 01:58:27 +00001#!/usr/bin/env bash
Pratik Prajapati0175fb12015-11-18 15:02:19 -08002
3#
4# This file is part of the coreboot project.
5#
6# Copyright (C) 2015 Intel Corporation.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; version 2 of the License.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FIMMA_TEST_NAMEESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17
18MMA_LOCAL_DATA_STORAGE=/usr/local/mma
19#
20# format of MMA_AUTOMATED_TEST_CONFIG file is as below
21# with 1 or more repeated lines with same format
22#
23# <testname> <testparam> <#times to run this test>
24#
25# e.g.
26# RMT.efi RMTConfig.bin 2
27# Margin1D.efi Margin1DCmdAllConfig.bin 1
28#
29#
30MMA_AUTOMATED_TEST_CONFIG="${MMA_LOCAL_DATA_STORAGE}"/tests
31MMA_AUTOMATED_TEST_COUNT="${MMA_LOCAL_DATA_STORAGE}"/count
32MMA_SETUP_TEST_TOOL=mma_setup_test.sh
33MMA_GET_RESULT_TOOL=mma_get_result.sh
34MMA_TEST_RESULTS_PATH="${MMA_LOCAL_DATA_STORAGE}/results$(date +_%y_%m_%d_%H_%M)"
35# Clear MMA_TEST_NUMBER just in case it is set in environment
36MMA_TEST_NUMBER=
37
38# Set a number of global params based on test number
39# MMA_TEST_NUMBER - test number, stored in MMA_AUTOMATED_TEST_COUNT
40# MMA_TEST_NAME - test name
41# MMA_TEST_PARAM - test parameter
42# MMA_TEST_COUNT - test count, number of times to run the test
43# MMA_TEST_RESULT_NAME - filename for result
44get_mma_autotest_params() {
45 typeset -i i=${MMA_TEST_NUMBER}
46 exec 9< "${MMA_AUTOMATED_TEST_CONFIG}"
47 while read -u9 MMA_TEST_NAME MMA_TEST_PARAM MMA_TEST_COUNT
48 do
49 case "${MMA_TEST_NAME}" in
50 ("#"*|"") continue;; # Allow blank lines and comments
51 esac
52 : $(( i -= MMA_TEST_COUNT ))
53 if (( i <= 0 )) ; then
54 printf -v MMA_TEST_RESULT_NAME \
55 "${MMA_TEST_NAME%.efi}_${MMA_TEST_PARAM%.bin}_%d.bin" \
56 $((MMA_TEST_COUNT+i))
57 return
58 fi
59 done
60 ${MMA_SETUP_TEST_TOOL} reset
61 rm "${MMA_AUTOMATED_TEST_COUNT}"
62 mv "${MMA_AUTOMATED_TEST_CONFIG}" "${MMA_TEST_RESULTS_PATH}"
63 exit 0
64}
65
66main() {
Pratik Prajapatide62e0f2016-02-22 16:50:31 -080067 # sleep 30 sec, before we start. This would give some time if we want
68 # to stop automation.
69 sleep 30s
70 mkdir -p "${MMA_LOCAL_DATA_STORAGE}"
Pratik Prajapati0175fb12015-11-18 15:02:19 -080071 # Exit if there are no tests
72 [ -e "${MMA_AUTOMATED_TEST_CONFIG}" ] || exit 0
73
74 if [ -e "${MMA_AUTOMATED_TEST_COUNT}" ] ; then
75 . "${MMA_AUTOMATED_TEST_COUNT}"
76 fi
77
78 mkdir -p "${MMA_TEST_RESULTS_PATH}"
79
80 if [ "${MMA_TEST_NUMBER}" ] ; then
81 get_mma_autotest_params
82 ${MMA_GET_RESULT_TOOL} \
83 "${MMA_TEST_RESULTS_PATH}"/"${MMA_TEST_RESULT_NAME}"
84 fi
85
86 : $(( MMA_TEST_NUMBER += 1 ))
87 printf "MMA_TEST_NUMBER=${MMA_TEST_NUMBER}\n" \
88 > "${MMA_AUTOMATED_TEST_COUNT}"
89 printf "MMA_TEST_RESULTS_PATH=%s" "${MMA_TEST_RESULTS_PATH}" \
90 >> "${MMA_AUTOMATED_TEST_COUNT}"
91 get_mma_autotest_params
92 ${MMA_SETUP_TEST_TOOL} set ${MMA_TEST_NAME} ${MMA_TEST_PARAM}
93
Pratik Prajapatide62e0f2016-02-22 16:50:31 -080094 # sync the filesystem, hoping this would minimize
95 # the chances of fs corruption
96 sync
97 sleep 2s
98 sync
99 sleep 2s
100 sync
101 sleep 2s
102 ectool reboot_ec
Pratik Prajapati0175fb12015-11-18 15:02:19 -0800103}
104
105main "$@"