From 0579d471546a4d9667b989492bedfb3262d01893 Mon Sep 17 00:00:00 2001
From: ROBERT Benoit <benoit.robert@syrtem.com>
Date: Fri, 25 Nov 2016 14:43:28 +0100
Subject: [PATCH] Complete autotest patch files set for OAI1B autotest setup

---
 .../autotests/patches/CmakeLists.patch        | 12 ++++++
 .../autotest_ue_dlsch_bitrate_metric.patch    | 11 +++--
 .../patches/autotest_ue_offsets_metric.patch  | 31 ++++++++++++++
 .../autotests/patches/build_oai.patch         | 40 +++++++++++++++++++
 cmake_targets/autotests/testsuite_ue_noS1.xml |  6 +--
 5 files changed, 91 insertions(+), 9 deletions(-)
 create mode 100644 cmake_targets/autotests/patches/CmakeLists.patch
 create mode 100644 cmake_targets/autotests/patches/autotest_ue_offsets_metric.patch
 create mode 100644 cmake_targets/autotests/patches/build_oai.patch

diff --git a/cmake_targets/autotests/patches/CmakeLists.patch b/cmake_targets/autotests/patches/CmakeLists.patch
new file mode 100644
index 0000000000..9f2731ca73
--- /dev/null
+++ b/cmake_targets/autotests/patches/CmakeLists.patch
@@ -0,0 +1,12 @@
+diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
+index 3169c6c..eaf5417 100644
+--- a/cmake_targets/CMakeLists.txt
++++ b/cmake_targets/CMakeLists.txt
+@@ -235,6 +235,7 @@ add_boolean_option(DEBUG_OMG           False "???")
+ add_boolean_option(XFORMS              False "This adds the possibility to see the signal oscilloscope")
+ add_boolean_option(PRINT_STATS         False "This adds the possibility to see the status")
+ add_boolean_option(T_TRACER            False "Activate the T tracer, a debugging/monitoring framework" )
++add_boolean_option(UE_AUTOTEST_TRACE   False "Activate UE autotest specific logs")
+ 
+ add_boolean_option(DEBUG_CONSOLE False "makes debugging easier, disables stdout/stderr buffering")
+ 
diff --git a/cmake_targets/autotests/patches/autotest_ue_dlsch_bitrate_metric.patch b/cmake_targets/autotests/patches/autotest_ue_dlsch_bitrate_metric.patch
index e8213960e1..b7a7dbfa02 100644
--- a/cmake_targets/autotests/patches/autotest_ue_dlsch_bitrate_metric.patch
+++ b/cmake_targets/autotests/patches/autotest_ue_dlsch_bitrate_metric.patch
@@ -1,18 +1,17 @@
 diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
-index 3ed4c79..da88000 100644
+index 3ed4c79..6023886 100644
 --- a/openair1/SCHED/phy_procedures_lte_ue.c
 +++ b/openair1/SCHED/phy_procedures_lte_ue.c
-@@ -2944,6 +2944,14 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
+@@ -2944,6 +2944,13 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
      LOG_D(PHY,"[UE %d] Calculating bitrate Frame %d: total_TBS = %d, total_TBS_last = %d, bitrate %f kbits\n",
  	  ue->Mod_id,frame_rx,ue->total_TBS[eNB_id],
  	  ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0);
 +
-+    /* SYRTEM */
++  #if UE_AUTOTEST_TRACE
 +    if ((frame_rx % 100 == 0)) {
-+      printf("AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", (float) ue->bitrate[eNB_id]/1000.0, frame_rx);
-+      /* End of SYRTEM */
++      LOG_I(PHY,"[UE  %d] AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", ue->Mod_id, (float) ue->bitrate[eNB_id]/1000.0, frame_rx);
 +    }
-+
++  #endif
 +
    }
  
