Test-Errortimer

Implements simple count down until error code is returned.  All exported functions are implemented inline.

Summary
Test-ErrortimerImplements simple count down until error code is returned.
CopyrightThis program is free software.
Files
C-kern/api/test/errortimer.hHeader file of Test-Errortimer.
Types
struct test_errortimer_tExport test_errortimer_t.
Functions
test
unittest_test_errortimerUnittest for test_errortimer_t.
test_errortimer_tHolds a timer value and an error code.
timercountThe number of times process_testerrortimer returns success.
errcodeThe error code which is returned by process_testerrortimer.
lifetime
test_errortimer_FREEStatic initializer.
init_testerrortimerInits errtimer with timercount and errcode.
free_testerrortimerSets errtimer to test_errortimer_FREE.
query
isenabled_testerrortimerReturns true if timer has not fired.
errcode_testerrortimerReturns the error code of the timer.
update
process_testerrortimerReturns error if timer has elapsed else 0.
ONERROR_testerrortimerNo op if KONFIG_UNITTEST is not defined.
PROCESS_testerrortimerThis function calls <process_testerrortimer>(errtimer) and returns its value.
SETONERROR_testerrortimerNo op if KONFIG_UNITTEST is not defined.
inline implementation
Macros
errcode_testerrortimerImplements test_errortimer_t.errcode_testerrortimer.
free_testerrortimerImplements test_errortimer_t.free_testerrortimer.
isenabled_testerrortimerImplements test_errortimer_t.isenabled_testerrortimer.
init_testerrortimerImplements test_errortimer_t.init_testerrortimer.
process_testerrortimerImplements test_errortimer_t.process_testerrortimer.
ONERROR_testerrortimerImplements test_errortimer_t.ONERROR_testerrortimer.
PROCESS_testerrortimerImplements test_errortimer_t.PROCESS_testerrortimer.
SETONERROR_testerrortimerImplements test_errortimer_t.SETONERROR_testerrortimer.

Copyright

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.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/test/errortimer.h

Header file of Test-Errortimer.

Types

struct test_errortimer_t

typedef struct test_errortimer_t test_errortimer_t

Export test_errortimer_t.

Functions

test

unittest_test_errortimer

int unittest_test_errortimer(void)

Unittest for test_errortimer_t.

test_errortimer_t

struct test_errortimer_t

Holds a timer value and an error code.  The function process_testerrortimer returns a stored error code if timercount has reached zero.

Summary
timercountThe number of times process_testerrortimer returns success.
errcodeThe error code which is returned by process_testerrortimer.
lifetime
test_errortimer_FREEStatic initializer.
init_testerrortimerInits errtimer with timercount and errcode.
free_testerrortimerSets errtimer to test_errortimer_FREE.
query
isenabled_testerrortimerReturns true if timer has not fired.
errcode_testerrortimerReturns the error code of the timer.
update
process_testerrortimerReturns error if timer has elapsed else 0.
ONERROR_testerrortimerNo op if KONFIG_UNITTEST is not defined.
PROCESS_testerrortimerThis function calls <process_testerrortimer>(errtimer) and returns its value.
SETONERROR_testerrortimerNo op if KONFIG_UNITTEST is not defined.

timercount

uint32_t timercount

The number of times process_testerrortimer returns success.

errcode

int errcode

The error code which is returned by process_testerrortimer.

lifetime

test_errortimer_FREE

#define test_errortimer_FREE { 0, 0 }

Static initializer.  Initializes timer disarmed.

init_testerrortimer

void init_testerrortimer(/*out*/test_errortimer_t *errtimer,
uint32_t timercount,
int errcode)

Inits errtimer with timercount and errcode.

Parameter

errtimerPointer to object of type test_errortimer_t which is initialized.
timercountThe number of times after process_testerrortimer returns an error.  A value of 0 disables the timer.
errcodeThe errorcode process_testerrortimer returns in timer has fired.

free_testerrortimer

void free_testerrortimer(test_errortimer_t *errtimer)

Sets errtimer to test_errortimer_FREE.

query

isenabled_testerrortimer

bool isenabled_testerrortimer(const test_errortimer_t *errtimer)

Returns true if timer has not fired.

errcode_testerrortimer

int errcode_testerrortimer(const test_errortimer_t *errtimer)

Returns the error code of the timer.  The returned value is the one set with init_testerrortimer independent if the timer is enabled or not.

update

process_testerrortimer

int process_testerrortimer(test_errortimer_t *errtimer)

Returns error if timer has elapsed else 0.  If test_errortimer_t.timercount is 0, nothing is done and 0 is returned.  Else timercount is decremented.  If timercount is zero after the decrement test_errortimer_t.errcode is returned else 0 is returned.

ONERROR_testerrortimer

void ONERROR_testerrortimer(test_errortimer_t *errtimer,
/*err*/int *err,
void **ONERROR_LABEL)

No op if KONFIG_UNITTEST is not defined.  This function calls <process_testerrortimer>(errtimer) and if it returns 0 it does nothing.  Else it sets the variable err to the returned code and jumps to ONERROR_LABEL.

PROCESS_testerrortimer

int PROCESS_testerrortimer(test_errortimer_t *errtimer)

This function calls <process_testerrortimer>(errtimer) and returns its value.  Returns always 0 if KONFIG_UNITTEST is not defined.

SETONERROR_testerrortimer

void SETONERROR_testerrortimer(test_errortimer_t *errtimer,
/*err*/int *err)

