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