From patchwork Thu Mar 26 14:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11460249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 402516CA for ; Thu, 26 Mar 2020 14:34:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1754D20714 for ; Thu, 26 Mar 2020 14:34:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IksjgUK9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1754D20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTaG-0001TR-6f for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 Mar 2020 10:34:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41461) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jHTWQ-0004D0-8k for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:30:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jHTWP-0002zl-1e for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:30:14 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:37141) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jHTWO-0002zN-T4 for qemu-devel@nongnu.org; Thu, 26 Mar 2020 10:30:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585233012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ds3GO1HPvZnBnCHWEUNrKnJOCxbvSIxgAYAkojhjyF8=; b=IksjgUK9MRMnXRP4TgzIyo2qrGuvkEUeIwl0dITWitV5HbZQtiyB5j8z2ornJgfpObuMkN lkGKIEQt8P3aTMpISXWEU2T42qwt0zACvSOfA18sekAnSvlXehpeGq872TsnfTrcCPcgMo d3jOYL+bXuRn0fglqtN5g4169XS9Acw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-Pf533dMcPzqX-C29rgsMRQ-1; Thu, 26 Mar 2020 10:30:10 -0400 X-MC-Unique: Pf533dMcPzqX-C29rgsMRQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 319AC189F771; Thu, 26 Mar 2020 14:30:09 +0000 (UTC) Received: from localhost (ovpn-112-132.ams2.redhat.com [10.36.112.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7E165C297; Thu, 26 Mar 2020 14:30:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 09/10] iotests: Add poke_file_[bl]e functions Date: Thu, 26 Mar 2020 15:29:32 +0100 Message-Id: <20200326142933.625037-10-mreitz@redhat.com> In-Reply-To: <20200326142933.625037-1-mreitz@redhat.com> References: <20200326142933.625037-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Similarly to peek_file_[bl]e, we may want to write binary integers into a file. Currently, this often means messing around with poke_file and raw binary strings. I hope these functions make it a bit more comfortable. Signed-off-by: Max Reitz Code-suggested-by: Eric Blake Message-Id: <20200324172757.1173824-3-mreitz@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 4c246c0450..bf3b9fdea0 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -53,6 +53,30 @@ poke_file() printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null } +# poke_file_le $img_filename $offset $byte_width $value +# Example: poke_file_le "$TEST_IMG" 512 2 65534 +poke_file_le() +{ + local img=$1 ofs=$2 len=$3 val=$4 str='' + + while ((len--)); do + str+=$(printf '\\x%02x' $((val & 0xff))) + val=$((val >> 8)) + done + + poke_file "$img" "$ofs" "$str" +} + +# poke_file_be $img_filename $offset $byte_width $value +# Example: poke_file_be "$TEST_IMG" 512 2 65279 +poke_file_be() +{ + local img=$1 ofs=$2 len=$3 val=$4 + local str=$(printf "%0$((len * 2))x\n" $val | sed 's/\(..\)/\\x\1/g') + + poke_file "$img" "$ofs" "$str" +} + # peek_file_le 'test.img' 512 2 => 65534 peek_file_le() {