[Coverage] Increase the code coverage by excluding some files
authorDongju Chae <dongju.chae@samsung.com>
Wed, 27 May 2020 07:27:10 +0000 (16:27 +0900)
committer송욱/On-Device Lab(SR)/Staff Engineer/삼성전자 <wook16.song@samsung.com>
Wed, 27 May 2020 22:12:13 +0000 (07:12 +0900)
This patch increases the coverage by excluding some files such as
NPUdrvAPI_triv and NPUdrvAPI_triv2 because they're available in
FastModel only. Also, remove deprecated functions in libnpuhost.h

In short, the final code coverage is 85.9 %.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
include/common/typedef.h
include/host/libnpuhost.h
packaging/npu-engine.spec
src/core/ne-handler.cc
src/core/npu/NPUdrvAPI.h
tests/apptests/dummy_run_async.c
tests/apptests/dummy_run_sync.c
tests/unittests/ne_core_npu_test.cc

index 6c51544..8a2ee47 100644 (file)
@@ -23,7 +23,7 @@
 /** alias */
 #define DEVICETYPE_TRIV DEVICETYPE_NPU
 #define DEVICETYPE_TRIA DEVICETYPE_ASR
-#define DEVICETYPE_TRIV2 (0x30000)      /** SR-NPU 2020 */
+#define DEVICETYPE_TRIV2 (0x30000)      /** VD/SR-NPU 2020 */
 
 #define DEVICETYPE_MASK (0xFFFF0000)
 
index 613f266..477c3bd 100644 (file)
@@ -16,6 +16,9 @@
  *         Wook Song <wook16.song@samsung.com>
  *         Parichay Kapoor <pk.kapoor@samsung.com>
  * @bug No known bugs except for NYI items
+ * @note libnpuhost.h is the entry point to access NPU Engine (by host handler).
+ *       Also, the term 'NPU' now includes all variants such as traditional NPU, ASR,
+ *       and new device types (i.e., TRIV, TRIV2, and TRIA).
  */
 
 #ifndef __NPU_HOST_LIBNPUHOST_H__
 #include <typedef.h>
 #include <npubinfmt.h>
 
