blob: f3127f330f2355286fdee37b2d45606c4a0d5400 [file] [log] [blame]
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +01003 *
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"
Matthew Bentham92046462020-03-07 22:15:55 +000027#include "support/StringSupport.h"
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010028
29#include <sstream>
30#include <string>
31
32namespace arm_compute
33{
34namespace test
35{
36namespace framework
37{
38TestFilter::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
43bool TestFilter::is_selected(const TestInfo &info) const
44{
Georgios Pinitas557d4ae2019-04-18 18:10:34 +010045 const bool include_disabled = (info.mode == _dataset_mode) && (_dataset_mode == DatasetMode::DISABLED);
46 if((info.mode & _dataset_mode) == DatasetMode::DISABLED && !include_disabled)
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010047 {
48 return false;
49 }
50
51 if(!std::regex_search(info.name, _name_filter))
52 {
53 return false;
54 }
55
56 if(!_id_filter.empty())
57 {
58 bool found = false;
59
Matthew Bentham6d76e4d2020-06-01 15:53:21 +010060 for(const auto &range : _id_filter)
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010061 {
62 if(range.first <= info.id && info.id <= range.second)
63 {
64 found = true;
65 break;
66 }
67 }
68
69 if(!found)
70 {
71 return false;
72 }
73 }
74
75 return true;
76}
77
78TestFilter::Ranges TestFilter::parse_id_filter(const std::string &id_filter) const
79{
80 Ranges ranges;
81 std::string str;
82 bool in_range = false;
83 int value = 0;
84 int start = 0;
85 int end = std::numeric_limits<int>::max();
86
87 std::stringstream stream(id_filter);
88
89 // Get first value
90 std::getline(stream, str, ',');
91
92 if(stream.fail())
93 {
94 return ranges;
95 }
96
97 if(str.find("...") != std::string::npos)
98 {
99 in_range = true;
100 }
101 else
102 {
103 start = support::cpp11::stoi(str);
104 end = start;
105 }
106
107 while(!stream.eof())
108 {
109 std::getline(stream, str, ',');
110
111 if(stream.fail())
112 {
113 break;
114 }
115
116 if(str.find("...") != std::string::npos)
117 {
118 end = std::numeric_limits<int>::max();
119 in_range = true;
120 }
121 else
122 {
123 value = support::cpp11::stoi(str);
124
125 if(in_range || end == value - 1)
126 {
127 end = value;
128 in_range = false;
129 }
130 else
131 {
132 ranges.emplace_back(start, end);
133 start = value;
134 end = start;
135 }
136 }
137 }
138
139 ranges.emplace_back(start, end);
140 return ranges;
141}
142} // namespace framework
143} // namespace test
144} // namespace arm_compute