[test] profile test only when emulator enabled
authorYelin Jeong <yelini.jeong@samsung.com>
Tue, 6 Dec 2022 04:29:04 +0000 (13:29 +0900)
committer추지호/NPU Lab(SR)/삼성전자 <jiho.chu@samsung.com>
Tue, 6 Dec 2022 06:22:26 +0000 (15:22 +0900)
This patch changes to test profile only when emulator is enabled.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
tests/unittests/meson.build
tests/unittests/ne_core_profiler_emul_test.cc [new file with mode: 0644]
tests/unittests/ne_core_profiler_test.cc [deleted file]

index 704d6a3d5d07e4b2f1e4b5e5a314c74b404d79f3..eab4b4dd2a6440bdd8582f335b672eade7c4aeac 100644 (file)
@@ -133,13 +133,15 @@ if ne_test_utils_gtest_dep.found()
   )
   test('unittest_ne_libnpuhost', unittest_ne_libnpuhost, env: testenv, suite: ['fast-test'])
 
-  unittest_ne_core_profiler = executable('unittest_ne_core_profiler',
-    ['ne_core_profiler_test.cc'],
-    include_directories: [ne_host_inc, ne_common_inc],
-    dependencies: [ne_test_utils_gtest_dep, ne_host_dep, ne_core_dep],
-    install : true,
-    install_rpath : ne_libdir,
-    install_dir : join_paths(ne_bindir, 'unittests')
-  )
-  test('unittest_ne_core_profiler', unittest_ne_core_profiler, env: testenv, suite: ['fast-test'])
+  if get_option('enable_npu_emul')
+    unittest_ne_core_profiler = executable('unittest_ne_core_profiler_emul',
+      ['ne_core_profiler_emul_test.cc'],
+      include_directories: [ne_host_inc, ne_common_inc],
+      dependencies: [ne_test_utils_gtest_dep, ne_host_dep, ne_core_dep],
+      install : true,
+      install_rpath : ne_libdir,
+      install_dir : join_paths(ne_bindir, 'unittests')
+    )
+    test('unittest_ne_core_profiler', unittest_ne_core_profiler, env: testenv, suite: ['fast-test'])
+  endif
 endif
