[Test] Modify parsing npu version for test Date
authorJiho Chu <jiho.chu@samsung.com>
Sat, 6 Apr 2024 13:05:25 +0000 (22:05 +0900)
committerWook Song <wook16.song@samsung.com>
Tue, 18 Mar 2025 07:28:09 +0000 (16:28 +0900)
NPU Test data is selected by NPU_VER environment variable.
This patch modifies parsing routine to use env value
to test data path.

Signed-off-by: Jiho Chu <jiho.chu@samsung.com>
tests/unittests/meson.build
tests/utils/ne_test_utils.cc

index 0b27ca84abac4a20eaf02eb636a2ad609c67e513..63c2287e7f20556dcab0459219a20a3d3e6a7bcd 100644 (file)
@@ -1,11 +1,11 @@
 if ne_test_utils_gtest_dep.found()
   testenv_23 = environment()
   testenv_23.set('LD_LIBRARY_PATH', ne_libdir)
-  testenv_23.set('NPU_VER', '2.3')
+  testenv_23.set('NPU_VER', '2.3.8')
 
   testenv_24 = environment()
   testenv_24.set('LD_LIBRARY_PATH', ne_libdir)
-  testenv_24.set('NPU_VER', '2.4')
+  testenv_24.set('NPU_VER', '2.4.4')
 
   unittest_ne_core_utils = executable('unittest_ne_core_utils',
     ['ne_core_utils_test.cc'],
index 974cc00699237f4ae69bb259bb44028ea00f1974..bd8c9d4be17303a32191ac4de82860dd14bf75cf 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <string.h>
+#include <sstream>
 #include <dirent.h>
 
 #include <sys/stat.h>
@@ -34,6 +35,8 @@
 #define ALIGN_SIZE 4096
 #define TO_ALIGN_SIZE(size) (((size - 1) / ALIGN_SIZE + 1) * ALIGN_SIZE)
 
+#define DEFAULT_NPU_VERSION "2.4.4"
+
 /** @brief fill program data for testing */
 static void
 fill_program (void *buf, size_t size) {
@@ -962,23 +965,45 @@ UtilTestEnv::set_info () {
     return -ENOMEM;
   }
 
-  /* default NPU version for testing is 2.4.2 */
-  if (npu_ver == NULL || strcmp (npu_ver, "2.4") == 0) {
-    devices_[0] = NPUCOND_TRIV24_CONN_UNKNOWN;
-    devices_[1] = NPUCOND_TRIV24_CONN_SOCIP;
-    version_ = 0x04030402;
-    model_ = "/testdata/TRIV243/CONV_2D_000";
-    tops_ = 4;
-  } else if (strcmp (npu_ver, "2.3") == 0) {
+  /* set default npu version */
+  if (npu_ver == NULL)
+    npu_ver = DEFAULT_NPU_VERSION;
+
+  /* parse npu version */
+  std::string ver (npu_ver);
+  std::string major, minor, extra;
+  std::stringstream ss (ver);
+
+  std::getline (ss, major, '.');
+  std::getline (ss, minor, '.');
+  std::getline (ss, extra, '.');
+
+  if (major.empty ())
+    major = "2";
+  if (minor.empty ())
+    minor = "4";
+  if (extra.empty ())
+    extra = "4";
+
+  if (major == "2" && minor == "3") {
     devices_[0] = NPUCOND_TRIV23_CONN_UNKNOWN;
     devices_[1] = NPUCOND_TRIV23_CONN_SOCIP;
-    version_ = 0x02080302;
-    model_ = "/testdata/TRIV238_2TOPS/CONV_2D_000";
     tops_ = 2;
+  } else if (major == "2" && minor == "4") {
+    devices_[0] = NPUCOND_TRIV24_CONN_UNKNOWN;
+    devices_[1] = NPUCOND_TRIV24_CONN_SOCIP;
+    tops_ = 4;
   } else {
     std::cerr << "Incompatible environmental variable npu version : " << npu_ver << "\n";
     return -EINVAL;
   }
 
+  model_ = std::string ("/testdata/TRIV") + major + minor + extra + "/CONV_2D_000";
+  version_ = 0;
+  version_ |= std::stoi (major);
+  version_ |= std::stoi (minor) << 8;
+  version_ |= std::stoi (extra) << 16;
+  version_ |= tops_ << 24;
+
   return 0;
 }