Use STD in testing suite (#2922)

* use std

* make gcc happy

---------

Co-authored-by: pfeatherstone <pfeatherstone@pf>
pull/2923/head
pfeatherstone 7 months ago committed by GitHub
parent 3d3bd7cee1
commit 405536051b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -34,10 +34,9 @@ int main (int argc, char** argv)
unsigned long num = 1; unsigned long num = 1;
// add the options for all the different tests // add the options for all the different tests
testers().reset(); for (auto& kv : testers())
while (testers().move_next())
{ {
tester& test = *testers().element().value(); tester& test = *kv.second;
parser.add_option(test.cmd_line_switch(), test.description(), test.num_of_args()); parser.add_option(test.cmd_line_switch(), test.description(), test.num_of_args());
if (test.num_of_args()==0) if (test.num_of_args()==0)
parser.add_option("no_"+test.cmd_line_switch(), "Don't run this option when using --runall."); parser.add_option("no_"+test.cmd_line_switch(), "Don't run this option when using --runall.");
@ -111,10 +110,9 @@ int main (int argc, char** argv)
dlog << LINFO << "************ Starting Test Run " << i+1 << " of " << num << ". ************"; dlog << LINFO << "************ Starting Test Run " << i+1 << " of " << num << ". ************";
// loop over all the testers and see if they are supposed to run // loop over all the testers and see if they are supposed to run
testers().reset(); for(auto& kv : testers())
while (testers().move_next())
{ {
tester& test= *testers().element().value(); tester& test= *kv.second;
const clp::option_type& opt = parser.option(test.cmd_line_switch()); const clp::option_type& opt = parser.option(test.cmd_line_switch());
// run the test for this option as many times as the user has requested. // run the test for this option as many times as the user has requested.
for (unsigned long j = 0; j < parser.option("runall").count() + opt.count(); ++j) for (unsigned long j = 0; j < parser.option("runall").count() + opt.count(); ++j)

@ -2,9 +2,10 @@
// License: Boost Software License See LICENSE.txt for the full license. // License: Boost Software License See LICENSE.txt for the full license.
#include <string> #include <string>
#include "tester.h"
#include <cstdlib> #include <cstdlib>
#include <dlib/threads.h> #include <atomic>
#include <mutex>
#include "tester.h"
namespace test namespace test
{ {
@ -14,25 +15,21 @@ namespace test
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static dlib::mutex spinner_mutex; static std::mutex spinner_mutex;
static dlib::mutex test_count_mutex; static std::atomic<uint64_t> test_count(0);
dlib::uint64 test_count = 0;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
dlib::uint64 number_of_testing_statements_executed ( std::uint64_t number_of_testing_statements_executed (
) )
{ {
dlib::auto_mutex lock(test_count_mutex);
return test_count; return test_count;
} }
void increment_test_count ( void increment_test_count (
) )
{ {
test_count_mutex.lock();
++test_count; ++test_count;
test_count_mutex.unlock();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -44,9 +41,7 @@ namespace test
const char* _exp_str const char* _exp_str
) )
{ {
test_count_mutex.lock();
++test_count; ++test_count;
test_count_mutex.unlock();
if ( !(_exp) ) if ( !(_exp) )
{ {
std::ostringstream dlib_o_out; std::ostringstream dlib_o_out;
@ -79,15 +74,13 @@ namespace test
num_of_args_(num_of_args_x) num_of_args_(num_of_args_x)
{ {
using namespace std; using namespace std;
if (testers().is_in_domain(switch_name)) if (testers().find(switch_name) != testers().end())
{ {
cerr << "ERROR: More than one tester has been defined with the switch '" << switch_name << "'." << endl; cerr << "ERROR: More than one tester has been defined with the switch '" << switch_name << "'." << endl;
exit(1); exit(1);
} }
string temp(switch_name); testers()[switch_name] = this;
tester* t = this;
testers().add(temp,t);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -152,7 +145,7 @@ namespace test
if (be_verbose) if (be_verbose)
{ {
using namespace std; using namespace std;
dlib::auto_mutex M(spinner_mutex); std::unique_lock<std::mutex> M(spinner_mutex);
static int i = 0; static int i = 0;
cout << "\b\b"; cout << "\b\b";
switch (i) switch (i)

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <dlib/map.h> #include <map>
#include <dlib/logger.h> #include <dlib/logger.h>
#include <dlib/assert.h> #include <dlib/assert.h>
#include <dlib/algs.h> #include <dlib/algs.h>
@ -33,7 +33,7 @@
namespace test namespace test
{ {
class tester; class tester;
typedef dlib::map<std::string,tester*>::kernel_1a_c map_of_testers; using map_of_testers = std::map<std::string,tester*>;
map_of_testers& testers ( map_of_testers& testers (
); );
@ -55,7 +55,7 @@ namespace test
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
dlib::uint64 number_of_testing_statements_executed ( std::uint64_t number_of_testing_statements_executed (
); );
/*! /*!
ensures ensures

Loading…
Cancel
Save