From 621b73938d35c077aa0f77324d2dcae082529c6f Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Tue, 31 Jul 2018 14:41:19 +0200
Subject: [PATCH] CI: hotfix for stability   -- stdbuf -o0 seems to be causing
 segmentation fault   -- using daemon instead of nohup   -- also repeating
 several time "got sync" message and flushing stdout/stderr

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 ci-scripts/main.py              | 8 ++++++--
 targets/RT/USER/lte-softmodem.c | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index 861e6f3e4e..bf85d08adc 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -253,8 +253,9 @@ class SSHConnection():
 		# Launch eNB with the modified config file
 		self.command('source oaienv', '\$', 5)
 		self.command('cd cmake_targets', '\$', 5)
-		# Replacing with a nohup and a direct redirection of stdout to a file
-		self.command('echo ' + self.eNBPassword + ' | nohup sudo -S -E stdbuf -o0 ./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + ' > enb_' + SSH.testCase_id + '.log 2>&1 &', '\$', 5)
+		self.command('echo "./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + '" > ./my-lte-softmodem-run.sh ', '\$', 5)
+		self.command('chmod 775 ./my-lte-softmodem-run.sh ', '\$', 5)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + SSH.testCase_id + '.log ./my-lte-softmodem-run.sh', '\$', 5)
 		time.sleep(6)
 		doLoop = True
 		loopCounter = 10
@@ -733,6 +734,9 @@ class SSHConnection():
 
 	def TerminateeNB(self):
 		self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword)
+		self.command('cd ' + self.eNBSourceCodePath + '/cmake_targets', '\$', 5)
+		self.command('echo ' + self.eNBPassword + ' | sudo -S daemon --name=enb_daemon --stop', '\$', 5)
+		self.command('rm -f my-lte-softmodem-run.sh', '\$', 5)
 		self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGINT lte-softmodem || true', '\$', 5)
 		time.sleep(5)
 		self.command('stdbuf -o0  ps -aux | grep -v grep | grep lte-softmodem', '\$', 5)
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 27c4a1f448..a349ec8134 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -913,7 +913,16 @@ static  void wait_nfapi_init(char *thread_name) {
   
   pthread_mutex_unlock(&nfapi_sync_mutex);
   
+  /*
+   * Raphael Defosseux: temporary workaround for CI
+   * -- Repeating the message thrice to make sure
+   * -- it is present during flush.
+   */
   printf( "NFAPI: got sync (%s)\n", thread_name);
+  printf( "NFAPI: got sync (%s)\n", thread_name);
+  printf( "NFAPI: got sync (%s)\n", thread_name);
+  fflush(stdout);
+  fflush(stderr);
 }
 
 int main( int argc, char **argv )
-- 
GitLab