summaryrefslogtreecommitdiffstats
path: root/src/unit_test.c
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2017-07-27 09:55:47 +0000
committerLennart Weller <lhw@ring0.de>2017-07-27 09:55:47 +0000
commita133c9c3b637b1dbe7b5b053f7e2572c1950cead (patch)
tree2207939a88e96bca329457f40a9d9d18ab659dc1 /src/unit_test.c
parentNew upstream version 1.6.0+dfsg (diff)
downloadnetdata-a133c9c3b637b1dbe7b5b053f7e2572c1950cead.tar.xz
netdata-a133c9c3b637b1dbe7b5b053f7e2572c1950cead.zip
New upstream version 1.7.0+dfsgupstream/1.7.0+dfsg
Diffstat (limited to 'src/unit_test.c')
-rw-r--r--src/unit_test.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/unit_test.c b/src/unit_test.c
index 0866d215c..9b008138f 100644
--- a/src/unit_test.c
+++ b/src/unit_test.c
@@ -17,8 +17,8 @@ int check_storage_number(calculated_number n, int debug) {
if(dcdiff < 0) dcdiff = -dcdiff;
- size_t len = print_calculated_number(buffer, d);
- calculated_number p = str2l(buffer);
+ size_t len = (size_t)print_calculated_number(buffer, d);
+ calculated_number p = str2ld(buffer, NULL);
calculated_number pdiff = n - p;
calculated_number pcdiff = pdiff * 100.0 / n;
if(pcdiff < 0) pcdiff = -pcdiff;
@@ -229,6 +229,45 @@ int unit_test_storage()
return r;
}
+int unit_test_str2ld() {
+ char *values[] = {
+ "1.234567", "-35.6", "0.00123", "23842384234234.2", ".1", "1.2e-10",
+ "hello", "1wrong", "nan", "inf", NULL
+ };
+
+ int i;
+ for(i = 0; values[i] ; i++) {
+ char *e_mine = "hello", *e_sys = "world";
+ long double mine = str2ld(values[i], &e_mine);
+ long double sys = strtold(values[i], &e_sys);
+
+ if(isnan(mine)) {
+ if(!isnan(sys)) {
+ fprintf(stderr, "Value '%s' is parsed as %Lf, but system believes it is %Lf.\n", values[i], mine, sys);
+ return -1;
+ }
+ }
+ else if(isinf(mine)) {
+ if(!isinf(sys)) {
+ fprintf(stderr, "Value '%s' is parsed as %Lf, but system believes it is %Lf.\n", values[i], mine, sys);
+ return -1;
+ }
+ }
+ else if(mine != sys && abs(mine-sys) > 0.000001) {
+ fprintf(stderr, "Value '%s' is parsed as %Lf, but system believes it is %Lf, delta %Lf.\n", values[i], mine, sys, sys-mine);
+ return -1;
+ }
+
+ if(e_mine != e_sys) {
+ fprintf(stderr, "Value '%s' is parsed correctly, but endptr is not right\n", values[i]);
+ return -1;
+ }
+
+ fprintf(stderr, "str2ld() parsed value '%s' exactly the same way with strtold(), returned %Lf vs %Lf\n", values[i], mine, sys);
+ }
+
+ return 0;
+}
// --------------------------------------------------------------------------------------------------------------------
@@ -244,7 +283,7 @@ struct test {
int update_every;
unsigned long long multiplier;
unsigned long long divisor;
- int algorithm;
+ RRD_ALGORITHM algorithm;
unsigned long feed_entries;
unsigned long result_entries;
@@ -884,7 +923,7 @@ int run_test(struct test *test)
{
fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description);
- default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
+ default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
default_rrd_update_every = test->update_every;
char name[101];
@@ -916,7 +955,9 @@ int run_test(struct test *test)
(float)time_now / 1000000.0,
((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor,
(((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor) / (calculated_number)test->feed[c].microseconds * (calculated_number)1000000);
- rrdset_next_usec_unfiltered(st, test->feed[c].microseconds);
+
+ // rrdset_next_usec_unfiltered(st, test->feed[c].microseconds);
+ st->usec_since_last_update = test->feed[c].microseconds;
}
else {
fprintf(stderr, " > %s: feeding position %lu\n", test->name, c+1);
@@ -1091,7 +1132,7 @@ int unit_test(long delay, long shift)
snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
//debug_flags = 0xffffffff;
- default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
+ default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC;
default_rrd_update_every = 1;
int do_abs = 1;
@@ -1125,7 +1166,8 @@ int unit_test(long delay, long shift)
fprintf(stderr, "\n\nLOOP = %lu, DELAY = %ld, VALUE = " COLLECTED_NUMBER_FORMAT "\n", c, delay, i);
if(c) {
- rrdset_next_usec_unfiltered(st, delay);
+ // rrdset_next_usec_unfiltered(st, delay);
+ st->usec_since_last_update = delay;
}
if(do_abs) rrddim_set(st, "absolute", i);
if(do_inc) rrddim_set(st, "incremental", i);