Re: [PATCH] Add tests for Bitmapset
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Greg Burd <greg@burd.me>
Cc: Michael Paquier <michael@paquier.xyz>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-09-30T23:00:39Z
Lists: pgsql-hackers
Attachments
- adjustments_to_test_bitmapset_module.patch (application/octet-stream) patch
On Wed, 1 Oct 2025 at 01:38, Greg Burd <greg@burd.me> wrote: > v2 attached. Thanks. I looked at this and I think we can do a bit better to simplify the code and standardise what we do when faced with bogus inputs. Here's what I've done: 1. Added helper macros PG_ARG_GETBITMAPSET() and PG_RETURN_BITMAPSET_AS_TEXT(). These themselves save a few hundred lines of code and make the functions easier to read. 2. Standardised that the test function returns NULL when it receives invalid input. e.g if we aim to pass an "int" to the underlying Bitmapset function, if someone calls the test function with an SQL NULL, just return NULL rather than trying to come up with some logic on what we should do about that. 3. I couldn't quite understand the extra parameter to test_bms_get_singleton_member() so I ended up removing it and making the test function return -1 when the set isn't a singleton. I didn't search for discussion about that so I might have missed the specific reason it was done that way. 4. Wrote some comments to try to communicate the standards defined. This aims to offer guidance to callers of these functions and anyone hacking on the module itself in the future. git diff --stat looks like: 4 files changed, 233 insertions(+), 505 deletions(-) Things not done: 1. I didn't update the expected test results. 2. I didn't rationalise the tests. I feel that there's no point in the tests that purposefully pass invalid input to the module's test function. It appears that's aiming to increase coverage on the test module's C code, which I don't quite understand. In any case, due to the helper macros, I don't think removing these will lower the per-source-file line coverage of the module itself. I've not checked my work very thoroughly. I can do that, or you can if you and Michael are ok with the proposed ideas. I'm also not aiming to commandeer anything here. Writing the patch was just the easiest way to communicate the ideas I had. I also wonder how worthwhile it is to try to free the Bitmapsets. I'd have expected these allocations to be in a pretty short-lived memory context. I count 44 calls to bms_free(). David
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Minor fixes for test_bitmapset.c
- 5142f0093e64 19 (unreleased) landed
-
test_bitmapset: Improve random function
- 9d46b86529e8 19 (unreleased) landed
-
Add mem_exceeded_count column to pg_stat_replication_slots.
- d3b6183dd988 19 (unreleased) landed
-
Tidy-up unneeded NULL parameter checks from SQL function
- a69b55cd4727 19 (unreleased) landed
-
Remove check for NULL in STRICT function
- 381f5cffae00 19 (unreleased) landed
-
Fixes for comments in test_bitmapset
- a1b064e4b226 19 (unreleased) landed
-
Minor fixups of test_bitmapset.c
- 3a6615806859 19 (unreleased) landed
-
test_bitmapset: Simplify code of the module
- 9952f6c05a40 19 (unreleased) landed
-
test_bitmapset: Expand more the test coverage
- 5668fff3c512 19 (unreleased) landed
-
Fix compiler warnings in test_bitmapset
- f83fe65f3fc1 19 (unreleased) landed
-
Add a test module for Bitmapset
- 00c3d87a5cab 19 (unreleased) landed