Implements simple count down until error code is returned. All exported functions are implemented inline.
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.
© 2011 Jörg Seebohn
Header file of Test-Errortimer.
typedef struct test_errortimer_t test_errortimer_t
Export test_errortimer_t.
test | |
unittest_test_errortimer | Unittest for test_errortimer_t. |
int unittest_test_errortimer( void )
Unittest for 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.
timercount | The number of times process_testerrortimer returns success. |
errcode | The error code which is returned by process_testerrortimer. |
lifetime | |
test_errortimer_FREE | Static initializer. |
init_testerrortimer | Inits errtimer with timercount and errcode. |
free_testerrortimer | Sets errtimer to test_errortimer_FREE. |
query | |
isenabled_testerrortimer | Returns true if timer has not fired. |
errcode_testerrortimer | Returns the error code of the timer. |
update | |
process_testerrortimer | Returns error if timer has elapsed else 0. |
ONERROR_testerrortimer | No op if KONFIG_UNITTEST is not defined. |
PROCESS_testerrortimer | This function calls <process_testerrortimer>(errtimer) and returns its value. |
SETONERROR_testerrortimer | No op if KONFIG_UNITTEST is not defined. |
uint32_t timercount
The number of times process_testerrortimer returns success.
int errcode
The error code which is returned by process_testerrortimer.
void init_testerrortimer( /*out*/test_errortimer_t * errtimer, uint32_t timercount, int errcode )
Inits errtimer with timercount and errcode.
errtimer | Pointer to object of type test_errortimer_t which is initialized. |
timercount | The number of times after process_testerrortimer returns an error. A value of 0 disables the timer. |
errcode | The errorcode process_testerrortimer returns in timer has fired. |
void free_testerrortimer( test_errortimer_t * errtimer )
Sets errtimer to test_errortimer_FREE.
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.
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.
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.
#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.
Export test_errortimer_t.
typedef struct test_errortimer_t test_errortimer_t
Holds a timer value and an error code.
struct test_errortimer_t
Unittest for test_errortimer_t.
int unittest_test_errortimer( void )
The number of times process_testerrortimer returns success.
uint32_t timercount
Returns error if timer has elapsed else 0.
int process_testerrortimer( test_errortimer_t * errtimer )
The error code which is returned by process_testerrortimer.
int errcode
Static initializer.
#define test_errortimer_FREE { 0, 0 }
Inits errtimer with timercount and errcode.
void init_testerrortimer( /*out*/test_errortimer_t * errtimer, uint32_t timercount, int errcode )
Sets errtimer to test_errortimer_FREE.
void free_testerrortimer( test_errortimer_t * errtimer )
Returns true if timer has not fired.
bool isenabled_testerrortimer( const test_errortimer_t * errtimer )
Returns the error code of the timer.
int errcode_testerrortimer( const test_errortimer_t * errtimer )
No op if KONFIG_UNITTEST is not defined.
void ONERROR_testerrortimer( test_errortimer_t * errtimer, /*err*/int * err, void ** ONERROR_LABEL )
This function calls <process_testerrortimer>(errtimer) and returns its value.
int PROCESS_testerrortimer( test_errortimer_t * errtimer )
No op if KONFIG_UNITTEST is not defined.
void SETONERROR_testerrortimer( test_errortimer_t * errtimer, /*err*/int * err )
Implements test_errortimer_t.errcode_testerrortimer.
#define errcode_testerrortimer( errtimer ) ((errtimer)->errcode)
Implements test_errortimer_t.free_testerrortimer.
#define free_testerrortimer( errtimer ) ((void)(*(errtimer) = (test_errortimer_t) test_errortimer_FREE))
Implements test_errortimer_t.isenabled_testerrortimer.
#define isenabled_testerrortimer( errtimer ) ((errtimer)->timercount > 0)
Implements test_errortimer_t.init_testerrortimer.
#define init_testerrortimer( errtimer, timercount, errcode ) ((void) (*(errtimer) = (test_errortimer_t){ timercount, errcode }))
Implements test_errortimer_t.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.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.PROCESS_testerrortimer.
#define PROCESS_testerrortimer( errtimer ) (process_testerrortimer(errtimer))
Implements test_errortimer_t.SETONERROR_testerrortimer.
#define SETONERROR_testerrortimer( errtimer, err ) do { typeof(err) _eret = (err) ; int _err2 ; _err2 = process_testerrortimer(errtimer) ; if (_err2) *_eret = _err2 ; } while(0)