| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:47:17 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QCommandLineOption>
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:41:55 +00:00
										 |  |  | #include <QRegularExpressionValidator>
 | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "parserbench.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ParserBench::ParserBench() : | 
					
						
							|  |  |  |     m_testOption(QStringList() << "t" << "test", | 
					
						
							| 
									
										
										
										
											2021-04-17 18:14:15 +02:00
										 |  |  |         "Test type: decimateii, decimatefi, decimateff, decimateif, decimateinfii, decimatesupii, ambe, golay2312", | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  |         "test", | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  |         "decimateii"), | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  |     m_nbSamplesOption(QStringList() << "n" << "nb-samples", | 
					
						
							|  |  |  |         "Number of sample to deal with.", | 
					
						
							|  |  |  |         "samples", | 
					
						
							|  |  |  |         "1048576"), | 
					
						
							|  |  |  |     m_repetitionOption(QStringList() << "r" << "repeat", | 
					
						
							|  |  |  |         "Number of repetitions.", | 
					
						
							|  |  |  |         "repetition", | 
					
						
							|  |  |  |         "1"), | 
					
						
							|  |  |  |     m_log2FactorOption(QStringList() << "l" << "log2-factor", | 
					
						
							|  |  |  |         "Log2 factor for rate conversion.", | 
					
						
							|  |  |  |         "log2", | 
					
						
							|  |  |  |         "2") | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  |     m_testStr = "decimateii"; | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  |     m_nbSamples = 1048576; | 
					
						
							|  |  |  |     m_repetition = 1; | 
					
						
							|  |  |  |     m_log2Factor = 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_parser.setApplicationDescription("Software Defined Radio application benchmarks"); | 
					
						
							|  |  |  |     m_parser.addHelpOption(); | 
					
						
							|  |  |  |     m_parser.addVersionOption(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_parser.addOption(m_testOption); | 
					
						
							|  |  |  |     m_parser.addOption(m_nbSamplesOption); | 
					
						
							|  |  |  |     m_parser.addOption(m_repetitionOption); | 
					
						
							|  |  |  |     m_parser.addOption(m_log2FactorOption); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ParserBench::~ParserBench() | 
					
						
							|  |  |  | { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ParserBench::parse(const QCoreApplication& app) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_parser.process(app); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int pos; | 
					
						
							|  |  |  |     bool ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // test switch
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString test = m_parser.value(m_testOption); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-17 18:14:15 +02:00
										 |  |  |     QString testStr = "([a-z0-9]+)"; | 
					
						
							| 
									
										
										
										
											2022-11-17 14:41:55 +00:00
										 |  |  |     QRegularExpression ipRegex ("^" + testStr + "$"); | 
					
						
							|  |  |  |     QRegularExpressionValidator ipValidator(ipRegex); | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (ipValidator.validate(test, pos) == QValidator::Acceptable) { | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  |         m_testStr = test; | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  |         qWarning() << "ParserBench::parse: test string invalid. Defaulting to " << m_testStr; | 
					
						
							| 
									
										
										
										
											2018-04-23 16:43:18 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // number of samples
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString nbSamplesStr = m_parser.value(m_nbSamplesOption); | 
					
						
							|  |  |  |     int nbSamples = nbSamplesStr.toInt(&ok); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ok && (nbSamples > 1024) && (nbSamples < 1073741824)) { | 
					
						
							|  |  |  |         m_nbSamples = nbSamples; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         qWarning() << "ParserBench::parse: number of samples invalid. Defaulting to " << m_nbSamples; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // repetition
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString repetitionStr = m_parser.value(m_repetitionOption); | 
					
						
							|  |  |  |     int repetition = repetitionStr.toInt(&ok); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ok && (repetition >= 0)) { | 
					
						
							|  |  |  |         m_repetition = repetition; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         qWarning() << "ParserBench::parse: repetition invalid. Defaulting to " << m_repetition; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // log2 factor
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString log2FactorStr = m_parser.value(m_log2FactorOption); | 
					
						
							|  |  |  |     int log2Factor = log2FactorStr.toInt(&ok); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ok && (log2Factor >= 0) && (log2Factor <= 6)) { | 
					
						
							|  |  |  |         m_log2Factor = log2Factor; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         qWarning() << "ParserBench::parse: repetilog2 factortion invalid. Defaulting to " << m_log2Factor; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ParserBench::TestType ParserBench::getTestType() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_testStr == "decimatefi") { | 
					
						
							|  |  |  |         return TestDecimatorsFI; | 
					
						
							| 
									
										
										
										
											2018-04-25 18:01:01 +02:00
										 |  |  |     } else if (m_testStr == "decimateff") { | 
					
						
							|  |  |  |         return TestDecimatorsFF; | 
					
						
							| 
									
										
										
										
											2018-05-09 21:50:41 +02:00
										 |  |  |     } else if (m_testStr == "decimateif") { | 
					
						
							| 
									
										
										
										
											2018-05-01 19:49:47 +02:00
										 |  |  |         return TestDecimatorsIF; | 
					
						
							| 
									
										
										
										
											2018-05-09 21:50:41 +02:00
										 |  |  |     } else if (m_testStr == "decimateinfii") { | 
					
						
							|  |  |  |         return TestDecimatorsInfII; | 
					
						
							|  |  |  |     } else if (m_testStr == "decimatesupii") { | 
					
						
							|  |  |  |         return TestDecimatorsSupII; | 
					
						
							| 
									
										
										
										
											2021-04-17 18:14:15 +02:00
										 |  |  |     } else if (m_testStr == "golay2312") { | 
					
						
							|  |  |  |         return TestGolay2312; | 
					
						
							| 
									
										
										
										
											2018-04-25 01:44:54 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         return TestDecimatorsII; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |