• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2021 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5set -e
6
7cd "$(dirname $0)/.."
8
9HELP="This will run presubmit checks for crosvm.
10
11To run all checks just run
12
13    $ ./tools/presubmit
14
15The checks can be run in parallel for faster execution:
16
17    $ ./tools/presubmit --tmux
18
19This will open a tmux session to run all presubmit builds in parallel. It will
20create a nested tmux session if you are already using it.
21
22All tests are executed in the local development environment. If your host is not
23set up for aarch64 builds, it will use './tools/dev_container' to build run
24those.
25
26There are three levels of presubmit tests that can be run:
27
28    $ ./tools/presubmit --quick
29    $ ./tools/presubmit
30    $ ./tools/presubmit --all
31
32The quick mode will only cover x86 and does not require a dev_container. The
33default mode will add aarch64 tests, and the all mode will test everything that
34is also tested on Kokoro.
35"
36
37while [[ $# -gt 0 ]]; do
38    case "$1" in
39    -q | --quick)
40        QUICK=true
41        shift
42        ;;
43    -a | --all)
44        ALL=true
45        shift
46        ;;
47    --tmux)
48        RUN_IN_TMUX=true
49        shift
50        ;;
51    -h | --help)
52        echo "$HELP"
53        exit 0
54        shift
55        ;;
56    *)
57        echo "unknown argument $1"
58        exit 1
59        ;;
60    esac
61done
62
63run_commands_in_tmux() {
64    local tmux_commands=(
65        set-option -g default-shell /bin/bash \;
66        new-session "$1; read -p 'Press enter to close.'" \;
67    )
68    for cmd in "${@:2}"; do
69        tmux_commands+=(
70            split-window -h "$cmd; read -p 'Press enter to close.'" \;
71        )
72    done
73    tmux_commands+=(
74        select-layout even-horizontal \;
75    )
76    TMUX="" tmux "${tmux_commands[@]}"
77}
78
79run_commands() {
80    for cmd in "$@"; do
81        echo "$ ${cmd}"
82        bash -c "$cmd"
83        echo
84    done
85}
86
87aarch64_wrapper() {
88    if ! (rustup target list --installed | grep -q aarch64 &&
89        dpkg --print-foreign-architectures | grep -q arm64); then
90        echo "./tools/dev_container"
91    fi
92}
93
94commands=(
95    "./tools/fmt --check && ./tools/clippy"
96    "./tools/run_tests --target=host"
97)
98
99if [ "$ALL" == true ]; then
100    commands+=(
101        "$(aarch64_wrapper) ./tools/run_tests --target=vm:aarch64"
102        "$(aarch64_wrapper) ./tools/run_tests --target=vm:aarch64 --arch=armhf"
103        "./tools/run_tests --target=host --arch=win64 --build-only"
104        "cargo build --verbose --no-default-features"
105    )
106elif [ "$QUICK" != true ]; then
107    commands+=(
108        # Test via user-space emulation for faster, but less complete results.
109        "$(aarch64_wrapper) ./tools/run_tests --target=host --arch=aarch64"
110        "./tools/run_tests --target=host --arch=win64 --build-only"
111    )
112fi
113
114if [ "$RUN_IN_TMUX" = true ]; then
115    run_commands_in_tmux "${commands[@]}"
116else
117    run_commands "${commands[@]}"
118fi
119