xref: /aosp_15_r20/external/libchrome-gestures/tools/regression_test.sh (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1#!/bin/bash
2
3# Copyright 2012 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Script to run the gesture regression test and check if there is any
8# regression for each submit.
9
10# Exit on errors.
11set -eu
12
13# Set current directory to the project one and load the common script.
14pushd . >/dev/null
15cd "$(dirname "$(readlink -f "$0")")/.."
16. "../../scripts/common.sh" || exit 1
17
18update_chroot_library() {
19  library=$1
20  version=$2
21  project=$3
22  info "Check chroot $library version ${version}..."
23
24  if ! grep -q ${version} /usr/lib/${library} ; then
25    info "Update the library ${library} under chroot.."
26    sudo emerge -q ${project}
27    info grep ${version} /usr/lib/${library}
28    if ! grep -q ${version} /usr/lib/${library} ; then
29      die_notrace "Can not install ${library} successfully"
30    fi
31  fi
32}
33
34install_regression_test_suite() {
35  info "Install regression test suite first..."
36  sudo emerge -q gestures chromeos-base/libevdev utouch-evemu -j3
37  pushd ~/chromiumos/src/platform/touchpad-tests >/dev/null
38  make -j${NUM_JOBS} -s all
39  sudo make -s local-install
40  popd >/dev/null
41}
42
43run_regression_tests() {
44  info "Running regression tests..."
45  if ! type touchtests > /dev/null; then
46    die_notrace \
47      "The touchtests aren't installed in your chroot. Please install them: "\
48      "https://chromium.googlesource.com/chromiumos/platform/touchpad-tests/+/HEAD/README.md#Setting-up"
49  fi
50  if ! touchtests --presubmit --ref tools/touchtests-report.json; then
51    die_notrace "Regression tests failed."
52  fi
53}
54
55check_test_setup() {
56  if [[ ! -e  /usr/lib/libgestures.so ]]; then
57    install_regression_test_suite
58  else
59    update_chroot_library libgestures.so ${libgestures_head_hash} gestures
60    update_chroot_library libevdev-cros.so ${libevdev_head_hash} \
61      chromeos-base/libevdev
62  fi
63}
64
65libevdev_head_hash=`cd ../libevdev; git rev-parse HEAD`
66libgestures_head_hash=`git rev-parse HEAD`
67if [[ ${INSIDE_CHROOT} -ne 1 ]]; then
68  if [[ "${PRESUBMIT_COMMIT}" == "${libgestures_head_hash}" ]]; then
69    popd >/dev/null
70    restart_in_chroot_if_needed "$@"
71  fi
72else
73  cros_workon --host start gestures chromeos-base/libevdev
74  check_test_setup
75  run_regression_tests
76  popd >/dev/null
77fi
78exit 0
79