From 5cadafc1546fb5f2262d55e209f38eabde7c35a0 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@openairinterface.org>
Date: Mon, 4 Jul 2022 14:02:27 +0200
Subject: [PATCH] CI: check for final 'Bye.' message

---
 ci-scripts/constants.py |  1 +
 ci-scripts/ran.py       | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/ci-scripts/constants.py b/ci-scripts/constants.py
index 4f82811ac1e..a7ce01615eb 100644
--- a/ci-scripts/constants.py
+++ b/ci-scripts/constants.py
@@ -46,6 +46,7 @@ ENB_PROCESS_NOLOGFILE_TO_ANALYZE = -14
 ENB_PROCESS_SLAVE_RRU_NOT_SYNCED = -15
 ENB_REAL_TIME_PROCESSING_ISSUE = -16
 ENB_RETX_ISSUE = -17
+ENB_SHUTDOWN_NO_BYE = -18
 HSS_PROCESS_FAILED = -2
 HSS_PROCESS_OK = +2
 MME_PROCESS_FAILED = -3
diff --git a/ci-scripts/ran.py b/ci-scripts/ran.py
index a576054370d..b9e7eb476ef 100644
--- a/ci-scripts/ran.py
+++ b/ci-scripts/ran.py
@@ -812,6 +812,7 @@ class RANManagement():
 		ULRetxIssue = False
 		nrRrcRcfgComplete = 0
 		harqFeedbackPast = 0
+		showedByeMsg = False # last line is Bye. -> stopped properly
 	
 		line_cnt=0 #log file line counter
 		for line in enb_log_file.readlines():
@@ -1024,6 +1025,12 @@ class RANManagement():
 				if result is not None:
 					gnb_markers[k].append(line_cnt)
 
+			# check whether e/gNB log finishes with "Bye." message
+			# Note that it is "=" not "|=" so not only is the regex
+			# asking for EOF (\Z) but we also only retain the last
+			# line's result
+			showedByeMsg = re.search(r'^Bye.\n\Z', str(line), re.MULTILINE) is not None
+
 		enb_log_file.close()
 
 
@@ -1208,6 +1215,13 @@ class RANManagement():
 				logging.debug('No real time stats found in the log file')
 				htmleNBFailureMsg += statMsg
 
+			if not showedByeMsg:
+				logging.debug('\u001B[1;37;41m ' + nodeB_prefix + 'NB did not show "Bye." message at end, it likely did not stop properly! \u001B[0m')
+				htmleNBFailureMsg += 'No Bye. message found, did not stop properly\n'
+				global_status = CONST.ENB_SHUTDOWN_NO_BYE
+			else:
+				logging.debug('"Bye." message found at end.')
+
 		else:
 			#Removing UE log
 			statMsg = '[MAC] Removing UE msg count =  '+str(removing_ue)
-- 
GitLab