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