From: Dongju Chae Date: Tue, 29 Jun 2021 07:22:39 +0000 (+0900) Subject: [Test] Add aging test to repeat whole APIs X-Git-Tag: accepted/tizen/unified/20220103.130045~107 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a3306333de9d012860c5341d05062a240b80f99;p=platform%2Fadaptation%2Fnpu%2Ftrix-engine.git [Test] Add aging test to repeat whole APIs This patch adds aging test to repease whole APIs. Signed-off-by: Dongju Chae --- diff --git a/tests/apptests/tvn_triv2_aging.cc b/tests/apptests/tvn_triv2_aging.cc index bd1cb5f..5a41e5b 100644 --- a/tests/apptests/tvn_triv2_aging.cc +++ b/tests/apptests/tvn_triv2_aging.cc @@ -16,6 +16,14 @@ using namespace std; +typedef enum { + AGING_TEST_NONE = 0, + AGING_TEST_MODEL, + AGING_TEST_INFERENCE, + AGING_TEST_MODEL_INFERENCE, + AGING_TEST_FULL, +} AGING_TEST_MODE; + #define NPU_TIMEOUT_MS 5000 #define PRINT_STATUS_UNIT 100 #define PRINT_STATUS_ITERS(iter, max) \ @@ -26,7 +34,7 @@ using namespace std; /** @brief C++ class to describe how to use npu-engine library */ class Tester : public UtilTRIV2 { public: - Tester () : num_iter_ (0), mode_ (0) {} + Tester () : tops_ (0), num_iter_ (0), mode_ (AGING_TEST_NONE) {} /** @brief initilize the device handle */ int init (string model_dir) { @@ -39,15 +47,9 @@ class Tester : public UtilTRIV2 { if (meta == nullptr) return -EINVAL; - uint32_t tops = NPU_VERSION_TOPS (meta->npu_version); + tops_ = NPU_VERSION_TOPS (meta->npu_version); free (meta); - int status = UtilTRIV2::init (tops); - if (status != test_ret_success) { - cerr << "Failed to initialize\n"; - return status; - } - return 0; } @@ -86,7 +88,13 @@ class Tester : public UtilTRIV2 { uint32_t model_id; int req_id, status; - if (mode_ == 0) { + status = UtilTRIV2::init (tops_); + if (status != test_ret_success) { + cerr << "Failed to initialize\n"; + return status; + } + + if (mode_ == AGING_TEST_MODEL) { /* repeat model_register/unregister */ for (uint32_t i = 0; i < num_iter_; i++) { PRINT_STATUS_ITERS (i, num_iter_); @@ -102,8 +110,9 @@ class Tester : public UtilTRIV2 { check_memleak (); } - return test_ret_success; - } else if (mode_ == 1) { + + status = test_ret_success; + } else if (mode_ == AGING_TEST_INFERENCE) { /* repeat model_inference only */ status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, NPU_TIMEOUT_MS); @@ -130,8 +139,9 @@ class Tester : public UtilTRIV2 { return status; check_memleak (); - return wait () == num_iter_ ? test_ret_success : test_ret_failure; - } else if (mode_ == 2) { + + status = wait () == num_iter_ ? test_ret_success : test_ret_failure; + } else if (mode_ == AGING_TEST_MODEL_INFERENCE) { /* repeat model_register/inference/unregister */ for (uint32_t i = 0; i < num_iter_; i++) { PRINT_STATUS_ITERS (i, num_iter_); @@ -164,15 +174,61 @@ class Tester : public UtilTRIV2 { check_memleak (); } - return wait () == num_iter_ ? test_ret_success : test_ret_failure; + status = wait () == num_iter_ ? test_ret_success : test_ret_failure; + } else if (mode_ == AGING_TEST_FULL) { + /* repeat whole APIs */ + for (uint32_t i = 0; i < num_iter_; i++) { + PRINT_STATUS_ITERS (i, num_iter_); + + UtilTRIV2::clear (); + status = UtilTRIV2::init (tops_); + if (status != test_ret_success) { + cerr << "Failed to initialize\n"; + return status; + } + + status = UtilTRIV2::loadModel (model_dir_, &model_id, NPU_PRIORITY_MID, + NPU_TIMEOUT_MS); + if (status != 0) + return status; + + req_id = UtilTRIV2::createRequest (model_id); + if (req_id < 0) + return req_id; + + status = UtilTRIV2::submitRequest (req_id); + if (status != 0) { + UtilTRIV2::removeRequest (req_id); + UtilTRIV2::unloadModel (model_id); + return status; + } + + status = UtilTRIV2::removeRequest (req_id); + if (status != 0) { + UtilTRIV2::unloadModel (model_id); + return status; + } + + status = UtilTRIV2::unloadModel (model_id); + if (status != 0) + return status; + + check_memleak (); + } + status = wait () == num_iter_ ? test_ret_success : test_ret_failure; } else { - cerr << "Unsupported mode... use 0 (model-only), 1 (fast), or 2 (slow)\n"; - return test_ret_failure; + cerr << "Supported mode: 1 (model), 2 (infer), 3 (model/infer), " + "or 4 (full)\n"; + status = test_ret_failure; } + + UtilTRIV2::clear (); + return status; } private: string model_dir_; + uint32_t tops_; uint32_t num_iter_; uint32_t mode_; }; @@ -180,7 +236,7 @@ class Tester : public UtilTRIV2 { /** @brief apptest main */ int main (int argc, char **argv) { - const char *help = "model_dir num_iterations test_mode"; + const char *help = "model_dir test_mode num_iterations"; Tester tester; int status; int index;