From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za9a0-0005io-7V for qemu-devel@nongnu.org; Thu, 10 Sep 2015 17:40:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Za9Zz-0004Dt-2u for qemu-devel@nongnu.org; Thu, 10 Sep 2015 17:40:28 -0400 References: <1440623592-13999-1-git-send-email-jsnow@redhat.com> <1440623592-13999-3-git-send-email-jsnow@redhat.com> <87pp1q7htu.fsf@blackfin.pond.sub.org> From: John Snow Message-ID: <55F1F8C2.1050807@redhat.com> Date: Thu, 10 Sep 2015 17:40:18 -0400 MIME-Version: 1.0 In-Reply-To: <87pp1q7htu.fsf@blackfin.pond.sub.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/4] qtest/ahci: export generate_pattern List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, qemu-block@nongnu.org, zuban32s@gmail.com, qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com On 09/10/2015 05:18 AM, Markus Armbruster wrote: > John Snow writes: >=20 >> Share the pattern function for ide and ahci test. >> >> Signed-off-by: John Snow >> --- >> tests/ahci-test.c | 26 -------------------------- >> tests/libqos/libqos.c | 26 ++++++++++++++++++++++++++ >> tests/libqos/libqos.h | 1 + >> 3 files changed, 27 insertions(+), 26 deletions(-) >> >> diff --git a/tests/ahci-test.c b/tests/ahci-test.c >> index b1a785c..59d387c 100644 >> --- a/tests/ahci-test.c >> +++ b/tests/ahci-test.c >> @@ -71,32 +71,6 @@ static void string_bswap16(uint16_t *s, size_t byte= s) >> } >> } >> =20 >> -static void generate_pattern(void *buffer, size_t len, size_t cycle_l= en) >> -{ >> - int i, j; >> - unsigned char *tx =3D (unsigned char *)buffer; >> - unsigned char p; >> - size_t *sx; >> - >> - /* Write an indicative pattern that varies and is unique per-cycl= e */ >> - p =3D rand() % 256; >> - for (i =3D 0; i < len; i++) { >> - tx[i] =3D p++ % 256; >> - if (i % cycle_len =3D=3D 0) { >> - p =3D rand() % 256; >> - } >> - } >> - >> - /* force uniqueness by writing an id per-cycle */ >> - for (i =3D 0; i < len / cycle_len; i++) { >> - j =3D i * cycle_len; >> - if (j + sizeof(*sx) <=3D len) { >> - sx =3D (size_t *)&tx[j]; >> - *sx =3D i; >> - } >> - } >> -} >> - >> /** >> * Verify that the transfer did not corrupt our state at all. >> */ >> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c >> index fce625b..8d7c5a9 100644 >> --- a/tests/libqos/libqos.c >> +++ b/tests/libqos/libqos.c >> @@ -212,3 +212,29 @@ void prepare_blkdebug_script(const char *debug_fn= , const char *event) >> ret =3D fclose(debug_file); >> g_assert(ret =3D=3D 0); >> } >> + >> +void generate_pattern(void *buffer, size_t len, size_t cycle_len) >> +{ >> + int i, j; >> + unsigned char *tx =3D (unsigned char *)buffer; >> + unsigned char p; >> + size_t *sx; >> + >> + /* Write an indicative pattern that varies and is unique per-cycl= e */ >> + p =3D rand() % 256; >> + for (i =3D 0; i < len; i++) { >> + tx[i] =3D p++ % 256; >> + if (i % cycle_len =3D=3D 0) { >> + p =3D rand() % 256; >> + } >> + } >> + >> + /* force uniqueness by writing an id per-cycle */ >> + for (i =3D 0; i < len / cycle_len; i++) { >> + j =3D i * cycle_len; >> + if (j + sizeof(*sx) <=3D len) { >> + sx =3D (size_t *)&tx[j]; >=20 > Relies on cycle_len being a multiple of size_t's alignment. So far, > it's always AHCI_SECTOR_SIZE, which should do. >=20 >> + *sx =3D i; >> + } >> + } >> +} >=20 > Looks like overkill to me, but since it's working code... :) >=20 I'll spare you the details, but I found it to be genuinely helpful to have a pattern like this while debugging. Makes it very easy to see which pattern came from where and so on. The per-sector uniqueness was critical, too ... >> diff --git a/tests/libqos/libqos.h b/tests/libqos/libqos.h >> index e1f14ea..492a651 100644 >> --- a/tests/libqos/libqos.h >> +++ b/tests/libqos/libqos.h >> @@ -24,6 +24,7 @@ void mkqcow2(const char *file, unsigned size_mb); >> void set_context(QOSState *s); >> void migrate(QOSState *from, QOSState *to, const char *uri); >> void prepare_blkdebug_script(const char *debug_fn, const char *event)= ; >> +void generate_pattern(void *buffer, size_t len, size_t cycle_len); >> =20 >> static inline uint64_t qmalloc(QOSState *q, size_t bytes) >> { --=20 =97js