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