expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)
Date: 2019-10-05 19:07:29
Message-ID: 20191005190729.6sx7g23ifdu65s7s@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Hi,

On 2019-10-05 17:08:38 +0000, Noah Misch wrote:
> Report test_atomic_ops() failures consistently, via macros.
>
> This prints the unexpected value in more failure cases, and it removes
> forty-eight hand-maintained error messages. Back-patch to 9.5, which
> introduced these tests.

Thanks for these, that's a nice improvement.

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=639feb92e1186e1de495d1bfdb191869cb56450a

...
+#define EXPECT_EQ_U32(result_expr, expected_expr) \
+ do { \
+ uint32 result = (result_expr); \
+ uint32 expected = (expected_expr); \
+ if (result != expected) \
+ elog(ERROR, \
+ "%s yielded %u, expected %s in file \"%s\" line %u", \
+ #result_expr, result, #expected_expr, __FILE__, __LINE__); \
+ } while (0)
...

I wonder if we should put these (and a few more, for other types), into
a more general place. I would like to have them for writing both tests
like regress.c:test_atomic_ops(), and for writing assertions that
actually display useful error messages. For the former it makes sense
to ERROR out, for the latter they ought to abort, as currently.

Seems like putting ASSERT_{EQ,LT,...}_{U32,S32,...} (or Assert_Eq_...,
but that'd imo look weirder than the inconsistency) into c.h would make
sense, and EXPECT_ somewhere in common/pg_test.h or such?

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2019-10-06 02:20:38 Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros)
Previous Message Tomas Vondra 2019-10-05 18:53:54 pgsql: Change MemoryContextMemAllocated to return Size

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2019-10-05 19:13:59 Re: Transparent Data Encryption (TDE) and encrypted files
Previous Message Noah Misch 2019-10-05 17:34:00 Re: [HACKERS] Deadlock in XLogInsert at AIX