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