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