diff --git a/cmake_targets/autotests/patches/autotest_ue_offsets_metric.patch b/cmake_targets/autotests/patches/autotest_ue_offsets_metric.patch
new file mode 100644
index 0000000000..3fca1a70fd
--- /dev/null
+++ b/cmake_targets/autotests/patches/autotest_ue_offsets_metric.patch
@@ -0,0 +1,31 @@
+diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
+index 3ed4c79..7185e5a 100644
+--- a/openair1/SCHED/phy_procedures_lte_ue.c
++++ b/openair1/SCHED/phy_procedures_lte_ue.c
+@@ -2748,7 +2748,25 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
+ 	   0);
+ 
+   // first slot has been processed (FFTs + Channel Estimation, PCFICH/PHICH/PDCCH)
+- 
++
++    /* SYRTEM */
++    if ( (frame_rx % 10 == 0) && (subframe_rx == 0)) {
++      printf("AUTOTEST Metric : UE_FREQ_OFFSET = %d Hz (frame = %d) \n", ue->common_vars.freq_offset, frame_rx);
++      printf("AUTOTEST Metric : UE_RX_OFFSET = %d (frame = %d) \n", ue->rx_offset, frame_rx);
++
++      printf("AUTOTEST Metric : RRC Measurments RSRP[0] %.2f dBm/RE, RSSI %.2f dBm, RSRQ[0] %.2f dB, N0 %d dBm/RE, NF %.1f dB (frame = %d)\n",
++        10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB,
++        10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB, 
++        10*log10(ue->measurements.rsrq[0]),
++        ue->measurements.n0_power_tot_dBm,
++        (double)ue->measurements.n0_power_tot_dBm+132.24,
++        frame_rx);
++     }
++
++
++
++
++
+   // do procedures for C-RNTI
+   if (ue->dlsch[eNB_id][0]->active == 1) {
+     ue_pdsch_procedures(ue,
diff --git a/cmake_targets/autotests/patches/build_oai.patch b/cmake_targets/autotests/patches/build_oai.patch
new file mode 100644
index 0000000000..d6cecda6e5
--- /dev/null
+++ b/cmake_targets/autotests/patches/build_oai.patch
@@ -0,0 +1,40 @@
+diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
+index b77a9ba..8e3021d 100755
+--- a/cmake_targets/build_oai
++++ b/cmake_targets/build_oai
+@@ -53,6 +53,7 @@ BUILD_DOXYGEN=0
+ T_TRACER="False"
+ DISABLE_HARDWARE_DEPENDENCY="False"
+ CMAKE_BUILD_TYPE=""
++UE_AUTOTEST_TRACE="False"
+ trap handle_ctrl_c INT
+ 
+ function print_help() {
+@@ -127,6 +128,8 @@ Options
+    Enables the T tracer.
+ --disable-hardware-dependency
+    Disable HW dependency during installation
++--ue-autotest-trace
++    Enable specific traces for UE autotest framework
+ Usage (first build):
+  oaisim (eNB + UE): ./build_oai -I  --oaisim -x --install-system-files
+  Eurecom EXMIMO + COTS UE : ./build_oai -I  --eNB -x --install-system-files
+@@ -278,6 +281,10 @@ function main() {
+             echo_info "Disabling hardware dependency for compiling software"
+             DISABLE_HARDWARE_DEPENDENCY="True"
+             shift 1;;
++        --ue-autotest-trace)
++            UE_AUTOTEST_TRACE="True"
++            echo_info "Enabling autotest specific trace for UE"
++            shift 1;;
+         -h | --help)
+             print_help
+             exit 1;;
+@@ -447,6 +454,7 @@ function main() {
+     echo "set (DEADLINE_SCHEDULER \"${DEADLINE_SCHEDULER_FLAG_USER}\" )"    >>$cmake_file
+     echo "set (CPU_AFFINITY \"${CPU_AFFINITY_FLAG_USER}\" )"      >>$cmake_file
+     echo "set ( T_TRACER $T_TRACER )"              >>  $cmake_file
++    echo "set (UE_AUTOTEST_TRACE $UE_AUTOTEST_TRACE)"        >>  $cmake_file
+     echo 'include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)' >> $cmake_file
+     cd  $DIR/$lte_build_dir/build
+     cmake ..
diff --git a/cmake_targets/autotests/testsuite_ue_noS1.xml b/cmake_targets/autotests/testsuite_ue_noS1.xml
index c2f87b881f..19b945dc28 100644
--- a/cmake_targets/autotests/testsuite_ue_noS1.xml
+++ b/cmake_targets/autotests/testsuite_ue_noS1.xml
@@ -2,11 +2,11 @@
 
 <MachineList>imb182-desktop yanbo-M4HM87P-00</MachineList> <!-- ued-PRM-130 -->
  <NFSResultsShare>/mnt/sradio/TEST_RESULTS/</NFSResultsShare>
- <GitOAI5GRepo> https://gitlab.eurecom.fr/oai1B/openairinterface5g.git</GitOAI5GRepo> 
-  <!-- <GitOAI5GRepo>https://gitlab.eurecom.fr/oai/openairinterface5g.git</GitOAI5GRepo> -->
+  <!-- <GitOAI5GRepo> https://gitlab.eurecom.fr/oai1B/openairinterface5g.git</GitOAI5GRepo> -->
+ <GitOAI5GRepo>https://gitlab.eurecom.fr/oai/openairinterface5g.git</GitOAI5GRepo> -->
  <!--  <GitOAI5GRepo>git@gitlab.com:TCL_Communications/openairinterface5g.git</GitOAI5GRepo> -->
  <GitOpenair-cnRepo>https://gitlab.eurecom.fr/oai/openair-cn.git</GitOpenair-cnRepo> -->
- <GitOAI5GRepoBranch>develop1B</GitOAI5GRepoBranch>
+ <GitOAI5GRepoBranch>Enhancement-142-OAI_UE_autotest_framework</GitOAI5GRepoBranch>
  <!-- <GitOAI5GHeadVersion>9fbbd0678a236ea9e7878f83fe7327dd29b26854</GitOAI5GHeadVersion> -->
  <!-- <GitOAI5GHeadVersion>23822ea203e00f2100fa41c7ee3084ec55b884fe</GitOAI5GHeadVersion> --> 
  <GitOAI5GHeadVersion></GitOAI5GHeadVersion>
-- 
2.26.2