MLECO-1987: Minor refactoring.

ASRSlidingWindow can be used in other use-cases,
thus it was renamed to decouple from ASR.

Signed-off-by: alexander <alexander.efremov@arm.com>
Change-Id: I2df977e4f18f490a532e0f27e3625b153ca464d7
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa84b3e..3345b6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -460,7 +460,7 @@
             add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES})
             target_include_directories(${TEST_TARGET_NAME} PUBLIC
                 ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE})
-            target_link_libraries(${TEST_TARGET_NAME} libethos-u-${use_case})
+            target_link_libraries(${TEST_TARGET_NAME} ${UC_LIB_NAME})
             target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
                 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}"
                 TESTS)
diff --git a/scripts/cmake/native-sources.cmake b/scripts/cmake/native-sources.cmake
index 1b1431a..dc8f263 100644
--- a/scripts/cmake/native-sources.cmake
+++ b/scripts/cmake/native-sources.cmake
@@ -33,6 +33,11 @@
 set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME  "libtensorflow-microlite.a")
 set(TENSORFLOW_LITE_MICRO_FLAGS "-DTF_LITE_STATIC_MEMORY -DACTIVATION_BUF_SRAM_SZ=0")
 
+if (DEFINED VERIFY_TEST_OUTPUT)
+    message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
+    set(PROFILING_OPT "${PROFILING_OPT} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}")
+endif ()
+
 set(CMAKE_C_FLAGS
         "${PROFILING_OPT} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}"
         CACHE INTERNAL "")
diff --git a/scripts/py/gen_test_data_cpp.py b/scripts/py/gen_test_data_cpp.py
index 7cc5f11..ea4bd6f 100644
--- a/scripts/py/gen_test_data_cpp.py
+++ b/scripts/py/gen_test_data_cpp.py
@@ -137,7 +137,7 @@
         if ifm_size == -1:
             ifm_size = get_npy_vec_size(filename)
         elif ifm_size != get_npy_vec_size(filename):
-            raise Exeception(f"ifm size changed for index {idx}")
+            raise Exception(f"ifm size changed for index {idx}")
 
         # Save the fm cc file
         base_name = "ofm" + str(idx)
@@ -149,7 +149,7 @@
         if ofm_size == -1:
             ofm_size = get_npy_vec_size(filename)
         elif ofm_size != get_npy_vec_size(filename):
-            raise Exeception(f"ofm size changed for index {idx}")
+            raise Exception(f"ofm size changed for index {idx}")
 
     common_cc_filepath = os.path.join(args.source_folder_path, common_cc_filename)
     write_hpp_file(header_filename, common_cc_filepath, args.license_template,
diff --git a/source/application/main/UseCaseCommonUtils.cc b/source/application/main/UseCaseCommonUtils.cc
index b3653d9..615f684 100644
--- a/source/application/main/UseCaseCommonUtils.cc
+++ b/source/application/main/UseCaseCommonUtils.cc
@@ -41,11 +41,30 @@
         return atoi(chInput);
     }
 
-    void DumpTensor(TfLiteTensor* tensor, const size_t lineBreakForNumElements)
-    {
-        char strhex[8];
-        std::string strdump;
+    void DumpTensorData(const uint8_t* tensorData,
+                        size_t size,
+                        size_t lineBreakForNumElements)
+        {
+            char strhex[8];
+            std::string strdump;
 
+            for (size_t i = 0; i < size; ++i) {
+                if (0 == i % lineBreakForNumElements) {
+                    printf("%s\n\t", strdump.c_str());
+                    strdump.clear();
+                }
+                snprintf(strhex, sizeof(strhex) - 1,
+                         "0x%02x, ", tensorData[i]);
+                strdump += std::string(strhex);
+            }
+
+            if (!strdump.empty()) {
+                printf("%s\n", strdump.c_str());
+            }
+        }
+
+    void DumpTensor(const TfLiteTensor* tensor, const size_t lineBreakForNumElements)
+    {
         if (!tensor) {
             printf_err("invalid tensor\n");
             return;
@@ -54,19 +73,7 @@
         const uint32_t tensorSz = tensor->bytes;
         const uint8_t* tensorData = tflite::GetTensorData<uint8_t>(tensor);
 
-        for (size_t i = 0; i < tensorSz; ++i) {
-            if (0 == i % lineBreakForNumElements) {
-                printf("%s\n\t", strdump.c_str());
-                strdump.clear();
-            }
-            snprintf(strhex, sizeof(strhex) - 1,
-                     "0x%02x, ", tensorData[i]);
-            strdump += std::string(strhex);
-        }
-
-        if (strdump.size()) {
-            printf("%s\n", strdump.c_str());
-        }
+        DumpTensorData(tensorData, tensorSz, lineBreakForNumElements);
     }
 
     bool ListFilesHandler(ApplicationContext& ctx)
@@ -92,7 +99,7 @@
                                              strNumFiles.size(),
                                              dataPsnTxtStartX,
                                              dataPsnTxtStartY,
-                                             0);
+                                             false);
 
 #if NUMBER_OF_FILES > 0
         constexpr uint32_t dataPsnTxtYIncr = 16;
