forked from 0ad/0ad
janwas
1c1200a049
- add translators from errno and GetLastError to LibError - clarified return values of callbacks (they must return INFO_CB_CONTINUE to continue) - this exposed a few bugs in error handling chains (returning incorrect values); also reduced say-nothing instances of return -1. - move CHECK_ERR etc. macros to lib_error This was SVN commit r3229.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
// helpers for built-in self tests
|
|
//
|
|
// Copyright (c) 2005 Jan Wassenberg
|
|
//
|
|
// 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; either version 2 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// 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 for more details.
|
|
//
|
|
// Contact info:
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
#include "precompiled.h"
|
|
|
|
#include "self_test.h"
|
|
#include "timer.h"
|
|
|
|
// checked by debug_assert_failed; disables asserts if true (see above).
|
|
// set/cleared by self_test_run.
|
|
bool self_test_active = false;
|
|
|
|
// trampoline that sets self_test_active and returns a dummy value;
|
|
// used by SELF_TEST_RUN.
|
|
int self_test_run(void (*func)())
|
|
{
|
|
self_test_active = true;
|
|
func();
|
|
self_test_active = false;
|
|
return 0; // assigned to dummy at file scope
|
|
}
|
|
|
|
|
|
static const SelfTestRecord* registered_tests;
|
|
|
|
int self_test_register(SelfTestRecord* r)
|
|
{
|
|
// SELF_TEST_REGISTER has already initialized r->func.
|
|
r->next = registered_tests;
|
|
registered_tests = r;
|
|
return 0; // assigned to dummy at file scope
|
|
}
|
|
|
|
|
|
void self_test_run_all()
|
|
{
|
|
debug_printf("SELF TESTS:\n");
|
|
const double t0 = get_time();
|
|
|
|
// someone somewhere may want to run self-tests twice (e.g. to help
|
|
// track down memory corruption), so don't destroy the list while
|
|
// iterating over it.
|
|
const SelfTestRecord* r = registered_tests;
|
|
while(r)
|
|
{
|
|
self_test_run(r->func);
|
|
r = r->next;
|
|
}
|
|
|
|
const double dt = get_time() - t0;
|
|
debug_printf("-- done (elapsed time %.0f ms)\n", dt*1e3);
|
|
} |