1# Running tests 2 3The testing strategy for Perfetto is rather complex due to the wide variety 4of build configurations and embedding targets. 5 6Common test targets (all platforms / checkouts): 7 8`perfetto_unittests`: 9Platform-agnostic unit-tests. 10 11`perfetto_integrationtests`: 12End-to-end tests, involving the protobuf-based IPC transport and ftrace 13integration (Linux/Android only). 14 15`perfetto_benchmarks`: 16Benchmarks tracking the performance of: (i) trace writing, (ii) trace readback 17and (iii) ftrace raw pipe -> protobuf translation. 18 19Running tests on Linux / MacOS 20------------------------------ 21 22```bash 23tools/ninja -C out/default perfetto_{unittests,integrationtests,benchmarks} 24out/default/perfetto_unittests --gtest_help 25``` 26 27`perfetto_integrationtests` requires that the ftrace debugfs directory is 28is readable/writable by the current user on Linux: 29```bash 30sudo chown -R $USER /sys/kernel/debug/tracing 31``` 32 33Running tests on Android 34------------------------ 351A) Connect a device through `adb` 361B) Start the build-in emulator (supported on Linux and MacOS): 37 38```bash 39tools/install-build-deps --android 40tools/run_android_emulator & 41``` 42 432) Run the tests (either on the emulator or physical device): 44 45```bash 46tools/run_android_test out/default perfetto_unittests 47``` 48 49Continuous testing 50------------------ 51Perfetto is tested in a variety of locations: 52 53**Perfetto CI**: https://ci.perfetto.dev/ 54Builds and runs perfetto_{unittests,integrationtests,benchmarks} from the 55standalone checkout. Benchmarks are ran in a reduced form for smoke testing. 56See [this doc](/docs/design-docs/continuous-integration.md) for more details. 57 58**Android CI** (see go/apct and go/apct-guide): 59runs only `perfetto_integrationtests` 60 61**Android presubmits (TreeHugger)**: 62Runs before submission of every AOSP CL of `external/perfetto`. 63 64**Android CTS** (Android test suite used run to ensure API compatibility): 65Rolling runs internally. 66 67Note that Perfetto CI uses the standalone build system and the others build as 68part of the Android tree. 69 70Unit tests 71---------- 72Unit tests exist for most of the code in Perfetto on the class level. They 73ensure that each class broadly works as expected. 74 75Unit tests are currently ran on ci.perfetto.dev and build.chromium.org. 76Running unit tests on APCT and Treehugger is WIP. 77 78Integration tests 79----------------- 80Integration tests ensure that subsystems (importantly ftrace and the IPC layer) 81and Perfetto as a whole is working correctly end-to-end. 82 83There are two configurations in which integration tests can be run: 84 85**1. Production mode** (Android-only) 86This mode assumes that both the tracing service (`traced`) and the OS probes 87service (`traced_probes`) are already running. In this mode the test enables 88only the consumer endpoint and tests the interaction with the production 89services. This is the way our Android CTS and APCT tests work. 90 91**2. Standalone mode**: 92Starting up the daemons in the test itself and then testing against them. 93This is how standalone builds are tested. This is the only supported way to 94run integration tests on Linux and MacOS. 95 96Android CTS tests 97----------------- 98CTS tests ensure that any vendors who modify Android remain compliant with the 99platform API. 100 101These tests include a subset of the integration tests above as well as adding 102more complex tests which ensure interaction between platform (e.g. Android apps 103etc.) and Perfetto is not broken. 104 105The relevant targets are `CtsPerfettoProducerApp` and `CtsPerfettoTestCases`. Once these are built, the following commands should be run: 106 107```bash 108adb push $ANDROID_HOST_OUT/cts/android-cts/testcases/CtsPerfettoTestCases64 /data/local/tmp/ 109adb install -r $ANDROID_HOST_OUT/cts/android-cts/testcases/CtsPerfettoProducerApp.apk 110``` 111 112Next, the app named `android.perfetto.producer` should be run on the device. 113 114Finally, the following command should be run: 115 116```bash 117adb shell /data/local/tmp/CtsPerfettoTestCases64 118``` 119 120Chromium waterfall 121------------------ 122Perfetto is constantly rolled into chromium's //third_party/perfetto via 123[this autoroller](https://autoroll.skia.org/r/perfetto-chromium-autoroll). 124 125The [Chromium CI](https://build.chromium.org) runs the `perfetto_unittests` 126target, as defined in the [buildbot config][chromium_buildbot]. 127 128[chromium_buildbot]: https://cs.chromium.org/search/?q=perfetto_.*tests+f:%5Esrc/testing.*json$&sq=package:chromium&type=cs 129