1# Checklist for making changes to `libpldm` 2 3## Philosophy and influences 4 5- [Good Practices in Library Design, Implementation, and Maintenance - Ulrich 6 Drepper][goodpractice] 7 8[goodpractice]: https://www.akkadia.org/drepper/goodpractice.pdf 9 10- [How Do I Make This Hard to Misuse? - Rusty Russell][rusty-api-scale-good] 11 12[rusty-api-scale-good]: https://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html 13 14- [What If I Don't Actually Like My Users? - Rusty Russell][rusty-api-scale-bad] 15 16[rusty-api-scale-bad]: https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html 17 18- [Red flags that indicate questionable quality - Lennart 19 Poettering][poettering-library-red-flags] 20 21[poettering-library-red-flags]: 22 https://mastodon.social/@pid_eins/112517953375791453 23 24- [Not sure if this is a gcc bug or some weird corner of UB or what... - Andrew 25 Zonenberg][azonenberg-packed-struct] 26 27[azonenberg-packed-struct]: https://ioc.exchange/@azonenberg/112535511250395148 28 29- [The Good, the Bad, and the Weird - Trail of Bits 30 Blog][trail-of-bits-weird-machines] 31 32[trail-of-bits-weird-machines]: 33 https://blog.trailofbits.com/2018/10/26/the-good-the-bad-and-the-weird/ 34 35- [Logic for Programmers - Hillel Wayne][logic-for-programmers] 36 37[logic-for-programmers]: https://leanpub.com/logic 38 39- [Parse, don’t validate][alexis-king-parse-dont-validate] 40 41[alexis-king-parse-dont-validate]: 42 https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ 43 44## References 45 46- [C17 draft standard][c17-draft-standard] 47 48[c17-draft-standard]: 49 https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf 50 51- [SEI CERT C Coding Standard][sei-cert-c-coding-standard] 52 53[sei-cert-c-coding-standard]: 54 https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard 55 56## Definitions 57 58- **Error condition**: An invalid state reached at runtime, caused either by 59 resource exhaustion, or incorrect use of the library's public APIs and data 60 types. 61 62- **Invariant**: A condition in the library's implementation that must never 63 evaluate false. 64 65- **Public API**: Any definitions and declarations under `include/libpldm`. 66 67- **Wire format**: Any message structure defined in the DMTF PLDM protocol 68 specifications. 69 70## Elaborations 71 72- Resource exhaustion is always an error condition and never an invariant 73 violation. 74 75- An invariant violation is always a programming failure of the library's 76 implementation, and never the result of incorrect use of the library's public 77 APIs (see error condition). 78 79- Corollaries of the above two points: 80 81 - Incorrect use of public API functions is always an error condition, and is 82 dealt with by returning an error code. 83 84 - Incorrect use of static functions in the library's implementation is an 85 invariant violation which may be established using `assert()`. 86 87- `assert()` is the recommended way to demonstrate invariants are upheld. 88 89## Adding a new API 90 91- [ ] My new public `struct` definitions are _not_ marked 92 `__attribute__((packed))` 93 94- [ ] My new public `struct` definitions do _not_ define a flexible array 95 member, unless: 96 97 - [ ] It's contained in an `#ifndef __cplusplus` macro guard, as flexible 98 arrays are not specified by C++, and 99 100 - [ ] I've implemented an accessor function so the array base pointer can be 101 accessed from C++, and 102 103 - [ ] It is defined as per the C17 specification by omitting the length[^1] 104 105 - Note: Any array defined with length 1 is _not_ a flexible array, and any 106 access beyond the first element invokes undefined behaviour in both C and 107 C++. 108 109[^1]: 110 [C17 draft specification][c17-draft-standard], 6.7.2.1 Structure and union 111 specifiers, paragraph 18. 112 113- [ ] If my work interacts with the PLDM wire format, then I have done so using 114 the `msgbuf` APIs found in `src/msgbuf.h` (and under `src/msgbuf/`) to 115 minimise concerns around spatial memory safety and endian-correctness. 116 117- [ ] All my error conditions are handled by returning an error code to the 118 caller. 119 120- [ ] All my invariants are tested using `assert()`. 121 122- [ ] I have not used `assert()` to evaluate any error conditions without also 123 handling the error condition by returning an error code the the caller. 124 125 - Release builds of the library are configured with `assert()` disabled 126 (`-Db_ndebug=if-release`, which provides `-DNDEBUG` in `CFLAGS`). 127 128- [ ] My new APIs return negative `errno` values on error and not PLDM 129 completion codes. 130 131 - [ ] The specific error values my function returns and their meaning in the 132 context of the function call are listed in the API documentation. 133 134- [ ] If I've added support for a new PLDM message type, then I've implemented 135 both the encoder and decoder for that message. Note this applies for both 136 request _and_ response message types. 137 138- [ ] My new function symbols are marked with `LIBPLDM_ABI_TESTING` in the 139 implementation 140 141- [ ] I've implemented test cases with reasonable branch coverage of each new 142 function I've added 143 144- [ ] I've guarded the test cases of functions marked `LIBPLDM_ABI_TESTING` so 145 that they are not compiled when the corresponding function symbols aren't 146 visible 147 148- [ ] If I've added support for a new message type, then my commit message 149 specifies all of: 150 151 - [ ] The relevant DMTF specification by its DSP number and title 152 - [ ] The relevant version of the specification 153 - [ ] The section of the specification that defines the message type 154 155- [ ] If my work impacts the public API of the library, then I've added an entry 156 to `CHANGELOG.md` describing my work 157 158## Stabilising an existing API 159 160- [ ] The API of interest is currently marked `LIBPLDM_ABI_TESTING` 161 162- [ ] My commit message links to a publicly visible patch that makes use of the 163 API 164 165- [ ] My commit updates the annotation from `LIBPLDM_ABI_TESTING` to 166 `LIBPLDM_ABI_STABLE` only for the function symbols demonstrated by the 167 patch linked in the commit message. 168 169- [ ] I've removed guards from the function's tests so they are always compiled 170 171- [ ] If I've updated the ABI dump, then I've used the OpenBMC CI container to 172 do so. 173 174## Updating an ABI dump 175 176Each of the following must succeed: 177 178- [ ] Enter the OpenBMC CI Docker container 179 - Approximately: 180 `docker run --cap-add=sys_admin --rm=true --privileged=true -u $USER -w $(pwd) -v $(pwd):$(pwd) -e MAKEFLAGS= -it openbmc/ubuntu-unit-test:2024-W21-ce361f95ff4fa669` 181- [ ] `CC=gcc CXX=g++; [ $(uname -m) = 'x86_64' ] && meson setup -Dabi=deprecated,stable build` 182- [ ] `meson compile -C build` 183- [ ] `./scripts/abi-dump-formatter < build/src/current.dump > abi/x86_64/gcc.dump` 184 185## Removing an API 186 187- [ ] If the function is marked `LIBPLDM_ABI_TESTING`, then I have removed it 188 189- [ ] If the function is marked `LIBPLDM_ABI_STABLE`, then I have changed the 190 annotation to `LIBPLDM_ABI_DEPRECATED` and left it in-place. 191 192 - [ ] I have updated the ABI dump, or will mark the change as WIP until it has 193 been. 194 195- [ ] If the function is marked `LIBPLDM_ABI_DEPRECATED`, then I have removed it 196 only after satisfying myself that each of the following is true: 197 198 - [ ] There are no known users of the function left in the community 199 - [ ] There has been at least one tagged release of `libpldm` subsequent to 200 the API being marked deprecated 201 202## Renaming an API 203 204A change to an API is a pure rename only if there are no additional behavioural 205changes. Renaming an API with no other behavioural changes is really two 206actions: 207 2081. Introducing the new API name 2092. Deprecating the old API name 210 211- [ ] Only the name of the function has changed. None of its behaviour has 212 changed. 213 214- [ ] Both the new and the old functions are declared in the public headers 215 216- [ ] I've aliased the old function name to the new function name via the 217 `libpldm_deprecated_aliases` list in `meson.build` 218 219- [ ] I've added a [semantic patch][coccinelle] to migrate users from the old 220 name to the new name 221 222[coccinelle]: https://coccinelle.gitlabpages.inria.fr/website/ 223 224- [ ] I've updated the ABI dump to capture the rename, or will mark the change 225 as WIP until it has been. 226 227## Testing my changes 228 229Each of the following must succeed when executed in order. Note that to avoid 230[googletest bug #4232][googletest-issue-4232] you must avoid using GCC 12 231(shipped in Debian Bookworm). 232 233[googletest-issue-4232]: https://github.com/google/googletest/issues/4232 234 235- [ ] `meson setup -Dabi-compliance-check=disabled build` 236- [ ] `meson compile -C build && meson test -C build` 237 238- [ ] `meson configure --buildtype=release build` 239- [ ] `meson compile -C build && meson test -C build` 240 241- [ ] `meson configure --buildtype=debug build` 242- [ ] `meson configure -Dabi=deprecated,stable build` 243- [ ] `meson compile -C build && meson test -C build` 244 245This process is captured in `scripts/pre-submit` for automation. 246