Debian Codegraph @

hacking/azp/README.md

raw
1 # Azure Pipelines Scripts
2
3 ## Scripts
4
5 This directory contains the following scripts:
6
7 - download.py - Download results from CI.
8 - get_recent_coverage_runs.py - Retrieve CI URLs of recent coverage test runs.
9 - incidental.py - Report on incidental code coverage using data from CI.
10 - run.py - Start new runs on CI.
11
12 ## Incidental Code Coverage
13
14 ### Background
15
16 Incidental testing and code coverage occurs when a test covers one or more portions of code as an unintentional side-effect of testing another portion of code.
17
18 For example, the ``dnf`` integration test intentionally tests the ``dnf`` Ansible module.
19 However, in doing so it also uses, and unintentionally tests the ``file`` module as well.
20
21 As part of the process of migrating modules and plugins into collections, integration tests were identified that provided exclusive incidental code coverage.
22 That is, tests which would be migrated out of the repository which covered code which would not be covered by any remaining tests.
23
24 These integration test targets were preserved as incidental tests with the ``incidental_`` prefix prior to migration.
25 The plugins necessary to support these tests were also preserved in the ``test/support/`` directory.
26
27 The long-term goal for these incidental tests is to replace them with tests that intentionally cover the relevant code.
28 As additional intentional tests are added, the exclusive coverage provided by incidental tests will decline, permitting them to be removed without loss of test coverage.
29
30 ### Reducing Incidental Coverage
31
32 Reducing incidental test coverage, and eventually removing incidental tests involves the following process:
33
34 1. Run the entire test suite with code coverage enabled.
35 This is done automatically each day on Azure Pipelines.
36 The URLs and statuses of the most recent such test runs can be found with:
37
38 ```shell
39 hacking/azp/get_recent_coverage_runs.py <optional branch name>
40 ```
41
42 The branch name defaults to `devel`.
43 2. Download code coverage data from Azure Pipelines for local analysis.
44 Example:
45
46 ```shell
47 # download results to ansible/ansible directory under cwd
48 # substitute the correct run number for the Azure Pipelines coverage run you want to download
49 hacking/azp/download.py 14075 --artifacts --run-metadata -v
50 ```
51
52 3. Analyze code coverage data to see which portions of the code are covered by each test.
53 Example:
54
55 ```shell
56 # make sure ansible-test is in $PATH
57 source hacking/env-setup
58 # run the script using whichever directory results were downloaded into
59 hacking/azp/incidental.py 14075/
60 ```
61
62 4. Create new intentional tests, or extend existing ones, to cover code that is currently covered by incidental tests.
63 Reports are created by default in a ``test/results/.tmp/incidental/{hash}/reports/`` directory.
64 The ``{hash}`` value is based on the input files used to generate the report.
65
66 Over time, as the above process is repeated, exclusive incidental code coverage will decline.
67 When incidental tests no longer provide exclusive coverage they can be removed.
68
69 > CAUTION: Only one incidental test should be removed at a time, as doing so may cause another test to gain exclusive incidental coverage.
70
71 #### Incidental Plugin Coverage
72
73 Incidental test coverage is not limited to ``incidental_`` prefixed tests.
74 For example, incomplete code coverage from a filter plugin's own tests may be covered by an unrelated test.
75 The ``incidental.py`` script can be used to identify these gaps as well.
76
77 Follow the steps 1 and 2 as outlined in the previous section.
78 For step 3, add the ``--plugin-path {path_to_plugin}`` option.
79 Repeat step 3 for as many plugins as desired.
80
81 To report on multiple plugins at once, such as all ``filter`` plugins, the following command can be used:
82
83 ```shell
84 find lib/ansible/plugins/filter -name '*.py' -not -name __init__.py -exec hacking/azp/incidental.py 14075/ --plugin-path '{}' ';'
85 ```
86
87 Each report will show the incidental code coverage missing from the plugin's own tests.
88
89 > NOTE: The report does not identify where the incidental coverage comes from.
90
91 ### Reading Incidental Coverage Reports
92
93 Each line of code covered will be included in a report.
94 The left column contains the line number where the source occurs.
95 If the coverage is for Python code a comment on the right side will indicate the coverage arcs involved.
96
97 Below is an example of a report:
98
99 ```text
100 Target: incidental_win_psexec
101 GitHub: https://github.com/ansible/ansible/blob/6994ef0b554a816f02e0771cb14341a421f7cead/test/integration/targets/incidental_win_psexec
102
103 Source: lib/ansible/executor/task_executor.py (2 arcs, 3/1141 lines):
104 GitHub: https://github.com/ansible/ansible/blob/6994ef0b554a816f02e0771cb14341a421f7cead/lib/ansible/executor/task_executor.py
105
106 705 if 'rc' in result and result['rc'] not in [0, "0"]: ### (here) -> 706
107 706 result['failed'] = True ### 705 -> (here) ### (here) -> 711
108
109 711 if self._task.until: ### 706 -> (here)
110 ```
111
112 The report indicates the test target responsible for the coverage and provides a link to the source on GitHub using the appropriate commit to match the code coverage.
113
114 Each file covered in the report indicates the lines affected, and in the case of Python code, arcs.
115 A link to the source file on GitHub using the appropriate commit is also included.
116
117 The left column includes the line number for the source code found to the right.
118 In the case of Python files, the rightmost comment indicates the coverage arcs involved.
119
120 ``### (here) -> 706`` for source line 705 indicates that execution flowed from line 705 to line 706.
121 Multiple outbound line numbers can be present.
122
123 ``### 706 -> (here)`` for source line 711 indicates that execution flowed from line 706 to line 711.
124 Multiple inbound line numbers can be present.
125
126 In both cases ``(here)`` is simply a reference to the current source line.
127
128 Arcs are only available for Python code.
129 PowerShell code only reports covered line numbers.