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## References 40 41- [C17 draft standard][c17-draft-standard] 42 43[c17-draft-standard]: 44 https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf 45 46- [SEI CERT C Coding Standard][sei-cert-c-coding-standard] 47 48[sei-cert-c-coding-standard]: 49 https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard 50 51## Definitions 52 53- **Error condition**: An invalid state reached at runtime, caused either by 54 resource exhaustion, or incorrect use of the library's public APIs and data 55 types. 56 57- **Invariant**: A condition in the library's implementation that must never 58 evaluate false. 59 60- **Public API**: Any definitions and declarations under `include/libpldm`. 61 62- **Wire format**: Any message structure defined in the DMTF PLDM protocol 63 specifications. 64 65## Elaborations 66 67- Resource exhaustion is always an error condition and never an invariant 68 violation. 69 70- An invariant violation is always a programming failure of the library's 71 implementation, and never the result of incorrect use of the library's public 72 APIs (see error condition). 73 74- Corollaries of the above two points: 75 76 - Incorrect use of public API functions is always an error condition, and is 77 dealt with by returning an error code. 78 79 - Incorrect use of static functions in the library's implementation is an 80 invariant violation which may be established using `assert()`. 81 82- `assert()` is the recommended way to demonstrate invariants are upheld. 83 84## Adding a new API 85 86- [ ] My new public `struct` definitions are _not_ marked 87 `__attribute__((packed))` 88 89- [ ] My new public `struct` definitions do _not_ define a flexible array 90 member, unless: 91 92 - [ ] It's contained in an `#ifndef __cplusplus` macro guard, as flexible 93 arrays are not specified by C++, and 94 95 - [ ] I've implemented an accessor function so the array base pointer can be 96 accessed from C++, and 97 98 - [ ] It is defined as per the C17 specification by omitting the length[^1] 99 100 - Note: Any array defined with length 1 is _not_ a flexible array, and any 101 access beyond the first element invokes undefined behaviour in both C and 102 C++. 103 104[^1]: 105 [C17 draft specification][c17-draft-standard], 6.7.2.1 Structure and union 106 specifiers, paragraph 18. 107 108- [ ] If my work interacts with the PLDM wire format, then I have done so using 109 the `msgbuf` APIs found in `src/msgbuf.h` (and under `src/msgbuf/`) to 110 minimise concerns around spatial memory safety and endian-correctness. 111 112- [ ] All my error conditions are handled by returning an error code to the 113 caller. 114 115- [ ] All my invariants are tested using `assert()`. 116 117- [ ] I have not used `assert()` to evaluate any error conditions without also 118 handling the error condition by returning an error code the the caller. 119 120 - Release builds of the library are configured with `assert()` disabled 121 (`-Db_ndebug=if-release`, which provides `-DNDEBUG` in `CFLAGS`). 122 123- [ ] My new APIs return negative `errno` values on error and not PLDM 124 completion codes. 125 126 - [ ] The specific error values my function returns and their meaning in the 127 context of the function call are listed in the API documentation. 128 129- [ ] If I've added support for a new PLDM message type, then I've implemented 130 both the encoder and decoder for that message. Note this applies for both 131 request _and_ response message types. 132 133- [ ] My new function symbols are marked with `LIBPLDM_ABI_TESTING` in the 134 implementation 135 136- [ ] I've implemented test cases with reasonable branch coverage of each new 137 function I've added 138 139- [ ] I've guarded the test cases of functions marked `LIBPLDM_ABI_TESTING` so 140 that they are not compiled when the corresponding function symbols aren't 141 visible 142 143- [ ] If I've added support for a new message type, then my commit message 144 specifies all of: 145 146 - [ ] The relevant DMTF specification by its DSP number and title 147 - [ ] The relevant version of the specification 148 - [ ] The section of the specification that defines the message type 149 150- [ ] If my work impacts the public API of the library, then I've added an entry 151 to `CHANGELOG.md` describing my work 152 153## Stabilising an existing API 154 155- [ ] The API of interest is currently marked `LIBPLDM_ABI_TESTING` 156 157- [ ] My commit message links to a publicly visible patch that makes use of the 158 API 159 160- [ ] My commit updates the annotation from `LIBPLDM_ABI_TESTING` to 161 `LIBPLDM_ABI_STABLE` only for the function symbols demonstrated by the 162 patch linked in the commit message. 163 164- [ ] I've removed guards from the function's tests so they are always compiled 165 166- [ ] If I've updated the ABI dump, then I've used the OpenBMC CI container to 167 do so. 168 169## Updating an ABI dump 170 171Each of the following must succeed: 172 173- [ ] Enter the OpenBMC CI Docker container 174 - Approximately: 175 `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` 176- [ ] `CC=gcc CXX=g++; [ $(uname -m) = 'x86_64' ] && meson setup -Dabi=deprecated,stable build` 177- [ ] `meson compile -C build` 178- [ ] `./scripts/abi-dump-formatter < build/src/current.dump > abi/x86_64/gcc.dump` 179 180## Removing an API 181 182- [ ] If the function is marked `LIBPLDM_ABI_TESTING`, then I have removed it 183 184- [ ] If the function is marked `LIBPLDM_ABI_STABLE`, then I have changed the 185 annotation to `LIBPLDM_ABI_DEPRECATED` and left it in-place. 186 187 - [ ] I have updated the ABI dump, or will mark the change as WIP until it has 188 been. 189 190- [ ] If the function is marked `LIBPLDM_ABI_DEPRECATED`, then I have removed it 191 only after satisfying myself that each of the following is true: 192 193 - [ ] There are no known users of the function left in the community 194 - [ ] There has been at least one tagged release of `libpldm` subsequent to 195 the API being marked deprecated 196 197## Renaming an API 198 199A change to an API is a pure rename only if there are no additional behavioural 200changes. Renaming an API with no other behavioural changes is really two 201actions: 202 2031. Introducing the new API name 2042. Deprecating the old API name 205 206- [ ] Only the name of the function has changed. None of its behaviour has 207 changed. 208 209- [ ] Both the new and the old functions are declared in the public headers 210 211- [ ] I've aliased the old function name to the new function name via the 212 `libpldm_deprecated_aliases` list in `meson.build` 213 214- [ ] I've added a [semantic patch][coccinelle] to migrate users from the old 215 name to the new name 216 217[coccinelle]: https://coccinelle.gitlabpages.inria.fr/website/ 218 219- [ ] I've updated the ABI dump to capture the rename, or will mark the change 220 as WIP until it has been. 221 222## Testing my changes 223 224Each of the following must succeed when executed in order. Note that to avoid 225[googletest bug #4232][googletest-issue-4232] you must avoid using GCC 12 226(shipped in Debian Bookworm). 227 228[googletest-issue-4232]: https://github.com/google/googletest/issues/4232 229 230- [ ] `meson setup -Dabi-compliance-check=disabled build` 231- [ ] `meson compile -C build && meson test -C build` 232 233- [ ] `meson configure --buildtype=release build` 234- [ ] `meson compile -C build && meson test -C build` 235 236- [ ] `meson configure --buildtype=debug build` 237- [ ] `meson configure -Dabi=deprecated,stable build` 238- [ ] `meson compile -C build && meson test -C build` 239 240This process is captured in `scripts/pre-submit` for automation. 241