selftest: wic: remove 2>/dev/null to help fail diagnostic

The wic test case previously used '2>/dev/null' to suppress error
messages. This commit updates the code to use 'stderr=subprocess.PIPE'
when calling runCmd().

Refer:
https://lists.openembedded.org/g/openembedded-core/topic/109308684

(From OE-Core rev: bd26d999a0ba1107ee5629a8e238f4fe945e9be5)

Signed-off-by: Vince Chang <vince_chang@aspeedtech.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Vince Chang
2024-11-01 15:27:27 +08:00
committed by Richard Purdie
parent f023756ef8
commit e07cda3174

View File

@@ -12,6 +12,7 @@ import os
import sys import sys
import unittest import unittest
import hashlib import hashlib
import subprocess
from glob import glob from glob import glob
from shutil import rmtree, copy from shutil import rmtree, copy
@@ -457,7 +458,7 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
wicimg = wicout[0] wicimg = wicout[0]
# verify partition size with wic # verify partition size with wic
res = runCmd("parted -m %s unit b p 2>/dev/null" % wicimg) res = runCmd("parted -m %s unit b p" % wicimg, stderr=subprocess.PIPE)
# parse parted output which looks like this: # parse parted output which looks like this:
# BYT;\n # BYT;\n
@@ -478,16 +479,16 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
# Test partition 1, should contain the normal root directories, except # Test partition 1, should contain the normal root directories, except
# /usr. # /usr.
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ res = runCmd("debugfs -R 'ls -p' %s" % \
os.path.join(self.resultdir, "selftest_img.part1")) os.path.join(self.resultdir, "selftest_img.part1"), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn("etc", files) self.assertIn("etc", files)
self.assertNotIn("usr", files) self.assertNotIn("usr", files)
# Partition 2, should contain common directories for /usr, not root # Partition 2, should contain common directories for /usr, not root
# directories. # directories.
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ res = runCmd("debugfs -R 'ls -p' %s" % \
os.path.join(self.resultdir, "selftest_img.part2")) os.path.join(self.resultdir, "selftest_img.part2"), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertNotIn("etc", files) self.assertNotIn("etc", files)
self.assertNotIn("usr", files) self.assertNotIn("usr", files)
@@ -495,15 +496,15 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r
# Partition 3, should contain the same as partition 2, including the bin # Partition 3, should contain the same as partition 2, including the bin
# directory, but not the files inside it. # directory, but not the files inside it.
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % \ res = runCmd("debugfs -R 'ls -p' %s" % \
os.path.join(self.resultdir, "selftest_img.part3")) os.path.join(self.resultdir, "selftest_img.part3"), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertNotIn("etc", files) self.assertNotIn("etc", files)
self.assertNotIn("usr", files) self.assertNotIn("usr", files)
self.assertIn("share", files) self.assertIn("share", files)
self.assertIn("bin", files) self.assertIn("bin", files)
res = runCmd("debugfs -R 'ls -p bin' %s 2>/dev/null" % \ res = runCmd("debugfs -R 'ls -p bin' %s" % \
os.path.join(self.resultdir, "selftest_img.part3")) os.path.join(self.resultdir, "selftest_img.part3"), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn(".", files) self.assertIn(".", files)
self.assertIn("..", files) self.assertIn("..", files)
@@ -541,13 +542,13 @@ part /part2 --source rootfs --ondisk mmcblk0 --fstype=ext4 --include-path %s"""
part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0] part2 = glob(os.path.join(self.resultdir, 'temp-*.direct.p2'))[0]
# Test partition 1, should not contain 'test-file' # Test partition 1, should not contain 'test-file'
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertNotIn('test-file', files) self.assertNotIn('test-file', files)
self.assertEqual(True, files_own_by_root(res.output)) self.assertEqual(True, files_own_by_root(res.output))
# Test partition 2, should contain 'test-file' # Test partition 2, should contain 'test-file'
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part2)) res = runCmd("debugfs -R 'ls -p' %s" % (part2), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn('test-file', files) self.assertIn('test-file', files)
self.assertEqual(True, files_own_by_root(res.output)) self.assertEqual(True, files_own_by_root(res.output))
@@ -576,12 +577,12 @@ part / --source rootfs --fstype=ext4 --include-path %s --include-path core-imag
part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0]
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn('test-file', files) self.assertIn('test-file', files)
self.assertEqual(True, files_own_by_root(res.output)) self.assertEqual(True, files_own_by_root(res.output))
res = runCmd("debugfs -R 'ls -p /export/etc/' %s 2>/dev/null" % (part1)) res = runCmd("debugfs -R 'ls -p /export/etc/' %s" % (part1), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn('passwd', files) self.assertIn('passwd', files)
self.assertEqual(True, files_own_by_root(res.output)) self.assertEqual(True, files_own_by_root(res.output))
@@ -668,7 +669,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
% (wks_file, self.resultdir)) % (wks_file, self.resultdir))
for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')): for part in glob(os.path.join(self.resultdir, 'temp-*.direct.p*')):
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) res = runCmd("debugfs -R 'ls -p' %s" % (part), stderr=subprocess.PIPE)
self.assertEqual(True, files_own_by_root(res.output)) self.assertEqual(True, files_own_by_root(res.output))
config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "%s"\n' % wks_file config = 'IMAGE_FSTYPES += "wic"\nWKS_FILE = "%s"\n' % wks_file
@@ -678,7 +679,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
# check each partition for permission # check each partition for permission
for part in glob(os.path.join(tmpdir, 'temp-*.direct.p*')): for part in glob(os.path.join(tmpdir, 'temp-*.direct.p*')):
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part)) res = runCmd("debugfs -R 'ls -p' %s" % (part), stderr=subprocess.PIPE)
self.assertTrue(files_own_by_root(res.output) self.assertTrue(files_own_by_root(res.output)
,msg='Files permission incorrect using wks set "%s"' % test) ,msg='Files permission incorrect using wks set "%s"' % test)
@@ -706,7 +707,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0] part1 = glob(os.path.join(self.resultdir, 'temp-*.direct.p1'))[0]
res = runCmd("debugfs -R 'ls -p' %s 2>/dev/null" % (part1)) res = runCmd("debugfs -R 'ls -p' %s" % (part1), stderr=subprocess.PIPE)
files = extract_files(res.output) files = extract_files(res.output)
self.assertIn('passwd', files) self.assertIn('passwd', files)
@@ -741,7 +742,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
bitbake('base-files -c do_install') bitbake('base-files -c do_install')
bf_fstab = os.path.join(get_bb_var('D', 'base-files'), 'etc', 'fstab') bf_fstab = os.path.join(get_bb_var('D', 'base-files'), 'etc', 'fstab')
self.assertEqual(True, os.path.exists(bf_fstab)) self.assertEqual(True, os.path.exists(bf_fstab))
bf_fstab_md5sum = runCmd('md5sum %s 2>/dev/null' % bf_fstab).output.split(" ")[0] bf_fstab_md5sum = runCmd('md5sum %s ' % bf_fstab).output.split(" ")[0]
try: try:
no_fstab_update_path = os.path.join(self.resultdir, 'test-no-fstab-update') no_fstab_update_path = os.path.join(self.resultdir, 'test-no-fstab-update')
@@ -757,7 +758,7 @@ part /etc --source rootfs --fstype=ext4 --change-directory=etc
part_fstab_md5sum = [] part_fstab_md5sum = []
for i in range(1, 3): for i in range(1, 3):
part = glob(os.path.join(self.resultdir, 'temp-*.direct.p') + str(i))[0] part = glob(os.path.join(self.resultdir, 'temp-*.direct.p') + str(i))[0]
part_fstab = runCmd("debugfs -R 'cat etc/fstab' %s 2>/dev/null" % (part)) part_fstab = runCmd("debugfs -R 'cat etc/fstab' %s" % (part), stderr=subprocess.PIPE)
part_fstab_md5sum.append(hashlib.md5((part_fstab.output + "\n\n").encode('utf-8')).hexdigest()) part_fstab_md5sum.append(hashlib.md5((part_fstab.output + "\n\n").encode('utf-8')).hexdigest())
# '/etc/fstab' in partition 2 should contain the same stock fstab file # '/etc/fstab' in partition 2 should contain the same stock fstab file
@@ -874,7 +875,8 @@ bootloader --ptable gpt""")
self.logger.info("result: %s \n" % result.output) self.logger.info("result: %s \n" % result.output)
# verify partition size with wic # verify partition size with wic
res = runCmd("export PARTED_SECTOR_SIZE=%d; parted -m %s unit b p 2>/dev/null" % (wic_sector_size, images[0])) res = runCmd("export PARTED_SECTOR_SIZE=%d; parted -m %s unit b p" % (wic_sector_size, images[0]),
stderr=subprocess.PIPE)
self.logger.info("res: %s \n" % res.output) self.logger.info("res: %s \n" % res.output)
# parse parted output which looks like this: # parse parted output which looks like this:
@@ -1052,8 +1054,8 @@ class Wic2(WicTestCase):
native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools")
# verify partition size with wic # verify partition size with wic
res = runCmd("parted -m %s unit kib p 2>/dev/null" % wicimg, res = runCmd("parted -m %s unit kib p" % wicimg,
native_sysroot=native_sysroot) native_sysroot=native_sysroot, stderr=subprocess.PIPE)
# parse parted output which looks like this: # parse parted output which looks like this:
# BYT;\n # BYT;\n