Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
DIOT Monitoring Module
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
DIOT Monitoring Module
Commits
5281fd9b
Commit
5281fd9b
authored
Jul 13, 2022
by
Adam Wujek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pytest: add PEC testing
Signed-off-by:
Adam Wujek
<
dev_public@wujek.eu
>
parent
e25da8e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
21 deletions
+74
-21
conftest.py
pytest/conftest.py
+25
-15
test_bootloader.py
pytest/test-00-basic/test_bootloader.py
+6
-2
test_fw_main.py
pytest/test-00-basic/test_fw_main.py
+43
-4
No files found.
pytest/conftest.py
View file @
5281fd9b
...
...
@@ -79,35 +79,36 @@ class monimod:
def
pmbus_read_byte_cmd
(
self
,
cmd
):
return
self
.
bus
.
read_byte_data
(
MONIMOD_ADDRESS
,
cmd
)
def
pmbus_write_byte_cmd
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_byte_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
pmbus_read_word_cmd
(
self
,
cmd
):
return
self
.
bus
.
read_word_data
(
MONIMOD_ADDRESS
,
cmd
)
def
pmbus_write_word_cmd
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_word_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
pmbus_read_block_cmd
(
self
,
cmd
):
return
self
.
bus
.
read_block_data
(
MONIMOD_ADDRESS
,
cmd
)
def
pmbus_write_block_cmd
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_block_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
read_i2c_block_data
(
self
,
cmd
,
read_size
):
return
self
.
bus
.
read_i2c_block_data
(
MONIMOD_ADDRESS
,
cmd
,
read_size
)
def
pmbus_block_process_call
(
self
,
cmd
,
vals
):
return
self
.
bus
.
block_process_call
(
MONIMOD_ADDRESS
,
cmd
,
vals
)
def
pmbus_write_byte_cmd
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_byte_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
pmbus_write_word_cmd
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_word_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
write_i2c_block_data
(
self
,
cmd
,
data
):
return
self
.
bus
.
write_i2c_block_data
(
MONIMOD_ADDRESS
,
cmd
,
data
)
def
get_fw_mode
(
self
):
fw_model
=
self
.
pmbus_read_b
lock_cmd
(
self
.
cmd_ids
[
"MFR_MODEL
"
])
if
self
.
var_to_str
(
fw_model
)
==
MONIMOD_MFR_MODEL
_BOOTLOADER
:
fw_model
=
self
.
pmbus_read_b
yte_cmd
(
self
.
cmd_ids
[
"BOOT_NEW_FW
"
])
if
fw_model
==
self
.
FW
_BOOTLOADER
:
return
self
.
FW_BOOTLOADER
if
self
.
var_to_str
(
fw_model
)
==
MONIMOD_MFR_MODEL
_MAIN
:
if
fw_model
==
self
.
FW
_MAIN
:
return
self
.
FW_MAIN
return
self
.
FW_UNKNOWN
def
switch_fw_mode
(
self
):
...
...
@@ -117,15 +118,24 @@ class monimod:
pass
def
get_uptime
(
self
):
data
=
self
.
read_i2c_block_data
(
self
.
cmd_ids
[
"UPTIME_SECS"
],
MONIMOD_UPTIME_SIZE
)
data
=
self
.
pmbus_read_block_cmd
(
self
.
cmd_ids
[
"UPTIME_SECS"
])
return
int
.
from_bytes
(
bytes
(
data
),
"little"
)
def
get_tmr
(
self
):
data
=
self
.
read_i2c_block_data
(
self
.
cmd_ids
[
"TMR_ERROR_CNT"
],
MONIMOD_TMR_SIZE
)
data
=
self
.
pmbus_read_block_cmd
(
self
.
cmd_ids
[
"TMR_ERROR_CNT"
])
return
int
.
from_bytes
(
bytes
(
data
),
"little"
)
def
set_pec
(
self
,
pec_val
):
# Turn off PEC in Linux i2c driver if enabled.
# Setting PEC in Monimod is possible only with PEC disabled in
# the linux driver.
if
self
.
bus
.
pec
:
self
.
bus
.
pec
=
False
self
.
pmbus_write_byte_cmd
(
self
.
cmd_ids
[
"USE_PEC"
],
pec_val
)
# Turn on PEC in Linux i2c driver if PEC was enabled in Monimod
if
pec_val
:
self
.
bus
.
pec
=
True
@
pytest
.
fixture
(
scope
=
"session"
)
def
monimod_bus
():
monimod_instance
=
monimod
()
...
...
pytest/test-00-basic/test_bootloader.py
View file @
5281fd9b
...
...
@@ -74,6 +74,8 @@ def check_boot_mode(monimod_bus):
if
monimod_bus
.
get_fw_mode
()
!=
monimod_bus
.
FW_BOOTLOADER
:
restore_boot_mode
=
1
# disable PEC
monimod_bus
.
set_pec
(
False
)
monimod_bus
.
switch_fw_mode
()
time
.
sleep
(
1
)
if
monimod_bus
.
get_fw_mode
()
!=
monimod_bus
.
FW_BOOTLOADER
:
...
...
@@ -168,8 +170,10 @@ class TestBootloaderOther(object):
def
test_switch_to_bootloader
(
self
,
monimod_bus
):
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_BOOTLOADER
,
"Monimod not in bootloader mode!"
monimod_bus
.
switch_fw_mode
()
time
.
sleep
(
2
)
time
.
sleep
(
1
)
# disable PEC
monimod_bus
.
set_pec
(
False
)
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_MAIN
,
"Failed to switch to main mode!"
monimod_bus
.
switch_fw_mode
()
time
.
sleep
(
2
)
time
.
sleep
(
1
)
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_BOOTLOADER
,
"Failed to switch to bootloader mode!"
pytest/test-00-basic/test_fw_main.py
View file @
5281fd9b
...
...
@@ -68,6 +68,31 @@ cmd_query = {
MFR_ID
=
"CERN (BE/CEM)"
MFR_MODEL
=
"DI/OT MoniMod"
PEC_OFF
=
0
PEC_ON
=
1
pec_map
=
{
"PEC_OFF"
:
PEC_OFF
,
"PEC_ON"
:
PEC_ON
}
pec_modes
=
[
"PEC_OFF"
,
"PEC_ON"
]
# run tests with disabled and enabled PEC
@
pytest
.
fixture
(
params
=
pec_modes
,
autouse
=
True
,
scope
=
"session"
)
def
use_pec
(
request
,
monimod_bus
):
if
pec_map
[
request
.
param
]
==
PEC_ON
:
monimod_bus
.
set_pec
(
True
)
else
:
monimod_bus
.
set_pec
(
False
)
yield
request
.
param
# restore PEC setting
if
pec_map
[
request
.
param
]
==
PEC_ON
:
monimod_bus
.
set_pec
(
False
)
@
pytest
.
fixture
(
scope
=
"module"
,
autouse
=
True
)
def
check_boot_mode
(
monimod_bus
):
if
monimod_bus
.
get_fw_mode
()
!=
monimod_bus
.
FW_MAIN
:
...
...
@@ -256,15 +281,21 @@ class TestFwMainRegValues(object):
assert
data_old_read
==
data_old
@
pytest
.
mark
.
parametrize
(
"cmds"
,
[
"USE_PEC"
,
"TC_ONOFF"
,])
def
test_on_off
(
self
,
monimod_bus
,
cmds
):
def
test_on_off
(
self
,
monimod_bus
,
use_pec
,
cmds
):
'''Check functionality to off then on by the write to the register.
A the end restore the old value'''
off_val
=
0
on_val
=
1
# For PEC testing disable PEC in the Linux i2c driver;
# Setting PEC in Monimod is possible only with PEC disabled in
# the driver.
if
cmds
==
"USE_PEC"
and
PEC_ON
==
pec_map
[
use_pec
]:
monimod_bus
.
bus
.
pec
=
False
old_val
=
monimod_bus
.
pmbus_read_byte_cmd
(
monimod_bus
.
cmd_ids
[
cmds
])
# set to off
monimod_bus
.
pmbus_write_byte_cmd
(
monimod_bus
.
cmd_ids
[
cmds
],
off_val
)
# let the driver to not use PEC
off_val_read
=
monimod_bus
.
pmbus_read_byte_cmd
(
monimod_bus
.
cmd_ids
[
cmds
])
assert
off_val
==
off_val_read
...
...
@@ -276,17 +307,25 @@ class TestFwMainRegValues(object):
# restore and verify the old value
monimod_bus
.
pmbus_write_byte_cmd
(
monimod_bus
.
cmd_ids
[
cmds
],
old_val
)
old_val_read
=
monimod_bus
.
pmbus_read_byte_cmd
(
monimod_bus
.
cmd_ids
[
cmds
])
# Restore PEC usage for Linux i2c driver
if
cmds
==
"USE_PEC"
and
PEC_ON
==
pec_map
[
use_pec
]:
monimod_bus
.
bus
.
pec
=
old_val
assert
old_val
==
old_val_read
@
pytest
.
mark
.
check_uptime
class
TestFwMainOther
(
object
):
def
test_switch_to_bootloader
(
self
,
monimod_bus
):
def
test_switch_to_bootloader
(
self
,
monimod_bus
,
use_pec
):
if
monimod_bus
.
get_tmr
():
warnings
.
warn
(
UserWarning
(
"TMR not zero"
))
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_MAIN
,
"Monimod not in main mode!"
monimod_bus
.
switch_fw_mode
()
time
.
sleep
(
2
)
time
.
sleep
(
1
)
if
PEC_ON
==
pec_map
[
use_pec
]:
monimod_bus
.
bus
.
pec
=
False
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_BOOTLOADER
,
"Failed to switch to bootloader mode!"
monimod_bus
.
switch_fw_mode
()
time
.
sleep
(
2
)
time
.
sleep
(
1
)
if
PEC_ON
==
pec_map
[
use_pec
]:
monimod_bus
.
bus
.
pec
=
True
assert
monimod_bus
.
get_fw_mode
()
==
monimod_bus
.
FW_MAIN
,
"Failed to switch to main mode!"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment