Skip to content

Commit

Permalink
Add Duff's device
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-cs committed Feb 2, 2024
1 parent e656e9a commit 899dace
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
44 changes: 44 additions & 0 deletions regression/cbmc/loop-duffs-device/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <assert.h>
#include <stdint.h>
#include <stdio.h>

#define ARRAYMAX 256

uint8_t *strndfy (uint8_t *dest, const uint8_t *src, size_t n) {
int i = 0;
int j = 0;

switch (n & 0x3) {
do {
case 0 : dest[i++] = src[j++];
case 1 : dest[i++] = src[j++];
case 2 : dest[i++] = src[j++];
case 3 : dest[i++] = src[j++];
} while (j < n);
}

return dest;
}


int main (int argc, char **argv) {
uint8_t src[ARRAYMAX];
uint8_t dest[ARRAYMAX];

int length = 0;
scanf("%u", &length);

if (length <= ARRAYMAX) {
for (int i = 0; i < length; ++i) {
src[i] = (uint8_t)i;
}

strndfy(dest, src, length);

for (int i = 0; i < length; ++i) {
assert(dest[i] == (uint8_t)i);
}
}

return 0;
}
12 changes: 12 additions & 0 deletions regression/cbmc/loop-duffs-device/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--unwind 257
^EXIT=0$
^SIGNAL=0$
^\[main.assertion.\d+\] line \d+ assertion 0: SUCCESS$
^\[main.assertion.\d+\] line \d+ assertion history == 0: SUCCESS$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
This checks whether Duff's device is handled correctly.

0 comments on commit 899dace

Please sign in to comment.