Compute Library
 22.08
TestFilter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020 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/StringSupport.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 
44 {
45  const bool include_disabled = (info.mode == _dataset_mode) && (_dataset_mode == DatasetMode::DISABLED);
46  if((info.mode & _dataset_mode) == DatasetMode::DISABLED && !include_disabled)
47  {
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 
60  for(const auto &range : _id_filter)
61  {
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 
78 TestFilter::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
DatasetMode mode
Test data set mode.
Definition: Framework.h:82
Copyright (c) 2017-2022 Arm Limited.
std::string name
Test name.
Definition: Framework.h:81
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
SimpleTensor< T > range(SimpleTensor< T > &dst, float start, const size_t num_of_elements, float step)
Definition: Range.cpp:50
Information about a test case.
Definition: Framework.h:78
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
int stoi(const std::string &str, std::size_t *pos=0, NumericBase base=NumericBase::BASE_10)
Convert string values to integer.
Definition: StringSupport.h:55
TestFilter()=default
Default constructor.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
bool is_selected(const TestInfo &info) const
Check if a test case is selected to be executed.
Definition: TestFilter.cpp:43