diff options
author | Markos Fountoulakis <44345837+mfundul@users.noreply.github.com> | 2019-10-30 15:38:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-30 15:38:46 +0200 |
commit | 69e5e128f6c42e9bdfbe18e0725e4ea91f9f6950 (patch) | |
tree | 19703c72ca1aeea3e1eb9ef91a08a75f103320ec /daemon | |
parent | c5487e20d8d591d2f9d6e141cc738f9cdb9a2e32 (diff) |
Fix counter reset detection (#7220)
* Removed support for 16-bit and 8-bit counter overflow
* Improve behaviour of counter overflow detection versus counter resets.
* Added support for signed 32-bit and 64-bit limits for counter overflows.
* Fixed signed incremental counter issues and added unit tests.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/unit_test.c | 172 |
1 files changed, 40 insertions, 132 deletions
diff --git a/daemon/unit_test.c b/daemon/unit_test.c index 31718eeeae..2e59273214 100644 --- a/daemon/unit_test.c +++ b/daemon/unit_test.c @@ -588,28 +588,28 @@ struct test test4 = { // test5 - 32 bit overflows struct feed_values test5_feed[] = { - { 0, 0x00000000FFFFFFFFULL / 3 * 0 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 1 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 2 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 0 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 1 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 2 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 0 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 1 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 2 }, - { 1000000, 0x00000000FFFFFFFFULL / 3 * 0 }, + { 0, 0x00000000FFFFFFFFULL / 15 * 0 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 7 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 14 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 0 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 7 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 14 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 0 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 7 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 14 }, + { 1000000, 0x00000000FFFFFFFFULL / 15 * 0 }, }; calculated_number test5_results[] = { - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, - 0x00000000FFFFFFFFULL / 3, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15 * 7, + 0x00000000FFFFFFFFULL / 15, }; struct test test5 = { @@ -628,36 +628,36 @@ struct test test5 = { }; // -------------------------------------------------------------------------------------------------------------------- -// test5b - 16 bit overflows +// test5b - 64 bit overflows struct feed_values test5b_feed[] = { - { 0, 0x000000000000FFFFULL / 3 * 0 }, - { 1000000, 0x000000000000FFFFULL / 3 * 1 }, - { 1000000, 0x000000000000FFFFULL / 3 * 2 }, - { 1000000, 0x000000000000FFFFULL / 3 * 0 }, - { 1000000, 0x000000000000FFFFULL / 3 * 1 }, - { 1000000, 0x000000000000FFFFULL / 3 * 2 }, - { 1000000, 0x000000000000FFFFULL / 3 * 0 }, - { 1000000, 0x000000000000FFFFULL / 3 * 1 }, - { 1000000, 0x000000000000FFFFULL / 3 * 2 }, - { 1000000, 0x000000000000FFFFULL / 3 * 0 }, + { 0, 0xFFFFFFFFFFFFFFFFULL / 15 * 0 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 7 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 14 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 0 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 7 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 14 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 0 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 7 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 14 }, + { 1000000, 0xFFFFFFFFFFFFFFFFULL / 15 * 0 }, }; calculated_number test5b_results[] = { - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, - 0x000000000000FFFFULL / 3, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15 * 7, + 0xFFFFFFFFFFFFFFFFULL / 15, }; struct test test5b = { "test5b", // name - "test 16-bit incremental values overflow", + "test 64-bit incremental values overflow", 1, // update_every 1, // multiplier 1, // divisor @@ -671,92 +671,6 @@ struct test test5b = { }; // -------------------------------------------------------------------------------------------------------------------- -// test5c - 8 bit overflows - -struct feed_values test5c_feed[] = { - { 0, 0x00000000000000FFULL / 3 * 0 }, - { 1000000, 0x00000000000000FFULL / 3 * 1 }, - { 1000000, 0x00000000000000FFULL / 3 * 2 }, - { 1000000, 0x00000000000000FFULL / 3 * 0 }, - { 1000000, 0x00000000000000FFULL / 3 * 1 }, - { 1000000, 0x00000000000000FFULL / 3 * 2 }, - { 1000000, 0x00000000000000FFULL / 3 * 0 }, - { 1000000, 0x00000000000000FFULL / 3 * 1 }, - { 1000000, 0x00000000000000FFULL / 3 * 2 }, - { 1000000, 0x00000000000000FFULL / 3 * 0 }, -}; - -calculated_number test5c_results[] = { - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, - 0x00000000000000FFULL / 3, -}; - -struct test test5c = { - "test5c", // name - "test 8-bit incremental values overflow", - 1, // update_every - 1, // multiplier - 1, // divisor - RRD_ALGORITHM_INCREMENTAL, // algorithm - 10, // feed entries - 9, // result entries - test5c_feed, // feed - test5c_results, // results - NULL, // feed2 - NULL // results2 -}; - -// -------------------------------------------------------------------------------------------------------------------- -// test5d - 64 bit overflows - -struct feed_values test5d_feed[] = { - { 0, 0xFFFFFFFFFFFFFFFFULL / 3 * 0 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 1 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 2 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 0 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 1 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 2 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 0 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 1 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 2 }, - { 1000000, 0xFFFFFFFFFFFFFFFFULL / 3 * 0 }, -}; - -calculated_number test5d_results[] = { - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, - 0xFFFFFFFFFFFFFFFFULL / 3, -}; - -struct test test5d = { - "test5d", // name - "test 64-bit incremental values overflow", - 1, // update_every - 1, // multiplier - 1, // divisor - RRD_ALGORITHM_INCREMENTAL, // algorithm - 10, // feed entries - 9, // result entries - test5d_feed, // feed - test5d_results, // results - NULL, // feed2 - NULL // results2 -}; - -// -------------------------------------------------------------------------------------------------------------------- // test6 struct feed_values test6_feed[] = { @@ -1417,12 +1331,6 @@ int run_all_mockup_tests(void) if(run_test(&test5b)) return 1; - if(run_test(&test5c)) - return 1; - - if(run_test(&test5d)) - return 1; - if(run_test(&test6)) return 1; |