summaryrefslogtreecommitdiff
path: root/chromium/docs/ios/coverage.md
blob: 72857182fe4d8c0a40855eea5165c60908e090b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Generate code coverage data

1.  Build a test target for coverage:

    ```
    ninja -C out/Coverage-iphonesimulator ios_chrome_unittests
    ```

    Targets that support code coverage need to call
    `coverage_util::ConfigureCoverageReportPath()`.
    If you don't use `setup-gn.py`, you can set the gn argument
    `ios_enable_coverage` to `true`.

1.  Run the test target. If using Xcode, don't forget to set `Coverage` in the
    target's scheme:

    ![](images/coverage_xcode.png)

1.  Find the `coverage.profraw` in the `Documents` folder of the app. You can
    look in the console output of the instrumented target. For example:

    ```
    Coverage data at /Users/johndoe/Library/Developer/CoreSimulator/Devices/
    82D642FA-FC18-4EDB-AFE0-A17454804BE4/data/Containers/Data/Application/
    E6B2B898-CE13-4958-93F3-E8B500446381/Documents/coverage.profraw
    ```

1.  Create a `coverage.profdata` file out of the `coverage.profraw` file:

    ```
    xcrun llvm-profdata merge \
        -o out/Coverage-iphonesimulator/coverage.profdata \
        path/to/coverage.profraw
    ```

1.  To see the **line coverage** for *all the instrumented source files*:

    ```
    xcrun llvm-cov show \
        out/Coverage-iphonesimulator/ios_chrome_unittests.app/ios_chrome_unittests \
        -instr-profile=out/Coverage-iphonesimulator/coverage.profdata \
        -arch=x86_64
    ```

    ![](images/llvm-cov_show.png)

    To see the **line coverage** for a *specific instrumented source
    file/folder* (e.g.
    `ios/chrome/browser/ui/coordinators/browser_coordinator.mm`):

    ```
    xcrun llvm-cov show \
        out/Coverage-iphonesimulator/ios_chrome_unittests.app/ios_chrome_unittests \
        -instr-profile=out/Coverage-iphonesimulator/coverage.profdata \
        -arch=x86_64 ios/chrome/browser/ui/coordinators/browser_coordinator.mm
    ```

    ![](images/llvm-cov_show_file.png)

    To see a **complete report**:

    ```
    xcrun llvm-cov report \
        out/Coverage-iphonesimulator/ios_chrome_unittests.app/ios_chrome_unittests \
        -instr-profile=path/to/coverage.profdata -arch=x86_64
    ```

    ![](images/llvm-cov_report.png)

    To see a **report** for a *folder/file* (e.g. `ios/chrome/browser` folder):

    ```
    xcrun llvm-cov show \
        out/Coverage-iphonesimulator/ios_chrome_unittests.app/ios_chrome_unittests \
        -instr-profile=path/to/coverage.profdata -arch=x86_64 ios/chrome/browser
    ```

    ![](images/llvm-cov_report_folder.png)