IVGCVSW-5686 Add GpuAcc MLGO tuning file configuration argument

Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I3f320499c379162f9d1b00cc8816bd144cd7eee4
diff --git a/src/backends/cl/test/ClOptimizedNetworkTests.cpp b/src/backends/cl/test/ClOptimizedNetworkTests.cpp
index 2797080..dddc5aa 100644
--- a/src/backends/cl/test/ClOptimizedNetworkTests.cpp
+++ b/src/backends/cl/test/ClOptimizedNetworkTests.cpp
@@ -10,6 +10,10 @@
 #include <test/GraphUtils.hpp>
 
 #include <cl/ClWorkloadFactory.hpp>
+#include <cl/ClBackendContext.hpp>
+
+#include <Filesystem.hpp>
+
 
 #include <boost/test/unit_test.hpp>
 
@@ -130,4 +134,113 @@
     BOOST_TEST(modelOptionsOut[0].GetOption(0).GetValue().AsBool() == true);
 }
 
+BOOST_AUTO_TEST_CASE(CheckMLGOTuningFile)
+{
+    class ClBackendContextTestClass : public armnn::ClBackendContext
+    {
+    public:
+        ClBackendContextTestClass(const armnn::IRuntime::CreationOptions &options) : ClBackendContext(options)
+        {}
+
+        bool call_reload_from_file()
+        {
+            return m_MLGOTuner.reload_from_file(m_MLGOTuningFile);
+        }
+    };
+
+    const std::string validText{
+            "<header>\n"
+            "gemm-version, [1,2,1]\n"
+            "ip-type,gpu\n"
+            "</header>\n"
+            "<heuristics-table>\n"
+            "0, g71 , 8, f32, best-performance, static, gemm-type, [m,n,k,n]\n"
+            "1, g71 , 8, f32, best-performance, static, gemm-config-reshaped-only-rhs, [m,n,k,n]\n"
+            "2, g71 , 8, f32, best-performance, static, gemm-config-reshaped, [m,n,k,n]\n"
+            "3, g71 , 8, qasymm8, best-performance, static, gemm-type, [m,n,k,n]\n"
+            "4, g71 , 8, qasymm8, best-performance, static, gemm-config-reshaped-only-rhs, [m,n,k,n]\n"
+            "5, g71 , 8, qasymm8, best-performance, static, gemm-config-native, [m,n,k,n]\n"
+            "</heuristics-table>\n"
+            "<heuristic, 0>\n"
+            "b , 0, var, r_mn, >=, num, 2., 1, 2\n"
+            "l , 1, gemm-type, reshaped\n"
+            "l , 2, gemm-type, reshaped-only-rhs\n"
+            "</heuristic>\n"
+            "<heuristic, 1>\n"
+            "l ,0,gemm-config-reshaped-only-rhs, [2, 4,4,4,1,1,0]\n"
+            "</heuristic>\n"
+            "<heuristic, 2>\n"
+            "l ,0,gemm-config-reshaped,[4,2,8,16,16,1,0,1,0]\n"
+            "</heuristic>\n"
+            "<heuristic, 3>\n"
+            "l , 0, gemm-type, native\n"
+            "</heuristic>\n"
+            "<heuristic, 4>\n"
+            "l ,0,gemm-config-reshaped-only-rhs, [2, 4,4,4,1,1,0]\n"
+            "</heuristic>\n"
+            "<heuristic, 5>\n"
+            "l ,0,gemm-config-native,[4,2,8]\n"
+            "</heuristic>\n"};
+
+    const std::string invalidText{"ʕノ•ᴥ•ʔノ ︵ ┻━┻"};
+
+    fs::path validFile = armnnUtils::Filesystem::NamedTempFile("validFile.mlgo");
+    fs::path invalidFile = armnnUtils::Filesystem::NamedTempFile("invalidFile.mlgo");
+
+    try
+    {
+        std::ofstream ofs1{validFile};
+        ofs1 << validText << std::endl;
+        ofs1.close();
+
+        std::ofstream ofs2{invalidFile};
+        ofs2 << invalidText << std::endl;
+        ofs2.close();
+    }
+    catch (std::exception &e)
+    {
+        std::cerr << "Unable to write to file at location [" << validFile.c_str() << "] : " << e.what() << std::endl;
+        BOOST_TEST(false);
+    }
+
+    armnn::IRuntime::CreationOptions creationOptions1;
+    armnn::BackendOptions validOptions
+            {
+                    "GpuAcc",
+                    {
+                            {"MLGOTuningFilePath", validFile.c_str()}
+                    }
+            };
+
+    creationOptions1.m_BackendOptions.emplace_back(validOptions);
+    ClBackendContextTestClass clBackendContext1(creationOptions1);
+    BOOST_TEST(clBackendContext1.call_reload_from_file());
+
+    armnn::BackendOptions invalidOptions
+            {
+                    "GpuAcc",
+                    {
+                            {"MLGOTuningFilePath", invalidFile.c_str()}
+                    }
+            };
+
+    armnn::IRuntime::CreationOptions creationOptions2;
+    creationOptions2.m_BackendOptions.emplace_back(invalidOptions);
+    ClBackendContextTestClass clBackendContext2(creationOptions2);
+    BOOST_TEST(clBackendContext2.call_reload_from_file() == false);
+
+    armnn::BackendOptions invalidPathOptions
+            {
+                    "GpuAcc",
+                    {
+                            {"MLGOTuningFilePath", "not_a_real_file_path"}
+                    }
+            };
+
+    armnn::IRuntime::CreationOptions creationOptions3;
+    creationOptions3.m_BackendOptions.emplace_back(invalidPathOptions);
+    ClBackendContextTestClass clBackendContext3(creationOptions3);
+    BOOST_TEST(clBackendContext3.call_reload_from_file() == false);
+}
+
 BOOST_AUTO_TEST_SUITE_END();