Moritz Pflanzer | ec2de0f | 2017-07-27 14:43:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 | #include "TestFilter.h" |
| 25 | |
| 26 | #include "Framework.h" |
| 27 | #include "support/ToolchainSupport.h" |
| 28 | |
| 29 | #include <sstream> |
| 30 | #include <string> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | namespace test |
| 35 | { |
| 36 | namespace framework |
| 37 | { |
| 38 | TestFilter::TestFilter(DatasetMode mode, const std::string &name_filter, const std::string &id_filter) |
| 39 | : _dataset_mode{ mode }, _name_filter{ name_filter }, _id_filter{ parse_id_filter(id_filter) } |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | bool TestFilter::is_selected(const TestInfo &info) const |
| 44 | { |
| 45 | if((info.mode & _dataset_mode) == DatasetMode::DISABLED) |
| 46 | { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | if(!std::regex_search(info.name, _name_filter)) |
| 51 | { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | if(!_id_filter.empty()) |
| 56 | { |
| 57 | bool found = false; |
| 58 | |
| 59 | for(const auto range : _id_filter) |
| 60 | { |
| 61 | if(range.first <= info.id && info.id <= range.second) |
| 62 | { |
| 63 | found = true; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | if(!found) |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | TestFilter::Ranges TestFilter::parse_id_filter(const std::string &id_filter) const |
| 78 | { |
| 79 | Ranges ranges; |
| 80 | std::string str; |
| 81 | bool in_range = false; |
| 82 | int value = 0; |
| 83 | int start = 0; |
| 84 | int end = std::numeric_limits<int>::max(); |
| 85 | |
| 86 | std::stringstream stream(id_filter); |
| 87 | |
| 88 | // Get first value |
| 89 | std::getline(stream, str, ','); |
| 90 | |
| 91 | if(stream.fail()) |
| 92 | { |
| 93 | return ranges; |
| 94 | } |
| 95 | |
| 96 | if(str.find("...") != std::string::npos) |
| 97 | { |
| 98 | in_range = true; |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | start = support::cpp11::stoi(str); |
| 103 | end = start; |
| 104 | } |
| 105 | |
| 106 | while(!stream.eof()) |
| 107 | { |
| 108 | std::getline(stream, str, ','); |
| 109 | |
| 110 | if(stream.fail()) |
| 111 | { |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | if(str.find("...") != std::string::npos) |
| 116 | { |
| 117 | end = std::numeric_limits<int>::max(); |
| 118 | in_range = true; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | value = support::cpp11::stoi(str); |
| 123 | |
| 124 | if(in_range || end == value - 1) |
| 125 | { |
| 126 | end = value; |
| 127 | in_range = false; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | ranges.emplace_back(start, end); |
| 132 | start = value; |
| 133 | end = start; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | ranges.emplace_back(start, end); |
| 139 | return ranges; |
| 140 | } |
| 141 | } // namespace framework |
| 142 | } // namespace test |
| 143 | } // namespace arm_compute |