Skip to content

Commit d0f0a61

Browse files
[build] Add timeout on python target and dpkg helper target. (sonic-net#19355)
Why I did it Some UT cases are not strong. They maybe hangs in some environment. Provide a variable to config timeout on some commands which contains UT. Work item tracking Microsoft ADO (number only): 28624525 How I did it Add a timeout when running UT. How to verify it
1 parent 084ba1a commit d0f0a61

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Makefile.work

+1
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
567567
ONIE_IMAGE_PART_SIZE=$(ONIE_IMAGE_PART_SIZE) \
568568
SONIC_OS_VERSION=$(SONIC_OS_VERSION) \
569569
PIP_HTTP_TIMEOUT=$(PIP_HTTP_TIMEOUT) \
570+
BUILD_PROCESS_TIMEOUT=$(BUILD_PROCESS_TIMEOUT) \
570571
LEGACY_SONIC_MGMT_DOCKER=$(LEGACY_SONIC_MGMT_DOCKER) \
571572
SONIC_PTF_ENV_PY_VER=$(SONIC_PTF_ENV_PY_VER) \
572573
$(SONIC_OVERRIDE_BUILD_VARS)

rules/config

+3
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,6 @@ BUILD_REDUCE_IMAGE_SIZE = n
320320
# SONIC_PTF_ENV_PY_VER - SONiC PTF test Python version. Set to 'mixed' to build the
321321
# image with both Python 2 and 3. Set to 'py3' to build a Python 3 only image
322322
SONIC_PTF_ENV_PY_VER = mixed
323+
324+
# Add timeout on some process which may hangs
325+
BUILD_PROCESS_TIMEOUT ?= 0

slave.mk

+6-6
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ $(addprefix $(DEBS_PATH)/, $(SONIC_DPKG_DEBS)) : $(DEBS_PATH)/% : .platform $$(a
789789
if [ -f ./autogen.sh ]; then ./autogen.sh $(LOG); fi
790790
$(SETUP_OVERLAYFS_FOR_DPKG_ADMINDIR)
791791
$(if $($*_DPKG_TARGET),
792-
${$*_BUILD_ENV} DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS_GENERIC} ${$*_DEB_BUILD_OPTIONS}" DEB_BUILD_PROFILES="${$*_DEB_BUILD_PROFILES}" $(ANT_DEB_CONFIG) $(CROSS_COMPILE_FLAGS) dpkg-buildpackage -rfakeroot -b $(ANT_DEB_CROSS_OPT) -us -uc -tc -j$(SONIC_CONFIG_MAKE_JOBS) --as-root -T$($*_DPKG_TARGET) --admindir $$mergedir $(LOG),
793-
${$*_BUILD_ENV} DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS_GENERIC} ${$*_DEB_BUILD_OPTIONS}" DEB_BUILD_PROFILES="${$*_DEB_BUILD_PROFILES}" $(ANT_DEB_CONFIG) $(CROSS_COMPILE_FLAGS) dpkg-buildpackage -rfakeroot -b $(ANT_DEB_CROSS_OPT) -us -uc -tc -j$(SONIC_CONFIG_MAKE_JOBS) --admindir $$mergedir $(LOG)
792+
${$*_BUILD_ENV} DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS_GENERIC} ${$*_DEB_BUILD_OPTIONS}" DEB_BUILD_PROFILES="${$*_DEB_BUILD_PROFILES}" $(ANT_DEB_CONFIG) $(CROSS_COMPILE_FLAGS) timeout --preserve-status -s 9 -k 10 $(BUILD_PROCESS_TIMEOUT) dpkg-buildpackage -rfakeroot -b $(ANT_DEB_CROSS_OPT) -us -uc -tc -j$(SONIC_CONFIG_MAKE_JOBS) --as-root -T$($*_DPKG_TARGET) --admindir $$mergedir $(LOG),
793+
${$*_BUILD_ENV} DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS_GENERIC} ${$*_DEB_BUILD_OPTIONS}" DEB_BUILD_PROFILES="${$*_DEB_BUILD_PROFILES}" $(ANT_DEB_CONFIG) $(CROSS_COMPILE_FLAGS) timeout --preserve-status -s 9 -k 10 $(BUILD_PROCESS_TIMEOUT) dpkg-buildpackage -rfakeroot -b $(ANT_DEB_CROSS_OPT) -us -uc -tc -j$(SONIC_CONFIG_MAKE_JOBS) --admindir $$mergedir $(LOG)
794794
)
795795
popd $(LOG_SIMPLE)
796796
# Clean up
@@ -940,19 +940,19 @@ $(addprefix $(PYTHON_WHEELS_PATH)/, $(SONIC_PYTHON_WHEELS)) : $(PYTHON_WHEELS_PA
940940
if [ -f ../$(notdir $($*_SRC_PATH)).patch/series ]; then ( quilt pop -a -f 1>/dev/null 2>&1 || true ) && QUILT_PATCHES=../$(notdir $($*_SRC_PATH)).patch quilt push -a; fi $(LOG)
941941
ifneq ($(CROSS_BUILD_ENVIRON),y)
942942
# Use pip instead of later setup.py to install dependencies into user home, but uninstall self
943-
pip$($*_PYTHON_VERSION) install . && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name`
943+
{ pip$($*_PYTHON_VERSION) install . && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name`; } $(LOG)
944944
ifeq ($(BLDENV),bookworm)
945-
if [ ! "$($*_TEST)" = "n" ]; then pip$($*_PYTHON_VERSION) install ".[testing]" && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name` && python$($*_PYTHON_VERSION) -m pytest $(LOG); fi
945+
if [ ! "$($*_TEST)" = "n" ]; then pip$($*_PYTHON_VERSION) install ".[testing]" && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name` && timeout --preserve-status -s 9 -k 10 $(BUILD_PROCESS_TIMEOUT) python$($*_PYTHON_VERSION) -m pytest; fi $(LOG)
946946
python$($*_PYTHON_VERSION) -m build -n $(LOG)
947947
else
948-
if [ ! "$($*_TEST)" = "n" ]; then python$($*_PYTHON_VERSION) setup.py test $(LOG); fi
948+
if [ ! "$($*_TEST)" = "n" ]; then timeout --preserve-status -s 9 -k 10 $(BUILD_PROCESS_TIMEOUT) python$($*_PYTHON_VERSION) setup.py test $(LOG); fi
949949
python$($*_PYTHON_VERSION) setup.py bdist_wheel $(LOG)
950950
endif
951951
else
952952
{
953953
export PATH=$(VIRTENV_BIN_CROSS_PYTHON$($*_PYTHON_VERSION)):${PATH}
954954
python$($*_PYTHON_VERSION) setup.py build $(LOG)
955-
if [ ! "$($*_TEST)" = "n" ]; then python$($*_PYTHON_VERSION) setup.py test $(LOG); fi
955+
if [ ! "$($*_TEST)" = "n" ]; then timeout --preserve-status -s 9 -k 10 $(BUILD_PROCESS_TIMEOUT) python$($*_PYTHON_VERSION) setup.py test $(LOG); fi
956956
python$($*_PYTHON_VERSION) setup.py bdist_wheel $(LOG)
957957
}
958958
endif

0 commit comments

Comments
 (0)