[Util] Add output dump mode
authorDongju Chae <dongju.chae@samsung.com>
Wed, 17 Mar 2021 09:28:48 +0000 (18:28 +0900)
committer송욱/On-Device Lab(SR)/Staff Engineer/삼성전자 <wook16.song@samsung.com>
Thu, 18 Mar 2021 07:34:11 +0000 (16:34 +0900)
This patch adds output dump mode for debugging.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
tests/utils/ne_test_utils.cc
tests/utils/ne_test_utils.h

index e5b3da0..fc08343 100644 (file)
@@ -283,6 +283,7 @@ std::condition_variable UtilTrinity::cv_;
 uint32_t UtilTrinity::success_ = 0;
 uint32_t UtilTrinity::total_ = 0;
 uint32_t UtilTrinity::done_ = 0;
+bool UtilTrinity::dump_ = false;
 
 /** @brief constructor of UtilTrinity */
 UtilTrinity::UtilTrinity (dev_type type, bool need_model, bool verify)
@@ -295,6 +296,7 @@ UtilTrinity::UtilTrinity (dev_type type, bool need_model, bool verify)
 
   mute_ = false;
   sync_ = false;
+  dump_ = false;
 }
 
 /** @brief destructor of UtilTrinity */
@@ -342,6 +344,7 @@ void UtilTrinity::printUsage (const char *prog_name, const char *param_str)
   std::cerr << "  -n <arg> \t Set output notimode [intr|polling]\n";
   std::cerr << "  -m \t\t Mute stdout/stderr messages\n";
   std::cerr << "  -s \t\t Enable run sync mode\n";
+  std::cerr << "  -o \t\t Enable output dump mode\n";
   std::cerr << "  -h \t\t Show help messages\n";
 }
 
@@ -383,7 +386,7 @@ int UtilTrinity::parseArgs (int argc, char **argv, char **param,
 
   optind = 0;
   opterr = 0;
-  while ((c = getopt (argc, argv, "d:n:msh")) != -1) {
+  while ((c = getopt (argc, argv, "d:n:msho")) != -1) {
     switch (c) {
       case 'd':
         setNodePath (optarg);
@@ -397,6 +400,9 @@ int UtilTrinity::parseArgs (int argc, char **argv, char **param,
       case 's':
         setSync ();
         break;
+      case 'o':
+        setDump ();
+        break;
       case '?':
         if (optopt == 'd' || optopt == 'n')
           std::cerr << "Option 'd' or 'n' requires an extra argument";
@@ -513,11 +519,23 @@ void UtilTrinity::callbackVerify (output_buffers *output, uint64_t sequence,
 
   for (uint32_t idx = 0; idx < output->num_buffers; idx++) {
     if (model != nullptr) {
+      const char *path = model->getOutputPath (idx);
       char *buf = static_cast<char*>(output->bufs[idx].addr);
       size_t size = output->bufs[idx].size;
 
-      if (compare_data (model->getOutputPath (idx), buf, size) != 0)
+      if (compare_data (path, buf, size) != 0)
         success = false;
+
+      if (dump_) {
+        std::string dump_path (path);
+        dump_path += ".dump";
+
+        FILE * dump_fp = fopen (dump_path.c_str (), "w");
+        if (dump_fp != NULL) {
+          fwrite (buf, size, 1, dump_fp);
+          fclose (dump_fp);
+        }
+      }
     }
 
     free (output->bufs[idx].addr);
index 069e722..158fa5f 100644 (file)
@@ -87,6 +87,7 @@ class UtilTrinity {
 
     npudev_h getDeviceHandle () { return dev_; }
 
+    static void setDump () { dump_ = true; }
     void setSync () { sync_ = true; }
     void setMute ();
     void setNotiMode (const std::string mode);
@@ -148,6 +149,8 @@ class UtilTrinity {
     static uint32_t success_;
     static uint32_t done_;
     static uint32_t total_;
+
+    static bool dump_;
 };
 
 class UtilTRIV2 : public UtilTrinity {