1*91f16700SchasingluluCode Review Guidelines 2*91f16700Schasinglulu====================== 3*91f16700Schasinglulu 4*91f16700SchasingluluWhy do we do code reviews? 5*91f16700Schasinglulu-------------------------- 6*91f16700Schasinglulu 7*91f16700SchasingluluThe main goal of code reviews is to improve the code quality. By reviewing each 8*91f16700Schasingluluother's code, we can help catch issues that were missed by the author 9*91f16700Schasinglulubefore they are integrated in the source tree. Different people bring different 10*91f16700Schasingluluperspectives, depending on their past work, experiences and their current use 11*91f16700Schasinglulucases of TF-A in their products. 12*91f16700Schasinglulu 13*91f16700SchasingluluCode reviews also play a key role in sharing knowledge within the 14*91f16700Schasinglulucommunity. People with more expertise in one area of the code base can 15*91f16700Schasingluluhelp those that are less familiar with it. 16*91f16700Schasinglulu 17*91f16700SchasingluluCode reviews are meant to benefit everyone through team work. It is not about 18*91f16700Schasingluluunfairly criticizing or belittling the work of any contributor. 19*91f16700Schasinglulu 20*91f16700Schasinglulu 21*91f16700SchasingluluOverview of the code review process 22*91f16700Schasinglulu----------------------------------- 23*91f16700Schasinglulu 24*91f16700SchasingluluAll contributions to Trusted Firmware-A project are reviewed by the community to 25*91f16700Schasingluluensure they meet the project's expectations before they get merged, according to 26*91f16700Schasingluluthe `Project Maintenance Process`_ defined for all `Trusted Firmware` projects. 27*91f16700Schasinglulu 28*91f16700SchasingluluTechnical ownership of most parts of the codebase falls on the :ref:`code 29*91f16700Schasingluluowners`. All patches are ultimately merged by the :ref:`maintainers`. 30*91f16700Schasinglulu 31*91f16700SchasingluluApproval of a patch is tracked using Gerrit `labels`. For a patch to be merged, 32*91f16700Schasingluluit must get all of the following votes: 33*91f16700Schasinglulu 34*91f16700Schasinglulu- At least one ``Code-Owner-Review+1`` up-vote, and no ``Code-Owner-Review-1`` 35*91f16700Schasinglulu down-vote. 36*91f16700Schasinglulu 37*91f16700Schasinglulu- At least one ``Maintainer-Review+1`` up-vote, and no ``Maintainer-Review-1`` 38*91f16700Schasinglulu down-vote. 39*91f16700Schasinglulu 40*91f16700Schasinglulu- ``Verified+1`` vote applied by the automated Continuous Integration (CI) 41*91f16700Schasinglulu system. 42*91f16700Schasinglulu 43*91f16700SchasingluluNote that, in some instances, the maintainers might give a waiver for some of 44*91f16700Schasingluluthe CI failures and manually override the ``Verified+1`` score. 45*91f16700Schasinglulu 46*91f16700Schasinglulu 47*91f16700SchasingluluGood practices for all reviewers 48*91f16700Schasinglulu-------------------------------- 49*91f16700Schasinglulu 50*91f16700SchasingluluTo ensure the code review gives the greatest possible benefit, participants in 51*91f16700Schasingluluthe project should: 52*91f16700Schasinglulu 53*91f16700Schasinglulu- Be considerate of other people and their needs. Participants may be working 54*91f16700Schasinglulu to different timescales, and have different priorities. Keep this in 55*91f16700Schasinglulu mind - be gracious while waiting for action from others, and timely in your 56*91f16700Schasinglulu actions when others are waiting for you. 57*91f16700Schasinglulu 58*91f16700Schasinglulu- Review other people's patches where possible. The more active reviewers there 59*91f16700Schasinglulu are, the more quickly new patches can be reviewed and merged. Contributing to 60*91f16700Schasinglulu code review helps everyone in the long run, as it creates a culture of 61*91f16700Schasinglulu participation which serves everyone's interests. 62*91f16700Schasinglulu 63*91f16700Schasinglulu 64*91f16700SchasingluluGuidelines for patch contributors 65*91f16700Schasinglulu--------------------------------- 66*91f16700Schasinglulu 67*91f16700SchasingluluIn addition to the rules outlined in the :ref:`Contributor's Guide`, as a patch 68*91f16700Schasinglulucontributor you are expected to: 69*91f16700Schasinglulu 70*91f16700Schasinglulu- Answer all comments from people who took the time to review your 71*91f16700Schasinglulu patches. 72*91f16700Schasinglulu 73*91f16700Schasinglulu- Be patient and resilient. It is quite common for patches to go through 74*91f16700Schasinglulu several rounds of reviews and rework before they get approved, especially 75*91f16700Schasinglulu for larger features. 76*91f16700Schasinglulu 77*91f16700Schasinglulu In the event that a code review takes longer than you would hope for, you 78*91f16700Schasinglulu may try the following actions to speed it up: 79*91f16700Schasinglulu 80*91f16700Schasinglulu - Ping the reviewers on Gerrit or on the mailing list. If it is urgent, 81*91f16700Schasinglulu explain why. Please remain courteous and do not abuse this. 82*91f16700Schasinglulu 83*91f16700Schasinglulu - If one code owner has become unresponsive, ask the other code owners for 84*91f16700Schasinglulu help progressing the patch. 85*91f16700Schasinglulu 86*91f16700Schasinglulu - If there is only one code owner and they have become unresponsive, ask one 87*91f16700Schasinglulu of the project maintainers for help. 88*91f16700Schasinglulu 89*91f16700Schasinglulu- Do the right thing for the project, not the fastest thing to get code merged. 90*91f16700Schasinglulu 91*91f16700Schasinglulu For example, if some existing piece of code - say a driver - does not quite 92*91f16700Schasinglulu meet your exact needs, go the extra mile and extend the code with the missing 93*91f16700Schasinglulu functionality you require - as opposed to copying the code into some other 94*91f16700Schasinglulu directory to have the freedom to change it in any way. This way, your changes 95*91f16700Schasinglulu benefit everyone and will be maintained over time. 96*91f16700Schasinglulu 97*91f16700Schasinglulu- It is the patch-author's responsibility to respond to review comments within 98*91f16700Schasinglulu 21 days. In the event that the patch-author does not respond within this 99*91f16700Schasinglulu timeframe, the maintainer is entitled to abandon the patch(es). 100*91f16700Schasinglulu Patch author(s) may be busy with other priorities, causing a delay in 101*91f16700Schasinglulu responding to active review comments after posting patch(es). In such a 102*91f16700Schasinglulu situation, if the author's patch(es) is/are abandoned, they can restore 103*91f16700Schasinglulu their work for review by resolving comments, merge-conflicts, and revising 104*91f16700Schasinglulu their original submissions. 105*91f16700Schasinglulu 106*91f16700SchasingluluGuidelines for all reviewers 107*91f16700Schasinglulu---------------------------- 108*91f16700Schasinglulu 109*91f16700SchasingluluThere are no good or bad review comments. If you have any doubt about a patch or 110*91f16700Schasingluluneed some clarifications, it's better to ask rather than letting a potential 111*91f16700Schasingluluissue slip. Examples of review comments could be: 112*91f16700Schasinglulu 113*91f16700Schasinglulu- Questions ("Why do you need to do this?", "What if X happens?") 114*91f16700Schasinglulu- Bugs ("I think you need a logical \|\| rather than a bitwise \|.") 115*91f16700Schasinglulu- Design issues ("This won't scale well when we introduce feature X.") 116*91f16700Schasinglulu- Improvements ("Would it be better if we did Y instead?") 117*91f16700Schasinglulu 118*91f16700Schasinglulu 119*91f16700SchasingluluGuidelines for code owners 120*91f16700Schasinglulu-------------------------- 121*91f16700Schasinglulu 122*91f16700SchasingluluCode owners are listed on the :ref:`Project Maintenance<code owners>` page, 123*91f16700Schasinglulualong with the module(s) they look after. 124*91f16700Schasinglulu 125*91f16700SchasingluluWhen reviewing a patch, code owners are expected to check the following: 126*91f16700Schasinglulu 127*91f16700Schasinglulu- The patch looks good from a technical point of view. For example: 128*91f16700Schasinglulu 129*91f16700Schasinglulu - The structure of the code is clear. 130*91f16700Schasinglulu 131*91f16700Schasinglulu - It complies with the relevant standards or technical documentation (where 132*91f16700Schasinglulu applicable). 133*91f16700Schasinglulu 134*91f16700Schasinglulu - It leverages existing interfaces rather than introducing new ones 135*91f16700Schasinglulu unnecessarily. 136*91f16700Schasinglulu 137*91f16700Schasinglulu - It fits well in the design of the module. 138*91f16700Schasinglulu 139*91f16700Schasinglulu - It adheres to the security model of the project. In particular, it does not 140*91f16700Schasinglulu increase the attack surface (e.g. new SMCs) without justification. 141*91f16700Schasinglulu 142*91f16700Schasinglulu- The patch adheres to the TF-A :ref:`Coding Style`. The CI system should help 143*91f16700Schasinglulu catch coding style violations. 144*91f16700Schasinglulu 145*91f16700Schasinglulu- (Only applicable to generic code) The code is MISRA-compliant (see 146*91f16700Schasinglulu :ref:`misra-compliance`). The CI system should help catch violations. 147*91f16700Schasinglulu 148*91f16700Schasinglulu- Documentation is provided/updated (where applicable). 149*91f16700Schasinglulu 150*91f16700Schasinglulu- The patch has had an appropriate level of testing. Testing details are 151*91f16700Schasinglulu expected to be provided by the patch author. If they are not, do not hesitate 152*91f16700Schasinglulu to request this information. 153*91f16700Schasinglulu 154*91f16700Schasinglulu- All CI automated tests pass. 155*91f16700Schasinglulu 156*91f16700SchasingluluIf a code owner is happy with a patch, they should give their approval 157*91f16700Schasingluluthrough the ``Code-Owner-Review+1`` label in Gerrit. If instead, they have 158*91f16700Schasingluluconcerns, questions, or any other type of blocking comment, they should set 159*91f16700Schasinglulu``Code-Owner-Review-1``. 160*91f16700Schasinglulu 161*91f16700SchasingluluCode owners are expected to behave professionally and responsibly. Here are some 162*91f16700Schasingluluguidelines for them: 163*91f16700Schasinglulu 164*91f16700Schasinglulu- Once you are engaged in a review, make sure you stay involved until the patch 165*91f16700Schasinglulu is merged. Rejecting a patch and going away is not very helpful. You are 166*91f16700Schasinglulu expected to monitor the patch author's answers to your review comments, 167*91f16700Schasinglulu answer back if needed and review new revisions of their patch. 168*91f16700Schasinglulu 169*91f16700Schasinglulu- Provide constructive feedback. Just saying, "This is wrong, you should do X 170*91f16700Schasinglulu instead." is usually not very helpful. The patch author is unlikely to 171*91f16700Schasinglulu understand why you are requesting this change and might feel personally 172*91f16700Schasinglulu attacked. 173*91f16700Schasinglulu 174*91f16700Schasinglulu- Be mindful when reviewing a patch. As a code owner, you are viewed as 175*91f16700Schasinglulu the expert for the relevant module. By approving a patch, you are partially 176*91f16700Schasinglulu responsible for its quality and the effects it has for all TF-A users. Make 177*91f16700Schasinglulu sure you fully understand what the implications of a patch might be. 178*91f16700Schasinglulu 179*91f16700Schasinglulu 180*91f16700SchasingluluGuidelines for maintainers 181*91f16700Schasinglulu-------------------------- 182*91f16700Schasinglulu 183*91f16700SchasingluluMaintainers are listed on the :ref:`Project Maintenance<maintainers>` page. 184*91f16700Schasinglulu 185*91f16700SchasingluluWhen reviewing a patch, maintainers are expected to check the following: 186*91f16700Schasinglulu 187*91f16700Schasinglulu- The general structure of the patch looks good. This covers things like: 188*91f16700Schasinglulu 189*91f16700Schasinglulu - Code organization. 190*91f16700Schasinglulu 191*91f16700Schasinglulu - Files and directories, names and locations. 192*91f16700Schasinglulu 193*91f16700Schasinglulu For example, platform code should be added under the ``plat/`` directory. 194*91f16700Schasinglulu 195*91f16700Schasinglulu - Naming conventions. 196*91f16700Schasinglulu 197*91f16700Schasinglulu For example, platform identifiers should be properly namespaced to avoid 198*91f16700Schasinglulu name clashes with generic code. 199*91f16700Schasinglulu 200*91f16700Schasinglulu - API design. 201*91f16700Schasinglulu 202*91f16700Schasinglulu- Interaction of the patch with other modules in the code base. 203*91f16700Schasinglulu 204*91f16700Schasinglulu- The patch aims at complying with any standard or technical documentation 205*91f16700Schasinglulu that applies. 206*91f16700Schasinglulu 207*91f16700Schasinglulu- New files must have the correct license and copyright headers. See :ref:`this 208*91f16700Schasinglulu paragraph<copyright-license-guidance>` for more information. The CI system 209*91f16700Schasinglulu should help catch files with incorrect or no copyright/license headers. 210*91f16700Schasinglulu 211*91f16700Schasinglulu- There is no third party code or binary blobs with potential IP concerns. 212*91f16700Schasinglulu Maintainers should look for copyright or license notices in code, and use 213*91f16700Schasinglulu their best judgement. If they are unsure about a patch, they should ask 214*91f16700Schasinglulu other maintainers for help. 215*91f16700Schasinglulu 216*91f16700Schasinglulu- Generally speaking, new driver code should be placed in the generic 217*91f16700Schasinglulu layer. There are cases where a driver has to stay into the platform layer but 218*91f16700Schasinglulu this should be the exception, rather than the rule. 219*91f16700Schasinglulu 220*91f16700Schasinglulu- Existing common drivers (in particular for Arm IPs like the GIC driver) should 221*91f16700Schasinglulu not be copied into the platform layer to cater for platform quirks. This 222*91f16700Schasinglulu type of code duplication hurts the maintainability of the project. The 223*91f16700Schasinglulu duplicate driver is less likely to benefit from bug fixes and future 224*91f16700Schasinglulu enhancements. In most cases, it is possible to rework a generic driver to 225*91f16700Schasinglulu make it more flexible and fit slightly different use cases. That way, these 226*91f16700Schasinglulu enhancements benefit everyone. 227*91f16700Schasinglulu 228*91f16700Schasinglulu- When a platform specific driver really is required, the burden lies with the 229*91f16700Schasinglulu patch author to prove the need for it. A detailed justification should be 230*91f16700Schasinglulu posted via the commit message or on the mailing list. 231*91f16700Schasinglulu 232*91f16700Schasinglulu- Before merging a patch, verify that all review comments have been addressed. 233*91f16700Schasinglulu If this is not the case, encourage the patch author and the relevant 234*91f16700Schasinglulu reviewers to resolve these together. 235*91f16700Schasinglulu 236*91f16700SchasingluluIf a maintainer is happy with a patch, they should give their approval 237*91f16700Schasingluluthrough the ``Maintainer-Review+1`` label in Gerrit. If instead, they have 238*91f16700Schasingluluconcerns, questions, or any other type of blocking comment, they should set 239*91f16700Schasinglulu``Maintainer-Review-1``. 240*91f16700Schasinglulu 241*91f16700Schasinglulu-------------- 242*91f16700Schasinglulu 243*91f16700Schasinglulu*Copyright (c) 2020-2023, Arm Limited. All rights reserved.* 244*91f16700Schasinglulu 245*91f16700Schasinglulu.. _Project Maintenance Process: https://developer.trustedfirmware.org/w/collaboration/project-maintenance-process/ 246