xref: /aosp_15_r20/external/perfetto/docs/contributing/testing.md (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker# Running tests
2*6dbdd20aSAndroid Build Coastguard Worker
3*6dbdd20aSAndroid Build Coastguard WorkerThe testing strategy for Perfetto is rather complex due to the wide variety
4*6dbdd20aSAndroid Build Coastguard Workerof build configurations and embedding targets.
5*6dbdd20aSAndroid Build Coastguard Worker
6*6dbdd20aSAndroid Build Coastguard WorkerCommon test targets (all platforms / checkouts):
7*6dbdd20aSAndroid Build Coastguard Worker
8*6dbdd20aSAndroid Build Coastguard Worker`perfetto_unittests`:
9*6dbdd20aSAndroid Build Coastguard WorkerPlatform-agnostic unit-tests.
10*6dbdd20aSAndroid Build Coastguard Worker
11*6dbdd20aSAndroid Build Coastguard Worker`perfetto_integrationtests`:
12*6dbdd20aSAndroid Build Coastguard WorkerEnd-to-end tests, involving the protobuf-based IPC transport and ftrace
13*6dbdd20aSAndroid Build Coastguard Workerintegration (Linux/Android only).
14*6dbdd20aSAndroid Build Coastguard Worker
15*6dbdd20aSAndroid Build Coastguard Worker`perfetto_benchmarks`:
16*6dbdd20aSAndroid Build Coastguard WorkerBenchmarks tracking the performance of: (i) trace writing, (ii) trace readback
17*6dbdd20aSAndroid Build Coastguard Workerand (iii) ftrace raw pipe -> protobuf translation.
18*6dbdd20aSAndroid Build Coastguard Worker
19*6dbdd20aSAndroid Build Coastguard WorkerRunning tests on Linux / MacOS
20*6dbdd20aSAndroid Build Coastguard Worker------------------------------
21*6dbdd20aSAndroid Build Coastguard Worker
22*6dbdd20aSAndroid Build Coastguard Worker```bash
23*6dbdd20aSAndroid Build Coastguard Workertools/ninja -C out/default perfetto_{unittests,integrationtests,benchmarks}
24*6dbdd20aSAndroid Build Coastguard Workerout/default/perfetto_unittests --gtest_help
25*6dbdd20aSAndroid Build Coastguard Worker```
26*6dbdd20aSAndroid Build Coastguard Worker
27*6dbdd20aSAndroid Build Coastguard Worker`perfetto_integrationtests` requires that the ftrace debugfs directory is
28*6dbdd20aSAndroid Build Coastguard Workeris readable/writable by the current user on Linux:
29*6dbdd20aSAndroid Build Coastguard Worker```bash
30*6dbdd20aSAndroid Build Coastguard Workersudo chown  -R $USER /sys/kernel/debug/tracing
31*6dbdd20aSAndroid Build Coastguard Worker```
32*6dbdd20aSAndroid Build Coastguard Worker
33*6dbdd20aSAndroid Build Coastguard WorkerRunning tests on Android
34*6dbdd20aSAndroid Build Coastguard Worker------------------------
35*6dbdd20aSAndroid Build Coastguard Worker1A) Connect a device through `adb`
36*6dbdd20aSAndroid Build Coastguard Worker1B) Start the build-in emulator (supported on Linux and MacOS):
37*6dbdd20aSAndroid Build Coastguard Worker
38*6dbdd20aSAndroid Build Coastguard Worker```bash
39*6dbdd20aSAndroid Build Coastguard Workertools/install-build-deps --android
40*6dbdd20aSAndroid Build Coastguard Workertools/run_android_emulator &
41*6dbdd20aSAndroid Build Coastguard Worker```
42*6dbdd20aSAndroid Build Coastguard Worker
43*6dbdd20aSAndroid Build Coastguard Worker2) Run the tests (either on the emulator or physical device):
44*6dbdd20aSAndroid Build Coastguard Worker
45*6dbdd20aSAndroid Build Coastguard Worker```bash
46*6dbdd20aSAndroid Build Coastguard Workertools/run_android_test out/default perfetto_unittests
47*6dbdd20aSAndroid Build Coastguard Worker```
48*6dbdd20aSAndroid Build Coastguard Worker
49*6dbdd20aSAndroid Build Coastguard WorkerContinuous testing
50*6dbdd20aSAndroid Build Coastguard Worker------------------
51*6dbdd20aSAndroid Build Coastguard WorkerPerfetto is tested in a variety of locations:
52*6dbdd20aSAndroid Build Coastguard Worker
53*6dbdd20aSAndroid Build Coastguard Worker**Perfetto CI**: https://ci.perfetto.dev/
54*6dbdd20aSAndroid Build Coastguard WorkerBuilds and runs perfetto_{unittests,integrationtests,benchmarks} from the
55*6dbdd20aSAndroid Build Coastguard Workerstandalone checkout. Benchmarks are ran in a reduced form for smoke testing.
56*6dbdd20aSAndroid Build Coastguard WorkerSee [this doc](/docs/design-docs/continuous-integration.md) for more details.
57*6dbdd20aSAndroid Build Coastguard Worker
58*6dbdd20aSAndroid Build Coastguard Worker**Android CI** (see go/apct and go/apct-guide):
59*6dbdd20aSAndroid Build Coastguard Workerruns only `perfetto_integrationtests`
60*6dbdd20aSAndroid Build Coastguard Worker
61*6dbdd20aSAndroid Build Coastguard Worker**Android presubmits (TreeHugger)**:
62*6dbdd20aSAndroid Build Coastguard WorkerRuns before submission of every AOSP CL of `external/perfetto`.
63*6dbdd20aSAndroid Build Coastguard Worker
64*6dbdd20aSAndroid Build Coastguard Worker**Android CTS** (Android test suite used run to ensure API compatibility):
65*6dbdd20aSAndroid Build Coastguard WorkerRolling runs internally.
66*6dbdd20aSAndroid Build Coastguard Worker
67*6dbdd20aSAndroid Build Coastguard WorkerNote that Perfetto CI uses the standalone build system and the others build as
68*6dbdd20aSAndroid Build Coastguard Workerpart of the Android tree.
69*6dbdd20aSAndroid Build Coastguard Worker
70*6dbdd20aSAndroid Build Coastguard WorkerUnit tests
71*6dbdd20aSAndroid Build Coastguard Worker----------
72*6dbdd20aSAndroid Build Coastguard WorkerUnit tests exist for most of the code in Perfetto on the class level. They
73*6dbdd20aSAndroid Build Coastguard Workerensure that each class broadly works as expected.
74*6dbdd20aSAndroid Build Coastguard Worker
75*6dbdd20aSAndroid Build Coastguard WorkerUnit tests are currently ran on ci.perfetto.dev and build.chromium.org.
76*6dbdd20aSAndroid Build Coastguard WorkerRunning unit tests on APCT and Treehugger is WIP.
77*6dbdd20aSAndroid Build Coastguard Worker
78*6dbdd20aSAndroid Build Coastguard WorkerIntegration tests
79*6dbdd20aSAndroid Build Coastguard Worker-----------------
80*6dbdd20aSAndroid Build Coastguard WorkerIntegration tests ensure that subsystems (importantly ftrace and the IPC layer)
81*6dbdd20aSAndroid Build Coastguard Workerand Perfetto as a whole is working correctly end-to-end.
82*6dbdd20aSAndroid Build Coastguard Worker
83*6dbdd20aSAndroid Build Coastguard WorkerThere are two configurations in which integration tests can be run:
84*6dbdd20aSAndroid Build Coastguard Worker
85*6dbdd20aSAndroid Build Coastguard Worker**1. Production mode** (Android-only)
86*6dbdd20aSAndroid Build Coastguard WorkerThis mode assumes that both the tracing service (`traced`) and the OS probes
87*6dbdd20aSAndroid Build Coastguard Workerservice (`traced_probes`) are already running. In this mode the test enables
88*6dbdd20aSAndroid Build Coastguard Workeronly the consumer endpoint and tests the interaction with the production
89*6dbdd20aSAndroid Build Coastguard Workerservices. This is the way our Android CTS and APCT tests work.
90*6dbdd20aSAndroid Build Coastguard Worker
91*6dbdd20aSAndroid Build Coastguard Worker**2. Standalone mode**:
92*6dbdd20aSAndroid Build Coastguard WorkerStarting up the daemons in the test itself and then testing against them.
93*6dbdd20aSAndroid Build Coastguard WorkerThis is how standalone builds are tested. This is the only supported way to
94*6dbdd20aSAndroid Build Coastguard Workerrun integration tests on Linux and MacOS.
95*6dbdd20aSAndroid Build Coastguard Worker
96*6dbdd20aSAndroid Build Coastguard WorkerTrace Processor diff tests
97*6dbdd20aSAndroid Build Coastguard Worker-----------------
98*6dbdd20aSAndroid Build Coastguard WorkerTrace processor is mainly tested using so called "diff tests".
99*6dbdd20aSAndroid Build Coastguard Worker
100*6dbdd20aSAndroid Build Coastguard WorkerFor these tests, trace processor parses a known trace and executes a query
101*6dbdd20aSAndroid Build Coastguard Workerstring or file. The output of these queries is then compared (i.e. "diff"ed) against
102*6dbdd20aSAndroid Build Coastguard Workeran expected output file and discrepencies are highlighted.
103*6dbdd20aSAndroid Build Coastguard Worker
104*6dbdd20aSAndroid Build Coastguard WorkerSimilar diff tests are also available when writing metrics - instead of a
105*6dbdd20aSAndroid Build Coastguard Workerquery, the metric name is used and the expected output string contains
106*6dbdd20aSAndroid Build Coastguard Workerthe expected result of computing the metric.
107*6dbdd20aSAndroid Build Coastguard Worker
108*6dbdd20aSAndroid Build Coastguard WorkerThese tests (for both queries and metrics) can be run as follows:
109*6dbdd20aSAndroid Build Coastguard Worker```bash
110*6dbdd20aSAndroid Build Coastguard Workertools/ninja -C <out directory>
111*6dbdd20aSAndroid Build Coastguard Workertools/diff_test_trace_processor.py <out directory>/trace_processor_shell
112*6dbdd20aSAndroid Build Coastguard Worker```
113*6dbdd20aSAndroid Build Coastguard Worker
114*6dbdd20aSAndroid Build Coastguard WorkerTIP: Query diff tests are expected to only have a single query which produces
115*6dbdd20aSAndroid Build Coastguard Workeroutput in the whole file (usually at the end). Calling
116*6dbdd20aSAndroid Build Coastguard Worker`SELECT RUN_METRIC('metric file')` can trip up this check as this query
117*6dbdd20aSAndroid Build Coastguard Workergenerates some hidden output. To address this issue, if a query only has
118*6dbdd20aSAndroid Build Coastguard Workercolumn is named `suppress_query_output`, even if it has output, this will
119*6dbdd20aSAndroid Build Coastguard Workerbe ignored (for example,
120*6dbdd20aSAndroid Build Coastguard Worker`SELECT RUN_METRIC('metric file') as suppress_query_output`)
121*6dbdd20aSAndroid Build Coastguard Worker
122*6dbdd20aSAndroid Build Coastguard WorkerUI pixel diff tests
123*6dbdd20aSAndroid Build Coastguard Worker-----------------
124*6dbdd20aSAndroid Build Coastguard WorkerThe pixel tests are used to ensure core user journeys work by verifying they
125*6dbdd20aSAndroid Build Coastguard Workerare the same pixel to pixel against a golden screenshot. They use a headless
126*6dbdd20aSAndroid Build Coastguard Workerchrome to load the webpage and take a screenshot and compare pixel by pixel a
127*6dbdd20aSAndroid Build Coastguard Workergolden screenshot. You can run these tests by using `ui/run-integrationtests`.
128*6dbdd20aSAndroid Build Coastguard Worker
129*6dbdd20aSAndroid Build Coastguard Worker
130*6dbdd20aSAndroid Build Coastguard WorkerThese test fail when a certain number of pixels are different. If these tests
131*6dbdd20aSAndroid Build Coastguard Workerfail, you'll need to investigate the diff and determine if its intentional. If
132*6dbdd20aSAndroid Build Coastguard Workerits a desired change you will need to update the screenshots on a linux machine
133*6dbdd20aSAndroid Build Coastguard Workerto get the CI to pass. You can update them by generating and uploading a new
134*6dbdd20aSAndroid Build Coastguard Workerbaseline (this requires access to a google bucket through gcloud which only
135*6dbdd20aSAndroid Build Coastguard Workergooglers have access to, googlers can install gcloud
136*6dbdd20aSAndroid Build Coastguard Worker[here](https://g3doc.corp.google.com/cloud/sdk/g3doc/index.md#installing-and-using-the-cloud-sdk)).
137*6dbdd20aSAndroid Build Coastguard Worker
138*6dbdd20aSAndroid Build Coastguard Worker```
139*6dbdd20aSAndroid Build Coastguard Workerui/run-integrationtests --rebaseline
140*6dbdd20aSAndroid Build Coastguard Workertools/test_data upload
141*6dbdd20aSAndroid Build Coastguard Worker```
142*6dbdd20aSAndroid Build Coastguard Worker
143*6dbdd20aSAndroid Build Coastguard WorkerOnce finished you can commit and upload as part of your CL to cause the CI to
144*6dbdd20aSAndroid Build Coastguard Workeruse your new screenshots.
145*6dbdd20aSAndroid Build Coastguard Worker
146*6dbdd20aSAndroid Build Coastguard WorkerNOTE: If you see a failing diff test you can see the pixel differences on the CI
147*6dbdd20aSAndroid Build Coastguard Workerby using a link ending with `ui-test-artifacts/index.html`. Report located on
148*6dbdd20aSAndroid Build Coastguard Workerthat page contains changed screenshots as well as a command to accept the
149*6dbdd20aSAndroid Build Coastguard Workerchanges if these are desirable.
150*6dbdd20aSAndroid Build Coastguard Worker
151*6dbdd20aSAndroid Build Coastguard WorkerAndroid CTS tests
152*6dbdd20aSAndroid Build Coastguard Worker-----------------
153*6dbdd20aSAndroid Build Coastguard WorkerCTS tests ensure that any vendors who modify Android remain compliant with the
154*6dbdd20aSAndroid Build Coastguard Workerplatform API.
155*6dbdd20aSAndroid Build Coastguard Worker
156*6dbdd20aSAndroid Build Coastguard WorkerThese tests include a subset of the integration tests above as well as adding
157*6dbdd20aSAndroid Build Coastguard Workermore complex tests which ensure interaction between platform (e.g. Android apps
158*6dbdd20aSAndroid Build Coastguard Workeretc.) and Perfetto is not broken.
159*6dbdd20aSAndroid Build Coastguard Worker
160*6dbdd20aSAndroid Build Coastguard WorkerThe relevant targets are `CtsPerfettoProducerApp` and `CtsPerfettoTestCases`. Once these are built, the following commands should be run:
161*6dbdd20aSAndroid Build Coastguard Worker
162*6dbdd20aSAndroid Build Coastguard Worker```bash
163*6dbdd20aSAndroid Build Coastguard Workeradb push $ANDROID_HOST_OUT/cts/android-cts/testcases/CtsPerfettoTestCases64 /data/local/tmp/
164*6dbdd20aSAndroid Build Coastguard Workeradb install -r $ANDROID_HOST_OUT/cts/android-cts/testcases/CtsPerfettoProducerApp.apk
165*6dbdd20aSAndroid Build Coastguard Worker```
166*6dbdd20aSAndroid Build Coastguard Worker
167*6dbdd20aSAndroid Build Coastguard WorkerNext, the app named `android.perfetto.producer` should be run on the device.
168*6dbdd20aSAndroid Build Coastguard Worker
169*6dbdd20aSAndroid Build Coastguard WorkerFinally, the following command should be run:
170*6dbdd20aSAndroid Build Coastguard Worker
171*6dbdd20aSAndroid Build Coastguard Worker```bash
172*6dbdd20aSAndroid Build Coastguard Workeradb shell /data/local/tmp/CtsPerfettoTestCases64
173*6dbdd20aSAndroid Build Coastguard Worker```
174*6dbdd20aSAndroid Build Coastguard Worker
175*6dbdd20aSAndroid Build Coastguard Worker{#chromium} Chromium waterfall
176*6dbdd20aSAndroid Build Coastguard Worker------------------
177*6dbdd20aSAndroid Build Coastguard WorkerPerfetto is constantly rolled into chromium's //third_party/perfetto via
178*6dbdd20aSAndroid Build Coastguard Worker[this autoroller](https://autoroll.skia.org/r/perfetto-chromium-autoroll).
179*6dbdd20aSAndroid Build Coastguard Worker
180*6dbdd20aSAndroid Build Coastguard WorkerThe [Chromium CI](https://build.chromium.org) runs the `perfetto_unittests`
181*6dbdd20aSAndroid Build Coastguard Workertarget, as defined in the [buildbot config][chromium_buildbot].
182*6dbdd20aSAndroid Build Coastguard Worker
183*6dbdd20aSAndroid Build Coastguard WorkerYou can also test a pending Perfetto CL against Chromium's CI / TryBots
184*6dbdd20aSAndroid Build Coastguard Workerbefore submitting it. This can be useful when making trickier API changes or to
185*6dbdd20aSAndroid Build Coastguard Workertest on platforms that the Perfetto CI doesn't cover (e.g. Windows, MacOS),
186*6dbdd20aSAndroid Build Coastguard Workerallowing you to verify the patch before you submit it (and it then eventually
187*6dbdd20aSAndroid Build Coastguard Workerauto-rolls into Chromium).
188*6dbdd20aSAndroid Build Coastguard Worker
189*6dbdd20aSAndroid Build Coastguard WorkerTo do this, first make sure you have uploaded your Perfetto patch to the
190*6dbdd20aSAndroid Build Coastguard WorkerAndroid Gerrit. Next, create a new Chromium CL that modifies Chromium's
191*6dbdd20aSAndroid Build Coastguard Worker`//src/DEPS` file.
192*6dbdd20aSAndroid Build Coastguard Worker
193*6dbdd20aSAndroid Build Coastguard WorkerIf you recently uploaded your change, it may be enough to modify the git commit
194*6dbdd20aSAndroid Build Coastguard Workerhash in the `DEPS` entry for `src/third_party/perfetto`:
195*6dbdd20aSAndroid Build Coastguard Worker
196*6dbdd20aSAndroid Build Coastguard Worker```
197*6dbdd20aSAndroid Build Coastguard Worker  'src/third_party/perfetto':
198*6dbdd20aSAndroid Build Coastguard Worker    Var('android_git') + '/platform/external/perfetto.git' + '@' + '8fe19f55468ee227e99c1a682bd8c0e8f7e5bcdb',
199*6dbdd20aSAndroid Build Coastguard Worker```
200*6dbdd20aSAndroid Build Coastguard Worker
201*6dbdd20aSAndroid Build Coastguard WorkerReplace the git hash with the commit hash of your most recent patch set, which
202*6dbdd20aSAndroid Build Coastguard Workeryou can find in gerrit next to the active patch set number.
203*6dbdd20aSAndroid Build Coastguard Worker
204*6dbdd20aSAndroid Build Coastguard WorkerAlternatively, you can add `hooks` to patch in the pending CL on top of
205*6dbdd20aSAndroid Build Coastguard WorkerChromium's current third_party/perfetto revision. For this, add the following
206*6dbdd20aSAndroid Build Coastguard Workerentries to the `hooks` array in Chromium's `//src/DEPS` file, modifying the
207*6dbdd20aSAndroid Build Coastguard Worker`refs/changes/XX/YYYYYYY/ZZ` to the appropriate values for your gerrit change.
208*6dbdd20aSAndroid Build Coastguard WorkerYou can see these values when pressing the "Download" button in gerrit. You can
209*6dbdd20aSAndroid Build Coastguard Workeralso use this method to patch in multiple Perfetto changes at once by
210*6dbdd20aSAndroid Build Coastguard Workeradding additional `hooks` entries. [Here][chromium_cl]'s an example CL.
211*6dbdd20aSAndroid Build Coastguard Worker
212*6dbdd20aSAndroid Build Coastguard Worker```
213*6dbdd20aSAndroid Build Coastguard Worker  {
214*6dbdd20aSAndroid Build Coastguard Worker    'name': 'fetch_custom_patch',
215*6dbdd20aSAndroid Build Coastguard Worker    'pattern': '.',
216*6dbdd20aSAndroid Build Coastguard Worker    'action': [ 'git', '-C', 'src/third_party/perfetto/',
217*6dbdd20aSAndroid Build Coastguard Worker                'fetch', 'https://android.googlesource.com/platform/external/perfetto',
218*6dbdd20aSAndroid Build Coastguard Worker                'refs/changes/XX/YYYYYYY/ZZ',
219*6dbdd20aSAndroid Build Coastguard Worker    ],
220*6dbdd20aSAndroid Build Coastguard Worker  },
221*6dbdd20aSAndroid Build Coastguard Worker  {
222*6dbdd20aSAndroid Build Coastguard Worker    'name': 'apply_custom_patch',
223*6dbdd20aSAndroid Build Coastguard Worker    'pattern': '.',
224*6dbdd20aSAndroid Build Coastguard Worker    'action': ['git', '-C', 'src/third_party/perfetto/',
225*6dbdd20aSAndroid Build Coastguard Worker               '-c', 'user.name=Custom Patch', '-c', 'user.email[email protected]',
226*6dbdd20aSAndroid Build Coastguard Worker               'cherry-pick', 'FETCH_HEAD',
227*6dbdd20aSAndroid Build Coastguard Worker    ],
228*6dbdd20aSAndroid Build Coastguard Worker  },
229*6dbdd20aSAndroid Build Coastguard Worker```
230*6dbdd20aSAndroid Build Coastguard Worker
231*6dbdd20aSAndroid Build Coastguard WorkerIf you'd like to test your change against the SDK build of Chrome, you
232*6dbdd20aSAndroid Build Coastguard Workercan add `Cq-Include-Trybots:` lines for perfetto SDK trybots to the change
233*6dbdd20aSAndroid Build Coastguard Workerdescription in gerrit (this won't be needed once Chrome's migration to the
234*6dbdd20aSAndroid Build Coastguard WorkerSDK is complete, see [tracking bug][sdk_migration_bug]):
235*6dbdd20aSAndroid Build Coastguard Worker
236*6dbdd20aSAndroid Build Coastguard Worker```
237*6dbdd20aSAndroid Build Coastguard WorkerCq-Include-Trybots: luci.chromium.try:linux-perfetto-rel
238*6dbdd20aSAndroid Build Coastguard WorkerCq-Include-Trybots: luci.chromium.try:android-perfetto-rel
239*6dbdd20aSAndroid Build Coastguard WorkerCq-Include-Trybots: luci.chromium.try:mac-perfetto-rel
240*6dbdd20aSAndroid Build Coastguard WorkerCq-Include-Trybots: luci.chromium.try:win-perfetto-rel
241*6dbdd20aSAndroid Build Coastguard Worker```
242*6dbdd20aSAndroid Build Coastguard Worker
243*6dbdd20aSAndroid Build Coastguard Worker[chromium_buildbot]: https://cs.chromium.org/search/?q=perfetto_.*tests+f:%5Esrc/testing.*json$&sq=package:chromium&type=cs
244*6dbdd20aSAndroid Build Coastguard Worker[chromium_cl]: https://chromium-review.googlesource.com/c/chromium/src/+/2030528
245*6dbdd20aSAndroid Build Coastguard Worker[sdk_migration_bug]: https://crbug.com/1006541
246