blob: a2c53eccdedb3adbe830633be82e140350cc25ad [file] [log] [blame]
Alex Thiessen52fdc052018-01-05 05:07:23 +00001#!/bin/bash
2
3##
4## This file is part of the coreboot project.
5##
6## Copyright (C) 2003-2018 Alex Thiessen <alex.thiessen.de+coreboot@gmail.com>
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 3 or later 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 FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## SPDX-License-Identifier: GPL-3.0-or-later
18## <https://spdx.org/licenses/GPL-3.0-or-later.html>
19##
20
21set -o errexit
22set -o nounset
23
24# static analysis
25if command -v shellcheck 1>/dev/null; then
26 shellcheck --exclude=1090,1091 \
27 "${BASH_SOURCE[0]}" \
28 "$(dirname "${BASH_SOURCE[0]}")/helpers.sh"
29else
30 echo "shellcheck not found, running unchecked" >&2
31fi
32
33# dependency check
34dependencies=(dirname git make mktemp rm timeout)
35for dependency in "${dependencies[@]}"; do
36 if ! command -v "${dependency}" 1>/dev/null; then
37 echo "missing ${dependency}, test skipped" >&2
38 exit 0
39 fi
40done
41
42source "$(dirname "${BASH_SOURCE[0]}")/helpers.sh"
43
44# setup
45base_dir="$(mktemp --directory --tmpdir \
46 "test-$(basename "${BASH_SOURCE[0]}" .sh)-XXXXXXXX")"
47clone_dir="${base_dir}/coreboot"
48git clone "$(git rev-parse --show-toplevel)" "${clone_dir}" \
49 1>"${base_dir}/clone.log" 2>&1
50
51(
52 set -o errexit
53 set -o nounset
54
55 clone_submodules "${clone_dir}" "${base_dir}"
56 git config user.name "John Doe"
57 git config user.email "john.doe@example.com"
58 make gitconfig
59
60 # test
61 echo "good case..."
62 log_file="${base_dir}/good_case.log"
63 echo "this is a test" >> README
64 timeout 4m git commit --all --signoff --message="good case" \
65 1>"${log_file}" 2>&1 \
66 || check_exit_code positive "${log_file}"
67 git reset --hard --quiet HEAD^
68 git clean -d --force --quiet -x
69
70 echo "bad case..."
71 log_file="${base_dir}/bad_case.log"
72 # Goal here is to verify whether a failing `util/lint` test will prevent
73 # a commit. It's a bit tricky because `checkpatch.pl` is run just after
74 # the lint tests and will cover many of those too. So we need a case
75 # that fails with `util/lint` but succeeds with `checkpatch.pl`. I found
76 # that `lint-stable-009-old-licenses` does the job quite well.
77 printf "You should have received a copy of the %s\n" "GNU" > src/test.c
78 git add src/test.c
79 timeout 4m git commit --signoff --message="bad case" \
80 1>"${log_file}" 2>&1 \
81 && check_exit_code negative "${log_file}"
82 git rm --force --quiet src/test.c
83 git clean -d --force --quiet -x
84)
85
86# teardown
87rm --force --recursive "${base_dir}"