Upgrade autogen to NICs and search types
[csit.git] / resources / libraries / bash / entry / check / autogen.sh
1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 set -exuo pipefail
15
16 # This file should be executed from tox, as the assumend working directory
17 # is different from where this file is located.
18 # This file does not have executable flag nor shebang,
19 # to dissuade non-tox callers.
20
21 # This script starts with copying ${CSIT_DIR}/tests to ${GENERATED_DIR}/.
22 # Then the script runs every executable *.py script anywhere in the copied dir,
23 # the working directory temporarily changed to where the *.py file is.
24 # Proper virtualenv is assumed to be active.
25 # Then another directory in ${GENERATED_DIR} is created, where
26 # the just generated content is copied and then overwitten by the non-generated.
27 # If "diff -dur" sees any changes by the overwrite, this script fails.
28 # The diff output is stored to autogen.log (overwriting).
29 # The executed *.py files are assumed to be robot suite generators,
30 # any change means the contribution is not consistent with the regenerated code.
31
32 # "set -eu" handles failures from the following two lines.
33 BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
34 BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")"
35 source "${BASH_FUNCTION_DIR}/common.sh" || {
36     echo "Source failed." >&2
37     exit 1
38 }
39 common_dirs
40 work_dir="$(pwd)" || die
41 trap "cd '${work_dir}'" EXIT || die
42
43 generate_tests
44
45 rm -rf "${GENERATED_DIR}/tests_tmp"
46 cp -r "${GENERATED_DIR}/tests" "${GENERATED_DIR}/tests_tmp"
47 # Default cp behavior is to put inside a targed dir, not to override.
48 cp -rf "${CSIT_DIR}/tests"/* "${GENERATED_DIR}/tests_tmp"/
49 # TODO: Do we want to archive ${GENERATED_DIR}?
50 # I think archiving the diff is enough.
51
52 diff_cmd=("diff" "-dur" "${GENERATED_DIR}/tests_tmp" "${GENERATED_DIR}/tests")
53 lines="$("${diff_cmd[@]}" | tee "autogen.log" | wc -l)" || die
54 if [ "${lines}" != "0" ]; then
55     # TODO: Decide which text goes to stdout and which to stderr.
56     warn "Autogen conflict diff nonzero lines: ${lines}"
57     # TODO: Disable if output size does more harm than good.
58     cat "autogen.log" >&2
59     warn
60     warn "Autogen checker: FAIL"
61     exit 1
62 fi
63
64 warn
65 warn "Autogen checker: PASS"