| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include <gtest/gtest.h> | |||
| 2 | #include <rusefi/rusefi_time_types.h> | |||
| 3 | #include <rusefi/rusefi_time_wraparound.h> | |||
| 4 | ||||
| 5 | 4 | TEST(util, WrapAround62) { | ||
| 6 | // Random test | |||
| 7 | { | |||
| 8 | 1 | WrapAround62 t; | ||
| 9 | 1 | uint32_t source = 0; | ||
| 10 | 1 | uint64_t actual = 0; | ||
| 11 | ||||
| 12 | // Test random progression, positive and negative. | |||
| 13 | 1 | uint32_t seed = time(NULL); | ||
| 14 |
1/1✓ Branch 1 taken 1 time.
|
1 | printf("Testing with seed 0x%08x\n", seed); | |
| 15 | 1 | srand(seed); | ||
| 16 |
2/2✓ Branch 0 taken 10000 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 10000 times.
✓ Decision 'false' taken 1 time.
|
10001 | for (unsigned i = 0; i < 10000; i++) { |
| 17 | 10000 | int32_t delta = rand(); | ||
| 18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10000 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 10000 times.
|
10000 | if (delta < 0) { |
| 19 | ✗ | delta = ~delta; | ||
| 20 | } | |||
| 21 | 10000 | delta -= RAND_MAX >> 1; | ||
| 22 | ||||
| 23 | // Cap negative test | |||
| 24 |
4/4✓ Branch 0 taken 5082 times.
✓ Branch 1 taken 4918 times.
✓ Branch 2 taken 250 times.
✓ Branch 3 taken 4832 times.
|
2/2✓ Decision 'true' taken 250 times.
✓ Decision 'false' taken 9750 times.
|
10000 | if (delta < 0 && uint64_t(-delta) > actual) { |
| 25 | 250 | delta = -actual; | ||
| 26 | } | |||
| 27 | ||||
| 28 | 10000 | source += delta; | ||
| 29 | 10000 | actual += delta; | ||
| 30 | ||||
| 31 | 10000 | uint64_t next = t.update(source); | ||
| 32 |
2/6✓ Branch 2 taken 10000 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10000 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
|
10000 | EXPECT_EQ(actual, next); | |
| 33 | } | |||
| 34 | } | |||
| 35 | ||||
| 36 | // More pointed test for expected edge conditions | |||
| 37 | { | |||
| 38 | 1 | WrapAround62 t; | ||
| 39 | ||||
| 40 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x03453455), 0x003453455ull); | |
| 41 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x042342323ull); | |
| 42 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x084356345ull); | |
| 43 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x042342323ull); | |
| 44 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x084356345ull); | |
| 45 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x0C5656565ull); | |
| 46 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x01122112), 0x101122112ull); // Wrap around! | |
| 47 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x0C5656565ull); | |
| 48 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x084356345ull); | |
| 49 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x0C5656565ull); | |
| 50 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x01122112), 0x101122112ull); // Wrap around! | |
| 51 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x142342323ull); | |
| 52 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x184356345ull); | |
| 53 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x142342323ull); | |
| 54 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x184356345ull); | |
| 55 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x1C5656565ull); | |
| 56 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x01122112), 0x201122112ull); // Wrap around! | |
| 57 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x1C5656565ull); | |
| 58 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x184356345ull); | |
| 59 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x1C5656565ull); | |
| 60 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x01122112), 0x201122112ull); // Wrap around! | |
| 61 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0xC5656565), 0x1C5656565ull); | |
| 62 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x184356345ull); | |
| 63 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x142342323ull); | |
| 64 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x01122112), 0x101122112ull); | |
| 65 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x84356345), 0x084356345ull); | |
| 66 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x42342323), 0x042342323ull); | |
| 67 |
2/6✓ Branch 5 taken 1 time.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
1 | EXPECT_EQ(t.update(0x03453455), 0x003453455ull); | |
| 68 | } | |||
| 69 | 1 | } | ||
| 70 | ||||
| 71 |