[Coverage] increase coverage of npu api header
authorDongju Chae <dongju.chae@samsung.com>
Fri, 23 Jul 2021 01:30:04 +0000 (10:30 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Fri, 23 Jul 2021 03:18:24 +0000 (12:18 +0900)
This patch increases coverage of npu api header.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/npu/NPUdrvAPI.h
src/core/npu/NPUdrvAPI_emul.cc
tests/unittests/ne_core_npu_test.cc

index 7d97b25..e737ccb 100644 (file)
@@ -59,7 +59,7 @@ class DriverAPI {
   virtual int getDspmSize (uint32_t *dspm) const { return -EPERM; }
   virtual int getNextRequest (int32_t *req_id) const { return -EPERM; }
 
-  virtual int checkSanity () { return 0; }
+  virtual int checkSanity () { return -EPERM; }
 
   /** The below requires initialized device */
   /** @brief check whether the device is ready (true) or busy (false) */
@@ -91,7 +91,7 @@ class DriverAPI {
   /** @brief run inference with the input config */
   virtual int runInput (input_config_t *input) const { return -EPERM; }
   /** @brief stop all requests. The stopped requests should be notified */
-  virtual int stop () const { return 0; }
+  virtual int stop () const { return -EPERM; }
   /** @brief stop the target request with the given id obtained by runInput() */
   virtual int stop_target (int id) const { return -EPERM; }
 
@@ -200,6 +200,7 @@ class TrinityEmulAPI : public DriverAPI {
   ~TrinityEmulAPI ();
 
   int open ();
+  int checkSanity ();
   int getNextRequest (int32_t *req_id) const;
 
   device_state_t isReady () const;
index 7e3a965..f6404e6 100644 (file)
@@ -370,6 +370,12 @@ TrinityEmulAPI::open () {
   return 0;
 }
 
+int
+TrinityEmulAPI::checkSanity () {
+  /* always true because it's emulated device */
+  return 0;
+}
+
 /**
  * @brief get next request id.
  * @param[out] req_id reqeust id
index a6641c1..2370cfd 100644 (file)
@@ -116,6 +116,34 @@ TEST (ne_core_npu_test, check_dev_status_triv2_n) {
 }
 
 /**
+ * @brief create API instance not using derived class
+ */
+TEST (ne_core_npu_test, create_instance_base_class_n) {
+  std::unique_ptr<DriverAPI> api (new DriverAPI (0));
+
+  EXPECT_EQ (api->open (), -ENODEV);
+  EXPECT_EQ (api->checkSanity (), -EPERM);
+  EXPECT_EQ (api->getAPILevel (nullptr), -EPERM);
+  EXPECT_EQ (api->getTops (nullptr), -EPERM);
+  EXPECT_EQ (api->getDspmSize (nullptr), -EPERM);
+  EXPECT_EQ (api->getNextRequest (nullptr), -EPERM);
+  EXPECT_LT (api->isReady (), 0);
+  EXPECT_EQ (api->alloc (0), -EPERM);
+  EXPECT_EQ (api->dealloc (0), -EPERM);
+  EXPECT_EQ (api->mmap (0, 0), nullptr);
+  EXPECT_EQ (api->munmap (nullptr, 0), -EPERM);
+  EXPECT_EQ (api->getMemoryStatus (nullptr, nullptr), -EPERM);
+  EXPECT_EQ (api->runInput (nullptr), -EPERM);
+  EXPECT_EQ (api->stop (), -EPERM);
+  EXPECT_EQ (api->stop_target (0), -EPERM);
+  EXPECT_EQ (api->registerModel (nullptr), -EPERM);
+  EXPECT_EQ (api->deregisterModel (0), -EPERM);
+  EXPECT_EQ (api->getProfile (0, nullptr), -EPERM);
+  EXPECT_EQ (api->getStatApps (nullptr), -EPERM);
+  EXPECT_EQ (api->getStatReqs (0, nullptr), -EPERM);
+}
+
+/**
  * @brief create API instances without initailiation
  */
 TEST (ne_core_npu_test, create_instance_uninitialized_n) {