@@ -103,7 +110,7 @@
             std::string currentFilename{get_filename(i)};
             platform.data_psn->present_data_text(currentFilename.c_str(),
                                                  currentFilename.size(),
-                                                 dataPsnTxtStartX, yVal, 0);
+                                                 dataPsnTxtStartX, yVal, false);
 
             info("\t%" PRIu32 " => %s\n", i, currentFilename.c_str());
         }
diff --git a/source/application/main/include/AudioUtils.hpp b/source/application/main/include/AudioUtils.hpp
index cba981d..cbf7bb7 100644
--- a/source/application/main/include/AudioUtils.hpp
+++ b/source/application/main/include/AudioUtils.hpp
@@ -124,18 +124,6 @@
             return ((m_dataSize - m_size)/m_stride);
         }
 
-        /**
-         * @brief  Calculates number of times the window can stride through the given data.
-         *         May not be a whole number.
-         * @return Number of strides to cover all data.
-         */
-        float FractionalTotalStrides() {
-            if (this->m_dataSize < this->m_size) {
-                return 0;
-            } else {
-                return ((this->m_dataSize - this->m_size)/ static_cast<float>(this->m_stride));
-            }
-        }
 
     protected:
         T *m_start = nullptr;
@@ -146,11 +134,11 @@
     };
 
     /*
-     * Sliding window for ASR will cover the whole of the input, even if
+     * Sliding window that will cover the whole length of the input, even if
      * this means the last window is not a full window length.
      */
     template<class T>
-    class ASRSlidingWindow : public SlidingWindow<T> {
+    class FractionalSlidingWindow : public SlidingWindow<T> {
     public:
         using SlidingWindow<T>::SlidingWindow;
 
@@ -161,6 +149,19 @@
         bool HasNext() {
             return this->m_count < 1 + this->FractionalTotalStrides() && (this->NextWindowStartIndex() < this->m_dataSize);
         }
+
+        /**
+        * @brief  Calculates number of times the window can stride through the given data.
+        *         May not be a whole number.
+        * @return Number of strides to cover all data.
+        */
+        float FractionalTotalStrides() {
+            if (this->m_dataSize < this->m_size) {
+                return 0;
+            } else {
+                return ((this->m_dataSize - this->m_size) / static_cast<float>(this->m_stride));
+            }
+        }
     };
 
 
diff --git a/source/application/main/include/UseCaseCommonUtils.hpp b/source/application/main/include/UseCaseCommonUtils.hpp
index d328392..0af22f3 100644
--- a/source/application/main/include/UseCaseCommonUtils.hpp
+++ b/source/application/main/include/UseCaseCommonUtils.hpp
@@ -58,8 +58,13 @@
      * @param[in]   lineBreakForNumElements     number of elements
      *              after which line break will be added.
      **/
-    void DumpTensor(TfLiteTensor* tensor,
-                    const size_t lineBreakForNumElements = 16);
+    void DumpTensor(const TfLiteTensor* tensor,
+                    size_t lineBreakForNumElements = 16);
+
+
+    void DumpTensorData(const uint8_t* tensorData,
+                        size_t size,
+                        size_t lineBreakForNumElements = 16);
 #endif /* VERIFY_TEST_OUTPUT */
 
     /**
diff --git a/source/use_case/asr/src/UseCaseHandler.cc b/source/use_case/asr/src/UseCaseHandler.cc
index dcc879f..8ef318f 100644
--- a/source/use_case/asr/src/UseCaseHandler.cc
+++ b/source/use_case/asr/src/UseCaseHandler.cc
@@ -135,7 +135,7 @@
             }
 
             /* Initialise an audio slider. */
-            auto audioDataSlider = audio::ASRSlidingWindow<const int16_t>(
+            auto audioDataSlider = audio::FractionalSlidingWindow<const int16_t>(
                                         audioArr,
                                         audioArrSize,
                                         audioParamsWinLen,
diff --git a/source/use_case/inference_runner/src/UseCaseHandler.cc b/source/use_case/inference_runner/src/UseCaseHandler.cc
index a75b2e4..b98b1c5 100644
--- a/source/use_case/inference_runner/src/UseCaseHandler.cc
+++ b/source/use_case/inference_runner/src/UseCaseHandler.cc
@@ -41,6 +41,17 @@
 
         const size_t numInputs = model.GetNumInputs();
 
+#if VERIFY_TEST_OUTPUT
+        info("Initial input tensors values:\n");
+        for (size_t inputIndex = 0; inputIndex < model.GetNumInputs(); inputIndex++) {
+            arm::app::DumpTensor(model.GetInputTensor(inputIndex));
+        }
+        info("Initial output tensors values:\n");
+        for (size_t outputIndex = 0; outputIndex < model.GetNumOutputs(); outputIndex++) {
+            arm::app::DumpTensor(model.GetOutputTensor(outputIndex));
+        }
+#endif /* VERIFY_TEST_OUTPUT */
+
         /* Populate each input tensor with random data. */
         for (size_t inputIndex = 0; inputIndex < numInputs; inputIndex++) {
 
diff --git a/source/use_case/kws_asr/src/UseCaseHandler.cc b/source/use_case/kws_asr/src/UseCaseHandler.cc
index 60c0fd2..9080348 100644
--- a/source/use_case/kws_asr/src/UseCaseHandler.cc
+++ b/source/use_case/kws_asr/src/UseCaseHandler.cc
@@ -357,7 +357,7 @@
         }
 
         /* Initialise an audio slider. */
-        auto audioDataSlider = audio::ASRSlidingWindow<const int16_t>(
+        auto audioDataSlider = audio::FractionalSlidingWindow<const int16_t>(
                 audioBuffer.data(),
                 audioBuffer.size(),
                 asrAudioParamsWinLen,
diff --git a/tests/common/SlidingWindowTests.cc b/tests/common/SlidingWindowTests.cc
index bfdb5b7..0185556 100644
--- a/tests/common/SlidingWindowTests.cc
+++ b/tests/common/SlidingWindowTests.cc
@@ -223,7 +223,7 @@
     /* Check we get the correct index returned */
     SECTION("Stride 1")
     {
-        auto slider = arm::app::audio::ASRSlidingWindow<int>(test.data(), test.size(), 1, 1);
+        auto slider = arm::app::audio::FractionalSlidingWindow<int>(test.data(), test.size(), 1, 1);
         REQUIRE(slider.NextWindowStartIndex() == 0);
         slider.Next();
         REQUIRE(slider.NextWindowStartIndex() == 1);
@@ -241,7 +241,7 @@
 
     SECTION("Stride 2")
     {
-        auto slider = arm::app::audio::ASRSlidingWindow<int>(test.data(), test.size(), 1, 2);
+        auto slider = arm::app::audio::FractionalSlidingWindow<int>(test.data(), test.size(), 1, 2);
         REQUIRE(slider.NextWindowStartIndex() == 0);
         slider.Next();
         REQUIRE(slider.NextWindowStartIndex() == 2);
@@ -252,7 +252,7 @@
 
     SECTION("Stride 3")
     {
-        auto slider = arm::app::audio::ASRSlidingWindow<int>(test.data(), test.size(), 1, 3);
+        auto slider = arm::app::audio::FractionalSlidingWindow<int>(test.data(), test.size(), 1, 3);
         REQUIRE(slider.NextWindowStartIndex() == 0);
         slider.Next();
         REQUIRE(slider.NextWindowStartIndex() == 3);