Compute Library
 23.11
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
TestFilter.h
StringSupport.h
arm_compute::test::framework::TestFilter::is_selected
bool is_selected(const TestInfo &info) const
Check if a test case is selected to be executed.
Definition: TestFilter.cpp:43
caffe_mnist_image_extractor.str
str
Definition: caffe_mnist_image_extractor.py:21
arm_compute::test::validation::reference::range
SimpleTensor< T > range(SimpleTensor< T > &dst, float start, const size_t num_of_elements, float step)
Definition: Range.cpp:50
arm_compute::test::framework::TestFilter::TestFilter
TestFilter()=default
Default constructor.
arm_compute::test::framework::DatasetMode::DISABLED
@ DISABLED
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
clang_tidy_rules.mode
mode
Definition: clang_tidy_rules.py:196
arm_compute::support::cpp11::stoi
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
arm_compute::mlgo::parser::end
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:283
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::test::framework::TestInfo
Information about a test case.
Definition: Framework.h:80
arm_compute::test::framework::DatasetMode
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
Framework.h