No op if KONFIG_UNITTEST is not defined.  This function calls <process_testerrortimer>(errtimer) and sets the variable err if the call returned an error else err is not changed.

Macros

errcode_testerrortimer

#define errcode_testerrortimer(errtimer) ((errtimer)->errcode)

Implements test_errortimer_t.errcode_testerrortimer.

free_testerrortimer

#define free_testerrortimer(
   errtimer
) ((void)(*(errtimer) = (test_errortimer_t) test_errortimer_FREE))

Implements test_errortimer_t.free_testerrortimer.

isenabled_testerrortimer

#define isenabled_testerrortimer(errtimer) ((errtimer)->timercount > 0)

Implements test_errortimer_t.isenabled_testerrortimer.

init_testerrortimer

#define init_testerrortimer(
   errtimer,
   timercount,
   errcode
) ((void) (*(errtimer) = (test_errortimer_t){ timercount, errcode }))

Implements test_errortimer_t.init_testerrortimer.

process_testerrortimer

#define process_testerrortimer(
   errtimer
) ( __extension__ ({ test_errortimer_t * _tm = (errtimer) ; int _err ; if ( _tm->timercount && ! (-- _tm->timercount)) { _err = _tm->errcode ; } else { _err = 0 ; } _err ; }))

Implements test_errortimer_t.process_testerrortimer.

ONERROR_testerrortimer

#define ONERROR_testerrortimer(
   errtimer,
   err,
   ONERROR_LABEL
) do { typeof(err) _eret = (err); int _err2; _err2 = process_testerrortimer(errtimer); if (_err2) { *_eret = _err2; goto ONERROR_LABEL; } } while(0)

Implements test_errortimer_t.ONERROR_testerrortimer.

PROCESS_testerrortimer

#define PROCESS_testerrortimer(errtimer) (process_testerrortimer(errtimer))

Implements test_errortimer_t.PROCESS_testerrortimer.

SETONERROR_testerrortimer

#define SETONERROR_testerrortimer(
   errtimer,
   err
) do { typeof(err) _eret = (err) ; int _err2 ; _err2 = process_testerrortimer(errtimer) ; if (_err2) *_eret = _err2 ; } while(0)

Implements test_errortimer_t.SETONERROR_testerrortimer.

Implements simple count down until error code is returned.
typedef struct test_errortimer_t test_errortimer_t
Export test_errortimer_t.
struct test_errortimer_t
Holds a timer value and an error code.
int unittest_test_errortimer(void)
Unittest for test_errortimer_t.
uint32_t timercount
The number of times process_testerrortimer returns success.
int process_testerrortimer(test_errortimer_t *errtimer)
Returns error if timer has elapsed else 0.
int errcode
The error code which is returned by process_testerrortimer.
#define test_errortimer_FREE { 0, 0 }
Static initializer.
void init_testerrortimer(/*out*/test_errortimer_t *errtimer,
uint32_t timercount,
int errcode)
Inits errtimer with timercount and errcode.
void free_testerrortimer(test_errortimer_t *errtimer)
Sets errtimer to test_errortimer_FREE.
bool isenabled_testerrortimer(const test_errortimer_t *errtimer)
Returns true if timer has not fired.
int errcode_testerrortimer(const test_errortimer_t *errtimer)
Returns the error code of the timer.
void ONERROR_testerrortimer(test_errortimer_t *errtimer,
/*err*/int *err,
void **ONERROR_LABEL)
No op if KONFIG_UNITTEST is not defined.
int PROCESS_testerrortimer(test_errortimer_t *errtimer)
This function calls <process_testerrortimer>(errtimer) and returns its value.
void SETONERROR_testerrortimer(test_errortimer_t *errtimer,
/*err*/int *err)
No op if KONFIG_UNITTEST is not defined.
#define errcode_testerrortimer(errtimer) ((errtimer)->errcode)
Implements test_errortimer_t.errcode_testerrortimer.
#define free_testerrortimer(
   errtimer
) ((void)(*(errtimer) = (test_errortimer_t) test_errortimer_FREE))
Implements test_errortimer_t.free_testerrortimer.
#define isenabled_testerrortimer(errtimer) ((errtimer)->timercount > 0)
Implements test_errortimer_t.isenabled_testerrortimer.
#define init_testerrortimer(
   errtimer,
   timercount,
   errcode
) ((void) (*(errtimer) = (test_errortimer_t){ timercount, errcode }))
Implements test_errortimer_t.init_testerrortimer.
#define process_testerrortimer(
   errtimer
) ( __extension__ ({ test_errortimer_t * _tm = (errtimer) ; int _err ; if ( _tm->timercount && ! (-- _tm->timercount)) { _err = _tm->errcode ; } else { _err = 0 ; } _err ; }))
Implements test_errortimer_t.process_testerrortimer.
#define ONERROR_testerrortimer(
   errtimer,
   err,
   ONERROR_LABEL
) do { typeof(err) _eret = (err); int _err2; _err2 = process_testerrortimer(errtimer); if (_err2) { *_eret = _err2; goto ONERROR_LABEL; } } while(0)
Implements test_errortimer_t.ONERROR_testerrortimer.
#define PROCESS_testerrortimer(errtimer) (process_testerrortimer(errtimer))
Implements test_errortimer_t.PROCESS_testerrortimer.
#define SETONERROR_testerrortimer(
   errtimer,
   err
) do { typeof(err) _eret = (err) ; int _err2 ; _err2 = process_testerrortimer(errtimer) ; if (_err2) *_eret = _err2 ; } while(0)
Implements test_errortimer_t.SETONERROR_testerrortimer.
Close