X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fmain.cc;h=0926dc6486568a35948b4060245fa60a53602372;hb=47f45992107361ad58c170bdf78fdc92523fab06;hp=dcbc50eb536879392b1bfa6ce9b1a373d299128e;hpb=450a9f280cd5d5b83da7561ff0362854f5c8b204;p=m6w6%2Flibmemcached diff --git a/libtest/main.cc b/libtest/main.cc index dcbc50eb..0926dc64 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -1,22 +1,37 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * - * libtest * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Data Differential YATL (i.e. libtest) library * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. + * Copyright (C) 2012 Data Differential, http://datadifferential.com/ * - * This library 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 - * Lesser General Public License for more details. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -25,14 +40,15 @@ #include #include #include +#include +#include +#include +#include +#include #include #include -#include #include #include -#include -#include -#include #include @@ -71,6 +87,44 @@ static long int timedif(struct timeval a, struct timeval b) return s + us; } +static test_return_t runner_code(Framework* frame, + test_st* run, + void* creators_ptr, + long int& load_time) +{ // Runner Code + + struct timeval start_time, end_time; + + gettimeofday(&start_time, NULL); + assert(frame->runner()); + assert(run->test_fn); + + test_return_t return_code; + try + { + return_code= frame->runner()->run(run->test_fn, creators_ptr); + } + // Special case where check for the testing of the exception + // system. + catch (libtest::fatal &e) + { + if (fatal::is_disabled()) + { + fatal::increment_disabled_counter(); + return_code= TEST_SUCCESS; + } + else + { + throw; + } + } + + gettimeofday(&end_time, NULL); + load_time= timedif(end_time, start_time); + + return return_code; +} + #include #include @@ -195,10 +249,12 @@ int main(int argc, char *argv[]) int exit_code; - try { - do { + try + { + do + { exit_code= EXIT_SUCCESS; - Framework world; + std::auto_ptr frame(new Framework); fatal_assert(sigignore(SIGPIPE) == 0); @@ -211,10 +267,10 @@ int main(int argc, char *argv[]) Stats stats; - get_world(&world); + get_world(frame.get()); test_return_t error; - void *creators_ptr= world.create(error); + void *creators_ptr= frame->create(error); switch (error) { @@ -253,11 +309,8 @@ int main(int argc, char *argv[]) wildcard= argv[2]; } - for (collection_st *next= world.collections; next and next->name and (not signal.is_shutdown()); next++) + for (collection_st *next= frame->collections; next and next->name and (not signal.is_shutdown()); next++) { - bool failed= false; - bool skipped= false; - if (collection_to_run.empty() == false and fnmatch(collection_to_run.c_str(), next->name, 0)) { continue; @@ -265,147 +318,111 @@ int main(int argc, char *argv[]) stats.collection_total++; - test_return_t collection_rc= world.startup(creators_ptr); - - if (collection_rc == TEST_SUCCESS and next->pre) - { - collection_rc= world.runner()->pre(next->pre, creators_ptr); - } - - switch (collection_rc) - { - case TEST_SUCCESS: - break; - - case TEST_FAILURE: - Out << next->name << " [ failed ]"; - failed= true; - signal.set_shutdown(SHUTDOWN_GRACEFUL); - goto cleanup; - - case TEST_SKIPPED: - Out << next->name << " [ skipping ]"; - skipped= true; - goto cleanup; - - default: - fatal_message("invalid return code"); - } - - Out << "Collection: " << next->name; - - for (test_st *run= next->tests; run->name; run++) + bool failed= false; + bool skipped= false; + test_return_t collection_rc; + if (test_success(collection_rc= frame->runner()->pre(next->pre, creators_ptr))) { - struct timeval start_time, end_time; - long int load_time= 0; + Out << "Collection: " << next->name; - if (wildcard && fnmatch(wildcard, run->name, 0)) + for (test_st *run= next->tests; run->name; run++) { - continue; - } + long int load_time= 0; + + if (wildcard && fnmatch(wildcard, run->name, 0)) + { + continue; + } - test_return_t return_code; - try { - if (test_success(return_code= world.item.startup(creators_ptr))) + test_return_t return_code; + try { - if (test_success(return_code= world.item.flush(creators_ptr, run))) + if (run->requires_flush) { - { // Runner Code - gettimeofday(&start_time, NULL); - assert(world.runner()); - assert(run->test_fn); - try - { - return_code= world.runner()->run(run->test_fn, creators_ptr); - } - // Special case where check for the testing of the exception - // system. - catch (libtest::fatal &e) - { - if (fatal::is_disabled()) - { - fatal::increment_disabled_counter(); - return_code= TEST_SUCCESS; - } - else - { - throw; - } - } - - gettimeofday(&end_time, NULL); - load_time= timedif(end_time, start_time); + if (test_failed(frame->runner()->flush(creators_ptr))) + { + Error << "frame->runner()->flush(creators_ptr)"; + continue; } } - else if (return_code == TEST_SKIPPED) + + return_code= runner_code(frame.get(), run, creators_ptr, load_time); + + if (return_code == TEST_SKIPPED) { } else if (return_code == TEST_FAILURE) { - Error << " item.flush(failure)"; +#if 0 + Error << " frame->runner()->run(failure)"; signal.set_shutdown(SHUTDOWN_GRACEFUL); +#endif } + } - else if (return_code == TEST_SKIPPED) - { } - else if (return_code == TEST_FAILURE) + catch (libtest::fatal &e) { - Error << " item.startup(failure)"; - signal.set_shutdown(SHUTDOWN_GRACEFUL); + Error << "Fatal exception was thrown: " << e.what(); + return_code= TEST_FAILURE; + throw; + } + catch (std::exception &e) + { + Error << "Exception was thrown: " << e.what(); + return_code= TEST_FAILURE; + throw; + } + catch (...) + { + Error << "Unknown exception occurred"; + return_code= TEST_FAILURE; + throw; } - } - - catch (libtest::fatal &e) - { - Error << "Fatal exception was thrown: " << e.what(); - return_code= TEST_FAILURE; - } - catch (std::exception &e) - { - Error << "Exception was thrown: " << e.what(); - return_code= TEST_FAILURE; - } - catch (...) - { - Error << "Unknown exception occurred"; - return_code= TEST_FAILURE; - } - stats.total++; + stats.total++; - switch (return_code) - { - case TEST_SUCCESS: - Out << "\tTesting " << run->name << "\t\t\t\t\t" << load_time / 1000 << "." << load_time % 1000 << "[ " << test_strerror(return_code) << " ]"; - stats.success++; - break; - - case TEST_FAILURE: - stats.failed++; - failed= true; - Out << "\tTesting " << run->name << "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]"; - break; - - case TEST_SKIPPED: - stats.skipped++; - skipped= true; - Out << "\tTesting " << run->name << "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]"; - break; - - default: - fatal_message("invalid return code"); + switch (return_code) + { + case TEST_SUCCESS: + Out << "\tTesting " << run->name << "\t\t\t\t\t" << load_time / 1000 << "." << load_time % 1000 << "[ " << test_strerror(return_code) << " ]"; + stats.success++; + break; + + case TEST_FAILURE: + stats.failed++; + failed= true; + Out << "\tTesting " << run->name << "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]"; + break; + + case TEST_SKIPPED: + stats.skipped++; + skipped= true; + Out << "\tTesting " << run->name << "\t\t\t\t\t" << "[ " << test_strerror(return_code) << " ]"; + break; + + default: + fatal_message("invalid return code"); + } +#if 0 + @TODO add code here to allow for a collection to define a method to reset to allow tests to continue. +#endif } - if (test_failed(world.on_error(return_code, creators_ptr))) - { - Error << "Failed while running on_error()"; - signal.set_shutdown(SHUTDOWN_GRACEFUL); - break; - } + (void) frame->runner()->post(next->post, creators_ptr); + } + else if (collection_rc == TEST_FAILURE) + { + Out << next->name << " [ failed ]"; + failed= true; +#if 0 + signal.set_shutdown(SHUTDOWN_GRACEFUL); +#endif + } + else if (collection_rc == TEST_SKIPPED) + { + Out << next->name << " [ skipping ]"; + skipped= true; } - (void) world.runner()->post(next->post, creators_ptr); - -cleanup: if (failed == false and skipped == false) { stats.collection_success++; @@ -421,11 +438,10 @@ cleanup: stats.collection_skipped++; } - world.shutdown(creators_ptr); Outn(); } - if (not signal.is_shutdown()) + if (signal.is_shutdown() == false) { signal.set_shutdown(SHUTDOWN_GRACEFUL); } @@ -445,7 +461,7 @@ cleanup: { Out << "Some tests were skipped."; } - else if (stats.collection_success and stats.collection_failed == 0) + else if (stats.collection_success and (stats.collection_failed == 0)) { Out << "All tests completed successfully."; }