Moritz Pflanzer | ec2de0f | 2017-07-27 14:43:46 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017 Arm Limited. |
Moritz Pflanzer | ec2de0f | 2017-07-27 14:43:46 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef ARM_COMPUTE_TEST_TESTFILTER |
| 25 | #define ARM_COMPUTE_TEST_TESTFILTER |
| 26 | |
| 27 | #include "DatasetModes.h" |
| 28 | |
| 29 | #include <regex> |
| 30 | #include <utility> |
| 31 | #include <vector> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace framework |
| 38 | { |
| 39 | struct TestInfo; |
| 40 | |
| 41 | /** Test filter class. |
| 42 | * |
| 43 | * Stores information about which test cases are selected for execution. Based |
| 44 | * on test name and test id. |
| 45 | */ |
| 46 | class TestFilter final |
| 47 | { |
| 48 | public: |
| 49 | /** Default constructor. All tests selected. */ |
| 50 | TestFilter() = default; |
| 51 | |
| 52 | /** Constructor. |
| 53 | * |
| 54 | * The id_filter string has be a comma separated list of test ids. ... can |
| 55 | * be used to include a range of tests. For instance, "..., 15" means all |
| 56 | * test up to and including 15, "3, 6, ..., 10" means tests 3 and 6 to 10, |
| 57 | * and "15, ..." means test 15 and all following. |
| 58 | * |
| 59 | * @param[in] mode Dataset mode. |
| 60 | * @param[in] name_filter Regular expression to filter tests by name. Only matching tests will be executed. |
| 61 | * @param[in] id_filter String to match selected test ids. Only matching tests will be executed. |
| 62 | */ |
| 63 | TestFilter(DatasetMode mode, const std::string &name_filter, const std::string &id_filter); |
| 64 | |
| 65 | /** Check if a test case is selected to be executed. |
| 66 | * |
| 67 | * @param[in] info Test case info. |
| 68 | * |
| 69 | * @return True if the test case is selected to be executed. |
| 70 | */ |
| 71 | bool is_selected(const TestInfo &info) const; |
| 72 | |
| 73 | private: |
| 74 | using Ranges = std::vector<std::pair<int, int>>; |
| 75 | Ranges parse_id_filter(const std::string &id_filter) const; |
| 76 | |
| 77 | DatasetMode _dataset_mode{ DatasetMode::ALL }; |
| 78 | std::regex _name_filter{ ".*" }; |
| 79 | Ranges _id_filter{}; |
| 80 | }; |
| 81 | } // namespace framework |
| 82 | } // namespace test |
| 83 | } // namespace arm_compute |
| 84 | #endif /* ARM_COMPUTE_TEST_TESTFILTER */ |