Skip to content

Commit e22cd7e

Browse files
author
David Sommerseth
committed
Do not try to dump DMI data if test hardware do not support it
1 parent 1d501fb commit e22cd7e

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

unit-tests/unit

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ try:
187187
vwrite(" * Testing that device has changed to %s..."%DUMP, 1)
188188
test(dmidecode.get_dev() == DUMP)
189189

190-
if root_user:
190+
if root_user and dmidecode.dmi is not None:
191191
vwrite(" * Testing that write on new file is ok...", 1)
192192
test(dmidecode.dump())
193193

@@ -196,10 +196,16 @@ try:
196196
if test(os.path.exists(DUMP)):
197197
os.unlink(DUMP)
198198
else:
199-
vwrite(
200-
" * %s\n" % red(
201-
"Skip testing API function, missing root privileges: dmidecode.dump()"
202-
), 1)
199+
if dmidecode.dmi is None:
200+
vwrite(
201+
" * %s\n" % yellow(
202+
"Skipped testing API function, hardware does not have DMI data"
203+
), 1)
204+
else:
205+
vwrite(
206+
" * %s\n" % red(
207+
"Skip testing API function, missing root privileges: dmidecode.dump()"
208+
), 1)
203209

204210
types = range(0, 42)+range(126, 128)
205211
bad_types = [-1, -1000, 256]
@@ -220,10 +226,11 @@ try:
220226
else:
221227
vwrite(" * If you have memory dumps to test, create a directory called `%s' and drop them in there.\n" % DUMPS_D, 1)
222228

223-
if root_user:
229+
if root_user and dmidecode.dmi is not None:
224230
devices.append("/dev/mem")
225231
else:
226-
vwrite(" * %s\n"%red("Running test as normal user, will not try to read /dev/mem"), 1)
232+
if dmidecode.dmi is not None:
233+
vwrite(" * %s\n"%red("Running test as normal user, will not try to read /dev/mem"), 1)
227234

228235
try:
229236
pymap = '../src/pymap.xml'

0 commit comments

Comments
 (0)