Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / NNPackages.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __NNFW_API_TEST_MODEL_PATH_H__
18 #define __NNFW_API_TEST_MODEL_PATH_H__
19
20 #include <string>
21
22 /**
23  * @brief A helper class to find NN Packages for testing
24  *        To add a nnpackage for your test, please do the followings:
25  *          0. Prerequisite: the actual file must be uploaded on the server
26  *                           Add `config.sh` file to `tests/scripts/nnfw_api_gtest_models`
27  *          1. Append an enum value to @c NNPackages::TestPackages
28  *          2. Append a string literal to @c TEST_PACKAGE_NAMES in the source file
29  */
30 class NNPackages
31 {
32 public:
33   /**
34    * @brief Serial numbers for test packages. The numbers are mapped with package names.
35    *        This is useful for creating GTest Fixtures with variable template to perform
36    *        different nn packages with no code duplication.
37    */
38   enum TestPackages
39   {
40     // for validation test
41     ADD,
42     ADD_NO_MANIFEST,      //< Contains "Add" model but no manifest file
43     ADD_INVALID_MANIFEST, //< Contains "Add" model but the manifest file is broken JSON
44
45     // for dynamic tensor test
46     INPUT_RESHAPING_ADD,
47     DYNAMIC_TENSOR_RESHAPE,
48     UNKNOWN_DIM_INPUT_CONCAT,
49     ADD_UNSPECIFIED_RANK_INPUTS,
50     NEG,
51     WHILE_DYNAMIC,
52     IF_DYNAMIC,
53
54     COUNT
55   };
56
57   /*
58    * @brief Singleton object getter
59    *
60    * @return NNPackages& The singleton object
61    */
62   static NNPackages &get();
63
64   /**
65    * @brief Get the Absolute of the model to find
66    *
67    * @param package_no Model's serial number
68    * @return std::string The absolute path of model directory
69    */
70   std::string getModelAbsolutePath(int package_no);
71
72   /**
73    * @brief Get the absolute of the model to find
74    *
75    * @param package_name Package name
76    * @return std::string The absolute path of model directory
77    */
78   std::string getModelAbsolutePath(const char *package_name);
79
80   /**
81    * @brief Save the current executable's directory based on argv[0] and CWD
82    *
83    * @param argv0 0th command line argument of the current process
84    */
85   void init(const char *argv0);
86
87   /**
88    * @brief Check all the nnpackages are installed
89    *        Must be run after @c init .
90    */
91   void checkAll();
92
93 private:
94   NNPackages() = default;
95
96 private:
97   std::string _base_path;
98 };
99
100 #endif // __NNFW_API_TEST_MODEL_PATH_H__