Skip to content

Commit d816608

Browse files
committed
WIP cbmc the normal tests
Get full formal verification of all containers, methods, algos, iterators. size (depth) can be 4, so it should be solvable.
1 parent 8c24174 commit d816608

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

ctl/deque.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,11 @@ static inline I *JOIN(A, insert_count)(I *pos, size_t count, T value)
574574
A *self = pos->container;
575575
// detect overflows, esp. silent signed conversions, like -1
576576
size_t index = pos->index;
577-
if (self->size + count < self->size || index + count < count || self->size + count > JOIN(A, max_size)())
577+
if (self->size + count < self->size || index + count < count
578+
#ifndef CBMC
579+
|| self->size + count > JOIN(A, max_size)()
580+
#endif
581+
)
578582
{
579583
ASSERT(self->size + count >= self->size || !"count overflow");
580584
ASSERT(index + count >= count || !"pos overflow");

tests/func/test_list.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ void print_list(std::list<DIGI> &b)
183183
#define print_list(x)
184184
#define TEST_MAX_VALUE INT_MAX
185185
#endif
186+
#ifdef CBMC
187+
# undef TEST_MAX_SIZE
188+
# undef TEST_MAX_LOOPS
189+
# define TEST_MAX_SIZE 4
190+
# define TEST_MAX_LOOPS 1
191+
#endif
186192

187193
int middle(list_digi *a)
188194
{

tests/test.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88
#include <string.h>
9+
#ifndef CBMC
910
#include <time.h>
1011
#ifndef _WIN32
1112
#include <sys/time.h>
@@ -21,6 +22,7 @@
2122
#endif
2223
#undef NDEBUG
2324
#include <assert.h>
25+
#endif
2426

2527
// deprecated in clang with C++14
2628
#if defined _LIBCPP_STD_VER && __cplusplus < 201402L
@@ -42,6 +44,7 @@
4244
#define CLANG_DIAG_RESTORE
4345
#endif
4446

47+
#ifndef CBMC
4548
#define POD
4649
#define T int
4750
#include <ctl/queue.h>
@@ -52,6 +55,7 @@ typedef uint16_t u16;
5255
#define INCLUDE_ALGORITHM
5356
#define INCLUDE_NUMERIC
5457
#include <ctl/string.h>
58+
#endif
5559

5660
// coverage counter for generic_iter: bitmask of 3 values
5761
union gen_cov_u {
@@ -64,13 +68,13 @@ union gen_cov_u {
6468
};
6569

6670
#ifdef LONG
67-
#define TEST_MAX_SIZE (4096)
71+
#define TEST_MAX_SIZE 4096
6872
#undef TEST_MAX_LOOPS
69-
#define TEST_MAX_LOOPS (8096)
73+
#define TEST_MAX_LOOPS 8096
7074
#else
71-
#define TEST_MAX_SIZE (512)
75+
#define TEST_MAX_SIZE 512
7276
#ifndef TEST_MAX_LOOPS
73-
# define TEST_MAX_LOOPS (512)
77+
# define TEST_MAX_LOOPS 512
7478
#endif
7579
#endif
7680

@@ -79,7 +83,16 @@ union gen_cov_u {
7983
#define TEST_PASS(f) printf("%s: PASS\n", f)
8084
#define TEST_FAIL(f) printf("%s: FAIL\n", f)
8185

86+
#ifndef CBMC
8287
#define TEST_RAND(max) (((max) == 0) ? 0 : (int)(rand() % (max)))
88+
#else
89+
# define DEQ_BUCKET_SIZE 4
90+
# undef TEST_MAX_SIZE
91+
# undef TEST_MAX_LOOPS
92+
# define TEST_MAX_SIZE 4
93+
# define TEST_MAX_LOOPS 1
94+
# define TEST_RAND(max) (((max) == 0) ? 0 : nondet_int())
95+
#endif
8396

8497
#define TEST_PERF_RUNS (100)
8598
#define TEST_PERF_CHUNKS (256)
@@ -116,6 +129,7 @@ static inline long TEST_TIME(void)
116129
#define INIT_SRAND const unsigned int seed = 0;
117130
#endif
118131

132+
#ifndef CBMC
119133
#define INIT_TEST_LOOPS(n, generic) \
120134
unsigned loops = TEST_TOTAL + TEST_RAND(TEST_MAX_LOOPS - TEST_TOTAL); \
121135
vec_u16 covvec = vec_u16_init(); \
@@ -138,7 +152,14 @@ static inline long TEST_TIME(void)
138152
sscanf(env, "%u", &loops); \
139153
} \
140154
loops:
155+
#else
156+
#define INIT_TEST_LOOPS(n, generic) \
157+
unsigned loops = TEST_TOTAL; \
158+
static int test = -1;
159+
#define FINISH_TEST(FILE)
160+
#endif
141161

162+
#ifndef CBMC
142163
#define RECORD_WHICH covvec.vector[(u16)which]++
143164

144165
/* check if we covered all tests. If not redo the missing tests. */
@@ -289,7 +310,8 @@ void parse_TEST(char *env, int *test, queue_int *tests, const int number_ok, boo
289310
str_free(&alts);
290311
}
291312

292-
#endif
313+
#endif // CBMC
314+
#endif // TEST_H
293315

294316
#ifndef MAX
295317
#define MAX(a, b) (a) > (b) ? (a) : (b)

0 commit comments

Comments
 (0)