From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Q2Mm7-0002om-Rj for mharc-grub-devel@gnu.org; Wed, 23 Mar 2011 08:02:55 -0400 Received: from [140.186.70.92] (port=38502 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2Mm5-0002ho-Bc for grub-devel@gnu.org; Wed, 23 Mar 2011 08:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2Mm0-0001tf-Vu for grub-devel@gnu.org; Wed, 23 Mar 2011 08:02:52 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:39600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2Mm0-0001sP-Ll for grub-devel@gnu.org; Wed, 23 Mar 2011 08:02:48 -0400 Received: by eyh6 with SMTP id 6so2219585eyh.0 for ; Wed, 23 Mar 2011 05:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:x-enigmail-version:content-type; bh=Zu8M5mNdqTQE6O8tAua+ITjlyrOXmKTC+SeY234ws8E=; b=awhaf7XuexCJ3c3tN+yXjrFIzp+c4ooKIdhFpjKuk1wHHO0v4gAjZZvMduTquHfcGv lWC0istCY53yTxpSoTeu2CImKrQIaDzgx+7H1E8zkRuu6wbCrYPE2Di7BzrmF9hBJl+N bB6ioCTNeAxHyWYy72cqie9WenFlgqwXSzjI4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=UZ2cEHKAUaYpPCfXrYWtzMjJUqAp+KEVus/mwE51/v31Sgd4klxxkCMLomN6hGWu4O WW9dxHQaD86xTFk2j4f/aT2/myTXNVZkq+sSMxw4hA6wOCeO65HkC1k/7bD3FWiN5UhA qHIVpY6voKdqL2jUBlW+2wmIFGnL1gzqTytVA= Received: by 10.14.137.200 with SMTP id y48mr2413500eei.166.1300881767319; Wed, 23 Mar 2011 05:02:47 -0700 (PDT) Received: from debian.x201.phnet (etx-public-dock-248-dhcp.ethz.ch [82.130.81.248]) by mx.google.com with ESMTPS id u45sm3594655eeh.16.2011.03.23.05.02.45 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Mar 2011 05:02:45 -0700 (PDT) Message-ID: <4D89E163.3060001@gmail.com> Date: Wed, 23 Mar 2011 13:02:43 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110303 Iceowl/1.0b1 Icedove/3.0.11 MIME-Version: 1.0 To: The development of GNU GRUB References: <1299097456-9033-1-git-send-email-pjones@redhat.com> In-Reply-To: <1299097456-9033-1-git-send-email-pjones@redhat.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigEF4356C93F51474A88BA9900" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.169 Subject: Re: [PATCH] Make grub_test_assert() correctly format its output. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2011 12:02:54 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigEF4356C93F51474A88BA9900 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 02.03.2011 21:24, Peter Jones wrote: > The old code gives arguments to a printf function which can't work > correctly, and the compiler complains. > =20 Committed. Thanks. > --- > grub-core/tests/example_functional_test.c | 2 +- > grub-core/tests/lib/test.c | 88 +++++++++++++++++++++= ++++++-- > include/grub/test.h | 10 ++- > 3 files changed, 90 insertions(+), 10 deletions(-) > > diff --git a/grub-core/tests/example_functional_test.c b/grub-core/test= s/example_functional_test.c > index 5259881..0c69749 100644 > --- a/grub-core/tests/example_functional_test.c > +++ b/grub-core/tests/example_functional_test.c > @@ -24,7 +24,7 @@ static void > example_test (void) > { > /* Check if 1st argument is true and report with default error messa= ge. */ > - grub_test_assert (1 =3D=3D 1); > + grub_test_assert (1 =3D=3D 1, "1 equal 1 expected"); > =20 > /* Check if 1st argument is true and report with custom error messag= e. */ > grub_test_assert (2 =3D=3D 2, "2 equal 2 expected"); > diff --git a/grub-core/tests/lib/test.c b/grub-core/tests/lib/test.c > index 06d78b7..e3e777c 100644 > --- a/grub-core/tests/lib/test.c > +++ b/grub-core/tests/lib/test.c > @@ -42,22 +42,75 @@ typedef struct grub_test_failure *grub_test_failure= _t; > grub_test_t grub_test_list; > static grub_test_failure_t failure_list; > =20 > -static void > -add_failure (const char *file, > - const char *funp, > - grub_uint32_t line, const char *fmt, va_list args) > +static grub_test_failure_t > +failure_start(const char *file, const char *funp, grub_uint32_t line);= > +static grub_test_failure_t > +failure_start(const char *file, const char *funp, grub_uint32_t line) > { > grub_test_failure_t failure; > =20 > failure =3D (grub_test_failure_t) grub_malloc (sizeof (*failure)); > if (!failure) > - return; > + return NULL; > =20 > failure->file =3D grub_strdup (file ? : ""); > + if (!failure->file) > + { > + grub_free(failure); > + return NULL; > + } > + > failure->funp =3D grub_strdup (funp ? : ""); > + if (!failure->funp) > + { > + grub_free(failure->file); > + grub_free(failure); > + return NULL; > + } > + > failure->line =3D line; > - failure->message =3D grub_xvasprintf (fmt, args); > =20 > + failure->message =3D NULL; > + > + return failure; > +} > + > +static void > +failure_append_vtext(grub_test_failure_t failure, const char *fmt, va_= list args); > +static void > +failure_append_vtext(grub_test_failure_t failure, const char *fmt, va_= list args) > +{ > + char *msg =3D grub_xvasprintf(fmt, args); > + if (failure->message) > + { > + char *oldmsg =3D failure->message; > + > + failure->message =3D grub_xasprintf("%s%s", oldmsg, msg); > + grub_free(oldmsg); > + } > + else > + { > + failure->message =3D msg; > + } > +} > + > +static void > +failure_append_text(grub_test_failure_t failure, const char *fmt, ...)= > +{ > + va_list args; > + > + va_start(args, fmt); > + failure_append_vtext(failure, fmt, args); > + va_end(args); > +} > + > +static void > +add_failure (const char *file, > + const char *funp, > + grub_uint32_t line, const char *fmt, va_list args) > +{ > + grub_test_failure_t failure =3D failure_start(file, funp, line); > + failure_append_text(failure, fmt, args); > grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failur= e)); > } > =20 > @@ -100,6 +153,29 @@ grub_test_nonzero (int cond, > } > =20 > void > +grub_test_assert_helper (int cond, const char *file, const char *funp,= > + grub_uint32_t line, const char *condstr, > + const char *fmt, ...) > +{ > + va_list ap; > + grub_test_failure_t failure; > + > + if (cond) > + return; > + > + failure =3D failure_start(file, funp, line); > + failure_append_text(failure, "assert failed: %s ", condstr); > + > + va_start(ap, fmt); > + > + failure_append_vtext(failure, fmt, ap); > + > + va_end(ap); > + > + grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failur= e)); > +} > + > +void > grub_test_register (const char *name, void (*test_main) (void)) > { > grub_test_t test; > diff --git a/include/grub/test.h b/include/grub/test.h > index 336d3b6..3f0bd9f 100644 > --- a/include/grub/test.h > +++ b/include/grub/test.h > @@ -53,10 +53,14 @@ void grub_test_nonzero (int cond, const char *file,= > __attribute__ ((format (printf, 5, 6))); > =20 > /* Macro to fill in location details and an optional error message. *= / > +void grub_test_assert_helper (int cond, const char *file, > + const char *func, grub_uint32_t line, > + const char *condstr, const char *fmt, ...) > + __attribute__ ((format (printf, 6, 7))); > + > #define grub_test_assert(cond, ...) \ > - grub_test_nonzero(cond, GRUB_FILE, __FUNCTION__, __LINE__, \ > - ## __VA_ARGS__, \ > - "assert failed: %s", #cond) > + grub_test_assert_helper(cond, GRUB_FILE, __FUNCTION__, __LINE__, \ > + #cond, ## __VA_ARGS__); > =20 > /* Macro to define a unit test. */ > #define GRUB_UNIT_TEST(name, funp) \ > =20 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enigEF4356C93F51474A88BA9900 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAk2J4WMACgkQNak7dOguQglIeAEAwbtR8KPyQJTXi/GuQ45f3Us4 XtQxIc6HFXSPHRDznG8A/0HSLRVYMRE3P1CgRwK7eaNv4za7mSoHj4lql1UiMv8O =FnaG -----END PGP SIGNATURE----- --------------enigEF4356C93F51474A88BA9900--