SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
parserbench.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QCommandLineOption>
20 #include <QRegExpValidator>
21 #include <QDebug>
22 
23 #include "parserbench.h"
24 
26  m_testOption(QStringList() << "t" << "test",
27  "Test type: decimateii, decimatefi, decimateff, decimateif, decimateinfii, decimatesupii, ambe",
28  "test",
29  "decimateii"),
30  m_nbSamplesOption(QStringList() << "n" << "nb-samples",
31  "Number of sample to deal with.",
32  "samples",
33  "1048576"),
34  m_repetitionOption(QStringList() << "r" << "repeat",
35  "Number of repetitions.",
36  "repetition",
37  "1"),
38  m_log2FactorOption(QStringList() << "l" << "log2-factor",
39  "Log2 factor for rate conversion.",
40  "log2",
41  "2")
42 {
43  m_testStr = "decimateii";
44  m_nbSamples = 1048576;
45  m_repetition = 1;
46  m_log2Factor = 4;
47 
48  m_parser.setApplicationDescription("Software Defined Radio application benchmarks");
49  m_parser.addHelpOption();
50  m_parser.addVersionOption();
51 
52  m_parser.addOption(m_testOption);
53  m_parser.addOption(m_nbSamplesOption);
54  m_parser.addOption(m_repetitionOption);
55  m_parser.addOption(m_log2FactorOption);
56 }
57 
59 { }
60 
61 void ParserBench::parse(const QCoreApplication& app)
62 {
63  m_parser.process(app);
64 
65  int pos;
66  bool ok;
67 
68  // test switch
69 
70  QString test = m_parser.value(m_testOption);
71 
72  QString testStr = "([a-z]+)";
73  QRegExp ipRegex ("^" + testStr + "$");
74  QRegExpValidator ipValidator(ipRegex);
75 
76  if (ipValidator.validate(test, pos) == QValidator::Acceptable) {
77  m_testStr = test;
78  } else {
79  qWarning() << "ParserBench::parse: test string invalid. Defaulting to " << m_testStr;
80  }
81 
82  // number of samples
83 
84  QString nbSamplesStr = m_parser.value(m_nbSamplesOption);
85  int nbSamples = nbSamplesStr.toInt(&ok);
86 
87  if (ok && (nbSamples > 1024) && (nbSamples < 1073741824)) {
88  m_nbSamples = nbSamples;
89  } else {
90  qWarning() << "ParserBench::parse: number of samples invalid. Defaulting to " << m_nbSamples;
91  }
92 
93  // repetition
94 
95  QString repetitionStr = m_parser.value(m_repetitionOption);
96  int repetition = repetitionStr.toInt(&ok);
97 
98  if (ok && (repetition >= 0)) {
99  m_repetition = repetition;
100  } else {
101  qWarning() << "ParserBench::parse: repetition invalid. Defaulting to " << m_repetition;
102  }
103 
104  // log2 factor
105 
106  QString log2FactorStr = m_parser.value(m_log2FactorOption);
107  int log2Factor = log2FactorStr.toInt(&ok);
108 
109  if (ok && (log2Factor >= 0) && (log2Factor <= 6)) {
110  m_log2Factor = log2Factor;
111  } else {
112  qWarning() << "ParserBench::parse: repetilog2 factortion invalid. Defaulting to " << m_log2Factor;
113  }
114 }
115 
117 {
118  if (m_testStr == "decimatefi") {
119  return TestDecimatorsFI;
120  } else if (m_testStr == "decimateff") {
121  return TestDecimatorsFF;
122  } else if (m_testStr == "decimateif") {
123  return TestDecimatorsIF;
124  } else if (m_testStr == "decimateinfii") {
125  return TestDecimatorsInfII;
126  } else if (m_testStr == "decimatesupii") {
127  return TestDecimatorsSupII;
128  } else if (m_testStr == "ambe") {
129  return TestAMBE;
130  } else {
131  return TestDecimatorsII;
132  }
133 }
QCommandLineParser m_parser
Definition: parserbench.h:56
void parse(const QCoreApplication &app)
Definition: parserbench.cpp:61
uint32_t m_repetition
Definition: parserbench.h:53
QCommandLineOption m_log2FactorOption
Definition: parserbench.h:60
uint32_t m_log2Factor
Definition: parserbench.h:54
QCommandLineOption m_nbSamplesOption
Definition: parserbench.h:58
QCommandLineOption m_repetitionOption
Definition: parserbench.h:59
QCommandLineOption m_testOption
Definition: parserbench.h:57
TestType getTestType() const
uint32_t m_nbSamples
Definition: parserbench.h:52
QString m_testStr
Definition: parserbench.h:51