1. "${CI_DIR}/common/build.sh"
2. "${CI_DIR}/common/suite.sh"
3
4submit_coverage() {
5  if [ -n "${GCOV}" ]; then
6    "${CI_DIR}/common/submit_coverage.sh" "$@" || echo 'codecov upload failed.'
7  fi
8}
9
10print_core() {
11  local app="$1"
12  local core="$2"
13  if test "$app" = quiet ; then
14    echo "Found core $core"
15    return 0
16  fi
17  echo "======= Core file $core ======="
18  if test "${CI_OS_NAME}" = osx ; then
19    lldb -Q -o "bt all" -f "${app}" -c "${core}"
20  else
21    gdb -n -batch -ex 'thread apply all bt full' "${app}" -c "${core}"
22  fi
23}
24
25check_core_dumps() {
26  local del=
27  if test "$1" = "--delete" ; then
28    del=1
29    shift
30  fi
31  local app="${1:-${BUILD_DIR}/bin/nvim}"
32  local cores
33  if test "${CI_OS_NAME}" = osx ; then
34    cores="$(find /cores/ -type f -print)"
35    local _sudo='sudo'
36  else
37    cores="$(find ./ -type f \( -name 'core.*' -o -name core -o -name nvim.core \) -print)"
38    local _sudo=
39  fi
40
41  if test -z "${cores}" ; then
42    return
43  fi
44  local core
45  for core in $cores; do
46    if test "$del" = "1" ; then
47      print_core "$app" "$core" >&2
48      "$_sudo" rm "$core"
49    else
50      print_core "$app" "$core"
51    fi
52  done
53  if test "$app" != quiet ; then
54    fail 'cores' E 'Core dumps found'
55  fi
56}
57
58check_logs() {
59  # Iterate through each log to remove an useless warning.
60  for log in $(find "${1}" -type f -name "${2}"); do
61    sed -i "${log}" \
62      -e '/Warning: noted but unhandled ioctl/d' \
63      -e '/could cause spurious value errors to appear/d' \
64      -e '/See README_MISSING_SYSCALL_OR_IOCTL for guidance/d'
65  done
66
67  # Now do it again, but only consider files with size > 0.
68  local err=""
69  for log in $(find "${1}" -type f -name "${2}" -size +0); do
70    cat "${log}"
71    err=1
72    rm "${log}"
73  done
74  if test -n "${err}" ; then
75    fail 'logs' E 'Runtime errors detected.'
76  fi
77}
78
79valgrind_check() {
80  check_logs "${1}" "valgrind-*"
81}
82
83check_sanitizer() {
84  if test -n "${CLANG_SANITIZER}"; then
85    check_logs "${1}" "*san.*" | ${SYMBOLIZER:-cat}
86  fi
87}
88
89run_unittests() {(
90  enter_suite unittests
91  ulimit -c unlimited || true
92  if ! build_make unittest ; then
93    fail 'unittests' F 'Unit tests failed'
94  fi
95  submit_coverage unittest
96  check_core_dumps "$(command -v luajit)"
97  exit_suite
98)}
99
100run_functionaltests() {(
101  enter_suite functionaltests
102  ulimit -c unlimited || true
103  if ! build_make ${FUNCTIONALTEST}; then
104    fail 'functionaltests' F 'Functional tests failed'
105  fi
106  submit_coverage functionaltest
107  check_sanitizer "${LOG_DIR}"
108  valgrind_check "${LOG_DIR}"
109  check_core_dumps
110  exit_suite
111)}
112
113run_oldtests() {(
114  enter_suite oldtests
115  ulimit -c unlimited || true
116  if ! make oldtest; then
117    reset
118    fail 'oldtests' F 'Legacy tests failed'
119  fi
120  submit_coverage oldtest
121  check_sanitizer "${LOG_DIR}"
122  valgrind_check "${LOG_DIR}"
123  check_core_dumps
124  exit_suite
125)}
126
127check_runtime_files() {(
128  set +x
129  local test_name="$1" ; shift
130  local message="$1" ; shift
131  local tst="$1" ; shift
132
133  cd runtime
134  for file in $(git ls-files "$@") ; do
135    # Check that test is not trying to work with files with spaces/etc
136    # Prefer failing the build over using more robust construct because files
137    # with IFS are not welcome.
138    if ! test -e "$file" ; then
139      fail "$test_name" E \
140        "It appears that $file is only a part of the file name"
141    fi
142    if ! test "$tst" "$INSTALL_PREFIX/share/nvim/runtime/$file" ; then
143      fail "$test_name" F "$(printf "$message" "$file")"
144    fi
145  done
146)}
147
148install_nvim() {(
149  enter_suite 'install_nvim'
150  if ! build_make install ; then
151    fail 'install' E 'make install failed'
152    exit_suite
153  fi
154
155  "${INSTALL_PREFIX}/bin/nvim" --version
156  if ! "${INSTALL_PREFIX}/bin/nvim" -u NONE -e -c ':help' -c ':qall' ; then
157    echo "Running ':help' in the installed nvim failed."
158    echo "Maybe the helptags have not been generated properly."
159    fail 'help' F 'Failed running :help'
160  fi
161
162  # Check that all runtime files were installed
163  check_runtime_files \
164    'runtime-install' \
165    'It appears that %s is not installed.' \
166    -e \
167    '*.vim' '*.ps' '*.dict' '*.py' '*.tutor'
168
169  # Check that some runtime files are installed and are executables
170  check_runtime_files \
171    'not-exe' \
172    'It appears that %s is not installed or is not executable.' \
173    -x \
174    '*.awk' '*.sh' '*.bat'
175
176  # Check that generated syntax file has function names, #5060.
177  local genvimsynf=syntax/vim/generated.vim
178  local gpat='syn keyword vimFuncName .*eval'
179  if ! grep -q "$gpat" "${INSTALL_PREFIX}/share/nvim/runtime/$genvimsynf" ; then
180    fail 'funcnames' F "It appears that $genvimsynf does not contain $gpat."
181  fi
182
183  exit_suite
184)}
185
186csi_clean() {
187  find "${BUILD_DIR}/bin" -name 'test-includes-*' -delete
188  find "${BUILD_DIR}" -name '*test-include*.o' -delete
189}
190