Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iGwBB-0004te-4x for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2019 02:21:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iGwAA-0007Mi-6Q for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2019 02:20:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iGwA9-0007MJ-JW for pgsql-hackers@lists.postgresql.org; Sun, 06 Oct 2019 02:20:45 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iGwA6-00043g-5h for pgsql-hackers@lists.postgresql.org; Sun, 06 Oct 2019 02:20:43 +0000 Received: by mail-pl1-x632.google.com with SMTP id s17so5036186plp.6 for ; Sat, 05 Oct 2019 19:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fHdqg2ix8a4kRK8KlDiUhwGyeXxMM8PwBIHzL68bWXQ=; b=Jfq/Du3F+u8viA52P+mpDFVUWWPK5eM8kdMqaAbFb3A9TUKz5v5cPfaJAfamA9Q9tk 9BM/Z/Sael7SG49HVMM0mYZd5Y2/tunXlkC1uC6y+wFycdIFURy/Lj/jtOL4UlMzwmj8 J/GHq4JBOHc8g1cKPMQi4ec4px29VjCM40q+c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fHdqg2ix8a4kRK8KlDiUhwGyeXxMM8PwBIHzL68bWXQ=; b=FKjG3UI487TXOeRoWRH7dkwoNViWxMsc1uvJN2zcN38oyOK4UZkUAmy2ajGHzd1nB3 X+AUy5cr61ygJshsKq7euVx4ZsAkCiZkQBzAHqpNf/W1w7nl7MWIe9AdDnYnuJW9/fun TfzelDuVkR34FTCvaPd3qCBYgoc8hte2w1fVvCWCRO4166fAobV4/sV8noyES9dJxwb6 imtjFLMwDE1qu70hzJEiSxrvCK6q0bYLmguYnnDHE82LkS5TfYZBzYXJoI4sAxM9pyCH XrdLcupwgkcCdP/za36BcOGtWx2LF52dImkaPHSELSu2CxZrDUyTiwx/Qn1+xYe0POwE l/bQ== X-Gm-Message-State: APjAAAUGygG2+LGLc+ssCvSMaycRn+wjHY1MvQYpUUujUqhRnwFZIsJF Vj6SQ3Ba1xASt8hqnhhpj1d3D8ANkgA= X-Google-Smtp-Source: APXvYqzmhyGi3v/8j06mulw+0wDZtOwFncZRBUkl2zQg2CTZ6ADtHlExCzGIihoLexKpNMLX4FjyAg== X-Received: by 2002:a17:902:524:: with SMTP id 33mr23206709plf.123.1570328440690; Sat, 05 Oct 2019 19:20:40 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id x20sm11743726pfp.120.2019.10.05.19.20.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Oct 2019 19:20:39 -0700 (PDT) Date: Sat, 5 Oct 2019 19:20:38 -0700 From: Noah Misch To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org Subject: Re: expressive test macros (was: Report test_atomic_ops() failures consistently, via macros) Message-ID: <20191006022038.GB4023404@rfd.leadboat.com> References: <20191005190729.6sx7g23ifdu65s7s@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191005190729.6sx7g23ifdu65s7s@alap3.anarazel.de> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Oct 05, 2019 at 12:07:29PM -0700, Andres Freund wrote: > +#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? Sounds reasonable. For broader use, I would include the expected value, not just expected_expr: elog(ERROR, \ "%s yielded %u, expected %s (%u) in file \"%s\" line %u", \ #result_expr, result, #expected_expr, expected, __FILE__, __LINE__); \ I didn't do that for the atomics tests, where expected_expr is always trivial. The codebase has plenty of Assert(x == y) where either of x or y could have the surprising value.