2010-02-08 17:23:39 +01:00
|
|
|
/* Copyright (c) 2010 Wildfire Games
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2010-02-08 17:23:39 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* helpers for built-in self tests
|
2006-04-24 01:14:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
2006-12-17 01:49:09 +01:00
|
|
|
#if 0
|
2006-06-08 21:03:43 +02:00
|
|
|
|
2010-03-01 15:52:58 +01:00
|
|
|
#include "lib/self_test.h"
|
|
|
|
#include "lib/timer.h"
|
2007-01-01 22:55:38 +01:00
|
|
|
|
2008-09-27 12:05:11 +02:00
|
|
|
// checked by debug_OnAssertionFailure; disables asserts if true (see above).
|
2006-04-24 01:14:18 +02:00
|
|
|
// 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()
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_printf(L"SELF TESTS:\n");
|
2008-01-07 21:03:19 +01:00
|
|
|
const double t0 = timer_Time();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
const double dt = timer_Time() - t0;
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_printf(L"-- done (elapsed time %.0f ms)\n", dt*1e3);
|
2006-06-08 21:03:43 +02:00
|
|
|
}
|
|
|
|
|
2006-12-17 01:49:09 +01:00
|
|
|
#endif
|