2009-04-14 20:21:05 +00:00
|
|
|
#include "../check_includes.h"
|
2007-02-06 02:32:01 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
#include <stasis/transactional.h>
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/io/rangeTracker.h>
|
2011-08-31 19:25:09 +00:00
|
|
|
#include <stasis/util/random.h>
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
#include <assert.h>
|
2007-01-25 22:38:22 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
#define LOG_NAME "check_rangeTracker.log"
|
|
|
|
#define QUANTIZATION 7
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
void rangeTrackerFreeRet(range ** ret) {
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; ret[i]; i++) {
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ret[i]);
|
|
|
|
}
|
|
|
|
free(ret);
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
void printRT(rangeTracker * rt) {
|
2007-01-25 22:38:22 +00:00
|
|
|
const transition ** ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
int i = 0;
|
|
|
|
printf("Range tracker:\n");
|
2009-04-14 20:21:05 +00:00
|
|
|
while(ts[i]) {
|
2007-01-24 01:03:52 +00:00
|
|
|
printf("%s\n", transitionToString(ts[i]));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
free (ts);
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
void check_no_overlap(range * r, int * explicit_pins) {
|
2007-02-12 07:54:32 +00:00
|
|
|
for(int j = r->start; j < r->stop; j++) {
|
|
|
|
assert(!explicit_pins[j]);
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
void check_overlap(range * r, int * explicit_pins) {
|
2007-02-12 07:54:32 +00:00
|
|
|
assert(!(r->start % QUANTIZATION));
|
|
|
|
assert(!(r->stop % QUANTIZATION));
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-02-12 07:54:32 +00:00
|
|
|
int overlap = 0;
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int j = r->start; j < r->stop; j++) {
|
2007-02-12 07:54:32 +00:00
|
|
|
if(explicit_pins[j]) { overlap = 1; }
|
2009-04-14 20:21:05 +00:00
|
|
|
if(! (j+1 % QUANTIZATION)) {
|
2007-02-12 07:54:32 +00:00
|
|
|
assert(overlap);
|
|
|
|
overlap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 01:03:52 +00:00
|
|
|
START_TEST(rangeTracker_smokeTest) {
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTracker * rt = rangeTrackerInit(QUANTIZATION);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
const transition ** ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
assert(ts[0] == 0);
|
|
|
|
|
|
|
|
free(ts);
|
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
|
|
|
|
|
|
|
range r;
|
|
|
|
r.start = 10;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 100;
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerAdd(rt, &r));
|
|
|
|
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111|11111111111111|1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 100&& ts[1]->delta == -1 && ts[1]->pins == 1 && !ts[2]);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
|
|
|
|
2007-01-24 01:03:52 +00:00
|
|
|
r.start = 20;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 80;
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111| |1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 20 && ts[1]->delta == -1 && ts[1]->pins == 1 &&
|
|
|
|
ts[2]->pos == 80 && ts[2]->delta == 1 && ts[2]->pins == 0 &&
|
|
|
|
ts[3]->pos == 100&& ts[3]->delta == -1 && ts[3]->pins == 1 && !ts[4]);
|
|
|
|
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerAdd(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111|11111111111111|1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 100&& ts[1]->delta == -1 && ts[1]->pins == 1 && !ts[2]);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerAdd(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111|22222222222222|1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 20 && ts[1]->delta == 1 && ts[1]->pins == 1 &&
|
|
|
|
ts[2]->pos == 80 && ts[2]->delta == -1 && ts[2]->pins == 2 &&
|
|
|
|
ts[3]->pos == 100&& ts[3]->delta == -1 && ts[3]->pins == 1 && !ts[4]);
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111|11111111111111|1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 100&& ts[1]->delta == -1 && ts[1]->pins == 1 && !ts[2]);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
|
|
|
|
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111| |1111|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 20 && ts[1]->delta == -1 && ts[1]->pins == 1 &&
|
|
|
|
ts[2]->pos == 80 && ts[2]->delta == 1 && ts[2]->pins == 0 &&
|
|
|
|
ts[3]->pos == 100&& ts[3]->delta == -1 && ts[3]->pins == 1 && !ts[4]);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-24 01:03:52 +00:00
|
|
|
r.start = 80;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 90;
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerAdd(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111| |2222|111|
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 20 && ts[1]->delta == -1 && ts[1]->pins == 1 &&
|
|
|
|
ts[2]->pos == 80 && ts[2]->delta == 2 && ts[2]->pins == 0 &&
|
|
|
|
ts[3]->pos == 90 && ts[3]->delta == -1 && ts[3]->pins == 2 &&
|
|
|
|
ts[4]->pos == 100&& ts[4]->delta == -1 && ts[4]->pins == 1 && !ts[5]);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-24 01:03:52 +00:00
|
|
|
r.start = 80;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 100;
|
2007-02-06 02:32:01 +00:00
|
|
|
|
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// |1111| |1111| |
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 10 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 20 && ts[1]->delta == -1 && ts[1]->pins == 1 &&
|
|
|
|
ts[2]->pos == 80 && ts[2]->delta == 1 && ts[2]->pins == 0 &&
|
|
|
|
ts[3]->pos == 90 && ts[3]->delta == -1 && ts[3]->pins == 1 && !ts[4]);
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-24 01:03:52 +00:00
|
|
|
r.start = 10;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 20;
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// | | |1111| |
|
|
|
|
// | | | | |
|
|
|
|
|
|
|
|
|
|
|
|
assert(ts[0]->pos == 80 && ts[0]->delta == 1 && ts[0]->pins == 0 &&
|
|
|
|
ts[1]->pos == 90 && ts[1]->delta == -1 && ts[1]->pins == 1 && !ts[2]);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
r.start = 80;
|
2007-01-25 22:38:22 +00:00
|
|
|
r.stop = 90;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTrackerFreeRet(rangeTrackerRemove(rt, &r));
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
// printRT(rt);
|
2007-01-25 22:38:22 +00:00
|
|
|
ts = rangeTrackerEnumerate(rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
// 10 20 80 90 100
|
2007-01-24 01:03:52 +00:00
|
|
|
// | | | | |
|
|
|
|
// | | | | |
|
|
|
|
// | | | | |
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(!ts[0]);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(ts);
|
|
|
|
|
2007-01-24 01:03:52 +00:00
|
|
|
rangeTrackerDeinit(rt);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
#define RANGE_SIZE 1000
|
2007-02-06 02:32:01 +00:00
|
|
|
#define ITERATIONS 10000 //1000
|
|
|
|
#define RANGE_COUNT 1000 // 100
|
2009-04-14 20:21:05 +00:00
|
|
|
void randomRange(range * r) {
|
2011-08-31 19:25:09 +00:00
|
|
|
long start = stasis_util_random64(RANGE_SIZE-1);
|
|
|
|
long len = 1+stasis_util_random64(RANGE_SIZE - start - 1);
|
2007-01-25 22:38:22 +00:00
|
|
|
|
|
|
|
r->start = start;
|
|
|
|
r->stop = start + len;
|
|
|
|
assert(r->start < RANGE_SIZE);
|
|
|
|
assert(r->stop < RANGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkRangeTrackerConsistency(rangeTracker * rt) {
|
|
|
|
const transition ** t = rangeTrackerEnumerate(rt);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
int pins = 0;
|
|
|
|
long pos = -1;
|
|
|
|
int i = 0;
|
2009-04-14 20:21:05 +00:00
|
|
|
while(t[i]) {
|
2007-01-25 22:38:22 +00:00
|
|
|
|
|
|
|
assert(pos < t[i]->pos);
|
|
|
|
assert(pins == t[i]->pins);
|
|
|
|
assert(pins >= 0);
|
|
|
|
assert(t[i]->delta);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
pos = t[i]->pos;
|
|
|
|
pins += t[i]->delta;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
i++;
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
assert(pins == 0);
|
|
|
|
|
|
|
|
free(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
START_TEST (rangeTracker_randomTest) {
|
2007-01-25 22:38:22 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
struct timeval time;
|
2007-01-25 22:38:22 +00:00
|
|
|
|
|
|
|
gettimeofday(&time,0);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-02-12 07:18:14 +00:00
|
|
|
int * explicit_pins = calloc(RANGE_SIZE, sizeof(int));
|
|
|
|
|
2007-03-03 01:56:05 +00:00
|
|
|
long seed = time.tv_usec + time.tv_sec * 1000000; //1170807889195512; //time.tv_usec + time.tv_sec * 1000000; //1170729550013502; //time.tv_usec + time.tv_sec * 1000000;// 1170727703805787; // 1170810757441165; 1170811024737237; 1171329519584370;
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
printf("\nSeed = %ld\n", seed);
|
|
|
|
srandom(seed);
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
range ** r_arry;
|
2007-01-25 22:38:22 +00:00
|
|
|
range * ranges = malloc(sizeof(range) * RANGE_COUNT);
|
|
|
|
int * pins = calloc(RANGE_COUNT, sizeof(int));
|
2007-02-06 02:32:01 +00:00
|
|
|
rangeTracker * rt = rangeTrackerInit(QUANTIZATION);
|
2009-04-14 20:21:05 +00:00
|
|
|
for(long i = 0; i < RANGE_COUNT; i++) {
|
2007-01-25 22:38:22 +00:00
|
|
|
randomRange(&(ranges[i]));
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
char * s;
|
2007-01-25 22:38:22 +00:00
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(long i = 0; i < ITERATIONS; i++) {
|
|
|
|
|
2011-08-31 19:25:09 +00:00
|
|
|
int range = stasis_util_random64(RANGE_COUNT);
|
|
|
|
switch(stasis_util_random64(3)) {
|
2007-01-25 22:38:22 +00:00
|
|
|
case 0: { // add range
|
2007-02-06 02:32:01 +00:00
|
|
|
s = rangeToString(&ranges[range]);
|
2007-02-12 07:54:32 +00:00
|
|
|
// printf("pin %s\n", s);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(s);
|
|
|
|
r_arry = rangeTrackerAdd(rt, &ranges[range]);
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-12 07:54:32 +00:00
|
|
|
check_no_overlap(r_arry[i], explicit_pins);
|
2007-02-12 07:18:14 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = ranges[range].start; i < ranges[range].stop; i++) {
|
2007-02-12 07:18:14 +00:00
|
|
|
explicit_pins[i]++;
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-06 02:32:01 +00:00
|
|
|
s = rangeToString(r_arry[i]);
|
2007-02-12 07:54:32 +00:00
|
|
|
// printf(" add returned %s\n", s);
|
|
|
|
|
|
|
|
check_overlap(r_arry[i], explicit_pins);
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(r_arry[i]->start >=
|
2007-02-12 07:54:32 +00:00
|
|
|
rangeTrackerRoundDown(ranges[range].start, QUANTIZATION));
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(r_arry[i]->stop <=
|
2007-02-12 07:54:32 +00:00
|
|
|
rangeTrackerRoundUp(ranges[range].stop, QUANTIZATION));
|
2007-02-06 02:32:01 +00:00
|
|
|
free(s);
|
|
|
|
free(r_arry[i]);
|
|
|
|
}
|
|
|
|
free(r_arry);
|
2007-01-25 22:38:22 +00:00
|
|
|
pins[range]++;
|
|
|
|
checkRangeTrackerConsistency(rt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: { // del range
|
2009-04-14 20:21:05 +00:00
|
|
|
if(pins[range]) {
|
2007-02-06 02:32:01 +00:00
|
|
|
s = rangeToString(&ranges[range]);
|
2007-02-12 07:54:32 +00:00
|
|
|
// printf("unpin %s\n", s);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(s);
|
|
|
|
r_arry = rangeTrackerRemove(rt, &ranges[range]);
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-12 07:54:32 +00:00
|
|
|
check_overlap(r_arry[i], explicit_pins);
|
|
|
|
}
|
2007-02-12 07:18:14 +00:00
|
|
|
for(int i = ranges[range].start; i < ranges[range].stop; i++) {
|
|
|
|
explicit_pins[i]--;
|
|
|
|
assert(explicit_pins[i] >= 0);
|
|
|
|
}
|
|
|
|
// return value should no longer overlap pins.
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-12 07:54:32 +00:00
|
|
|
check_no_overlap(r_arry[i], explicit_pins);
|
|
|
|
// for(int j = r_arry[i]->start; j < r_arry[i]->stop; j++) {
|
|
|
|
// assert(!explicit_pins[j]);
|
|
|
|
// }
|
2007-02-06 02:32:01 +00:00
|
|
|
s = rangeToString(r_arry[i]);
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(r_arry[i]->start >=
|
2007-02-12 07:54:32 +00:00
|
|
|
rangeTrackerRoundDown(ranges[range].start, QUANTIZATION));
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(r_arry[i]->stop <=
|
2007-02-12 07:54:32 +00:00
|
|
|
rangeTrackerRoundUp(ranges[range].stop, QUANTIZATION));
|
|
|
|
// printf(" del returned %s\n", s);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(s);
|
|
|
|
free(r_arry[i]);
|
|
|
|
}
|
|
|
|
free(r_arry);
|
2007-01-25 22:38:22 +00:00
|
|
|
pins[range]--;
|
|
|
|
}
|
|
|
|
checkRangeTrackerConsistency(rt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: { // change range
|
2011-08-31 19:25:09 +00:00
|
|
|
if(!stasis_util_random64(100)) {
|
2009-04-14 20:21:05 +00:00
|
|
|
for(long i = 0; i < RANGE_COUNT; i++) {
|
|
|
|
if(!pins[i]) {
|
2007-02-06 02:32:01 +00:00
|
|
|
randomRange(&ranges[i]);
|
|
|
|
}
|
2007-01-25 22:38:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
default:
|
2007-01-25 22:38:22 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
|
|
|
for(long i = 0; i < RANGE_COUNT; i++) {
|
|
|
|
while(pins[i]) {
|
2007-02-06 02:32:01 +00:00
|
|
|
s = rangeToString(&ranges[i]);
|
2007-02-12 07:54:32 +00:00
|
|
|
// printf("unpin %s\n", s);
|
2007-02-06 02:32:01 +00:00
|
|
|
free(s);
|
|
|
|
range ** r_arry = rangeTrackerRemove(rt, &ranges[i]);
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-12 07:54:32 +00:00
|
|
|
check_overlap(r_arry[i], explicit_pins);
|
|
|
|
}
|
2007-02-12 07:18:14 +00:00
|
|
|
for(int j = ranges[i].start; j < ranges[i].stop; j++) {
|
|
|
|
explicit_pins[j]--;
|
|
|
|
assert(explicit_pins[j] >= 0);
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i = 0; r_arry[i]; i++) {
|
2007-02-12 07:18:14 +00:00
|
|
|
s = rangeToString(r_arry[i]);
|
2007-02-12 07:54:32 +00:00
|
|
|
// printf(" del returned %s\n", s);
|
|
|
|
check_no_overlap(r_arry[i], explicit_pins);
|
2007-02-12 07:18:14 +00:00
|
|
|
free(s);
|
|
|
|
free(r_arry[i]);
|
|
|
|
}
|
|
|
|
free(r_arry);
|
2007-01-25 22:38:22 +00:00
|
|
|
pins[i]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
for(int i =0 ; i < RANGE_SIZE; i++ ) {
|
2007-02-12 07:18:14 +00:00
|
|
|
assert(explicit_pins[i] == 0);
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:32:01 +00:00
|
|
|
free (ranges);
|
|
|
|
free (pins);
|
2007-01-25 22:38:22 +00:00
|
|
|
rangeTrackerDeinit(rt);
|
|
|
|
|
|
|
|
} END_TEST
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
/**
|
2007-01-24 01:03:52 +00:00
|
|
|
Add suite declarations here
|
|
|
|
*/
|
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("rangeTracker");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("rangeTracker");
|
|
|
|
tcase_set_timeout(tc, 600); // ten minute timeout
|
|
|
|
|
|
|
|
/* Sub tests are added, one per line, here */
|
|
|
|
tcase_add_test(tc, rangeTracker_smokeTest);
|
2007-01-25 22:38:22 +00:00
|
|
|
tcase_add_test(tc, rangeTracker_randomTest);
|
2007-01-24 01:03:52 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------- */
|
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|