Commit 5281fd9b authored by Adam Wujek's avatar Adam Wujek

pytest: add PEC testing

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent e25da8e9
......@@ -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_block_cmd(self.cmd_ids["MFR_MODEL"])
if self.var_to_str(fw_model) == MONIMOD_MFR_MODEL_BOOTLOADER:
fw_model = self.pmbus_read_byte_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()
......
......@@ -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!"
......@@ -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!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment