mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-23 01:21:42 +08:00
Prove buffer lemmas (#124)
* Prove buffer lemmas * Update queue proofs to latest kernel source All changes were syntactic due to uncrustify code-formatting * Strengthen prvCopyDataToQueue proof * Add extract script for diff comparison Co-authored-by: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com>
This commit is contained in:
FreeRTOS/Test/VeriFast
MakefileREADME.md
include/proof
queue
README.mdcreate.cprvCopyDataFromQueue.cprvCopyDataToQueue.cprvIsQueueEmpty.cprvIsQueueFull.cprvLockQueue.cprvUnlockQueue.cuxQueueMessagesWaiting.cuxQueueSpacesAvailable.cvQueueDelete.cxQueueGenericSend.cxQueueGenericSendFromISR.cxQueueIsQueueEmptyFromISR.cxQueueIsQueueFullFromISR.cxQueuePeek.cxQueuePeekFromISR.cxQueueReceive.cxQueueReceiveFromISR.c
scripts
@ -18,35 +18,35 @@ all: queue
|
||||
|
||||
.PHONY: queue
|
||||
queue:
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/create.c | $(call check_coverage,269)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvCopyDataFromQueue.c | $(call check_coverage,253)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/prvCopyDataToQueue.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueEmpty.c | $(call check_coverage,234)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueFull.c | $(call check_coverage,234)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvLockQueue.c | $(call check_coverage,235)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvUnlockQueue.c | $(call check_coverage,249)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueMessagesWaiting.c | $(call check_coverage,237)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueSpacesAvailable.c | $(call check_coverage,235)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/vQueueDelete.c | $(call check_coverage,232)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueGenericSend.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueGenericSendFromISR.c | $(call check_coverage,262)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueEmptyFromISR.c | $(call check_coverage,232)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueFullFromISR.c | $(call check_coverage,232)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeek.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeekFromISR.c | $(call check_coverage,245)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueReceive.c | $(call check_coverage,282)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueReceiveFromISR.c | $(call check_coverage,259)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/create.c | $(call check_coverage,317)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvCopyDataFromQueue.c | $(call check_coverage,301)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/prvCopyDataToQueue.c | $(call check_coverage,329)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueEmpty.c | $(call check_coverage,282)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueFull.c | $(call check_coverage,282)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvLockQueue.c | $(call check_coverage,283)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/prvUnlockQueue.c | $(call check_coverage,297)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueMessagesWaiting.c | $(call check_coverage,285)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueSpacesAvailable.c | $(call check_coverage,283)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/vQueueDelete.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueGenericSend.c | $(call check_coverage,328)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueGenericSendFromISR.c | $(call check_coverage,310)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueEmptyFromISR.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueFullFromISR.c | $(call check_coverage,280)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeek.c | $(call check_coverage,328)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeekFromISR.c | $(call check_coverage,293)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueReceive.c | $(call check_coverage,330)
|
||||
@$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueReceiveFromISR.c | $(call check_coverage,307)
|
||||
|
||||
.PHONY: proof_changes
|
||||
proof_changes:
|
||||
@git grep "if[n]*def VERIFAST" -- '*.c' | cut -f 3- -d ' ' | sort | uniq
|
||||
@git grep "if[n]*def VERIFAST" | cut -f 3- -d ' ' | sort | uniq
|
||||
|
||||
GIT?=git
|
||||
NO_CHANGE_CHECKOUT_DIR=no-change-check-freertos-kernel
|
||||
NO_CHANGE_EXPECTED_HASH=4a61f9ff7e2
|
||||
NO_CHANGE_EXPECTED_HASH=587a83d6476
|
||||
.PHONY: synced_with_source_check
|
||||
synced_with_source_check:
|
||||
@rm -rf $(NO_CHANGE_CHECKOUT_DIR)
|
||||
@$(GIT) clone --shallow-since="30-06-2020" https://github.com/FreeRTOS/FreeRTOS-Kernel.git $(NO_CHANGE_CHECKOUT_DIR)
|
||||
@$(GIT) clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git $(NO_CHANGE_CHECKOUT_DIR)
|
||||
@cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH) queue.c
|
||||
@cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH) include/queue.h
|
||||
|
@ -49,7 +49,7 @@ and uncheck `Check arithmetic overflow`).
|
||||
- `queue/xQueueReceiveFromISR.c`
|
||||
|
||||
A successful proof results in the top banner turning green with a statement
|
||||
similar to: `0 errors found (286 statements verified)`.
|
||||
similar to: `0 errors found (328 statements verified)`.
|
||||
|
||||
## Proof checking a single proof at the command-line
|
||||
|
||||
@ -65,7 +65,7 @@ A successful proof results in output similar to:
|
||||
|
||||
```
|
||||
queue/xQueueGenericSend.c
|
||||
0 errors found (286 statements verified)
|
||||
0 errors found (328 statements verified)
|
||||
```
|
||||
|
||||
## Running proof regression
|
||||
@ -87,7 +87,7 @@ $ VERIFAST=/path/to/verifast NO_COVERAGE=1 make
|
||||
## Annotation burden
|
||||
|
||||
VeriFast can emit statistics about the number of source code lines and
|
||||
annotations.
|
||||
annotations. These range from .3-2x annotations per line of source code.
|
||||
|
||||
```
|
||||
$ VERIFAST=/path/to/verifast ./scripts/annotation_overhead.sh
|
||||
|
@ -328,6 +328,22 @@ lemma void remove_remove_nth<t>(list<t> xs, t x)
|
||||
}
|
||||
}
|
||||
|
||||
/* Following lemma from `verifast/bin/rt/_list.java`. Renamed to
|
||||
avoid clash with listex.c's nth_drop lemma. */
|
||||
lemma void nth_drop2<t>(list<t> vs, int i)
|
||||
requires 0 <= i && i < length(vs);
|
||||
ensures nth(i, vs) == head(drop(i, vs));
|
||||
{
|
||||
switch (vs) {
|
||||
case nil:
|
||||
case cons(v, vs0):
|
||||
if (i == 0) {
|
||||
} else {
|
||||
nth_drop2(vs0, i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lemma void enq_lemma<t>(int k, int i, list<t> xs, list<t> ys, t z)
|
||||
requires 0 <= k && 0 <= i && 0 < length(xs) && k < length(xs) && i < length(xs) && take(k, rotate_left(i, xs)) == ys;
|
||||
ensures take(k+1, rotate_left(i, update((i+k)%length(xs), z, xs))) == append(ys, cons(z, nil));
|
||||
|
@ -64,9 +64,9 @@ typedef ssize_t BaseType_t;
|
||||
#define pvPortMalloc malloc
|
||||
#define vPortFree free
|
||||
|
||||
#define queueSEND_TO_BACK 0
|
||||
#define queueSEND_TO_FRONT 1
|
||||
#define queueOVERWRITE 2
|
||||
#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
|
||||
#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
|
||||
#define queueOVERWRITE ( ( BaseType_t ) 2 )
|
||||
|
||||
#define pdTRUE 1
|
||||
#define pdFALSE 0
|
||||
@ -76,6 +76,7 @@ typedef ssize_t BaseType_t;
|
||||
#define errQUEUE_FULL 0
|
||||
#define errQUEUE_EMPTY 0
|
||||
|
||||
/* Constants used with the cRxLock and cTxLock structure members. */
|
||||
#define queueUNLOCKED ( ( int8_t ) -1 )
|
||||
#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 )
|
||||
#define queueINT8_MAX ( ( int8_t ) 127 )
|
||||
@ -110,7 +111,8 @@ typedef struct xLIST {
|
||||
#endif
|
||||
} List_t;
|
||||
|
||||
typedef struct QueueDefinition /* The old naming convention is used to prevent breaking kernel aware debuggers. */ {
|
||||
typedef struct QueueDefinition /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
int8_t * pcHead; /*< Points to the beginning of the queue storage area. */
|
||||
int8_t * pcWriteTo; /*< Points to the free next place in the storage area. */
|
||||
|
||||
@ -134,6 +136,19 @@ typedef struct QueueDefinition /* The old naming convention is used to prevent
|
||||
volatile int8_t cRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
|
||||
volatile int8_t cTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
|
||||
|
||||
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
|
||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the memory used by the queue was statically allocated to ensure no attempt is made to free the memory. */
|
||||
#endif
|
||||
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
struct QueueDefinition * pxQueueSetContainer;
|
||||
#endif
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxQueueNumber;
|
||||
uint8_t ucQueueType;
|
||||
#endif
|
||||
|
||||
/*@struct mutex *irqMask;@*/ /*< Ghost mutex simulates the effect of irq masking */
|
||||
/*@struct mutex *schedulerSuspend;@*/ /*< Ghost mutex simulates the effect of scheduler suspension */
|
||||
/*@struct mutex *locked;@*/ /*< Ghost mutex simulates the effect of queue locking */
|
||||
@ -185,32 +200,132 @@ predicate queue(QueueHandle_t q, int8_t *Storage, size_t N, size_t M, size_t W,
|
||||
malloc_block(Storage, N*M) &*&
|
||||
true
|
||||
;
|
||||
@*/
|
||||
|
||||
/* A buffer allows us to interpret a flat character array of `N*M` bytes as a
|
||||
list of `N` elements where each element is `M` bytes */
|
||||
/*@
|
||||
predicate buffer(char *buffer, size_t N, size_t M; list<list<char> > elements) =
|
||||
N == 0
|
||||
? elements == nil
|
||||
: chars(buffer, M, ?x) &*& buffer(buffer + M, N - 1, M, ?xs) &*& elements == cons(x, xs);
|
||||
|
||||
// TODO: buffer_from_chars proof
|
||||
lemma void buffer_from_chars(char *buffer, size_t N, size_t M);
|
||||
requires chars(buffer, N*M, _);
|
||||
ensures exists<list<list<char> > >(?elements) &*& buffer(buffer, N, M, elements) &*& length(elements) == N;
|
||||
lemma void buffer_length(char *buffer, size_t N, size_t M)
|
||||
requires buffer(buffer, N, M, ?elements);
|
||||
ensures buffer(buffer, N, M, elements) &*& length(elements) == N;
|
||||
{
|
||||
if (N == 0) {
|
||||
open buffer(buffer, N, M, elements);
|
||||
close buffer(buffer, N, M, elements);
|
||||
} else {
|
||||
open buffer(buffer, N, M, elements);
|
||||
buffer_length(buffer+M, N-1, M);
|
||||
}
|
||||
}
|
||||
@*/
|
||||
|
||||
// TODO: split_element proof
|
||||
lemma void split_element<t>(char *buffer, size_t N, size_t M, size_t i);
|
||||
requires buffer(buffer, N, M, ?elements) &*& i < N;
|
||||
/*
|
||||
There is no need in the queue proofs to preserve a relationship between `cs`
|
||||
and `elements` (i.e., `flatten(elements) == cs`) because we only move in one
|
||||
direction from `cs` to `elements` during queue creation when the contents is
|
||||
fresh from `malloc` (i.e., uninitialized). If we needed to do a roundtrip from
|
||||
elements back to cs then this would require a stronger lemma.
|
||||
*/
|
||||
/*@
|
||||
lemma void buffer_from_chars(char *buffer, size_t N, size_t M)
|
||||
requires chars(buffer, N*M, ?cs) &*& 0 <= N &*& 0 < M;
|
||||
ensures exists<list<list<char> > >(?elements) &*& buffer(buffer, N, M, elements) &*& length(elements) == N;
|
||||
{
|
||||
if (N == 0) {
|
||||
close exists(nil);
|
||||
} else {
|
||||
int i = 0;
|
||||
while (i < N)
|
||||
invariant 0 <= i &*& i <= N &*&
|
||||
chars(buffer, (N-i)*M, ?xs) &*& xs == take((N-i)*M, cs) &*&
|
||||
buffer(buffer + (N-i)*M, i, M, ?ys);
|
||||
decreases N-i;
|
||||
{
|
||||
mul_mono_l(0, N-i-1, M);
|
||||
chars_split(buffer, (N-i-1)*M);
|
||||
mul_mono_l(i, N, M);
|
||||
mul_mono_l(N-i, N, M);
|
||||
take_take((N-i-1)*M, (N-i)*M, cs);
|
||||
i++;
|
||||
}
|
||||
close exists(ys);
|
||||
buffer_length(buffer, N, M);
|
||||
}
|
||||
}
|
||||
|
||||
lemma void append_buffer(char *buffer, size_t N1, size_t N2, size_t M)
|
||||
requires
|
||||
buffer(buffer, N1, M, ?elements1) &*&
|
||||
buffer(buffer + N1 * M, N2, M, ?elements2) &*&
|
||||
0 <= N1 &*& 0 <= N2;
|
||||
ensures buffer(buffer, N1+N2, M, append(elements1, elements2));
|
||||
{
|
||||
if (N1 == 0) {
|
||||
open buffer(buffer, 0, M, _);
|
||||
} else if (N2 == 0) {
|
||||
open buffer(buffer + N1 * M, 0, M, _);
|
||||
} else {
|
||||
open buffer(buffer, N1, M, elements1);
|
||||
append_buffer(buffer + M, N1-1, N2, M);
|
||||
close buffer(buffer, N1+N2, M, cons(?x, append(xs, elements2)));
|
||||
}
|
||||
}
|
||||
|
||||
lemma void split_element<t>(char *buffer, size_t N, size_t M, size_t i)
|
||||
requires buffer(buffer, N, M, ?elements) &*& 0 <= i &*& i < N;
|
||||
ensures
|
||||
buffer(buffer, i, M, take(i, elements)) &*&
|
||||
chars(buffer + i * M, M, nth(i, elements)) &*&
|
||||
buffer(buffer + (i + 1) * M, (N-1-i), M, drop(i+1, elements));
|
||||
{
|
||||
if (i == 0) {
|
||||
// straightforward
|
||||
} else {
|
||||
buffer_length(buffer, N, M);
|
||||
int j = 0;
|
||||
while (j < i)
|
||||
invariant 0 <= j &*& j <= i &*&
|
||||
buffer(buffer, j, M, take(j, elements)) &*&
|
||||
buffer(buffer + j * M, N-j, M, drop(j, elements));
|
||||
decreases i-j;
|
||||
{
|
||||
drop_drop(1, j, elements);
|
||||
nth_drop2(elements, j);
|
||||
open buffer(buffer + j * M, N-j, M, drop(j, elements));
|
||||
assert chars(buffer + j * M, M, ?x) &*& x == nth(j, elements);
|
||||
close buffer(buffer + j * M, 1, M, singleton(x));
|
||||
append_buffer(buffer, j, 1, M);
|
||||
take_plus_one(j, elements);
|
||||
j++;
|
||||
}
|
||||
drop_drop(1, j, elements);
|
||||
nth_drop2(elements, i);
|
||||
open buffer(buffer + (i+1) * M, (N-1-i), M, _);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: join_element proof
|
||||
lemma void join_element(char *buffer, size_t N, size_t M, size_t i);
|
||||
lemma void join_element(char *buffer, size_t N, size_t M, size_t i)
|
||||
requires
|
||||
0 <= i &*& i < N &*&
|
||||
buffer(buffer, i, M, ?prefix) &*&
|
||||
chars(buffer + i * M, M, ?element) &*&
|
||||
buffer(buffer + (i + 1) * M, (N-1-i), M, ?suffix);
|
||||
ensures buffer(buffer, N, M, append(prefix, cons(element, suffix)));
|
||||
{
|
||||
if (i == 0) {
|
||||
open buffer(buffer, i, M, prefix);
|
||||
assert prefix == nil;
|
||||
close buffer(buffer, N, M, cons(element, suffix));
|
||||
} else {
|
||||
close buffer(buffer + i * M, N-i, M, cons(element, suffix));
|
||||
append_buffer(buffer, i, N-i, M);
|
||||
}
|
||||
}
|
||||
|
||||
predicate list(List_t *l;) =
|
||||
l->uxNumberOfItems |-> _;
|
||||
|
@ -2,24 +2,27 @@
|
||||
|
||||
In the queue predicates and proofs we use the following variable names.
|
||||
|
||||
- `N` : the queue length (i.e., the maximum number of items the queue can
|
||||
store)
|
||||
- `M` : the size in bytes of each element
|
||||
- `W` : the logical index of the write pointer, necessarily between `0..(N-1)`
|
||||
- `R` : the logical index of the read pointer, necessarily between `0..(N-1)`
|
||||
- `K` : the number of items currently in the queue
|
||||
|
||||
Consequently, the size of the concrete queue storage is `N*M` bytes. The
|
||||
`buffer` predicate, defined in `include/proof/queue.h` allows us to treat the
|
||||
queue storage as a list `contents` of `N` items, each of which is `M` bytes.
|
||||
- `Storage` : The concrete queue storage of `N*M` bytes. The `buffer`
|
||||
predicate, defined in `include/proof/queue.h` allows us to treat the
|
||||
storage as a list `contents` of `N` items, each of which is `M` bytes.
|
||||
- `N` : queue length (i.e., the maximum number of items the queue can store)
|
||||
- `M` : size in bytes of each element
|
||||
- `W` : logical index of the write pointer, necessarily between
|
||||
`0..(N-1)` such that the write pointer `pcWriteTo == Storage + W * M`.
|
||||
- `R` : logical index of the read pointer, necessarily between
|
||||
`0..(N-1)` such that the read pointer `pcReadFrom == Storage + R * M`.
|
||||
- `K` : number of items currently in the queue corresponding to
|
||||
`uxMessagesWaiting`
|
||||
|
||||
The `queue` predicate, defined in `include/proof/queue.h`, relates the concrete
|
||||
representation to an abstract list `abs` of `K` items. More precisely, the main
|
||||
queue storage to an abstract list `abs` of `K` items. More precisely, the key
|
||||
queue invariant is:
|
||||
|
||||
```
|
||||
abs == take(K, rotate_left((R+1)%N, contents))
|
||||
abs == take(K, rotate_left((R+1)%N, contents)) &*&
|
||||
W == (R + 1 + K) % N
|
||||
```
|
||||
|
||||
where `(R+1)%N` is the front of the queue, `rotate_left` allows for the
|
||||
wraparound of queue storage, and `take` gives the first `K` elements.
|
||||
where `(R+1)%N` is the front of the queue, `W` is the back of the queue,
|
||||
`rotate_left` allows for the wraparound of queue storage, and `take` gives the
|
||||
first `K` elements.
|
||||
|
@ -23,16 +23,16 @@
|
||||
#include "proof/queue.h"
|
||||
|
||||
/* Simplifying assumption: we do not verify queue initialisation in a
|
||||
concurrent environment. We assume the queue initialization (including reset)
|
||||
happens-before all concurrent send/receives. */
|
||||
* concurrent environment. We assume the queue initialization (including reset)
|
||||
* happens-before all concurrent send/receives. */
|
||||
#ifdef VERIFAST /*< ***xQueueGenericReset happens-before concurrent behavior*** */
|
||||
#define taskENTER_CRITICAL()
|
||||
#define taskEXIT_CRITICAL()
|
||||
#endif
|
||||
|
||||
/* The following intermediate queue predicates summarise states used by queue
|
||||
initialization but not used elsewhere so we confine them to these proofs
|
||||
locally. */
|
||||
* initialization but not used elsewhere so we confine them to these proofs
|
||||
* locally. */
|
||||
/*@
|
||||
predicate queue_init1(QueueHandle_t q;) =
|
||||
QUEUE_SHAPE(q, _, _, _, _) &*&
|
||||
@ -50,7 +50,8 @@ predicate queue_init2(QueueHandle_t q, int8_t *Storage, size_t N, size_t M;) =
|
||||
;
|
||||
@*/
|
||||
|
||||
BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue )
|
||||
BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
|
||||
BaseType_t xNewQueue )
|
||||
/*@requires queue_init2(xQueue, ?Storage, ?N, ?M);@*/
|
||||
/*@ensures 0 == M
|
||||
? freertos_mutex(xQueue, Storage, N, 0)
|
||||
@ -77,10 +78,10 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xNewQueue == pdFALSE )
|
||||
{
|
||||
/* If there are tasks blocked waiting to read from the queue, then
|
||||
the tasks will remain blocked as after this function exits the queue
|
||||
will still be empty. If there are tasks blocked waiting to write to
|
||||
the queue, then one should be unblocked as after this function exits
|
||||
it will be possible to write to it. */
|
||||
* the tasks will remain blocked as after this function exits the queue
|
||||
* will still be empty. If there are tasks blocked waiting to write to
|
||||
* the queue, then one should be unblocked as after this function exits
|
||||
* it will be possible to write to it. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
|
||||
@ -103,19 +104,22 @@ Queue_t * const pxQueue = xQueue;
|
||||
vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
|
||||
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
|
||||
}
|
||||
/* Logically, we move from a flat character array of `N*M` bytes (using
|
||||
the `chars` predicate) to an array of `N` elements where each element
|
||||
is `M` bytes (using the `buffer` predicate) */
|
||||
|
||||
/*@if (M != 0) { buffer_from_chars(pxQueue->pcHead, N, M); }@*/
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
/* A value is returned for calling semantic consistency with previous
|
||||
versions. */
|
||||
* versions. */
|
||||
return pdPASS;
|
||||
}
|
||||
|
||||
static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue )
|
||||
static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
|
||||
const UBaseType_t uxItemSize,
|
||||
uint8_t * pucQueueStorage,
|
||||
const uint8_t ucQueueType,
|
||||
Queue_t * pxNewQueue )
|
||||
|
||||
/*@requires queue_init1(pxNewQueue) &*&
|
||||
0 < uxQueueLength &*& 0 < uxItemSize &*&
|
||||
malloc_block(pucQueueStorage, uxQueueLength * uxItemSize) &*&
|
||||
@ -126,16 +130,16 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
{
|
||||
#ifndef VERIFAST /*< void cast of unused var */
|
||||
/* Remove compiler warnings about unused parameters should
|
||||
configUSE_TRACE_FACILITY not be set to 1. */
|
||||
* configUSE_TRACE_FACILITY not be set to 1. */
|
||||
( void ) ucQueueType;
|
||||
#endif
|
||||
|
||||
if( uxItemSize == ( UBaseType_t ) 0 )
|
||||
{
|
||||
/* No RAM was allocated for the queue storage area, but PC head cannot
|
||||
be set to NULL because NULL is used as a key to say the queue is used as
|
||||
a mutex. Therefore just set pcHead to point to the queue as a benign
|
||||
value that is known to be within the memory map. */
|
||||
* be set to NULL because NULL is used as a key to say the queue is used as
|
||||
* a mutex. Therefore just set pcHead to point to the queue as a benign
|
||||
* value that is known to be within the memory map. */
|
||||
#ifdef VERIFAST /*< stricter casting */
|
||||
pxNewQueue->pcHead = ( int8_t * ) ( void * ) pxNewQueue;
|
||||
#else
|
||||
@ -153,7 +157,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
}
|
||||
|
||||
/* Initialise the queue members as described where the queue type is
|
||||
defined. */
|
||||
* defined. */
|
||||
pxNewQueue->uxLength = uxQueueLength;
|
||||
pxNewQueue->uxItemSize = uxItemSize;
|
||||
/*@close queue_init2(pxNewQueue, _, uxQueueLength, uxItemSize);@*/
|
||||
@ -178,7 +182,10 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
traceQUEUE_CREATE( pxNewQueue );
|
||||
}
|
||||
|
||||
QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType )
|
||||
|
||||
QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
|
||||
const UBaseType_t uxItemSize,
|
||||
const uint8_t ucQueueType )
|
||||
/*@requires 0 < uxQueueLength &*&
|
||||
0 < uxItemSize &*&
|
||||
0 < uxQueueLength * uxItemSize &*&
|
||||
@ -198,8 +205,8 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
configASSERT( uxQueueLength > ( UBaseType_t ) 0 );
|
||||
|
||||
/* Allocate enough space to hold the maximum number of items that
|
||||
can be in the queue at any time. It is valid for uxItemSize to be
|
||||
zero in the case the queue is used as a semaphore. */
|
||||
* can be in the queue at any time. It is valid for uxItemSize to be
|
||||
* zero in the case the queue is used as a semaphore. */
|
||||
xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
|
||||
|
||||
/* Check for multiplication overflow. */
|
||||
@ -209,14 +216,14 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) );
|
||||
#else
|
||||
/* Allocate the queue and storage area. Justification for MISRA
|
||||
deviation as follows: pvPortMalloc() always ensures returned memory
|
||||
blocks are aligned per the requirements of the MCU stack. In this case
|
||||
pvPortMalloc() must return a pointer that is guaranteed to meet the
|
||||
alignment requirements of the Queue_t structure - which in this case
|
||||
is an int8_t *. Therefore, whenever the stack alignment requirements
|
||||
are greater than or equal to the pointer to char requirements the cast
|
||||
is safe. In other cases alignment requirements are not strict (one or
|
||||
two bytes). */
|
||||
* deviation as follows: pvPortMalloc() always ensures returned memory
|
||||
* blocks are aligned per the requirements of the MCU stack. In this case
|
||||
* pvPortMalloc() must return a pointer that is guaranteed to meet the
|
||||
* alignment requirements of the Queue_t structure - which in this case
|
||||
* is an int8_t *. Therefore, whenever the stack alignment requirements
|
||||
* are greater than or equal to the pointer to char requirements the cast
|
||||
* is safe. In other cases alignment requirements are not strict (one or
|
||||
* two bytes). */
|
||||
pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */
|
||||
#endif
|
||||
|
||||
@ -224,14 +231,17 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
{
|
||||
#ifdef VERIFAST /*< ***model single malloc of struct and buffer*** */
|
||||
pucQueueStorage = ( uint8_t * ) pvPortMalloc( xQueueSizeInBytes );
|
||||
if ( pucQueueStorage == NULL ) {
|
||||
|
||||
if( pucQueueStorage == NULL )
|
||||
{
|
||||
vPortFree( pxNewQueue );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*@malloc_block_limits(pucQueueStorage);@*/
|
||||
#else
|
||||
/* Jump past the queue structure to find the location of the queue
|
||||
storage area. */
|
||||
* storage area. */
|
||||
pucQueueStorage = ( uint8_t * ) pxNewQueue;
|
||||
pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
|
||||
#endif
|
||||
@ -239,8 +249,8 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||
{
|
||||
/* Queues can be created either statically or dynamically, so
|
||||
note this task was created dynamically in case it is later
|
||||
deleted. */
|
||||
* note this task was created dynamically in case it is later
|
||||
* deleted. */
|
||||
pxNewQueue->ucStaticallyAllocated = pdFALSE;
|
||||
}
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
@ -255,4 +265,3 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
|
||||
|
||||
return pxNewQueue;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@
|
||||
|
||||
#include "proof/queue.h"
|
||||
|
||||
static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer )
|
||||
static void prvCopyDataFromQueue( Queue_t * const pxQueue,
|
||||
void * const pvBuffer )
|
||||
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*& 0 < K &*& chars(pvBuffer, M, _);@*/
|
||||
/*@ensures queue_after_prvCopyDataFromQueue(pxQueue, Storage, N, M, W, (R+1)%N, K, is_locked, abs) &*&
|
||||
chars(pvBuffer, M, head(abs));@*/
|
||||
@ -32,9 +33,10 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
|
||||
/*@assert buffer(Storage, N, M, ?contents);@*/
|
||||
/*@mul_mono_l(R, N-1, M);@*/
|
||||
pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
|
||||
|
||||
if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */
|
||||
{
|
||||
/*@div_leq(N, R+1, M);@*/ // now we know R == N-1
|
||||
/*@div_leq(N, R+1, M);@*/ /* now we know R == N-1 */
|
||||
pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead;
|
||||
}
|
||||
else
|
||||
@ -47,6 +49,7 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
|
||||
}@*/
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
/*@mod_plus(R+1, K, N);@*/
|
||||
/*@mod_mod(R+1, N);@*/
|
||||
/*@split_element(Storage, N, M, (R+1)%N);@*/
|
||||
@ -69,7 +72,8 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer
|
||||
}
|
||||
}
|
||||
|
||||
void caller_reinstates_queue_predicate(Queue_t *const pxQueue, void *const pvBuffer)
|
||||
void caller_reinstates_queue_predicate( Queue_t * const pxQueue,
|
||||
void * const pvBuffer )
|
||||
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
|
||||
0 < K &*&
|
||||
chars(pvBuffer, M, _);@*/
|
||||
|
@ -22,7 +22,9 @@
|
||||
|
||||
#include "proof/queue.h"
|
||||
|
||||
static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
|
||||
static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
|
||||
const void * pvItemToQueue,
|
||||
const BaseType_t xPosition )
|
||||
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
|
||||
(K < N || xPosition == queueOVERWRITE) &*&
|
||||
chars(pvItemToQueue, M, ?x) &*&
|
||||
@ -70,9 +72,9 @@ UBaseType_t uxMessagesWaiting;
|
||||
{
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/* Now we focus the proof on the logical element of the buffer that
|
||||
will be updated using the following lemma to split the buffer into 3
|
||||
parts: a prefix, the element we want to update, and the suffix. This
|
||||
enables the subsequent memcpy to verify. */
|
||||
* will be updated using the following lemma to split the buffer into 3
|
||||
* parts: a prefix, the element we want to update, and the suffix. This
|
||||
* enables the subsequent memcpy to verify. */
|
||||
/*@split_element(Storage, N, M, W);@*/
|
||||
/*@assert
|
||||
buffer(Storage, W, M, ?prefix) &*&
|
||||
@ -85,10 +87,12 @@ UBaseType_t uxMessagesWaiting;
|
||||
#else
|
||||
( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
|
||||
#endif
|
||||
/*@mul_mono_l(W, N-1, M);@*/
|
||||
pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
|
||||
|
||||
if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
|
||||
{
|
||||
/*@div_leq(N, W+1, M);@*/ // now we know W == N-1
|
||||
/*@div_leq(N, W+1, M);@*/ /* now we know W == N-1 so (W+1)%N == 0 */
|
||||
pxQueue->pcWriteTo = pxQueue->pcHead;
|
||||
}
|
||||
else
|
||||
@ -117,13 +121,11 @@ UBaseType_t uxMessagesWaiting;
|
||||
( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. Assert checks null pointer only used when length is 0. */
|
||||
#endif
|
||||
pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize;
|
||||
|
||||
if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
|
||||
{
|
||||
pxQueue->u.xQueue.pcReadFrom = ( pxQueue->u.xQueue.pcTail - pxQueue->uxItemSize );
|
||||
/*@{
|
||||
div_leq(R-1, 0, M);
|
||||
leq_bound(R, 0);
|
||||
}@*/
|
||||
/*@{ div_leq(R-1, 0, M); leq_bound(R, 0); }@*/
|
||||
/*@assert R == 0;@*/
|
||||
/*@assert pxQueue->u.xQueue.pcReadFrom == Storage + (N-1) * M;@*/
|
||||
}
|
||||
@ -135,7 +137,8 @@ UBaseType_t uxMessagesWaiting;
|
||||
}
|
||||
|
||||
/*@
|
||||
if (R == 0) {
|
||||
if (R == 0)
|
||||
{
|
||||
mod_plus(N, (K+1), N); mod_same(N); mod_mod(K+1, N);
|
||||
assert W == ((N-1) + 1 + (K+1)) % N;
|
||||
}
|
||||
@ -145,9 +148,9 @@ UBaseType_t uxMessagesWaiting;
|
||||
if( uxMessagesWaiting > ( UBaseType_t ) 0 )
|
||||
{
|
||||
/* An item is not being added but overwritten, so subtract
|
||||
one from the recorded number of items in the queue so when
|
||||
one is added again below the number of recorded items remains
|
||||
correct. */
|
||||
* one from the recorded number of items in the queue so when
|
||||
* one is added again below the number of recorded items remains
|
||||
* correct. */
|
||||
--uxMessagesWaiting;
|
||||
}
|
||||
else
|
||||
@ -164,13 +167,17 @@ UBaseType_t uxMessagesWaiting;
|
||||
pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
|
||||
|
||||
/*@
|
||||
if (xPosition == queueSEND_TO_BACK) {
|
||||
if (xPosition == queueSEND_TO_BACK)
|
||||
{
|
||||
enq_lemma(K, (R+1)%N, contents, abs, x);
|
||||
mod_plus_one(W, R + 1 + K, N);
|
||||
mod_plus_distr(R+1, K, N);
|
||||
} else if (xPosition == queueSEND_TO_FRONT) {
|
||||
}
|
||||
else if (xPosition == queueSEND_TO_FRONT)
|
||||
{
|
||||
front_enq_lemma(K, R, contents, abs, x);
|
||||
if (0 < R) {
|
||||
if (0 < R)
|
||||
{
|
||||
mod_lt(R, N);
|
||||
}
|
||||
}
|
||||
|
@ -47,4 +47,3 @@ BaseType_t xReturn;
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include "proof/queue.h"
|
||||
|
||||
/* In this case we cannot wrap the macro in a function call to give a function
|
||||
contract because we require annotations within the macro body, which is not
|
||||
supported by VeriFast */
|
||||
* contract because we require annotations within the macro body, which is not
|
||||
* supported by VeriFast */
|
||||
#define prvLockQueue( pxQueue ) \
|
||||
taskENTER_CRITICAL(); \
|
||||
{ \
|
||||
@ -40,6 +40,7 @@ supported by VeriFast */
|
||||
taskEXIT_CRITICAL()
|
||||
|
||||
void wrapper_prvLockQueue( QueueHandle_t xQueue )
|
||||
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
|
||||
[1/2]queuelock(xQueue);@*/
|
||||
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
|
||||
@ -54,6 +55,7 @@ void wrapper_prvLockQueue( QueueHandle_t xQueue )
|
||||
{
|
||||
( xQueue )->cRxLock = queueLOCKED_UNMODIFIED;
|
||||
}
|
||||
|
||||
if( ( xQueue )->cTxLock == queueUNLOCKED )
|
||||
{
|
||||
( xQueue )->cTxLock = queueLOCKED_UNMODIFIED;
|
||||
|
@ -25,7 +25,7 @@
|
||||
#define taskEXIT_CRITICAL() clearInterruptMask( pxQueue )
|
||||
|
||||
/* VeriFast: we make one major change. We merge the critical regions for
|
||||
decrementing `cTxLock` and `cRxLock`. */
|
||||
* decrementing `cTxLock` and `cRxLock`. */
|
||||
|
||||
static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
/*@requires [1/2]queuehandle(pxQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
|
||||
@ -38,9 +38,9 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
|
||||
|
||||
/* The lock counts contains the number of extra data items placed or
|
||||
removed from the queue while the queue was locked. When a queue is
|
||||
locked items can be added or removed, but the event lists cannot be
|
||||
updated. */
|
||||
* removed from the queue while the queue was locked. When a queue is
|
||||
* locked items can be added or removed, but the event lists cannot be
|
||||
* updated. */
|
||||
taskENTER_CRITICAL();
|
||||
/*@open queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, _, ?abs);@*/
|
||||
{
|
||||
@ -51,7 +51,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
/*@invariant queuelists(pxQueue);@*/
|
||||
{
|
||||
/* Data was posted while the queue was locked. Are any tasks
|
||||
blocked waiting for data to become available? */
|
||||
* blocked waiting for data to become available? */
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
{
|
||||
if( pxQueue->pxQueueSetContainer != NULL )
|
||||
@ -59,8 +59,8 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
|
||||
{
|
||||
/* The queue is a member of a queue set, and posting to
|
||||
the queue set caused a higher priority task to unblock.
|
||||
A context switch is required. */
|
||||
* the queue set caused a higher priority task to unblock.
|
||||
* A context switch is required. */
|
||||
vTaskMissedYield();
|
||||
}
|
||||
else
|
||||
@ -71,14 +71,14 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
else
|
||||
{
|
||||
/* Tasks that are removed from the event list will get
|
||||
added to the pending ready list as the scheduler is still
|
||||
suspended. */
|
||||
* added to the pending ready list as the scheduler is still
|
||||
* suspended. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority so record that a
|
||||
context switch is required. */
|
||||
* context switch is required. */
|
||||
vTaskMissedYield();
|
||||
}
|
||||
else
|
||||
@ -95,13 +95,13 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
|
||||
#else /* configUSE_QUEUE_SETS */
|
||||
{
|
||||
/* Tasks that are removed from the event list will get added to
|
||||
the pending ready list as the scheduler is still suspended. */
|
||||
* the pending ready list as the scheduler is still suspended. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority so record that
|
||||
a context switch is required. */
|
||||
* a context switch is required. */
|
||||
vTaskMissedYield();
|
||||
}
|
||||
else
|
||||
|
@ -23,19 +23,20 @@
|
||||
#include "proof/queue.h"
|
||||
|
||||
/* It may seem that the read of `pxQueue->uxMessagesWaiting` is required to be
|
||||
contained in a critical region to be thread-safe. However, it is impossible for
|
||||
this read to be involved in a data race due to the atomicity mechanism used by
|
||||
tasks and ISRs: masking and enabling interrupts. If we assume (1) a
|
||||
uniprocessor system and (2) that higher priority ISRs never call queue API
|
||||
functions then masking interrupts ensures *strong isolation* meaning critical
|
||||
regions protected by interrupt masking/enabling are isolated from other
|
||||
critical regions and code outside of critical regions. */
|
||||
* contained in a critical region to be thread-safe. However, it is impossible for
|
||||
* this read to be involved in a data race due to the atomicity mechanism used by
|
||||
* tasks and ISRs: masking and enabling interrupts. If we assume (1) a
|
||||
* uniprocessor system and (2) that higher priority ISRs never call queue API
|
||||
* functions then masking interrupts ensures *strong isolation* meaning critical
|
||||
* regions protected by interrupt masking/enabling are isolated from other
|
||||
* critical regions and code outside of critical regions. */
|
||||
|
||||
UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )
|
||||
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
|
||||
/*@ensures queue(xQueue, Storage, N, M, W, R, K, is_locked, abs) &*& result == K;@*/
|
||||
{
|
||||
UBaseType_t uxReturn;
|
||||
|
||||
#ifdef VERIFAST /*< const pointer declaration */
|
||||
Queue_t * pxQueue = xQueue;
|
||||
#else
|
||||
|
@ -27,6 +27,7 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
|
||||
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr);@*/
|
||||
{
|
||||
UBaseType_t uxReturn;
|
||||
|
||||
#ifdef VERIFAST /*< const pointer declaration */
|
||||
Queue_t * pxQueue = xQueue;
|
||||
#else
|
||||
|
@ -50,7 +50,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
|
||||
{
|
||||
/* The queue can only have been allocated dynamically - free it
|
||||
again. */
|
||||
* again. */
|
||||
vPortFree( pxQueue );
|
||||
#ifdef VERIFAST /*< leak ghost state on deletion */
|
||||
/*@leak buffer(_, _, _, _);@*/
|
||||
@ -60,7 +60,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
#elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
|
||||
{
|
||||
/* The queue could have been allocated statically or dynamically, so
|
||||
check before attempting to free the memory. */
|
||||
* check before attempting to free the memory. */
|
||||
if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
|
||||
{
|
||||
vPortFree( pxQueue );
|
||||
@ -70,10 +70,10 @@ Queue_t * const pxQueue = xQueue;
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
#else
|
||||
#else /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) */
|
||||
{
|
||||
/* The queue must have been statically allocated, so is not going to be
|
||||
deleted. Avoid compiler warnings about the unused parameter. */
|
||||
* deleted. Avoid compiler warnings about the unused parameter. */
|
||||
( void ) pxQueue;
|
||||
}
|
||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||
|
@ -23,7 +23,10 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition )
|
||||
BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
|
||||
const void * const pvItemToQueue,
|
||||
TickType_t xTicksToWait,
|
||||
const BaseType_t xCopyPosition )
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
chars(pvItemToQueue, M, ?x) &*&
|
||||
@ -47,12 +50,11 @@ Queue_t * const pxQueue = xQueue;
|
||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*lint -save -e904 This function relaxes the coding standard somewhat to
|
||||
allow return statements within the function itself. This is done in the
|
||||
interest of execution time efficiency. */
|
||||
* allow return statements within the function itself. This is done in the
|
||||
* interest of execution time efficiency. */
|
||||
for( ; ; )
|
||||
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
@ -65,9 +67,9 @@ Queue_t * const pxQueue = xQueue;
|
||||
{
|
||||
/*@assert queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
|
||||
/* Is there room on the queue now? The running task must be the
|
||||
highest priority task wanting to access the queue. If the head item
|
||||
in the queue is to be overwritten then it does not matter if the
|
||||
queue is full. */
|
||||
* highest priority task wanting to access the queue. If the head item
|
||||
* in the queue is to be overwritten then it does not matter if the
|
||||
* queue is full. */
|
||||
if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
|
||||
{
|
||||
traceQUEUE_SEND( pxQueue );
|
||||
@ -84,15 +86,15 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
|
||||
{
|
||||
/* Do not notify the queue set as an existing item
|
||||
was overwritten in the queue so the number of items
|
||||
in the queue has not changed. */
|
||||
* was overwritten in the queue so the number of items
|
||||
* in the queue has not changed. */
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
|
||||
{
|
||||
/* The queue is a member of a queue set, and posting
|
||||
to the queue set caused a higher priority task to
|
||||
unblock. A context switch is required. */
|
||||
* to the queue set caused a higher priority task to
|
||||
* unblock. A context switch is required. */
|
||||
queueYIELD_IF_USING_PREEMPTION();
|
||||
}
|
||||
else
|
||||
@ -103,15 +105,15 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* If there was a task waiting for data to arrive on the
|
||||
queue then unblock it now. */
|
||||
* queue then unblock it now. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The unblocked task has a priority higher than
|
||||
our own so yield immediately. Yes it is ok to
|
||||
do this from within the critical section - the
|
||||
kernel takes care of that. */
|
||||
* our own so yield immediately. Yes it is ok to
|
||||
* do this from within the critical section - the
|
||||
* kernel takes care of that. */
|
||||
queueYIELD_IF_USING_PREEMPTION();
|
||||
}
|
||||
else
|
||||
@ -122,9 +124,9 @@ Queue_t * const pxQueue = xQueue;
|
||||
else if( xYieldRequired != pdFALSE )
|
||||
{
|
||||
/* This path is a special case that will only get
|
||||
executed if the task was holding multiple mutexes
|
||||
and the mutexes were given back in an order that is
|
||||
different to that in which they were taken. */
|
||||
* executed if the task was holding multiple mutexes
|
||||
* and the mutexes were given back in an order that is
|
||||
* different to that in which they were taken. */
|
||||
queueYIELD_IF_USING_PREEMPTION();
|
||||
}
|
||||
else
|
||||
@ -139,15 +141,15 @@ Queue_t * const pxQueue = xQueue;
|
||||
xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
|
||||
|
||||
/* If there was a task waiting for data to arrive on the
|
||||
queue then unblock it now. */
|
||||
* queue then unblock it now. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The unblocked task has a priority higher than
|
||||
our own so yield immediately. Yes it is ok to do
|
||||
this from within the critical section - the kernel
|
||||
takes care of that. */
|
||||
* our own so yield immediately. Yes it is ok to do
|
||||
* this from within the critical section - the kernel
|
||||
* takes care of that. */
|
||||
queueYIELD_IF_USING_PREEMPTION();
|
||||
}
|
||||
else
|
||||
@ -158,9 +160,9 @@ Queue_t * const pxQueue = xQueue;
|
||||
else if( xYieldRequired != pdFALSE )
|
||||
{
|
||||
/* This path is a special case that will only get
|
||||
executed if the task was holding multiple mutexes and
|
||||
the mutexes were given back in an order that is
|
||||
different to that in which they were taken. */
|
||||
* executed if the task was holding multiple mutexes and
|
||||
* the mutexes were given back in an order that is
|
||||
* different to that in which they were taken. */
|
||||
queueYIELD_IF_USING_PREEMPTION();
|
||||
}
|
||||
else
|
||||
@ -171,11 +173,16 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif /* configUSE_QUEUE_SETS */
|
||||
|
||||
/*@
|
||||
if (xCopyPosition == queueSEND_TO_BACK) {
|
||||
if (xCopyPosition == queueSEND_TO_BACK)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
|
||||
} else if (xCopyPosition == queueSEND_TO_FRONT) {
|
||||
}
|
||||
else if (xCopyPosition == queueSEND_TO_FRONT)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, W, (R == 0 ? (N-1) : (R-1)), (K+1), is_locked, cons(x, abs));
|
||||
} else if (xCopyPosition == queueOVERWRITE) {
|
||||
}
|
||||
else if (xCopyPosition == queueOVERWRITE)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
|
||||
}
|
||||
@*/
|
||||
@ -188,18 +195,18 @@ Queue_t * const pxQueue = xQueue;
|
||||
{
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
/* The queue was full and no block time is specified (or
|
||||
the block time has expired) so leave now. */
|
||||
* the block time has expired) so leave now. */
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
/* Return to the original privilege level before exiting
|
||||
the function. */
|
||||
* the function. */
|
||||
traceQUEUE_SEND_FAILED( pxQueue );
|
||||
return errQUEUE_FULL;
|
||||
}
|
||||
else if( xEntryTimeSet == pdFALSE )
|
||||
{
|
||||
/* The queue was full and a block time was specified so
|
||||
configure the timeout structure. */
|
||||
* configure the timeout structure. */
|
||||
vTaskInternalSetTimeOutState( &xTimeOut );
|
||||
xEntryTimeSet = pdTRUE;
|
||||
}
|
||||
@ -214,7 +221,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
now the critical section has been exited. */
|
||||
* now the critical section has been exited. */
|
||||
|
||||
/*@close exists(pxQueue);@*/
|
||||
vTaskSuspendAll();
|
||||
@ -230,18 +237,18 @@ Queue_t * const pxQueue = xQueue;
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
|
||||
|
||||
/* Unlocking the queue means queue events can effect the
|
||||
event list. It is possible that interrupts occurring now
|
||||
remove this task from the event list again - but as the
|
||||
scheduler is suspended the task will go onto the pending
|
||||
ready last instead of the actual ready list. */
|
||||
* event list. It is possible that interrupts occurring now
|
||||
* remove this task from the event list again - but as the
|
||||
* scheduler is suspended the task will go onto the pending
|
||||
* ready last instead of the actual ready list. */
|
||||
/*@close queue_locked_invariant(xQueue)();@*/
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
/* Resuming the scheduler will move tasks from the pending
|
||||
ready list into the ready list - so it is feasible that this
|
||||
task is already in a ready list before it yields - in which
|
||||
case the yield will not cause a context switch unless there
|
||||
is also a higher priority task in the pending ready list. */
|
||||
* ready list into the ready list - so it is feasible that this
|
||||
* task is already in a ready list before it yields - in which
|
||||
* case the yield will not cause a context switch unless there
|
||||
* is also a higher priority task in the pending ready list. */
|
||||
/*@close exists(pxQueue);@*/
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
|
@ -23,7 +23,10 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition )
|
||||
BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
|
||||
const void * const pvItemToQueue,
|
||||
BaseType_t * const pxHigherPriorityTaskWoken,
|
||||
const BaseType_t xCopyPosition )
|
||||
/*@requires
|
||||
[1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
|
||||
chars(pvItemToQueue, M, ?x) &*&
|
||||
@ -36,6 +39,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pv
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
UBaseType_t uxSavedInterruptStatus;
|
||||
|
||||
#ifdef VERIFAST /*< const pointer declaration */
|
||||
Queue_t * pxQueue = xQueue;
|
||||
#else
|
||||
@ -47,26 +51,26 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif
|
||||
|
||||
/* RTOS ports that support interrupt nesting have the concept of a maximum
|
||||
system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
above the maximum system call priority are kept permanently enabled, even
|
||||
when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
assigned a priority above the configured maximum system call priority.
|
||||
Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
that have been assigned a priority at or (logically) below the maximum
|
||||
system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
More information (albeit Cortex-M specific) is provided on the following
|
||||
link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
* system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
* above the maximum system call priority are kept permanently enabled, even
|
||||
* when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
* FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
* then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
* failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
* assigned a priority above the configured maximum system call priority.
|
||||
* Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
* that have been assigned a priority at or (logically) below the maximum
|
||||
* system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
* safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
* More information (albeit Cortex-M specific) is provided on the following
|
||||
* link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
|
||||
|
||||
/* Similar to xQueueGenericSend, except without blocking if there is no room
|
||||
in the queue. Also don't directly wake a task that was blocked on a queue
|
||||
read, instead return a flag to say whether a context switch is required or
|
||||
not (i.e. has a task with a higher priority than us been woken by this
|
||||
post). */
|
||||
* in the queue. Also don't directly wake a task that was blocked on a queue
|
||||
* read, instead return a flag to say whether a context switch is required or
|
||||
* not (i.e. has a task with a higher priority than us been woken by this
|
||||
* post). */
|
||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||
/*@assert queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
|
||||
{
|
||||
@ -78,10 +82,10 @@ Queue_t * const pxQueue = xQueue;
|
||||
traceQUEUE_SEND_FROM_ISR( pxQueue );
|
||||
|
||||
/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a
|
||||
semaphore or mutex. That means prvCopyDataToQueue() cannot result
|
||||
in a task disinheriting a priority and prvCopyDataToQueue() can be
|
||||
called here even though the disinherit function does not check if
|
||||
the scheduler is suspended before accessing the ready lists. */
|
||||
* semaphore or mutex. That means prvCopyDataToQueue() cannot result
|
||||
* in a task disinheriting a priority and prvCopyDataToQueue() can be
|
||||
* called here even though the disinherit function does not check if
|
||||
* the scheduler is suspended before accessing the ready lists. */
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
|
||||
@ -91,7 +95,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
/*@open queue(pxQueue, _, N, M, _, _, _, _, _);@*/
|
||||
|
||||
/* The event list is not altered if the queue is locked. This will
|
||||
be done when the queue is unlocked later. */
|
||||
* be done when the queue is unlocked later. */
|
||||
if( cTxLock == queueUNLOCKED )
|
||||
{
|
||||
/* VeriFast: we do not verify this configuration option */
|
||||
@ -102,15 +106,15 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )
|
||||
{
|
||||
/* Do not notify the queue set as an existing item
|
||||
was overwritten in the queue so the number of items
|
||||
in the queue has not changed. */
|
||||
* was overwritten in the queue so the number of items
|
||||
* in the queue has not changed. */
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE )
|
||||
{
|
||||
/* The queue is a member of a queue set, and posting
|
||||
to the queue set caused a higher priority task to
|
||||
unblock. A context switch is required. */
|
||||
* to the queue set caused a higher priority task to
|
||||
* unblock. A context switch is required. */
|
||||
if( pxHigherPriorityTaskWoken != NULL )
|
||||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
@ -132,7 +136,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority so
|
||||
record that a context switch is required. */
|
||||
* record that a context switch is required. */
|
||||
if( pxHigherPriorityTaskWoken != NULL )
|
||||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
@ -160,7 +164,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority so record that a
|
||||
context switch is required. */
|
||||
* context switch is required. */
|
||||
if( pxHigherPriorityTaskWoken != NULL )
|
||||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
@ -190,7 +194,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* Increment the lock count so the task that unlocks the queue
|
||||
knows that data was posted while it was locked. */
|
||||
* knows that data was posted while it was locked. */
|
||||
configASSERT( cTxLock != queueINT8_MAX );
|
||||
|
||||
pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );
|
||||
@ -198,15 +202,22 @@ Queue_t * const pxQueue = xQueue;
|
||||
|
||||
xReturn = pdPASS;
|
||||
/*@
|
||||
if (xCopyPosition == queueSEND_TO_BACK) {
|
||||
if (xCopyPosition == queueSEND_TO_BACK)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
|
||||
} else if (xCopyPosition == queueSEND_TO_FRONT) {
|
||||
if (R == 0) {
|
||||
}
|
||||
else if (xCopyPosition == queueSEND_TO_FRONT)
|
||||
{
|
||||
if (R == 0)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs));
|
||||
}
|
||||
} else if (xCopyPosition == queueOVERWRITE) {
|
||||
} else if (xCopyPosition == queueOVERWRITE)
|
||||
{
|
||||
close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
|
||||
}
|
||||
@*/
|
||||
|
@ -28,6 +28,7 @@ BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
|
||||
result == ((K == 0) ? pdTRUE : pdFALSE);@*/
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
|
||||
#ifdef VERIFAST /*< const pointer declaration */
|
||||
Queue_t * pxQueue = xQueue;
|
||||
#else
|
||||
@ -35,6 +36,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif
|
||||
|
||||
configASSERT( pxQueue );
|
||||
|
||||
if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 )
|
||||
{
|
||||
xReturn = pdTRUE;
|
||||
|
@ -28,6 +28,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
|
||||
result == ((K == N) ? pdTRUE : pdFALSE);@*/
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
|
||||
#ifdef VERIFAST /*< const pointer declaration */
|
||||
Queue_t * pxQueue = xQueue;
|
||||
#else
|
||||
@ -35,6 +36,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif
|
||||
|
||||
configASSERT( pxQueue );
|
||||
|
||||
if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
|
||||
{
|
||||
xReturn = pdTRUE;
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )
|
||||
BaseType_t xQueuePeek( QueueHandle_t xQueue,
|
||||
void * const pvBuffer,
|
||||
TickType_t xTicksToWait )
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
chars(pvBuffer, M, ?x);@*/
|
||||
@ -43,7 +45,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
configASSERT( ( pxQueue ) );
|
||||
|
||||
/* The buffer into which data is received can only be NULL if the data size
|
||||
is zero (so no data is copied into the buffer. */
|
||||
* is zero (so no data is copied into the buffer. */
|
||||
configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
|
||||
|
||||
/* Cannot block if the scheduler is suspended. */
|
||||
@ -52,12 +54,11 @@ Queue_t * const pxQueue = xQueue;
|
||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*lint -save -e904 This function relaxes the coding standard somewhat to
|
||||
allow return statements within the function itself. This is done in the
|
||||
interest of execution time efficiency. */
|
||||
* allow return statements within the function itself. This is done in the
|
||||
* interest of execution time efficiency. */
|
||||
for( ; ; )
|
||||
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
@ -71,12 +72,12 @@ Queue_t * const pxQueue = xQueue;
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
/* Is there data in the queue now? To be running the calling task
|
||||
must be the highest priority task wanting to access the queue. */
|
||||
* must be the highest priority task wanting to access the queue. */
|
||||
if( uxMessagesWaiting > ( UBaseType_t ) 0 )
|
||||
{
|
||||
/* Remember the read position so it can be reset after the data
|
||||
is read from the queue as this function is only peeking the
|
||||
data, not removing it. */
|
||||
* is read from the queue as this function is only peeking the
|
||||
* data, not removing it. */
|
||||
pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
|
||||
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
@ -87,7 +88,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition;
|
||||
|
||||
/* The data is being left in the queue, so see if there are
|
||||
any other tasks waiting for the data. */
|
||||
* any other tasks waiting for the data. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
|
||||
@ -114,7 +115,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTicksToWait == ( TickType_t ) 0 )
|
||||
{
|
||||
/* The queue was empty and no block time is specified (or
|
||||
the block time has expired) so leave now. */
|
||||
* the block time has expired) so leave now. */
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
taskEXIT_CRITICAL();
|
||||
traceQUEUE_PEEK_FAILED( pxQueue );
|
||||
@ -123,8 +124,8 @@ Queue_t * const pxQueue = xQueue;
|
||||
else if( xEntryTimeSet == pdFALSE )
|
||||
{
|
||||
/* The queue was empty and a block time was specified so
|
||||
configure the timeout structure ready to enter the blocked
|
||||
state. */
|
||||
* configure the timeout structure ready to enter the blocked
|
||||
* state. */
|
||||
vTaskInternalSetTimeOutState( &xTimeOut );
|
||||
xEntryTimeSet = pdTRUE;
|
||||
}
|
||||
@ -139,7 +140,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
now the critical section has been exited. */
|
||||
* now the critical section has been exited. */
|
||||
|
||||
/*@close exists<QueueHandle_t>(pxQueue);@*/
|
||||
vTaskSuspendAll();
|
||||
@ -149,7 +150,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
{
|
||||
/* Timeout has not expired yet, check to see if there is data in the
|
||||
queue now, and if not enter the Blocked state to wait for data. */
|
||||
* queue now, and if not enter the Blocked state to wait for data. */
|
||||
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
|
||||
{
|
||||
traceBLOCKING_ON_QUEUE_PEEK( pxQueue );
|
||||
@ -157,6 +158,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
|
||||
/*@close queue_locked_invariant(xQueue)();@*/
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
/*@close exists<QueueHandle_t>(pxQueue);@*/
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
@ -170,7 +172,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* There is data in the queue now, so don't enter the blocked
|
||||
state, instead return to try and obtain the data. */
|
||||
* state, instead return to try and obtain the data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/*@close exists<QueueHandle_t>(pxQueue);@*/
|
||||
@ -183,7 +185,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* The timeout has expired. If there is still no data in the queue
|
||||
exit, otherwise go back and try to read the data again. */
|
||||
* exit, otherwise go back and try to read the data again. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/*@close exists<QueueHandle_t>(pxQueue);@*/
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer )
|
||||
BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
|
||||
void * const pvBuffer )
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
|
||||
chars(pvBuffer, M, ?x);@*/
|
||||
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
|
||||
@ -43,19 +44,19 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif
|
||||
|
||||
/* RTOS ports that support interrupt nesting have the concept of a maximum
|
||||
system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
above the maximum system call priority are kept permanently enabled, even
|
||||
when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
assigned a priority above the configured maximum system call priority.
|
||||
Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
that have been assigned a priority at or (logically) below the maximum
|
||||
system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
More information (albeit Cortex-M specific) is provided on the following
|
||||
link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
* system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
* above the maximum system call priority are kept permanently enabled, even
|
||||
* when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
* FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
* then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
* failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
* assigned a priority above the configured maximum system call priority.
|
||||
* Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
* that have been assigned a priority at or (logically) below the maximum
|
||||
* system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
* safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
* More information (albeit Cortex-M specific) is provided on the following
|
||||
* link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
|
||||
|
||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||
@ -67,7 +68,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
traceQUEUE_PEEK_FROM_ISR( pxQueue );
|
||||
|
||||
/* Remember the read position so it can be reset as nothing is
|
||||
actually being removed from the queue. */
|
||||
* actually being removed from the queue. */
|
||||
pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom;
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
prvCopyDataFromQueue( pxQueue, pvBuffer );
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )
|
||||
BaseType_t xQueueReceive( QueueHandle_t xQueue,
|
||||
void * const pvBuffer,
|
||||
TickType_t xTicksToWait )
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
chars(pvBuffer, M, ?x);@*/
|
||||
@ -42,7 +44,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
configASSERT( ( pxQueue ) );
|
||||
|
||||
/* The buffer into which data is received can only be NULL if the data size
|
||||
is zero (so no data is copied into the buffer). */
|
||||
* is zero (so no data is copied into the buffer). */
|
||||
configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
|
||||
|
||||
/* Cannot block if the scheduler is suspended. */
|
||||
@ -51,12 +53,11 @@ Queue_t * const pxQueue = xQueue;
|
||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*lint -save -e904 This function relaxes the coding standard somewhat to
|
||||
allow return statements within the function itself. This is done in the
|
||||
interest of execution time efficiency. */
|
||||
* allow return statements within the function itself. This is done in the
|
||||
* interest of execution time efficiency. */
|
||||
for( ; ; )
|
||||
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
|
||||
[1/2]queuesuspend(xQueue) &*&
|
||||
@ -70,7 +71,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;
|
||||
|
||||
/* Is there data in the queue now? To be running the calling task
|
||||
must be the highest priority task wanting to access the queue. */
|
||||
* must be the highest priority task wanting to access the queue. */
|
||||
if( uxMessagesWaiting > ( UBaseType_t ) 0 )
|
||||
{
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
@ -79,14 +80,14 @@ Queue_t * const pxQueue = xQueue;
|
||||
/*@open queue_after_prvCopyDataFromQueue(pxQueue, Storage, N, M, W, (R+1)%N, K, is_locked, abs);@*/
|
||||
traceQUEUE_RECEIVE( pxQueue );
|
||||
pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
|
||||
|
||||
/*@assert
|
||||
pxQueue->pcHead |-> ?buffer &*&
|
||||
buffer(buffer, N, M, ?contents);@*/
|
||||
/*@deq_lemma(K, (R+1)%N, contents, abs, head(abs));@*/
|
||||
|
||||
/* There is now space in the queue, were any tasks waiting to
|
||||
post to the queue? If so, unblock the highest priority waiting
|
||||
task. */
|
||||
* post to the queue? If so, unblock the highest priority waiting
|
||||
* task. */
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
|
||||
{
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
|
||||
@ -114,7 +115,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
{
|
||||
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
|
||||
/* The queue was empty and no block time is specified (or
|
||||
the block time has expired) so leave now. */
|
||||
* the block time has expired) so leave now. */
|
||||
taskEXIT_CRITICAL();
|
||||
traceQUEUE_RECEIVE_FAILED( pxQueue );
|
||||
return errQUEUE_EMPTY;
|
||||
@ -122,7 +123,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else if( xEntryTimeSet == pdFALSE )
|
||||
{
|
||||
/* The queue was empty and a block time was specified so
|
||||
configure the timeout structure. */
|
||||
* configure the timeout structure. */
|
||||
vTaskInternalSetTimeOutState( &xTimeOut );
|
||||
xEntryTimeSet = pdTRUE;
|
||||
}
|
||||
@ -137,7 +138,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
/* Interrupts and other tasks can send to and receive from the queue
|
||||
now the critical section has been exited. */
|
||||
* now the critical section has been exited. */
|
||||
|
||||
/*@close exists(pxQueue);@*/
|
||||
vTaskSuspendAll();
|
||||
@ -147,7 +148,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
|
||||
{
|
||||
/* The timeout has not expired. If the queue is still empty place
|
||||
the task on the list of tasks waiting to receive from the queue. */
|
||||
* the task on the list of tasks waiting to receive from the queue. */
|
||||
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
|
||||
{
|
||||
traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
|
||||
@ -155,6 +156,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
|
||||
/*@close queue_locked_invariant(xQueue)();@*/
|
||||
prvUnlockQueue( pxQueue );
|
||||
|
||||
/*@close exists(pxQueue);@*/
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
@ -168,7 +170,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* The queue contains data again. Loop back to try and read the
|
||||
data. */
|
||||
* data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/*@close exists(pxQueue);@*/
|
||||
@ -181,7 +183,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* Timed out. If there is no data in the queue exit, otherwise loop
|
||||
back and attempt to read the data. */
|
||||
* back and attempt to read the data. */
|
||||
prvUnlockQueue( pxQueue );
|
||||
#ifdef VERIFAST /*< void cast of unused return value */
|
||||
/*@close exists(pxQueue);@*/
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "proof/queue.h"
|
||||
#include "proof/queuecontracts.h"
|
||||
|
||||
BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken )
|
||||
BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
|
||||
void * const pvBuffer,
|
||||
BaseType_t * const pxHigherPriorityTaskWoken )
|
||||
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
|
||||
chars(pvBuffer, M, ?x) &*&
|
||||
pxHigherPriorityTaskWoken == NULL ? true : integer(pxHigherPriorityTaskWoken, _);@*/
|
||||
@ -43,19 +45,19 @@ Queue_t * const pxQueue = xQueue;
|
||||
#endif
|
||||
|
||||
/* RTOS ports that support interrupt nesting have the concept of a maximum
|
||||
system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
above the maximum system call priority are kept permanently enabled, even
|
||||
when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
assigned a priority above the configured maximum system call priority.
|
||||
Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
that have been assigned a priority at or (logically) below the maximum
|
||||
system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
More information (albeit Cortex-M specific) is provided on the following
|
||||
link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
* system call (or maximum API call) interrupt priority. Interrupts that are
|
||||
* above the maximum system call priority are kept permanently enabled, even
|
||||
* when the RTOS kernel is in a critical section, but cannot make any calls to
|
||||
* FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
|
||||
* then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
|
||||
* failure if a FreeRTOS API function is called from an interrupt that has been
|
||||
* assigned a priority above the configured maximum system call priority.
|
||||
* Only FreeRTOS functions that end in FromISR can be called from interrupts
|
||||
* that have been assigned a priority at or (logically) below the maximum
|
||||
* system call interrupt priority. FreeRTOS maintains a separate interrupt
|
||||
* safe API to ensure interrupt entry is as fast and as simple as possible.
|
||||
* More information (albeit Cortex-M specific) is provided on the following
|
||||
* link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
|
||||
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
|
||||
|
||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||
@ -78,9 +80,9 @@ Queue_t * const pxQueue = xQueue;
|
||||
/*@deq_lemma(K, (R+1)%N, contents, abs, head(abs));@*/
|
||||
|
||||
/* If the queue is locked the event list will not be modified.
|
||||
Instead update the lock count so the task that unlocks the queue
|
||||
will know that an ISR has removed data while the queue was
|
||||
locked. */
|
||||
* Instead update the lock count so the task that unlocks the queue
|
||||
* will know that an ISR has removed data while the queue was
|
||||
* locked. */
|
||||
if( cRxLock == queueUNLOCKED )
|
||||
{
|
||||
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
|
||||
@ -88,7 +90,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
|
||||
{
|
||||
/* The task waiting has a higher priority than us so
|
||||
force a context switch. */
|
||||
* force a context switch. */
|
||||
if( pxHigherPriorityTaskWoken != NULL )
|
||||
{
|
||||
*pxHigherPriorityTaskWoken = pdTRUE;
|
||||
@ -111,7 +113,7 @@ Queue_t * const pxQueue = xQueue;
|
||||
else
|
||||
{
|
||||
/* Increment the lock count so the task that unlocks the queue
|
||||
knows that data was removed while it was locked. */
|
||||
* knows that data was removed while it was locked. */
|
||||
configASSERT( cRxLock != queueINT8_MAX );
|
||||
|
||||
pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 );
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
NO_COVERAGE=1 EXTRA_VERIFAST_ARGS=-stats make list queue | grep overhead: | sort | uniq
|
||||
NO_COVERAGE=1 EXTRA_VERIFAST_ARGS=-stats make queue | grep overhead: | sort | uniq
|
||||
|
73
FreeRTOS/Test/VeriFast/scripts/extract.py
Executable file
73
FreeRTOS/Test/VeriFast/scripts/extract.py
Executable file
@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Extractor(object):
|
||||
@staticmethod
|
||||
def __parse_ctags(tags_filename):
|
||||
def convert_excmd(excmd):
|
||||
assert excmd.endswith(';"')
|
||||
linenum = excmd[:-2] # remove ';"'
|
||||
return int(linenum)
|
||||
result = {}
|
||||
with open(tags_filename) as f:
|
||||
for line in f:
|
||||
if line.startswith('!'):
|
||||
continue
|
||||
parts = line.split('\t')
|
||||
funcname = parts[0]
|
||||
funcfile = parts[1]
|
||||
linenum = convert_excmd(parts[2])
|
||||
result[funcname] = (funcfile, linenum)
|
||||
return result
|
||||
|
||||
def __init__(self, tags_filename):
|
||||
self.map = Extractor.__parse_ctags(tags_filename)
|
||||
|
||||
class State(Enum):
|
||||
INIT = 0
|
||||
HEAD = 1
|
||||
BODY = 2
|
||||
|
||||
def text_of_funcname(self, funcname):
|
||||
if funcname not in self.map:
|
||||
return []
|
||||
funcfile, linenum = self.map[funcname]
|
||||
result = []
|
||||
state, bracecount = Extractor.State.INIT, 0
|
||||
with open(funcfile) as f:
|
||||
for i, line in enumerate(f, start=1): # ctags counts linenums from 1
|
||||
if state == Extractor.State.INIT and linenum <= i:
|
||||
state = Extractor.State.HEAD
|
||||
if state == Extractor.State.HEAD:
|
||||
result.append(line)
|
||||
lbrace = line.count('{')
|
||||
rbrace = line.count('}')
|
||||
bracecount += lbrace
|
||||
bracecount -= rbrace
|
||||
if '{' in line:
|
||||
state = Extractor.State.BODY
|
||||
continue
|
||||
if state == Extractor.State.BODY:
|
||||
result.append(line)
|
||||
lbrace = line.count('{')
|
||||
rbrace = line.count('}')
|
||||
bracecount += lbrace
|
||||
bracecount -= rbrace
|
||||
if bracecount == 0:
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: %s <tagfile> <funcname>" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
tag_filename = sys.argv[1]
|
||||
funcname = sys.argv[2]
|
||||
extractor = Extractor('tags')
|
||||
result = extractor.text_of_funcname(funcname)
|
||||
print(''.join(result))
|
||||
sys.exit(0)
|
Reference in New Issue
Block a user