celix icon indicating copy to clipboard operation
celix copied to clipboard

Memory allocation failure and whitebox unit testing

Open PengZheng opened this issue 3 years ago • 0 comments

As discussed in https://github.com/apache/celix/pull/392#discussion_r790315940, Celix currently assumes that malloc/calloc always succeeds. Rust standard library makes similar assumption, i.e. , memory allocation failure causes direct abort().

However, as far as I know, malloc/calloc can fail on Linux:

  • overcommit can be turned off
  • ulimit setting
  • calloc returns NULL when integer overflow (nmemb * size) is detected in glibc

@pnoltes asks me for an effective way of testing malloc/calloc failure. My answer is summarized in Malloc/Calloc failure emulation playing nicely with Google Address Sanitizer .

More general whitebox unit testing and its tradeoff is discussed in https://github.com/apache/celix/pull/392#discussion_r791780927. The suggested testing strategy is battle-tested in my day-time job, monitoring a 1MLOC C/C++ codebase, where AlarmUploader in https://github.com/apache/celix/pull/392#discussion_r791780927 comes from.

PengZheng avatar Jan 26 '22 08:01 PengZheng