sonic-buildimage/platform/mellanox/integration-scripts/tests/test_filehandler.py
Vivek 397908aa59
[Mellanox] Facilitate automatic integration of new hw-mgmt (#14594)
- Why I did it
Facilitate Automatic integration of new hw-mgmt version into SONiC.

Inputs to the Script:

MLNX_HW_MANAGEMENT_VERSION Eg: 7.0040.5202
CREATE_BRANCH: (y|n) Creates a branch instead of a commit (optional, default: n)
BRANCH_SONIC: Only relevant when CREATE_BRANCH is y. Default: master.
Note: These should be provided through SONIC_OVERRIDE_BUILD_VARS  parameter

Output:

Script creates a commit (in each of sonic-buildimage, sonic-linux-kernel) with all the changes required for upgrading the hw-management version to a version provided by MLNX_HW_MANAGEMENT_VERSION
Brief Summary of the changes made:

MLNX_HW_MANAGEMENT_VERSION flag in the hw-management.mk file
hw-mgmt submodule is updated to the corresponding version
Updates are made to non-upstream-patches/patches and series.patch file
series, kconfig-inclusion and kconfig-exclusion files can be updated in the sonic-linux-kernel repo
sonic-linux-kernel/patches folder is updated with the corresponding upstream patches
Based on the inputs, there could be a branch seen in the local for each of the repo's. Branch is named as <branch>_<parent_commit>_integrate_<hw_mgmt_version>

- How I did it
Added a new make target which can be invoked by calling make integrate-mlnx-hw-mgmt
user@server:/sonic-buildimage$ git rev-parse --abbrev-ref HEAD
master_23193446a_integrate_7.0020.5052
user@server:/sonic-buildimage$ git log --oneline -n 2
f66e01867 (HEAD -> master_23193446a_integrate_V.7.0020.5052, show) Intgerate HW-MGMT V.7.0020.5052 Changes
23193446a (master_intg_hw_mgmt) Update logic

user@server:/sonic-buildimage/src/sonic-linux-kernel$ git rev-parse --abbrev-ref HEAD
master_6847319_integrate_7.0020.4104
user@server:/sonic-buildimage/src/sonic-linux-kernel$ git log --oneline -n 2
6094f71 (HEAD -> master_6847319_integrate_V.7.0020.5052) Intgerate HW-MGMT V.7.0020.5052 Changes
6847319 (origin/master, origin/HEAD) Read ID register for optoe1 to find pageable bit in optoe driver  (#308)
Changes made will be summarized under sonic-buildimage/integrate-mlnx-hw-mgmt_user.out file. Debugging and troubleshooting output is written to sonic-buildimage/integrate-mlnx-hw-mgmt.log files

User output file & stdout file:

log_files.tar.gz

Limitations:
Assumes the changes would only work for amd64
Assumes the non-upstream patches in mellanox only belong to hw-mgmt

- How to verify it
Build the Kernel

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
2023-04-13 14:18:09 +03:00

160 lines
4.5 KiB
Python

import sys
from unittest import mock
sys.path.append('../')
from helper import *
MOCK_SLK_SERIES = """\
# Trtnetlink-catch-EOPNOTSUPP-errors.patch
# Tbridge-per-port-multicast-broadcast-flood-flags.patch
#
# Mellanox patches for 5.10
###-> mellanox_sdk-start
###-> mellanox_sdk-end
###-> mellanox_hw_mgmt-start
0001-i2c-mlxcpld-Update-module-license.patch
0002-i2c-mlxcpld-Decrease-polling-time-for-performan.patch
0003-i2c-mlxcpld-Add-support-for-I2C-bus-frequency-s.patch
0004-i2c-mux-mlxcpld-Update-module-license.patch
###-> mellanox_hw_mgmt-end
"""
MOCK_SLK_KCFG = """\
CONFIG_RANDOM=rrr
[common]
CONFIG_LOG_BUF_SHIFT=20
[amd64]
CONFIG_SENSORS_DPS1900=m
###-> mellanox-start
CONFIG_OF=y
CONFIG_THERMAL_OF=y
CONFIG_DW_DMAC_PCI=y
###-> mellanox-end
[armhf]
CONFIG_EEPROM_SFF_8436=m
CONFIG_EEPROM_OPTOE=m
CONFIG_I2C_MUX_GPIO=y
"""
UPDATED_MLNX_KCFG = """\
CONFIG_OF=y
CONFIG_THERMAL_OF=y
CONFIG_DW_DMAC_PCI=y
CONFIG_I2C_I801=m
CONFIG_PINCTRL=y
CONFIG_PINCTRL_INTEL=m
CONFIG_I2C_MUX_PCA954X=m
CONFIG_SPI_PXA2XX=m
"""
FINAL_MOCK_SLK_KCFG = """\
CONFIG_RANDOM=rrr
[common]
CONFIG_LOG_BUF_SHIFT=20
[amd64]
CONFIG_SENSORS_DPS1900=m
###-> mellanox-start
CONFIG_OF=y
CONFIG_THERMAL_OF=y
CONFIG_DW_DMAC_PCI=y
CONFIG_I2C_I801=m
CONFIG_PINCTRL=y
CONFIG_PINCTRL_INTEL=m
CONFIG_I2C_MUX_PCA954X=m
CONFIG_SPI_PXA2XX=m
###-> mellanox-end
[armhf]
CONFIG_EEPROM_SFF_8436=m
CONFIG_EEPROM_OPTOE=m
CONFIG_I2C_MUX_GPIO=y
"""
LINES_WRITE = []
LINES_READ = []
def writer_mock(path, lines, raw=False):
global LINES_WRITE
if raw:
join_with = ""
else:
join_with = "\n"
print("Expected: ")
print(join_with.join(LINES_WRITE))
print("Recieved:")
print(join_with.join(lines))
assert LINES_WRITE == lines
def read_raw_mock(path):
global LINES_READ
return LINES_READ
class TestFilehandler:
def test_find_markers(self):
lines = MOCK_SLK_SERIES.split("\n")
print(lines)
i_start, i_end = FileHandler.find_marker_indices(lines, "mellanox_hw_mgmt")
print(i_start, i_end)
assert lines[i_start] == "###-> mellanox_hw_mgmt-start"
assert lines[i_end] == "###-> mellanox_hw_mgmt-end"
i_start, i_end = FileHandler.find_marker_indices(lines, "mellanox_sdk")
print(i_start, i_end)
assert lines[i_start] == "###-> mellanox_sdk-start"
assert lines[i_end] == "###-> mellanox_sdk-end"
i_start, i_end = FileHandler.find_marker_indices(lines, "whatevrr")
print(i_start, i_end)
assert i_start == -1
assert i_end == len(lines)
i_start, i_end = FileHandler.find_marker_indices(lines)
print(i_start, i_end)
assert i_start == -1
assert i_end == len(lines)
@mock.patch('helper.FileHandler.read_raw', side_effect=read_raw_mock)
def test_read_kconfig_parser(self, mock_read_raw):
global LINES_READ
LINES_READ = MOCK_SLK_KCFG.split("\n")
all_cfg = FileHandler.read_kconfig_parser("")
print(all_cfg)
assert all_cfg['no_parent'] == ['CONFIG_RANDOM=rrr']
assert all_cfg['common'] == ['CONFIG_LOG_BUF_SHIFT=20']
assert all_cfg['amd64'] == ['CONFIG_SENSORS_DPS1900=m', 'CONFIG_OF=y', 'CONFIG_THERMAL_OF=y', 'CONFIG_DW_DMAC_PCI=y']
assert all_cfg['armhf'] == ['CONFIG_EEPROM_SFF_8436=m', 'CONFIG_EEPROM_OPTOE=m', 'CONFIG_I2C_MUX_GPIO=y']
@mock.patch('helper.FileHandler.write_lines', side_effect=writer_mock)
@mock.patch('helper.FileHandler.read_raw', side_effect=read_raw_mock)
def test_write_lines_marker(self, mock_read_raw, mock_write_lines_marker):
global LINES_READ
global LINES_WRITE
LINES_READ = MOCK_SLK_KCFG.splitlines(True)
LINES_WRITE = FINAL_MOCK_SLK_KCFG.splitlines(True)
list_opts = KCFG.parse_opts_strs(UPDATED_MLNX_KCFG.split("\n"))
writable_opts = KCFG.get_writable_opts(list_opts)
FileHandler.write_lines_marker("", writable_opts, marker="mellanox")
@mock.patch('helper.FileHandler.write_lines', side_effect=writer_mock)
@mock.patch('helper.FileHandler.read_raw', side_effect=read_raw_mock)
def test_read_kconfig_inclusion(self, mock_read_raw, mock_write_lines_marker):
global LINES_READ
LINES_READ = FINAL_MOCK_SLK_KCFG.splitlines(True)
opts = FileHandler.read_kconfig_inclusion("")
global LINES_WRITE
LINES_WRITE = UPDATED_MLNX_KCFG.splitlines()
writable_opts = KCFG.get_writable_opts(KCFG.parse_opts_strs(opts))
print(writable_opts)
FileHandler.write_lines("", writable_opts)