xref: /aosp_15_r20/external/perfetto/infra/ci/sandbox/testrunner.sh (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker#!/bin/bash
2*6dbdd20aSAndroid Build Coastguard Worker# Copyright (C) 2019 The Android Open Source Project
3*6dbdd20aSAndroid Build Coastguard Worker#
4*6dbdd20aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
5*6dbdd20aSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
6*6dbdd20aSAndroid Build Coastguard Worker# You may obtain a copy of the License at
7*6dbdd20aSAndroid Build Coastguard Worker#
8*6dbdd20aSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
9*6dbdd20aSAndroid Build Coastguard Worker#
10*6dbdd20aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
11*6dbdd20aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
12*6dbdd20aSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*6dbdd20aSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
14*6dbdd20aSAndroid Build Coastguard Worker# limitations under the License.
15*6dbdd20aSAndroid Build Coastguard Worker
16*6dbdd20aSAndroid Build Coastguard Worker# Should code live in this script or in the PERFETTO_TEST_SCRIPT script?
17*6dbdd20aSAndroid Build Coastguard Worker# You might argue: after all they are both part of the same repo? The difference
18*6dbdd20aSAndroid Build Coastguard Worker# is in temporal pinning.
19*6dbdd20aSAndroid Build Coastguard Worker# Code in this script is part of the Docker image that is manually pushed
20*6dbdd20aSAndroid Build Coastguard Worker# on the VMs. Everything in here is orthogonal to the evolution of the repo.
21*6dbdd20aSAndroid Build Coastguard Worker# Everything from /ramdisk instead will reflect the state of the repo at the
22*6dbdd20aSAndroid Build Coastguard Worker# point in time of the checkout.
23*6dbdd20aSAndroid Build Coastguard Worker# Things like script that upload performance data to dashboarads should probably
24*6dbdd20aSAndroid Build Coastguard Worker# be in the docker image. Things that depend on build artifacts should probably
25*6dbdd20aSAndroid Build Coastguard Worker# come from the repo.
26*6dbdd20aSAndroid Build Coastguard Worker
27*6dbdd20aSAndroid Build Coastguard Workerset -eux
28*6dbdd20aSAndroid Build Coastguard Worker
29*6dbdd20aSAndroid Build Coastguard Worker# CWD is /ci/ramdisk. In the CI this is based on a tmpfs ramdisk.
30*6dbdd20aSAndroid Build Coastguard Worker
31*6dbdd20aSAndroid Build Coastguard Worker# Print env vars for debugging. They contain GN args and entrypoint.
32*6dbdd20aSAndroid Build Coastguard Workerdate
33*6dbdd20aSAndroid Build Coastguard Workerhostname
34*6dbdd20aSAndroid Build Coastguard Workerenv
35*6dbdd20aSAndroid Build Coastguard Worker
36*6dbdd20aSAndroid Build Coastguard Workermkdir src && cd src
37*6dbdd20aSAndroid Build Coastguard Worker
38*6dbdd20aSAndroid Build Coastguard Workerif [[ -f "$PERFETTO_TEST_GIT_REF" ]]; then
39*6dbdd20aSAndroid Build Coastguard Worker# This is used only by tools/run_test_like_ci.
40*6dbdd20aSAndroid Build Coastguard Workergit clone -q --no-tags --single-branch --depth=1 "$PERFETTO_TEST_GIT_REF" .
41*6dbdd20aSAndroid Build Coastguard Workerelse
42*6dbdd20aSAndroid Build Coastguard Workergit clone -q --no-tags --single-branch \
43*6dbdd20aSAndroid Build Coastguard Worker  https://android.googlesource.com/platform/external/perfetto.git .
44*6dbdd20aSAndroid Build Coastguard Workergit config user.email "[email protected]"
45*6dbdd20aSAndroid Build Coastguard Workergit config user.name "Perfetto CI"
46*6dbdd20aSAndroid Build Coastguard Workergit fetch -q origin "$PERFETTO_TEST_GIT_REF"
47*6dbdd20aSAndroid Build Coastguard Worker
48*6dbdd20aSAndroid Build Coastguard Worker# We really want to test the result of the merge of the CL in ToT main. Don't
49*6dbdd20aSAndroid Build Coastguard Worker# really care about whether the CL passes the test at the time it was written.
50*6dbdd20aSAndroid Build Coastguard Workergit merge -q FETCH_HEAD -m merge
51*6dbdd20aSAndroid Build Coastguard Workerfi
52*6dbdd20aSAndroid Build Coastguard Worker
53*6dbdd20aSAndroid Build Coastguard Worker# The android buildtools are huge due to the emulator, keep that as a separate
54*6dbdd20aSAndroid Build Coastguard Worker# cache and pack/unpack separately. It's worth  ~30s on each non-android test.
55*6dbdd20aSAndroid Build Coastguard Workerif [[ "$PERFETTO_TEST_GN_ARGS" =~ "android" ]]; then
56*6dbdd20aSAndroid Build Coastguard WorkerPREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d)-android.tar.lz4
57*6dbdd20aSAndroid Build Coastguard Workerelse
58*6dbdd20aSAndroid Build Coastguard WorkerPREBUILTS_ARCHIVE=/ci/cache/buildtools-$(date +%Y-%m-%d).tar.lz4
59*6dbdd20aSAndroid Build Coastguard Workerfi
60*6dbdd20aSAndroid Build Coastguard Worker
61*6dbdd20aSAndroid Build Coastguard Worker# Clear stale buildtools caches after 24h.
62*6dbdd20aSAndroid Build Coastguard Worker(echo /ci/cache/buildtools-* | grep -v $PREBUILTS_ARCHIVE | xargs rm -f) || true
63*6dbdd20aSAndroid Build Coastguard Worker
64*6dbdd20aSAndroid Build Coastguard Workerif [ -f $PREBUILTS_ARCHIVE ]; then
65*6dbdd20aSAndroid Build Coastguard Worker  lz4 -d $PREBUILTS_ARCHIVE | tar xf - || rm -f $PREBUILTS_ARCHIVE
66*6dbdd20aSAndroid Build Coastguard Worker  git reset --hard  # Just in case some versioned file gets overwritten.
67*6dbdd20aSAndroid Build Coastguard Workerfi
68*6dbdd20aSAndroid Build Coastguard Worker
69*6dbdd20aSAndroid Build Coastguard Worker
70*6dbdd20aSAndroid Build Coastguard Worker# By default ccache uses the mtime of the compiler. This doesn't work because
71*6dbdd20aSAndroid Build Coastguard Worker# our compilers are hermetic and their mtime is the time when we run
72*6dbdd20aSAndroid Build Coastguard Worker# install-build-deps. Given that the toolchain is rolled via install-build-deps
73*6dbdd20aSAndroid Build Coastguard Worker# we use that file as an identity function for the compiler check.
74*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_COMPILERCHECK=string:$(shasum tools/install-build-deps)
75*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_UMASK=000
76*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_DEPEND=1
77*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_MAXSIZE=32G
78*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_DIR=/ci/cache/ccache
79*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime
80*6dbdd20aSAndroid Build Coastguard Workerexport CCACHE_NOCOMPRESS=1
81*6dbdd20aSAndroid Build Coastguard Workermkdir -m 777 -p $CCACHE_DIR
82*6dbdd20aSAndroid Build Coastguard Worker
83*6dbdd20aSAndroid Build Coastguard Workerexport PERFETTO_TEST_GN_ARGS="${PERFETTO_TEST_GN_ARGS} cc_wrapper=\"ccache\""
84*6dbdd20aSAndroid Build Coastguard Worker
85*6dbdd20aSAndroid Build Coastguard Workerexport PERFETTO_TEST_NINJA_ARGS=""
86*6dbdd20aSAndroid Build Coastguard Worker$PERFETTO_TEST_SCRIPT
87*6dbdd20aSAndroid Build Coastguard Worker
88*6dbdd20aSAndroid Build Coastguard Worker# The code after this point will NOT run if the test fails (because of set -e).
89*6dbdd20aSAndroid Build Coastguard Worker
90*6dbdd20aSAndroid Build Coastguard Workerccache --show-stats
91*6dbdd20aSAndroid Build Coastguard Worker
92*6dbdd20aSAndroid Build Coastguard Worker# Populate the cache on the first run. Do that atomically so in case of races
93*6dbdd20aSAndroid Build Coastguard Worker# one random worker wins.
94*6dbdd20aSAndroid Build Coastguard Workerif [ ! -f $PREBUILTS_ARCHIVE ]; then
95*6dbdd20aSAndroid Build Coastguard Worker  TMPFILE=/ci/cache/buildtools-$(hostname -s).tar.lz4
96*6dbdd20aSAndroid Build Coastguard Worker  # Add only git-ignored dirs to the cache.
97*6dbdd20aSAndroid Build Coastguard Worker  git check-ignore buildtools/* | xargs tar c | lz4 -z - "$TMPFILE"
98*6dbdd20aSAndroid Build Coastguard Worker  mv -f "$TMPFILE" $PREBUILTS_ARCHIVE
99*6dbdd20aSAndroid Build Coastguard Workerfi
100