-/**
- * Note that libnpuhost is the entry point to access NPU Engine (by host handler).
- * Also, the term 'NPU' now includes all variants such as traditional NPU, ASR,
- * and new device types (i.e., TRIV, TRIV2, and TRIA). Existing APIs that do not
- * specify a device type in their names (e.g., getNPUdevice/getASRdevice) are now
- * deprecated (but still supported).
- */
-
 #if defined(__cplusplus)
 extern "C" {
 #endif
@@ -124,37 +119,6 @@ int getnumNPUdeviceByType (dev_type type);
 int getNPUdeviceByType (npudev_h *dev, dev_type type, uint32_t id);
 
 /**
- * @brief Description of npu device search conditions.
- * @todo this feature is not supported yet
- */
-typedef struct {
-  dev_type connection; /**< Desginates NPU connection types. Use NPUCOND_CONN_UNKNOWN to say "I don't care." */
-
-  enum {
-    NPUCOND_SORT_ANY = 0, /**< Choose any. Don't care ID num */
-    NPUCOND_SORT_MIN_ID = 1, /**< Choose smaller device ID */
-    NPUCOND_SORT_MAX_ID = 2, /**< Choose larger device ID */
-  } sort; /**< Choose based on device id number */
-
-  enum {
-    NPUCOND_LOAD_ANY = 0, /**< Does not care how many models are loaded */
-    NPUCOND_LOAD_NO = 1, /**< Choose a device without any models loaded */
-    NPUCOND_LOAD_MIN_MODEL = 2, /**< Choose a device with least models loaded */
-    NPUCOND_LOAD_MAX_MEMORY = 3, /**< Choose a device with the most free memory available */
-  } loads; /**< Choose based on device resource status */
-} npucondition;
-
-/**
- * @brief Returns the handle of an NPU device meeting the condition
- * @param[out] dev The NPU device handle
- * @param[in] cond The condition for device search.
- * @return @c 0 if no error. otherwise a negative error value
- * @note the caller should call putNPUdevice() to release the device handle
- * @todo this feature is not supported yet
- */
-int getNPUdeviceByCondition(npudev_h *dev, const npucondition *cond);
-
-/**
  * @brief release the NPU device instance obtained by getDevice ()
  * @param[in] dev the NPU device handle
  */
@@ -320,23 +284,6 @@ int runNPU_async(npudev_h dev, uint32_t modelid, const input_buffers *input,
  */
 int getNPU_memoryStatus(npudev_h dev, size_t *alloc_total, size_t *free_total);
 
-/** Optional Features. May be left unimplemented until later versions */
-/** @todo func prototype TBD. This does not use callback. */
-int runNPU_async_noalloc(npudev_h dev, uint32_t modelid, const input_buffers *input,
-    output_buffers *output, uint64_t *sequence, npu_async_mode mode);
-
-/** @todo func prototype TBD */
-int getRegisteredNPUmodels(npudev_h dev, uint32_t **modelids, uint32_t *nummodels);
-
-/** @todo func prototype TBD */
-int waitNPUrun(npudev_h dev);
-
-/** @todo func prototype TBD */
-int getNPUrunStatus(npudev_h dev, uint64_t *status);
-
-/** @todo func prototype TBD */
-int getNPUstatus(npudev_h dev, uint64_t *status);
-
 /**
  * [IMPORTANT] Descriptions for buffer allocation APIs.
  *
@@ -436,61 +383,25 @@ int allocNPU_inputBuffers (npudev_h dev, input_buffers * input);
  */
 int cleanNPU_inputBuffers (npudev_h dev, input_buffers * input);
 
-/** deprecated buffer APIs; please use the above APIs */
-
 /**
- * @deprecated
- * @brief Returns the list of NPU devices.
- * @return @c The number of NPU devices.
- * @retval 0 if no NPU devices available. if positive (number of NPUs) if NPU devices available. otherwise, a negative error value.
+ * Optional Features. May be left unimplemented until later versions
  */
-int getnumNPUdevice(void);
 
-/**
- * @deprecated
- * @brief Returns the handle of the chosen NPU devices.
- * @param[out] dev The NPU device handle
- * @param[in] id The NPU id to get the handle. 0 <= id < getNumNPUDevices().
- * @return @c 0 if no error. otherwise a negative error value
- * @note the caller should call putNPUdevice() to release the device handle
- */
-int getNPUdevice(npudev_h *dev, uint32_t id);
+/** @todo func prototype TBD. This does not use callback. */
+int runNPU_async_noalloc(npudev_h dev, uint32_t modelid, const input_buffers *input,
+    output_buffers *output, uint64_t *sequence, npu_async_mode mode);
 
-/**
- * @deprecated
- * @brief Returns the list of ASR devices
- * @return @c The number of ASR devices.
- * @retval 0 if no ASR devices available. if positive (number of ASRs) if ASR devices available. otherwise, a negative error value.
- */
-int getnumASRdevice(void);
+/** @todo func prototype TBD */
+int getRegisteredNPUmodels(npudev_h dev, uint32_t **modelids, uint32_t *nummodels);
 
-/**
- * @deprecated
- * @brief Returns the handle of the chosen ASR device.
- * @param[out] dev The ASR device handle
- * @param[in] id The ASRi-dev id to get the handle. 0 <= id < getNumASRDevices().
- * @return @c 0 if no error. otherwise a negative error value
- * @note the caller should call putNPUdevice() to release the device handle
- */
-int getASRdevice(npudev_h *dev, uint32_t id);
-
-/** @deprecated */
-int allocModelBuffer (generic_buffer *buffer);
-/** @deprecated */
-int cleanModelBuffer (generic_buffer *buffer);
-/** @deprecated */
-int allocInputBuffer (generic_buffer *buffer);
-/** @deprecated */
-int cleanInputBuffer (generic_buffer *buffer);
-/** @deprecated */
-int allocInputBuffers (input_buffers * input);
-/** @deprecated */
-int cleanInputBuffers (input_buffers * input);
-/** @deprecated */
-int allocNPUBuffer (uint64_t size, buffer_types type,
-    const char * filepath, generic_buffer *buffer);
-/** @deprecated */
-int cleanNPUBuffer (generic_buffer * buffer);
+/** @todo func prototype TBD */
+int waitNPUrun(npudev_h dev);
+
+/** @todo func prototype TBD */
+int getNPUrunStatus(npudev_h dev, uint64_t *status);
+
+/** @todo func prototype TBD */
+int getNPUstatus(npudev_h dev, uint64_t *status);
 
 #if defined(__cplusplus)
 }
index 7c93949..fce1861 100644 (file)
@@ -109,7 +109,7 @@ DESTDIR=%{buildroot} ninja install -C build %{?_smp_mflags}
   %endif
   done
 
-  # Run example_visa with sample models
+  # Run example_visa with a few sample models (due to performance issues)
   mkdir -p sample_models_v1
   mkdir -p sample_models_v2
   mkdir -p sample_models_v3
@@ -135,10 +135,13 @@ DESTDIR=%{buildroot} ninja install -C build %{?_smp_mflags}
 
   pushd build
 
-  # Collect coverage statistics using gcovr
+  # Collect coverage statistics using gcovr (excluding some files used only in FastModel)
   gcovr -r .. --html --html-details \
     --html-title "NPU SystemService Coverage" \
     --filter ../src/ --filter ../include/ \
+    --exclude ../src/core/npu/NPUdrvAPI_triv.cc \
+    --exclude ../src/core/npu/NPUdrvAPI_triv2.cc \
+    --exclude ../src/core/npu/NPUdrvAPI_tria.cc \
     -o index.html
 
   # Copy the coverage results
index 37a78b6..2eb46a6 100644 (file)
@@ -64,20 +64,6 @@ int getNPUdeviceByType (npudev_h *dev, dev_type type, uint32_t id)
 }
 
 /**
- * @brief Returns the handle of an NPU device meeting the condition
- * @param[out] dev The NPU device handle
- * @param[in] cond The condition for device search.
- * @return @c 0 if no error. otherwise a negative error value
- * @note the caller should call putNPUdevice() to release the device handle
- * @note it's not supported yet
- */
-int getNPUdeviceByCondition(npudev_h *dev, const npucondition *cond)
-{
-  /** not implmeneted yet */
-  return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, 0);
-}
-
-/**
  * @brief release the NPU device instance obtained by getDevice ()
  * @param[in] dev the NPU device handle
  */
@@ -377,107 +363,6 @@ exit_err:
   return nullptr;
 }
 
-/** deprecated buffer APIs; please use the above APIs */
-
-/**
- * @brief Returns the number of NPU devices (TRIV).
- */
-int getnumNPUdevice (void)
-{
-  logwarn (TAG, "deprecated. Please use getnumNPUdeviceByType ()\n");
-  return getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
-}
-
-/**
- * @brief Returns the list of ASR devices (TRIA)
- */
-int getnumASRdevice (void)
-{
-  logwarn (TAG, "deprecated. Please use getnumNPUdeviceByType ()\n");
-  return getnumNPUdeviceByType (NPUCOND_TRIA_CONN_SOCIP);
-}
-
-/**
- * @brief Returns the handle of the chosen TRIV device.
- */
-int getNPUdevice (npudev_h *dev, uint32_t id)
-{
-  logwarn (TAG, "deprecated. Please use getNPUdeviceByType ()\n");
-  return getNPUdeviceByType (dev, NPUCOND_TRIV_CONN_SOCIP, id);
-}
-
-/**
- * @brief Returns the handle of the chosen TRIA device.
- */
-int getASRdevice (npudev_h *dev, uint32_t id)
-{
-  logwarn (TAG, "deprecated. Please use getNPUdeviceByType ()\n");
-  return getNPUdeviceByType (dev, NPUCOND_TRIA_CONN_SOCIP, id);
-}
-
-/** @brief deprecated */
-int allocModelBuffer (generic_buffer *buffer)
-{
-  logwarn (TAG, "deprecated. Please use allocNPU_modelBuffer\n");
-  return allocNPU_modelBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int cleanModelBuffer (generic_buffer *buffer)
-{
-  logwarn (TAG, "deprecated. Please use cleanNPU_modelBuffer\n");
-  return allocNPU_modelBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int allocInputBuffer (generic_buffer *buffer)
-{
-  logwarn (TAG, "deprecated. Please use allocNPU_inputBuffer\n");
-  return allocNPU_inputBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int cleanInputBuffer (generic_buffer *buffer)
-{
-  logwarn (TAG, "deprecated. Please use cleanNPU_inputBuffer\n");
-  return cleanNPU_inputBuffer (HostHandler::getLatestDevice(), buffer);
-}
-
-/** @brief deprecated */
-int allocInputBuffers (input_buffers * input)
-{
-  logwarn (TAG, "deprecated. Please use allocNPU_inputBuffers\n");
-  return allocNPU_inputBuffers (HostHandler::getLatestDevice(), input);
-}
-
-/** @brief deprecated */
-int cleanInputBuffers (input_buffers * input)
-{
-  logwarn (TAG, "deprecated. Please use cleanNPU_inputBuffers\n");
-  return cleanNPU_inputBuffers (HostHandler::getLatestDevice(), input);
-}
-
-/** @brief deprecated */
-int allocNPUBuffer (uint64_t size, buffer_types type,
-    const char * filepath, generic_buffer *buffer)
-{
-  if (buffer) {
-    buffer->size = size;
-    buffer->type = type;
-    buffer->filepath = filepath;
-  }
-
-  logwarn (TAG, "deprecated. Please use allocNPU_* APIs\n");
-  return allocModelBuffer (buffer);
-}
-
-/** @brief deprecated */
-int cleanNPUBuffer (generic_buffer * buffer)
-{
-  logwarn (TAG, "deprecated. Please use cleanNPU_* APIs\n");
-  return cleanModelBuffer (buffer);
-}
-
 /** implement methods of HostHandler class */
 
 /** @brief host handler constructor */
index 6de39b8..09b9190 100644 (file)
@@ -70,7 +70,7 @@ class DriverAPI {
 
     /** The below requires initialized device */
     /** @brief check whether the device is ready (true) or busy (false) */
-    virtual device_state_t isReady () const { return device_state_t::STATE_END; }
+    virtual device_state_t isReady () const { return device_state_t::STATE_UNKNOWN; }
 
     /** @brief allocate memory with the given size. return dmabuf fd */
     virtual int alloc (size_t size) const { return -EPERM; }
index 9da80b5..750752a 100644 (file)
@@ -161,12 +161,12 @@ out:
 int
 main (int argc, char **argv)
 {
-  npudev_h dev;
-  int num_devices = getnumNPUdevice();
+  int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
   int result = -1;
+  npudev_h dev;
 
   if (num_devices) {
-    if (getNPUdevice (&dev, num_devices - 1) == 0) {
+    if (getNPUdeviceByType (&dev, NPUCOND_TRIV_CONN_SOCIP, num_devices - 1) == 0) {
       result = run_inference (dev);
       if (result == 0)
         fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
index 19e83b6..9d33269 100644 (file)
@@ -118,12 +118,12 @@ out:
 int
 main (int argc, char **argv)
 {
-  npudev_h dev;
-  int num_devices = getnumNPUdevice();
+  int num_devices = getnumNPUdeviceByType (NPUCOND_TRIV_CONN_SOCIP);
   int result = -1;
+  npudev_h dev;
 
   if (num_devices) {
-    if (getNPUdevice (&dev, num_devices - 1) == 0) {
+    if (getNPUdeviceByType (&dev, NPUCOND_TRIV_CONN_SOCIP, num_devices - 1) == 0) {
       result = run_inference (dev);
       if (result == 0) {
         fprintf(stderr, "[APPTEST] %s: PASSED\n", argv[0]);
index 1a28876..3194b93 100644 (file)
@@ -173,48 +173,50 @@ TEST (ne_core_npu_test, create_instance_uninitialized_n)
   const size_t size = 4096;
   model_config_t model;
   input_config_t input;
+  size_t alloc, free;
 
   /** create driver APIs not using createDriverAPI() */
   std::unique_ptr<DriverAPI> api (new TrinityVisionAPI (0));
 
-  /** TODO unimplemented yet */
   EXPECT_NE (api->open (), 0);
 
-  EXPECT_EQ (api->isReady (), -EPERM);
+  EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
   EXPECT_EQ (api->alloc (size), -EPERM);
   EXPECT_EQ (api->dealloc (0), -EPERM);
   EXPECT_EQ (api->mmap (0, size), nullptr);
   EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
   EXPECT_EQ (api->registerModel (&model), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
   EXPECT_EQ (api->runInput (&input), -EPERM);
 
   api.reset (new TrinityVision2API (0));
 
-  /** @todo unimplemented yet */
   EXPECT_NE (api->open (), 0);
 
-  EXPECT_EQ (api->isReady (), -EPERM);
+  EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
   EXPECT_EQ (api->alloc (size), -EPERM);
   EXPECT_EQ (api->dealloc (0), -EPERM);
   EXPECT_EQ (api->mmap (0, size), nullptr);
   EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
   EXPECT_EQ (api->registerModel (&model), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
   EXPECT_EQ (api->runInput (&input), -EPERM);
 
-#if 0
   api.reset (new TrinityAsrAPI (0));
 
-  /** TODO unimplemented yet */
   EXPECT_NE (api->open (), 0);
 
-  EXPECT_EQ (api->isReady (), -EPERM);
+  EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
   EXPECT_EQ (api->alloc (size), -EPERM);
   EXPECT_EQ (api->dealloc (0), -EPERM);
   EXPECT_EQ (api->mmap (0, size), nullptr);
   EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
   EXPECT_EQ (api->registerModel (&model), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
   EXPECT_EQ (api->runInput (&input), -EPERM);
-#endif
 
 #ifdef ENABLE_EMUL
   api.reset (new TrinityEmulAPI (0, NPUCOND_TRIV_CONN_SOCIP));
@@ -224,12 +226,14 @@ TEST (ne_core_npu_test, create_instance_uninitialized_n)
   EXPECT_NE (api->open (), 0);
 
   /** but, not initialized */
-  EXPECT_EQ (api->isReady (), -EPERM);
+  EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
   EXPECT_EQ (api->alloc (size), -EPERM);
   EXPECT_EQ (api->dealloc (0), -EPERM);
   EXPECT_EQ (api->mmap (0, size), nullptr);
   EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
   EXPECT_EQ (api->registerModel (&model), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
   EXPECT_EQ (api->runInput (&input), -EPERM);
 
   api.reset (new TrinityEmulAPI (0, NPUCOND_TRIV2_CONN_SOCIP));
@@ -239,12 +243,14 @@ TEST (ne_core_npu_test, create_instance_uninitialized_n)
   EXPECT_NE (api->open (), 0);
 
   /** but, not initialized */
-  EXPECT_EQ (api->isReady (), -EPERM);
+  EXPECT_EQ (api->isReady (), device_state_t::STATE_UNKNOWN);
   EXPECT_EQ (api->alloc (size), -EPERM);
   EXPECT_EQ (api->dealloc (0), -EPERM);
   EXPECT_EQ (api->mmap (0, size), nullptr);
   EXPECT_EQ (api->munmap (nullptr, size), -EPERM);
   EXPECT_EQ (api->registerModel (&model), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (&alloc, &free), -EPERM);
   EXPECT_EQ (api->runInput (&input), -EPERM);
 #endif
 }