Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13F24C04A95 for ; Sat, 22 Oct 2022 20:17:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 443F884E3A; Sat, 22 Oct 2022 22:16:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="e+rp0GZb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 64E9284D8E; Sat, 22 Oct 2022 22:16:56 +0200 (CEST) Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7DDEA84D8E for ; Sat, 22 Oct 2022 22:16:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2c.google.com with SMTP id ml12so3120575qvb.0 for ; Sat, 22 Oct 2022 13:16:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5UdBWYGNOw2cJTpK9RuRUxRHwNWek007CJ9FxFMrrp0=; b=e+rp0GZbTMWf+Mbu/jvp8c7syyU2+xsU0ILBEX0jAhwLWqhdxMvEG2GftvFXqDKBRK OMDqgLfx12bL5r7FdMuDeCXHsquokoVNFapJ/+c99ZQec4FlsNn60MJVGEn98BJMSmN6 bK0UTiX8qbC/7YACID3JKMVXRdjTY3J5CBSgcnVTNbtB0UHqCtzfO80GMrrVGJgXTHeh jgyftHxFV+XvNsJ/HpkmA0UCaljQ0RYqd0mJmhkZi7fEDyO0rPh4UaNadiCzcAgJna7c 3MlWiROz59j1vmmdzHcnCdx/9TuAr8ojeGB4cEn7hBQmbF6dGB985r8VV6kRKnNn/rpp 8qlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5UdBWYGNOw2cJTpK9RuRUxRHwNWek007CJ9FxFMrrp0=; b=aW0cMWfVc6PFmK0paSZ2ARYsEWzgra4AkH/ZEPX0VdT/vsdVIf/Z8gT97TgTScrcJV MrOjeOJB00xvI8yf9wOdWsFn9cEJbNooxCk5GxxzGVZalVTVoER+5LhnB1U0a/Lra3rx wXvgzkcvD6SL/TSdJK31g+TMfsXWeswdgoj9ofiL8Dx99v+6aqt+xg9EgAtkqPS5eU0a xAF03uFUEmtM8MonGE5ihHDaUCHODRq76B1C7sdgIOg9MIrm5nsfFCe2Sk2slO8NYmzv 0BEQLvGZtBmSxJmGg052QvROuCW3lrx59ZDC0JEQS2BHOiC6KpmdKEoN45gaYqZs1HOF k8EQ== X-Gm-Message-State: ACrzQf1GmEhh863pHkj9eXWEZExtptN+0Sw1nu3vAIsPoEh4X1TD7FJX yu4V/7liuZdi7OoxPZr+Xr2erJVO+95VVw== X-Google-Smtp-Source: AMsMyM6p5vbc80xjnGafK8675URktJpZJpVJBDf+D7UVj1PA2EPhl/J4MX1NPz9qTJiExqMBJhvRDg== X-Received: by 2002:a0c:e44d:0:b0:4bb:6814:cacc with SMTP id d13-20020a0ce44d000000b004bb6814caccmr385548qvm.73.1666469812012; Sat, 22 Oct 2022 13:16:52 -0700 (PDT) Received: from localhost (pool-173-73-95-180.washdc.fios.verizon.net. [173.73.95.180]) by smtp.gmail.com with UTF8SMTPSA id t28-20020a37ea1c000000b006f3e6933bacsm634259qkj.113.2022.10.22.13.16.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Oct 2022 13:16:51 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Simon Glass , Heinrich Schuchardt , Tom Rini Cc: Sean Anderson Subject: [PATCH] test: Don't use sudo in unit test Date: Sat, 22 Oct 2022 16:16:49 -0400 Message-Id: <20221022201649.1346300-1-seanga2@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean I originally did this with fusefat, but it was unbearably slow. It could be useful with some optimization work... I switched to mtools instead. I have used fuse2fs on another project and it worked great. I didn't test this too throughoughly; I just made sure that the contents were intact (by using a loopback mount). Signed-off-by: Sean Anderson --- test/py/tests/test_ut.py | 44 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index 9d42390373..8bd7153ed7 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -21,26 +21,14 @@ def setup_bootflow_image(u_boot_console): """Create a 20MB disk image with a single FAT partition""" cons = u_boot_console fname = os.path.join(cons.config.source_dir, 'mmc1.img') + fatpart = os.path.join(cons.config.source_dir, 'mmc1p1.img') mnt = os.path.join(cons.config.persistent_data_dir, 'mnt') mkdir_cond(mnt) - u_boot_utils.run_and_log(cons, 'qemu-img create %s 20M' % fname) - u_boot_utils.run_and_log(cons, 'sudo sfdisk %s' % fname, - stdin=b'type=c') - - loop = None - mounted = False - complete = False try: - out = u_boot_utils.run_and_log(cons, - 'sudo losetup --show -f -P %s' % fname) - loop = out.strip() - fatpart = '%sp1' % loop - u_boot_utils.run_and_log(cons, 'sudo mkfs.vfat %s' % fatpart) - u_boot_utils.run_and_log( - cons, 'sudo mount -o loop %s %s -o uid=%d,gid=%d' % - (fatpart, mnt, os.getuid(), os.getgid())) - mounted = True + with open(fatpart, 'ab') as part: + part.truncate(19 * 1024 * 1024) + u_boot_utils.run_and_log(cons, f'mkfs.vfat {fatpart}') vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' @@ -78,17 +66,22 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) dtb_file = os.path.join(mnt, '%s/sandbox.dtb' % dtbdir) u_boot_utils.run_and_log( cons, 'dtc -o %s' % dtb_file, stdin=b'/dts-v1/; / {};') - complete = True + + u_boot_utils.run_and_log(cons, ('mcopy', '-bQmsi', fatpart, + *(os.path.join(mnt, file) for file in + (vmlinux, initrd, dtbdir, 'extlinux')), + '::')) + + with open(fname, 'ab') as image: + image.truncate(20 * 1024 * 1024) + u_boot_utils.run_and_log(cons, f'sfdisk {fname}', + stdin=b'type=c, start=1M, size=19M') + image.seek(1 * 1024 * 1024) + with open(fatpart, 'rb') as part: + image.write(part.read()) except ValueError as exc: - print('Falled to create image, failing back to prepared copy: %s', + print('Failed to create image, failing back to prepared copy:', str(exc)) - finally: - if mounted: - u_boot_utils.run_and_log(cons, 'sudo umount %s' % mnt) - if loop: - u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop) - - if not complete: # Use a prepared image since we cannot create one infname = os.path.join(cons.config.source_dir, 'test/py/tests/bootstd/mmc1.img.xz') @@ -96,7 +89,6 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) cons, ['sh', '-c', 'xz -dc %s >%s' % (infname, fname)]) - @pytest.mark.buildconfigspec('ut_dm') def test_ut_dm_init(u_boot_console): """Initialize data for ut dm tests.""" -- 2.37.1