Adding option -Coutput_dir= to control output location.

- If not specified, will be initialized with dirname(test_desc)
- Like -Cflatbuffer_dir, reference model isn't responsible for creating directory.
  User need to make sure target directory path exists.

Signed-off-by: Kevin Cheng <kevin.cheng@arm.com>
Change-Id: I9cfcc801cff648e53306f8de8ea8d5eaaf87ea80
diff --git a/reference_model/src/func_config.def b/reference_model/src/func_config.def
index 8270dbb..cf78ab8 100644
--- a/reference_model/src/func_config.def
+++ b/reference_model/src/func_config.def
@@ -66,6 +66,7 @@
 DEF_OPTION_STR(operator_fbs, "Flat buffer syntax file", FOF_STR_LEN, "tosa.fbs")
 DEF_OPTION_STR(test_desc, "Json test descriptor", FOF_STR_LEN, "desc.json")
 DEF_OPTION_STR(flatbuffer_dir, "Flatbuffer directory to load. If not specified, it will be overwritten by dirname(test_desc)", FOF_STR_LEN, "")
+DEF_OPTION_STR(output_dir, "Output directory to write. If not specified, it will be overwritten by dirname(test_desc)", FOF_STR_LEN, "")
 DEF_OPTION_STR(tosa_file, "Flatbuffer file. Support .json or .tosa. Specifying this will overwrite the one initialized by -Ctest_desc.", FOF_STR_LEN, "")
 DEF_OPTION_STR(ifm_name, "Input tensor name. Comma(,) seperated. Specifying this will overwrite the one initialized by -Ctest_desc.", FOF_STR_LEN, "")
 DEF_OPTION_STR(ifm_file, "Input tensor numpy Comma(,) seperated. file to initialize with placeholder. Specifying this will overwrite the one initialized by -Ctest_desc.", FOF_STR_LEN, "")
diff --git a/reference_model/src/main.cpp b/reference_model/src/main.cpp
index 0d6d8a3..412894c 100644
--- a/reference_model/src/main.cpp
+++ b/reference_model/src/main.cpp
@@ -285,7 +285,7 @@
                 return 1;
             }
 
-            snprintf(filename, sizeof(filename), "%s/%s", g_func_config.flatbuffer_dir,
+            snprintf(filename, sizeof(filename), "%s/%s", g_func_config.output_dir,
                      test_desc["ofm_file"][i].get<std::string>().c_str());
 
             DEBUG_MED(GT, "Writing output tensor[%d] %s to filename: %s", i, tensor->getName().c_str(), filename);
@@ -347,13 +347,21 @@
         }
     }
 
-    // Overwrite g_func_config.flatbuffer_dir with dirname(g_func_config.test_desc) if it's not specified.
+    // Overwrite flatbuffer_dir/output_dir with dirname(g_func_config.test_desc) if it's not specified.
     std::string flatbuffer_dir_str(g_func_config.flatbuffer_dir);
-    if (flatbuffer_dir_str.empty())
+    std::string output_dir_str(g_func_config.output_dir);
+    if (flatbuffer_dir_str.empty() || output_dir_str.empty())
     {
         std::string test_path(g_func_config.test_desc);
         std::string test_dir = test_path.substr(0, test_path.find_last_of("/\\"));
-        strncpy(g_func_config.flatbuffer_dir, test_dir.c_str(), 1024);
+        if (flatbuffer_dir_str.empty())
+        {
+            strncpy(g_func_config.flatbuffer_dir, test_dir.c_str(), FOF_STR_LEN);
+        }
+        if (output_dir_str.empty())
+        {
+            strncpy(g_func_config.output_dir, test_dir.c_str(), FOF_STR_LEN);
+        }
     }
 
     // Overwrite test_desc["tosa_file"] if -Ctosa_file= specified.