mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Add check for tests
This commit is contained in:
parent
790064be7f
commit
b7053cafdf
104
src/contacts.c
104
src/contacts.c
@ -57,6 +57,10 @@ int register_record(record_t* record) {
|
|||||||
int get_number_of_infected_for_multiple_intervals_simple(infected_for_interval_ident_ctx_t* ctx, int count) {
|
int get_number_of_infected_for_multiple_intervals_simple(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
record_iterator_t iterator;
|
record_iterator_t iterator;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (!ctx[i].met) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ctx[i].met = 0;
|
||||||
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
|
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
// on error, skip this rpi
|
// on error, skip this rpi
|
||||||
@ -66,7 +70,7 @@ int get_number_of_infected_for_multiple_intervals_simple(infected_for_interval_i
|
|||||||
while ((current = ens_records_iterator_next(&iterator))) {
|
while ((current = ens_records_iterator_next(&iterator))) {
|
||||||
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
||||||
sizeof(rolling_proximity_identifier_t)) == 0) {
|
sizeof(rolling_proximity_identifier_t)) == 0) {
|
||||||
ctx[i].infected++;
|
ctx[i].met++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,23 +111,12 @@ int64_t bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
|||||||
// test bloom performance
|
// test bloom performance
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (bloom_probably_has_record(bloom, &ctx[i].interval_identifier)) {
|
if (bloom_probably_has_record(bloom, &ctx[i].interval_identifier)) {
|
||||||
ctx[i].infected++;
|
ctx[i].met++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy infected records to start of array
|
|
||||||
int amount = 0;
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
if (ctx[i].infected) {
|
|
||||||
memcpy(&ctx[amount], &ctx[i], sizeof(ctx[i]));
|
|
||||||
amount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = get_number_of_infected_for_multiple_intervals_simple(ctx, amount);
|
|
||||||
|
|
||||||
bloom_destroy(bloom);
|
bloom_destroy(bloom);
|
||||||
return ret;
|
|
||||||
|
return get_number_of_infected_for_multiple_intervals_simple(ctx, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
@ -134,9 +127,12 @@ static ENPeriodKey infectedPeriodKey = {
|
|||||||
.b = {0x75, 0xc7, 0x34, 0xc6, 0xdd, 0x1a, 0x78, 0x2d, 0xe7, 0xa9, 0x65, 0xda, 0x5e, 0xb9, 0x31, 0x25}};
|
.b = {0x75, 0xc7, 0x34, 0xc6, 0xdd, 0x1a, 0x78, 0x2d, 0xe7, 0xa9, 0x65, 0xda, 0x5e, 0xb9, 0x31, 0x25}};
|
||||||
static ENPeriodKey dummyPeriodKey = {
|
static ENPeriodKey dummyPeriodKey = {
|
||||||
.b = {0x89, 0xa7, 0x34, 0xc6, 0xdd, 0x1a, 0x14, 0xda, 0xe7, 0x00, 0x65, 0xda, 0x6a, 0x9b, 0x13, 0x52}};
|
.b = {0x89, 0xa7, 0x34, 0xc6, 0xdd, 0x1a, 0x14, 0xda, 0xe7, 0x00, 0x65, 0xda, 0x6a, 0x9b, 0x13, 0x52}};
|
||||||
|
static ENPeriodKey testKey = {
|
||||||
|
.b = {0x89, 0xa7, 0x72, 0xc6, 0xdd, 0x10, 0x14, 0xda, 0xe7, 0x00, 0x65, 0xda, 0x8a, 0x9b, 0x13, 0x52}};
|
||||||
|
|
||||||
static ENPeriodIdentifierKey infectedPik;
|
static ENPeriodIdentifierKey infectedPik;
|
||||||
static ENPeriodIdentifierKey dummyPik;
|
static ENPeriodIdentifierKey dummyPik;
|
||||||
|
static ENPeriodIdentifierKey testPik;
|
||||||
|
|
||||||
void fill_test_rki_data(infected_for_interval_ident_ctx_t* infectedIntervals, int count) {
|
void fill_test_rki_data(infected_for_interval_ident_ctx_t* infectedIntervals, int count) {
|
||||||
int totalTime = EN_TEK_ROLLING_PERIOD * EN_INTERVAL_LENGTH;
|
int totalTime = EN_TEK_ROLLING_PERIOD * EN_INTERVAL_LENGTH;
|
||||||
@ -144,7 +140,7 @@ void fill_test_rki_data(infected_for_interval_ident_ctx_t* infectedIntervals, in
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
int intervalNumber = (i * stepSize) / EN_INTERVAL_LENGTH;
|
int intervalNumber = (i * stepSize) / EN_INTERVAL_LENGTH;
|
||||||
en_derive_interval_identifier(&infectedIntervals[i].interval_identifier, &infectedPik, intervalNumber);
|
en_derive_interval_identifier(&infectedIntervals[i].interval_identifier, &infectedPik, intervalNumber);
|
||||||
infectedIntervals[i].infected = 0;
|
infectedIntervals[i].met = 0;
|
||||||
infectedIntervals[i].search_start = i < 3 ? 0 : (i - 2) * stepSize;
|
infectedIntervals[i].search_start = i < 3 ? 0 : (i - 2) * stepSize;
|
||||||
infectedIntervals[i].search_end = (i + 2) * stepSize;
|
infectedIntervals[i].search_end = (i + 2) * stepSize;
|
||||||
}
|
}
|
||||||
@ -154,13 +150,15 @@ void fill_test_rki_data(infected_for_interval_ident_ctx_t* infectedIntervals, in
|
|||||||
// MEASURING FUNC //
|
// MEASURING FUNC //
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
||||||
void measure_perf(test_func_t func,
|
void measure_perf(infected_for_interval_ident_ctx_t testIntervals[], int count) {
|
||||||
const char* label,
|
const char* label = "bloom filter";
|
||||||
infected_for_interval_ident_ctx_t* infectedIntervals,
|
|
||||||
int count) {
|
|
||||||
printk("---------------------------\n'%s': starting measurement\n", label);
|
printk("---------------------------\n'%s': starting measurement\n", label);
|
||||||
|
|
||||||
fill_test_rki_data(infectedIntervals, count);
|
// fill_test_rki_data(infectedIntervals, count);
|
||||||
|
|
||||||
|
// setup our ordered array with met RPIs
|
||||||
|
printk("Starting measurements with %d RPIs to seach and an infection rate of %d\n", count,
|
||||||
|
CONFIG_TEST_INFECTED_RATE);
|
||||||
|
|
||||||
timing_t start_time, end_time;
|
timing_t start_time, end_time;
|
||||||
uint64_t total_cycles;
|
uint64_t total_cycles;
|
||||||
@ -170,7 +168,7 @@ void measure_perf(test_func_t func,
|
|||||||
timing_start();
|
timing_start();
|
||||||
start_time = timing_counter_get();
|
start_time = timing_counter_get();
|
||||||
|
|
||||||
func(infectedIntervals, count);
|
check_possible_contacts_for_intervals(testIntervals, count);
|
||||||
|
|
||||||
end_time = timing_counter_get();
|
end_time = timing_counter_get();
|
||||||
|
|
||||||
@ -182,6 +180,27 @@ void measure_perf(test_func_t func,
|
|||||||
printk("\n'%s' took %lld ms\n---------------------------\n", label, total_ns / 1000000);
|
printk("\n'%s' took %lld ms\n---------------------------\n", label, total_ns / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check_results(infected_for_interval_ident_ctx_t testIntervals[], int count) {
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < count / 2; i++) {
|
||||||
|
counter += CONFIG_TEST_RECORDS_PER_INTERVAL * CONFIG_TEST_INFECTED_RATE;
|
||||||
|
int met = counter / 100;
|
||||||
|
counter %= 100;
|
||||||
|
if (testIntervals[i].met != met) {
|
||||||
|
printk("interval %d should have been met %d times (met %d)\n", i, met, testIntervals[i].met);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = count / 2; j < count; j++) {
|
||||||
|
if (testIntervals[j].met) {
|
||||||
|
printk("infected interval should not have been met (interval %d)\n", j);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printk("all results are as expected!\n");
|
||||||
|
}
|
||||||
|
|
||||||
int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
||||||
bloom_filter_t* bloom = bloom_init(count * 2);
|
bloom_filter_t* bloom = bloom_init(count * 2);
|
||||||
if (!bloom) {
|
if (!bloom) {
|
||||||
@ -194,14 +213,13 @@ int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
|||||||
bloom_add_record(bloom, &ctx[i].interval_identifier);
|
bloom_add_record(bloom, &ctx[i].interval_identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t amount = 0;
|
int rc = 0;
|
||||||
|
|
||||||
// init iterator over the entire storage
|
// init iterator over the entire storage
|
||||||
record_iterator_t iterator;
|
record_iterator_t iterator;
|
||||||
int rc = ens_records_iterator_init_timerange(&iterator, NULL, NULL);
|
rc = ens_records_iterator_init_timerange(&iterator, NULL, NULL);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
printk("init iterator failed (err %d)\n", rc);
|
printk("init iterator failed (err %d)\n", rc);
|
||||||
amount = rc;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +229,7 @@ int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
if (memcmp(&(current->rolling_proximity_identifier), &ctx[i].interval_identifier,
|
||||||
sizeof(current->rolling_proximity_identifier)) == 0) {
|
sizeof(current->rolling_proximity_identifier)) == 0) {
|
||||||
ctx[i].infected = 1;
|
ctx[i].met++;
|
||||||
amount++;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,16 +238,17 @@ int reverse_bloom_filter(infected_for_interval_ident_ctx_t* ctx, int count) {
|
|||||||
cleanup:
|
cleanup:
|
||||||
// destroy bloom filter after things are finished
|
// destroy bloom filter after things are finished
|
||||||
bloom_destroy(bloom);
|
bloom_destroy(bloom);
|
||||||
return amount;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// SETUP DATA //
|
// SETUP DATA //
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
||||||
void setup_test_data() {
|
void setup_test_data(infected_for_interval_ident_ctx_t testIntervals[], int count) {
|
||||||
en_derive_period_identifier_key(&infectedPik, &infectedPeriodKey);
|
en_derive_period_identifier_key(&infectedPik, &infectedPeriodKey);
|
||||||
en_derive_period_identifier_key(&dummyPik, &dummyPeriodKey);
|
en_derive_period_identifier_key(&dummyPik, &dummyPeriodKey);
|
||||||
|
en_derive_period_identifier_key(&testPik, &testKey);
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (int i = 0; i < EN_TEK_ROLLING_PERIOD; i++) {
|
for (int i = 0; i < EN_TEK_ROLLING_PERIOD; i++) {
|
||||||
@ -257,21 +274,30 @@ void setup_test_data() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < count / 2; i++) {
|
||||||
|
en_derive_interval_identifier(&testIntervals[i].interval_identifier, &infectedPik, i);
|
||||||
|
testIntervals[i].met = 0;
|
||||||
|
testIntervals[i].search_start = MAX(0, (i * EN_INTERVAL_LENGTH - 2 * 60 * 60));
|
||||||
|
testIntervals[i].search_end = i * EN_INTERVAL_LENGTH + 2 * 60 * 60;
|
||||||
|
|
||||||
|
int j = i + count / 2;
|
||||||
|
en_derive_interval_identifier(&testIntervals[j].interval_identifier, &testPik, i);
|
||||||
|
testIntervals[j].met = 0;
|
||||||
|
testIntervals[j].search_start = MAX(0, (i * EN_INTERVAL_LENGTH - 2 * 60 * 60));
|
||||||
|
testIntervals[j].search_end = i * EN_INTERVAL_LENGTH + 2 * 60 * 60;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_contacts() {
|
int init_contacts() {
|
||||||
#if CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST
|
#if CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST
|
||||||
|
static infected_for_interval_ident_ctx_t testIntervals[EN_TEK_ROLLING_PERIOD * 2];
|
||||||
|
|
||||||
reset_record_storage();
|
reset_record_storage();
|
||||||
setup_test_data();
|
setup_test_data(testIntervals, EN_TEK_ROLLING_PERIOD * 2);
|
||||||
|
|
||||||
// setup our ordered array with infected RPIs
|
measure_perf(testIntervals, EN_TEK_ROLLING_PERIOD * 2);
|
||||||
static infected_for_interval_ident_ctx_t infectedIntervals[CONFIG_CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT];
|
check_results(testIntervals, EN_TEK_ROLLING_PERIOD * 2);
|
||||||
|
|
||||||
printk("Starting measurements with %d RPIs to seach and an infection rate of %d\n",
|
|
||||||
CONFIG_CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT, CONFIG_TEST_INFECTED_RATE);
|
|
||||||
|
|
||||||
measure_perf(check_possible_contacts_for_intervals, "bloom filter", infectedIntervals,
|
|
||||||
CONFIG_CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT);
|
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ENIntervalIdentifier interval_identifier;
|
ENIntervalIdentifier interval_identifier;
|
||||||
int infected;
|
int met;
|
||||||
time_t search_start;
|
time_t search_start;
|
||||||
time_t search_end;
|
time_t search_end;
|
||||||
} __packed infected_for_interval_ident_ctx_t;
|
} __packed infected_for_interval_ident_ctx_t;
|
||||||
|
@ -49,7 +49,7 @@ config CONTACTS_RISC_CHECK_TEST_PUBLIC_INTERVAL_COUNT
|
|||||||
help
|
help
|
||||||
Amount of interval identifiers to test against stored test data.
|
Amount of interval identifiers to test against stored test data.
|
||||||
|
|
||||||
config CONFIG_CONTACTS_BLOOM_REVERSE
|
config CONTACTS_BLOOM_REVERSE
|
||||||
bool ""
|
bool ""
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
|
@ -47,4 +47,7 @@ CONFIG_LOG=y
|
|||||||
# # Run protobuf unpack tests at startup
|
# # Run protobuf unpack tests at startup
|
||||||
# CONFIG_TEST_UNPACK_KEYS_N=12
|
# CONFIG_TEST_UNPACK_KEYS_N=12
|
||||||
# CONFIG_TEST_UNPACK_KEYS=y
|
# CONFIG_TEST_UNPACK_KEYS=y
|
||||||
|
|
||||||
|
# # Run bloom filter tests at startup
|
||||||
# CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST=y
|
# CONFIG_CONTACTS_PERFORM_RISC_CHECK_TEST=y
|
||||||
|
# CONFIG_CONTACTS_BLOOM_REVERSE=y
|
||||||
|
Loading…
Reference in New Issue
Block a user