diff --git a/tests/unittests/ne_core_profiler_emul_test.cc b/tests/unittests/ne_core_profiler_emul_test.cc
new file mode 100644 (file)
index 0000000..165d11b
--- /dev/null
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/**
+ * Copyright (C) 2022 Samsung Electronics
+ * Copyright (C) 2022 Yelin Jeong <yelini.jeong@samsung.com>
+ */
+/**
+ * @file ne_core_profiler_test.cc
+ * @date 23 Nov 2022
+ * @brief Test npu profiler
+ * @author Yelin Jeong <yelini.jeong@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#include <ne_test_utils_gtest.h>
+#include <ne-profiler.h>
+#include <ne-handler.h>
+
+#define REC_PATH NE_BINDIR "/testdata/triv2.4_nodlp_284.rec"
+#define DLP_REC_PATH NE_BINDIR "/testdata/triv2.4_dlp_284_485.rec"
+
+/**
+ * @brief check mergeProfile
+ */
+TEST (ne_core_profiler_test, merge_profile) {
+  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
+
+  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
+  ASSERT_GT (num_devices, 0);
+
+  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+  ModelProfiler *profiler = new ModelProfiler (api.get ());
+  ASSERT_NE (api.get (), nullptr);
+
+  npu_profile profile = {0};
+
+  if (!std::ifstream (REC_PATH)) {
+    printf ("no rec file %s found\n", REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_visa, &profile, REC_PATH);
+  ASSERT_EQ (ret, 0);
+
+  npu_profile profile_dlp = {0};
+
+  if (!std::ifstream (DLP_REC_PATH)) {
+    printf ("no rec file %s found\n", DLP_REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_visa, &profile_dlp, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+
+  ASSERT_EQ (profile.num_layers, profile_dlp.num_layers);
+  for (int i = 0; i < profile.num_layers; i++) {
+    EXPECT_EQ (profile.layers[i].visa_opcode, profile_dlp.layers[i].visa_opcode);
+  }
+}
+
+/**
+ * @brief check mergeProfile
+ */
+TEST (ne_core_profiler_test, profile_level_visa_dlp) {
+  const npu_profile_opt opt_dlp = {.level = PROFILE_LEVEL_VISA_DLP};
+  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
+
+  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
+  ASSERT_GT (num_devices, 0);
+
+  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+  ModelProfiler *profiler = new ModelProfiler (api.get ());
+  ASSERT_NE (api.get (), nullptr);
+
+  npu_profile profile_dlp = {0};
+  npu_profile profile_visa = {0};
+
+  if (!std::ifstream (DLP_REC_PATH)) {
+    printf ("no rec file %s found\n", DLP_REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_dlp, &profile_dlp, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+  ASSERT_EQ (profile_dlp.num_layers, 485);
+
+  ret = profiler->getProfile (1, opt_visa, &profile_visa, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+  ASSERT_EQ (profile_visa.num_layers, 284);
+}
+
+/**
+ * @brief main function for unit test
+ */
+int
+main (int argc, char **argv) {
+  return start_gtest (argc, argv);
+}
diff --git a/tests/unittests/ne_core_profiler_test.cc b/tests/unittests/ne_core_profiler_test.cc
deleted file mode 100644 (file)
index 165d11b..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/* SPDX-License-Identifier: Apache-2.0 */
-/**
- * Copyright (C) 2022 Samsung Electronics
- * Copyright (C) 2022 Yelin Jeong <yelini.jeong@samsung.com>
- */
-/**
- * @file ne_core_profiler_test.cc
- * @date 23 Nov 2022
- * @brief Test npu profiler
- * @author Yelin Jeong <yelini.jeong@samsung.com>
- * @bug No known bugs except for NYI items
- */
-
-#include <ne_test_utils_gtest.h>
-#include <ne-profiler.h>
-#include <ne-handler.h>
-
-#define REC_PATH NE_BINDIR "/testdata/triv2.4_nodlp_284.rec"
-#define DLP_REC_PATH NE_BINDIR "/testdata/triv2.4_dlp_284_485.rec"
-
-/**
- * @brief check mergeProfile
- */
-TEST (ne_core_profiler_test, merge_profile) {
-  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
-
-  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
-  ASSERT_GT (num_devices, 0);
-
-  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
-  ModelProfiler *profiler = new ModelProfiler (api.get ());
-  ASSERT_NE (api.get (), nullptr);
-
-  npu_profile profile = {0};
-
-  if (!std::ifstream (REC_PATH)) {
-    printf ("no rec file %s found\n", REC_PATH);
-    return;
-  }
-
-  ret = profiler->getProfile (1, opt_visa, &profile, REC_PATH);
-  ASSERT_EQ (ret, 0);
-
-  npu_profile profile_dlp = {0};
-
-  if (!std::ifstream (DLP_REC_PATH)) {
-    printf ("no rec file %s found\n", DLP_REC_PATH);
-    return;
-  }
-
-  ret = profiler->getProfile (1, opt_visa, &profile_dlp, DLP_REC_PATH);
-  ASSERT_EQ (ret, 0);
-
-  ASSERT_EQ (profile.num_layers, profile_dlp.num_layers);
-  for (int i = 0; i < profile.num_layers; i++) {
-    EXPECT_EQ (profile.layers[i].visa_opcode, profile_dlp.layers[i].visa_opcode);
-  }
-}
-
-/**
- * @brief check mergeProfile
- */
-TEST (ne_core_profiler_test, profile_level_visa_dlp) {
-  const npu_profile_opt opt_dlp = {.level = PROFILE_LEVEL_VISA_DLP};
-  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
-
-  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
-  ASSERT_GT (num_devices, 0);
-
-  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
-  ModelProfiler *profiler = new ModelProfiler (api.get ());
-  ASSERT_NE (api.get (), nullptr);
-
-  npu_profile profile_dlp = {0};
-  npu_profile profile_visa = {0};
-
-  if (!std::ifstream (DLP_REC_PATH)) {
-    printf ("no rec file %s found\n", DLP_REC_PATH);
-    return;
-  }
-
-  ret = profiler->getProfile (1, opt_dlp, &profile_dlp, DLP_REC_PATH);
-  ASSERT_EQ (ret, 0);
-  ASSERT_EQ (profile_dlp.num_layers, 485);
-
-  ret = profiler->getProfile (1, opt_visa, &profile_visa, DLP_REC_PATH);
-  ASSERT_EQ (ret, 0);
-  ASSERT_EQ (profile_visa.num_layers, 284);
-}
-
-/**
- * @brief main function for unit test
- */
-int
-main (int argc, char **argv) {
-  return start_gtest (argc, argv);
-}