summaryrefslogtreecommitdiffstats
path: root/daemon/unit_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/unit_test.c')
-rw-r--r--daemon/unit_test.c87
1 files changed, 72 insertions, 15 deletions
diff --git a/daemon/unit_test.c b/daemon/unit_test.c
index 52b55c4e5..fa3fa847f 100644
--- a/daemon/unit_test.c
+++ b/daemon/unit_test.c
@@ -68,17 +68,36 @@ static int check_number_printing(void) {
{ .n = 0.000000001, .correct = "0" },
{ .n = 99.99999999999999999, .correct = "100" },
{ .n = -99.99999999999999999, .correct = "-100" },
+ { .n = 123.4567899123456789, .correct = "123.4567899" },
{ .n = 123.4567890123456789, .correct = "123.456789" },
+ { .n = 123.4567800123456789, .correct = "123.45678" },
+ { .n = 123.4567000123456789, .correct = "123.4567" },
+ { .n = 123.4560000123456789, .correct = "123.456" },
+ { .n = 123.4500000123456789, .correct = "123.45" },
+ { .n = 123.4000000123456789, .correct = "123.4" },
+ { .n = 123.0000000123456789, .correct = "123" },
+ { .n = 123.0000000923456789, .correct = "123.0000001" },
+ { .n = 4294967295.123456789, .correct = "4294967295.123457" },
+ { .n = 8294967295.123456789, .correct = "8294967295.123457" },
+ { .n = 1.000000000000002e+19, .correct = "1.000000000000001998e+19" },
+ { .n = 9.2233720368547676e+18, .correct = "9.223372036854767584e+18" },
+ { .n = 18446744073709541376.0, .correct = "1.84467440737095424e+19" },
+ { .n = 18446744073709551616.0, .correct = "1.844674407370955136e+19" },
+ { .n = 12318446744073710600192.0, .correct = "1.231844674407371008e+22" },
+ { .n = 1677721499999999885312.0, .correct = "1.677721499999999872e+21" },
+ { .n = -1677721499999999885312.0, .correct = "-1.677721499999999872e+21" },
+ { .n = -1.677721499999999885312e40, .correct = "-1.677721499999999872e+40" },
+ { .n = -16777214999999997337621690403742592008192.0, .correct = "-1.677721499999999616e+40" },
{ .n = 9999.9999999, .correct = "9999.9999999" },
{ .n = -9999.9999999, .correct = "-9999.9999999" },
{ .n = 0, .correct = NULL },
};
- char netdata[50], system[50];
+ char netdata[512 + 2], system[512 + 2];
int i, failed = 0;
for(i = 0; values[i].correct ; i++) {
print_netdata_double(netdata, values[i].n);
- snprintfz(system, 49, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
+ snprintfz(system, 512, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n);
int ok = 1;
if(strcmp(netdata, values[i].correct) != 0) {
@@ -86,7 +105,18 @@ static int check_number_printing(void) {
failed++;
}
- fprintf(stderr, "'%s' (system) printed as '%s' (netdata): %s\n", system, netdata, ok?"OK":"FAILED");
+ NETDATA_DOUBLE parsed_netdata = str2ndd(netdata, NULL);
+ NETDATA_DOUBLE parsed_system = strtondd(netdata, NULL);
+
+ if(parsed_system != parsed_netdata)
+ failed++;
+
+ fprintf(stderr, "[%d]. '%s' (system) printed as '%s' (netdata): PRINT %s, "
+ "PARSED %0.12" NETDATA_DOUBLE_MODIFIER " (system), %0.12" NETDATA_DOUBLE_MODIFIER " (netdata): %s\n",
+ i,
+ system, netdata, ok?"OK":"FAILED",
+ parsed_system, parsed_netdata,
+ parsed_netdata == parsed_system ? "OK" : "FAILED");
}
if(failed) return 1;
@@ -395,9 +425,35 @@ int unit_test_storage() {
}
int unit_test_str2ld() {
+ is_system_ieee754_double();
+
char *values[] = {
- "1.2345678", "-35.6", "0.00123", "23842384234234.2", ".1", "1.2e-10",
- "hello", "1wrong", "nan", "inf", NULL
+ "1.2345678",
+ "-35.6",
+ "0.00123",
+ "23842384234234.2",
+ ".1",
+ "1.2e-10",
+ "18446744073709551616.0",
+ "18446744073709551616123456789123456789123456789123456789123456789123456789123456789.0",
+ "1.8446744073709551616123456789123456789123456789123456789123456789123456789123456789e+300",
+ "9.",
+ "9.e2",
+ "1.2e",
+ "1.2e+",
+ "1.2e-",
+ "1.2e0",
+ "1.2e-0",
+ "1.2e+0",
+ "-1.2e+1",
+ "-1.2e-1",
+ "1.2e1",
+ "1.2e400",
+ "hello",
+ "1wrong",
+ "nan",
+ "inf",
+ NULL
};
int i;
@@ -427,7 +483,8 @@ int unit_test_str2ld() {
}
if(e_mine != e_sys) {
- fprintf(stderr, "Value '%s' is parsed correctly, but endptr is not right\n", values[i]);
+ fprintf(stderr, "Value '%s' is parsed correctly, but endptr is not right (netdata returned %d, but system returned %d)\n",
+ values[i], (int)(e_mine - values[i]), (int)(e_sys - values[i]));
return -1;
}
@@ -1880,7 +1937,7 @@ static time_t test_dbengine_create_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS
// feed it with the test data
for (i = 0 ; i < CHARTS ; ++i) {
for (j = 0 ; j < DIMS ; ++j) {
- rd[i][j]->tiers[0].collect_ops->change_collection_frequency(rd[i][j]->tiers[0].db_collection_handle, update_every);
+ storage_engine_store_change_collection_frequency(rd[i][j]->tiers[0].db_collection_handle, update_every);
rd[i][j]->last_collected_time.tv_sec =
st[i]->last_collected_time.tv_sec = st[i]->last_updated.tv_sec = time_now;
@@ -1931,13 +1988,13 @@ static int test_dbengine_check_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DI
time_now = time_start + (c + 1) * update_every;
for (i = 0 ; i < CHARTS ; ++i) {
for (j = 0; j < DIMS; ++j) {
- rd[i][j]->tiers[0].query_ops->init(rd[i][j]->tiers[0].db_metric_handle, &handle, time_now, time_now + QUERY_BATCH * update_every, STORAGE_PRIORITY_NORMAL);
+ storage_engine_query_init(rd[i][j]->tiers[0].backend, rd[i][j]->tiers[0].db_metric_handle, &handle, time_now, time_now + QUERY_BATCH * update_every, STORAGE_PRIORITY_NORMAL);
for (k = 0; k < QUERY_BATCH; ++k) {
last = ((collected_number)i * DIMS) * REGION_POINTS[current_region] +
j * REGION_POINTS[current_region] + c + k;
expected = unpack_storage_number(pack_storage_number((NETDATA_DOUBLE)last, SN_DEFAULT_FLAGS));
- STORAGE_POINT sp = rd[i][j]->tiers[0].query_ops->next_metric(&handle);
+ STORAGE_POINT sp = storage_engine_query_next_metric(&handle);
value = sp.sum;
time_retrieved = sp.start_time_s;
end_time = sp.end_time_s;
@@ -1959,7 +2016,7 @@ static int test_dbengine_check_metrics(RRDSET *st[CHARTS], RRDDIM *rd[CHARTS][DI
errors++;
}
}
- rd[i][j]->tiers[0].query_ops->finalize(&handle);
+ storage_engine_query_finalize(&handle);
}
}
}
@@ -2327,7 +2384,7 @@ void generate_dbengine_dataset(unsigned history_seconds)
}
freez(thread_info);
rrd_wrlock();
- rrdhost_free___while_having_rrd_wrlock(host, true);
+ rrdhost_free___while_having_rrd_wrlock(localhost, true);
rrd_unlock();
}
@@ -2387,13 +2444,13 @@ static void query_dbengine_chart(void *arg)
time_before = MIN(time_after + duration, time_max); /* up to 1 hour queries */
}
- rd->tiers[0].query_ops->init(rd->tiers[0].db_metric_handle, &handle, time_after, time_before, STORAGE_PRIORITY_NORMAL);
+ storage_engine_query_init(rd->tiers[0].backend, rd->tiers[0].db_metric_handle, &handle, time_after, time_before, STORAGE_PRIORITY_NORMAL);
++thread_info->queries_nr;
for (time_now = time_after ; time_now <= time_before ; time_now += update_every) {
generatedv = generate_dbengine_chart_value(i, j, time_now);
expected = unpack_storage_number(pack_storage_number((NETDATA_DOUBLE) generatedv, SN_DEFAULT_FLAGS));
- if (unlikely(rd->tiers[0].query_ops->is_finished(&handle))) {
+ if (unlikely(storage_engine_query_is_finished(&handle))) {
if (!thread_info->delete_old_data) { /* data validation only when we don't delete */
fprintf(stderr, " DB-engine stresstest %s/%s: at %lu secs, expecting value " NETDATA_DOUBLE_FORMAT
", found data gap, ### E R R O R ###\n",
@@ -2403,7 +2460,7 @@ static void query_dbengine_chart(void *arg)
break;
}
- STORAGE_POINT sp = rd->tiers[0].query_ops->next_metric(&handle);
+ STORAGE_POINT sp = storage_engine_query_next_metric(&handle);
value = sp.sum;
time_retrieved = sp.start_time_s;
end_time = sp.end_time_s;
@@ -2441,7 +2498,7 @@ static void query_dbengine_chart(void *arg)
}
}
}
- rd->tiers[0].query_ops->finalize(&handle);
+ storage_engine_query_finalize(&handle);
} while(!thread_info->done);
if(value_errors)