11f19411aSSandrine BailleuxCode Review Guidelines 21f19411aSSandrine Bailleux====================== 31f19411aSSandrine Bailleux 41f19411aSSandrine BailleuxWhy do we do code reviews? 51f19411aSSandrine Bailleux-------------------------- 61f19411aSSandrine Bailleux 71f19411aSSandrine BailleuxThe main goal of code reviews is to improve the code quality. By reviewing each 81f19411aSSandrine Bailleuxother's code, we can help catch issues that were missed by the author 91f19411aSSandrine Bailleuxbefore they are integrated in the source tree. Different people bring different 101f19411aSSandrine Bailleuxperspectives, depending on their past work, experiences and their current use 111f19411aSSandrine Bailleuxcases of TF-A in their products. 121f19411aSSandrine Bailleux 131f19411aSSandrine BailleuxCode reviews also play a key role in sharing knowledge within the 141f19411aSSandrine Bailleuxcommunity. People with more expertise in one area of the code base can 151f19411aSSandrine Bailleuxhelp those that are less familiar with it. 161f19411aSSandrine Bailleux 171f19411aSSandrine BailleuxCode reviews are meant to benefit everyone through team work. It is not about 181f19411aSSandrine Bailleuxunfairly criticizing or belittling the work of any contributor. 191f19411aSSandrine Bailleux 201f19411aSSandrine Bailleux 21*ca4febacSSandrine BailleuxOverview of the code review process 22*ca4febacSSandrine Bailleux----------------------------------- 23*ca4febacSSandrine Bailleux 24*ca4febacSSandrine BailleuxAll contributions to Trusted Firmware-A project are reviewed by the community to 25*ca4febacSSandrine Bailleuxensure they meet the project's expectations before they get merged, according to 26*ca4febacSSandrine Bailleuxthe `Project Maintenance Process`_ defined for all `Trusted Firmware` projects. 27*ca4febacSSandrine Bailleux 28*ca4febacSSandrine BailleuxTechnical ownership of most parts of the codebase falls on the :ref:`code 29*ca4febacSSandrine Bailleuxowners`. All patches are ultimately merged by the :ref:`maintainers`. 30*ca4febacSSandrine Bailleux 31*ca4febacSSandrine BailleuxApproval of a patch is tracked using Gerrit `labels`. For a patch to be merged, 32*ca4febacSSandrine Bailleuxit must get all of the following votes: 33*ca4febacSSandrine Bailleux 34*ca4febacSSandrine Bailleux- At least one ``Code-Owner-Review+1`` up-vote, and no ``Code-Owner-Review-1`` 35*ca4febacSSandrine Bailleux down-vote. 36*ca4febacSSandrine Bailleux 37*ca4febacSSandrine Bailleux- At least one ``Maintainer-Review+1`` up-vote, and no ``Maintainer-Review-1`` 38*ca4febacSSandrine Bailleux down-vote. 39*ca4febacSSandrine Bailleux 40*ca4febacSSandrine Bailleux- ``Verified+1`` vote applied by the automated Continuous Integration (CI) 41*ca4febacSSandrine Bailleux system. 42*ca4febacSSandrine Bailleux 43*ca4febacSSandrine BailleuxNote that, in some instances, the maintainers might give a waiver for some of 44*ca4febacSSandrine Bailleuxthe CI failures and manually override the ``Verified+1`` score. 45*ca4febacSSandrine Bailleux 46*ca4febacSSandrine Bailleux 47*ca4febacSSandrine BailleuxGood practices for all reviewers 48*ca4febacSSandrine Bailleux-------------------------------- 491f19411aSSandrine Bailleux 501f19411aSSandrine BailleuxTo ensure the code review gives the greatest possible benefit, participants in 511f19411aSSandrine Bailleuxthe project should: 521f19411aSSandrine Bailleux 531f19411aSSandrine Bailleux- Be considerate of other people and their needs. Participants may be working 541f19411aSSandrine Bailleux to different timescales, and have different priorities. Keep this in 551f19411aSSandrine Bailleux mind - be gracious while waiting for action from others, and timely in your 561f19411aSSandrine Bailleux actions when others are waiting for you. 571f19411aSSandrine Bailleux 581f19411aSSandrine Bailleux- Review other people's patches where possible. The more active reviewers there 591f19411aSSandrine Bailleux are, the more quickly new patches can be reviewed and merged. Contributing to 601f19411aSSandrine Bailleux code review helps everyone in the long run, as it creates a culture of 611f19411aSSandrine Bailleux participation which serves everyone's interests. 621f19411aSSandrine Bailleux 631f19411aSSandrine Bailleux 641f19411aSSandrine BailleuxGuidelines for patch contributors 651f19411aSSandrine Bailleux--------------------------------- 661f19411aSSandrine Bailleux 671f19411aSSandrine BailleuxIn addition to the rules outlined in the :ref:`Contributor's Guide`, as a patch 681f19411aSSandrine Bailleuxcontributor you are expected to: 691f19411aSSandrine Bailleux 701f19411aSSandrine Bailleux- Answer all comments from people who took the time to review your 711f19411aSSandrine Bailleux patches. 721f19411aSSandrine Bailleux 731f19411aSSandrine Bailleux- Be patient and resilient. It is quite common for patches to go through 741f19411aSSandrine Bailleux several rounds of reviews and rework before they get approved, especially 751f19411aSSandrine Bailleux for larger features. 761f19411aSSandrine Bailleux 771f19411aSSandrine Bailleux In the event that a code review takes longer than you would hope for, you 781f19411aSSandrine Bailleux may try the following actions to speed it up: 791f19411aSSandrine Bailleux 801f19411aSSandrine Bailleux - Ping the reviewers on Gerrit or on the mailing list. If it is urgent, 811f19411aSSandrine Bailleux explain why. Please remain courteous and do not abuse this. 821f19411aSSandrine Bailleux 831f19411aSSandrine Bailleux - If one code owner has become unresponsive, ask the other code owners for 841f19411aSSandrine Bailleux help progressing the patch. 851f19411aSSandrine Bailleux 861f19411aSSandrine Bailleux - If there is only one code owner and they have become unresponsive, ask one 871f19411aSSandrine Bailleux of the project maintainers for help. 881f19411aSSandrine Bailleux 891f19411aSSandrine Bailleux- Do the right thing for the project, not the fastest thing to get code merged. 901f19411aSSandrine Bailleux 911f19411aSSandrine Bailleux For example, if some existing piece of code - say a driver - does not quite 921f19411aSSandrine Bailleux meet your exact needs, go the extra mile and extend the code with the missing 931f19411aSSandrine Bailleux functionality you require - as opposed to copying the code into some other 941f19411aSSandrine Bailleux directory to have the freedom to change it in any way. This way, your changes 951f19411aSSandrine Bailleux benefit everyone and will be maintained over time. 961f19411aSSandrine Bailleux 971f19411aSSandrine Bailleux 981f19411aSSandrine BailleuxGuidelines for all reviewers 991f19411aSSandrine Bailleux---------------------------- 1001f19411aSSandrine Bailleux 1011f19411aSSandrine BailleuxThere are no good or bad review comments. If you have any doubt about a patch or 1021f19411aSSandrine Bailleuxneed some clarifications, it's better to ask rather than letting a potential 1031f19411aSSandrine Bailleuxissue slip. Examples of review comments could be: 1041f19411aSSandrine Bailleux 1051f19411aSSandrine Bailleux- Questions ("Why do you need to do this?", "What if X happens?") 1061f19411aSSandrine Bailleux- Bugs ("I think you need a logical \|\| rather than a bitwise \|.") 1071f19411aSSandrine Bailleux- Design issues ("This won't scale well when we introduce feature X.") 1081f19411aSSandrine Bailleux- Improvements ("Would it be better if we did Y instead?") 1091f19411aSSandrine Bailleux 1101f19411aSSandrine Bailleux 1111f19411aSSandrine BailleuxGuidelines for code owners 1121f19411aSSandrine Bailleux-------------------------- 1131f19411aSSandrine Bailleux 1141f19411aSSandrine BailleuxCode owners are listed on the :ref:`Project Maintenance<code owners>` page, 1151f19411aSSandrine Bailleuxalong with the module(s) they look after. 1161f19411aSSandrine Bailleux 1171f19411aSSandrine BailleuxWhen reviewing a patch, code owners are expected to check the following: 1181f19411aSSandrine Bailleux 1191f19411aSSandrine Bailleux- The patch looks good from a technical point of view. For example: 1201f19411aSSandrine Bailleux 1211f19411aSSandrine Bailleux - The structure of the code is clear. 1221f19411aSSandrine Bailleux 1231f19411aSSandrine Bailleux - It complies with the relevant standards or technical documentation (where 1241f19411aSSandrine Bailleux applicable). 1251f19411aSSandrine Bailleux 1261f19411aSSandrine Bailleux - It leverages existing interfaces rather than introducing new ones 1271f19411aSSandrine Bailleux unnecessarily. 1281f19411aSSandrine Bailleux 1291f19411aSSandrine Bailleux - It fits well in the design of the module. 1301f19411aSSandrine Bailleux 1311f19411aSSandrine Bailleux - It adheres to the security model of the project. In particular, it does not 1321f19411aSSandrine Bailleux increase the attack surface (e.g. new SMCs) without justification. 1331f19411aSSandrine Bailleux 1341f19411aSSandrine Bailleux- The patch adheres to the TF-A :ref:`Coding Style`. The CI system should help 1351f19411aSSandrine Bailleux catch coding style violations. 1361f19411aSSandrine Bailleux 1371f19411aSSandrine Bailleux- (Only applicable to generic code) The code is MISRA-compliant (see 1381f19411aSSandrine Bailleux :ref:`misra-compliance`). The CI system should help catch violations. 1391f19411aSSandrine Bailleux 1401f19411aSSandrine Bailleux- Documentation is provided/updated (where applicable). 1411f19411aSSandrine Bailleux 1421f19411aSSandrine Bailleux- The patch has had an appropriate level of testing. Testing details are 1431f19411aSSandrine Bailleux expected to be provided by the patch author. If they are not, do not hesitate 1441f19411aSSandrine Bailleux to request this information. 1451f19411aSSandrine Bailleux 1461f19411aSSandrine Bailleux- All CI automated tests pass. 1471f19411aSSandrine Bailleux 1481f19411aSSandrine BailleuxIf a code owner is happy with a patch, they should give their approval 1491f19411aSSandrine Bailleuxthrough the ``Code-Owner-Review+1`` label in Gerrit. If instead, they have 1501f19411aSSandrine Bailleuxconcerns, questions, or any other type of blocking comment, they should set 1511f19411aSSandrine Bailleux``Code-Owner-Review-1``. 1521f19411aSSandrine Bailleux 1531f19411aSSandrine BailleuxCode owners are expected to behave professionally and responsibly. Here are some 1541f19411aSSandrine Bailleuxguidelines for them: 1551f19411aSSandrine Bailleux 1561f19411aSSandrine Bailleux- Once you are engaged in a review, make sure you stay involved until the patch 1571f19411aSSandrine Bailleux is merged. Rejecting a patch and going away is not very helpful. You are 1581f19411aSSandrine Bailleux expected to monitor the patch author's answers to your review comments, 1591f19411aSSandrine Bailleux answer back if needed and review new revisions of their patch. 1601f19411aSSandrine Bailleux 1611f19411aSSandrine Bailleux- Provide constructive feedback. Just saying, "This is wrong, you should do X 1621f19411aSSandrine Bailleux instead." is usually not very helpful. The patch author is unlikely to 1631f19411aSSandrine Bailleux understand why you are requesting this change and might feel personally 1641f19411aSSandrine Bailleux attacked. 1651f19411aSSandrine Bailleux 1661f19411aSSandrine Bailleux- Be mindful when reviewing a patch. As a code owner, you are viewed as 1671f19411aSSandrine Bailleux the expert for the relevant module. By approving a patch, you are partially 1681f19411aSSandrine Bailleux responsible for its quality and the effects it has for all TF-A users. Make 1691f19411aSSandrine Bailleux sure you fully understand what the implications of a patch might be. 1701f19411aSSandrine Bailleux 1711f19411aSSandrine Bailleux 1721f19411aSSandrine BailleuxGuidelines for maintainers 1731f19411aSSandrine Bailleux-------------------------- 1741f19411aSSandrine Bailleux 1751f19411aSSandrine BailleuxMaintainers are listed on the :ref:`Project Maintenance<maintainers>` page. 1761f19411aSSandrine Bailleux 1771f19411aSSandrine BailleuxWhen reviewing a patch, maintainers are expected to check the following: 1781f19411aSSandrine Bailleux 1791f19411aSSandrine Bailleux- The general structure of the patch looks good. This covers things like: 1801f19411aSSandrine Bailleux 1811f19411aSSandrine Bailleux - Code organization. 1821f19411aSSandrine Bailleux 1831f19411aSSandrine Bailleux - Files and directories, names and locations. 1841f19411aSSandrine Bailleux 1851f19411aSSandrine Bailleux For example, platform code should be added under the ``plat/`` directory. 1861f19411aSSandrine Bailleux 1871f19411aSSandrine Bailleux - Naming conventions. 1881f19411aSSandrine Bailleux 1891f19411aSSandrine Bailleux For example, platform identifiers should be properly namespaced to avoid 1901f19411aSSandrine Bailleux name clashes with generic code. 1911f19411aSSandrine Bailleux 1921f19411aSSandrine Bailleux - API design. 1931f19411aSSandrine Bailleux 1941f19411aSSandrine Bailleux- Interaction of the patch with other modules in the code base. 1951f19411aSSandrine Bailleux 1961f19411aSSandrine Bailleux- The patch aims at complying with any standard or technical documentation 1971f19411aSSandrine Bailleux that applies. 1981f19411aSSandrine Bailleux 1991f19411aSSandrine Bailleux- New files must have the correct license and copyright headers. See :ref:`this 2001f19411aSSandrine Bailleux paragraph<copyright-license-guidance>` for more information. The CI system 2011f19411aSSandrine Bailleux should help catch files with incorrect or no copyright/license headers. 2021f19411aSSandrine Bailleux 2031f19411aSSandrine Bailleux- There is no third party code or binary blobs with potential IP concerns. 2041f19411aSSandrine Bailleux Maintainers should look for copyright or license notices in code, and use 2051f19411aSSandrine Bailleux their best judgement. If they are unsure about a patch, they should ask 2061f19411aSSandrine Bailleux other maintainers for help. 2071f19411aSSandrine Bailleux 2081f19411aSSandrine Bailleux- Generally speaking, new driver code should be placed in the generic 2091f19411aSSandrine Bailleux layer. There are cases where a driver has to stay into the platform layer but 2101f19411aSSandrine Bailleux this should be the exception, rather than the rule. 2111f19411aSSandrine Bailleux 2121f19411aSSandrine Bailleux- Existing common drivers (in particular for Arm IPs like the GIC driver) should 2131f19411aSSandrine Bailleux not be copied into the platform layer to cater for platform quirks. This 2141f19411aSSandrine Bailleux type of code duplication hurts the maintainability of the project. The 2151f19411aSSandrine Bailleux duplicate driver is less likely to benefit from bug fixes and future 2161f19411aSSandrine Bailleux enhancements. In most cases, it is possible to rework a generic driver to 2171f19411aSSandrine Bailleux make it more flexible and fit slightly different use cases. That way, these 2181f19411aSSandrine Bailleux enhancements benefit everyone. 2191f19411aSSandrine Bailleux 2201f19411aSSandrine Bailleux- When a platform specific driver really is required, the burden lies with the 2211f19411aSSandrine Bailleux patch author to prove the need for it. A detailed justification should be 2221f19411aSSandrine Bailleux posted via the commit message or on the mailing list. 2231f19411aSSandrine Bailleux 2241f19411aSSandrine Bailleux- Before merging a patch, verify that all review comments have been addressed. 2251f19411aSSandrine Bailleux If this is not the case, encourage the patch author and the relevant 2261f19411aSSandrine Bailleux reviewers to resolve these together. 2271f19411aSSandrine Bailleux 2281f19411aSSandrine BailleuxIf a maintainer is happy with a patch, they should give their approval 2291f19411aSSandrine Bailleuxthrough the ``Maintainer-Review+1`` label in Gerrit. If instead, they have 2301f19411aSSandrine Bailleuxconcerns, questions, or any other type of blocking comment, they should set 2311f19411aSSandrine Bailleux``Maintainer-Review-1``. 2321f19411aSSandrine Bailleux 2331f19411aSSandrine Bailleux-------------- 2341f19411aSSandrine Bailleux 235*ca4febacSSandrine Bailleux*Copyright (c) 2020-2023, Arm Limited. All rights reserved.* 2361f19411aSSandrine Bailleux 2371f19411aSSandrine Bailleux.. _Project Maintenance Process: https://developer.trustedfirmware.org/w/collaboration/project-maintenance-process/ 238