aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/minunit/minunit.h
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2023-01-02 21:52:03 +0100
committerGravatar Tim Segers <tsegers@pm.me>2023-01-07 15:24:51 +0100
commit2fcfc12ea05a8707910376f2e025506db0d89164 (patch)
tree5a099b04a6ea68f474cc192a75e0fac9df4ed5a6 /minunit/minunit.h
parentc26b175ba3afb2dc2a94bd129005b1a6f0acfe35 (diff)
downloadopendeco-2fcfc12ea05a8707910376f2e025506db0d89164.tar.gz
Replicate multi-file hack from bzgec/minunit
Diffstat (limited to 'minunit/minunit.h')
-rw-r--r--minunit/minunit.h175
1 files changed, 13 insertions, 162 deletions
diff --git a/minunit/minunit.h b/minunit/minunit.h
index b716888..608fddf 100644
--- a/minunit/minunit.h
+++ b/minunit/minunit.h
@@ -71,25 +71,25 @@
#define MINUNIT_EPSILON 1E-12
/* Misc. counters */
-static int minunit_run = 0;
-static int minunit_assert = 0;
-static int minunit_fail = 0;
-static int minunit_status = 0;
+extern int minunit_run;
+extern int minunit_assert;
+extern int minunit_fail;
+extern int minunit_status;
/* Timers */
-static double minunit_real_timer = 0;
-static double minunit_proc_timer = 0;
+extern double minunit_real_timer;
+extern double minunit_proc_timer;
/* Last message */
-static char minunit_last_message[MINUNIT_MESSAGE_LEN];
+extern char minunit_last_message[MINUNIT_MESSAGE_LEN];
/* Test setup and teardown function pointers */
-static void (*minunit_setup)(void) = NULL;
-static void (*minunit_teardown)(void) = NULL;
+extern void (*minunit_setup)(void);
+extern void (*minunit_teardown)(void);
/* Definitions */
-#define MU_TEST(method_name) static void method_name(void)
-#define MU_TEST_SUITE(suite_name) static void suite_name(void)
+#define MU_TEST(method_name) void method_name(void)
+#define MU_TEST_SUITE(suite_name) void suite_name(void)
#define MU__SAFE_BLOCK(block) do {\
block\
@@ -220,12 +220,6 @@ static void (*minunit_teardown)(void) = NULL;
}\
)
-/*
- * The following two functions were written by David Robert Nadeau
- * from http://NadeauSoftware.com/ and distributed under the
- * Creative Commons Attribution 3.0 Unported License
- */
-
/**
* Returns the real time, in seconds, or -1.0 if an error occurred.
*
@@ -233,156 +227,13 @@ static void (*minunit_teardown)(void) = NULL;
* The returned real time is only useful for computing an elapsed time
* between two calls to this function.
*/
-static double mu_timer_real(void)
-{
-#if defined(_WIN32)
- /* Windows 2000 and later. ---------------------------------- */
- LARGE_INTEGER Time;
- LARGE_INTEGER Frequency;
-
- QueryPerformanceFrequency(&Frequency);
- QueryPerformanceCounter(&Time);
-
- Time.QuadPart *= 1000000;
- Time.QuadPart /= Frequency.QuadPart;
-
- return (double)Time.QuadPart / 1000000.0;
-
-#elif (defined(__hpux) || defined(hpux)) || ((defined(__sun__) || defined(__sun) || defined(sun)) && (defined(__SVR4) || defined(__svr4__)))
- /* HP-UX, Solaris. ------------------------------------------ */
- return (double)gethrtime( ) / 1000000000.0;
-
-#elif defined(__MACH__) && defined(__APPLE__)
- /* OSX. ----------------------------------------------------- */
- static double timeConvert = 0.0;
- if ( timeConvert == 0.0 )
- {
- mach_timebase_info_data_t timeBase;
- (void)mach_timebase_info( &timeBase );
- timeConvert = (double)timeBase.numer /
- (double)timeBase.denom /
- 1000000000.0;
- }
- return (double)mach_absolute_time( ) * timeConvert;
-
-#elif defined(_POSIX_VERSION)
- /* POSIX. --------------------------------------------------- */
- struct timeval tm;
-#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
- {
- struct timespec ts;
-#if defined(CLOCK_MONOTONIC_PRECISE)
- /* BSD. --------------------------------------------- */
- const clockid_t id = CLOCK_MONOTONIC_PRECISE;
-#elif defined(CLOCK_MONOTONIC_RAW)
- /* Linux. ------------------------------------------- */
- const clockid_t id = CLOCK_MONOTONIC_RAW;
-#elif defined(CLOCK_HIGHRES)
- /* Solaris. ----------------------------------------- */
- const clockid_t id = CLOCK_HIGHRES;
-#elif defined(CLOCK_MONOTONIC)
- /* AIX, BSD, Linux, POSIX, Solaris. ----------------- */
- const clockid_t id = CLOCK_MONOTONIC;
-#elif defined(CLOCK_REALTIME)
- /* AIX, BSD, HP-UX, Linux, POSIX. ------------------- */
- const clockid_t id = CLOCK_REALTIME;
-#else
- const clockid_t id = (clockid_t)-1; /* Unknown. */
-#endif /* CLOCK_* */
- if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 )
- return (double)ts.tv_sec +
- (double)ts.tv_nsec / 1000000000.0;
- /* Fall thru. */
- }
-#endif /* _POSIX_TIMERS */
-
- /* AIX, BSD, Cygwin, HP-UX, Linux, OSX, POSIX, Solaris. ----- */
- gettimeofday( &tm, NULL );
- return (double)tm.tv_sec + (double)tm.tv_usec / 1000000.0;
-#else
- return -1.0; /* Failed. */
-#endif
-}
+double mu_timer_real(void);
/**
* Returns the amount of CPU time used by the current process,
* in seconds, or -1.0 if an error occurred.
*/
-static double mu_timer_cpu(void)
-{
-#if defined(_WIN32)
- /* Windows -------------------------------------------------- */
- FILETIME createTime;
- FILETIME exitTime;
- FILETIME kernelTime;
- FILETIME userTime;
-
- /* This approach has a resolution of 1/64 second. Unfortunately, Windows' API does not offer better */
- if ( GetProcessTimes( GetCurrentProcess( ),
- &createTime, &exitTime, &kernelTime, &userTime ) != 0 )
- {
- ULARGE_INTEGER userSystemTime;
- memcpy(&userSystemTime, &userTime, sizeof(ULARGE_INTEGER));
- return (double)userSystemTime.QuadPart / 10000000.0;
- }
-
-#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
- /* AIX, BSD, Cygwin, HP-UX, Linux, OSX, and Solaris --------- */
-
-#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
- /* Prefer high-res POSIX timers, when available. */
- {
- clockid_t id;
- struct timespec ts;
-#if _POSIX_CPUTIME > 0
- /* Clock ids vary by OS. Query the id, if possible. */
- if ( clock_getcpuclockid( 0, &id ) == -1 )
-#endif
-#if defined(CLOCK_PROCESS_CPUTIME_ID)
- /* Use known clock id for AIX, Linux, or Solaris. */
- id = CLOCK_PROCESS_CPUTIME_ID;
-#elif defined(CLOCK_VIRTUAL)
- /* Use known clock id for BSD or HP-UX. */
- id = CLOCK_VIRTUAL;
-#else
- id = (clockid_t)-1;
-#endif
- if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 )
- return (double)ts.tv_sec +
- (double)ts.tv_nsec / 1000000000.0;
- }
-#endif
-
-#if defined(RUSAGE_SELF)
- {
- struct rusage rusage;
- if ( getrusage( RUSAGE_SELF, &rusage ) != -1 )
- return (double)rusage.ru_utime.tv_sec +
- (double)rusage.ru_utime.tv_usec / 1000000.0;
- }
-#endif
-
-#if defined(_SC_CLK_TCK)
- {
- const double ticks = (double)sysconf( _SC_CLK_TCK );
- struct tms tms;
- if ( times( &tms ) != (clock_t)-1 )
- return (double)tms.tms_utime / ticks;
- }
-#endif
-
-#if defined(CLOCKS_PER_SEC)
- {
- clock_t cl = clock( );
- if ( cl != (clock_t)-1 )
- return (double)cl / (double)CLOCKS_PER_SEC;
- }
-#endif
-
-#endif
-
- return -1; /* Failed. */
-}
+double mu_timer_cpu(void);
#ifdef __cplusplus
}