Merge lp:~sil2100/unity/tests_glib_timeout_modifications into lp:unity

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2936
Proposed branch: lp:~sil2100/unity/tests_glib_timeout_modifications
Merge into: lp:unity
Diff against target: 71 lines (+12/-21)
1 file modified
tests/test_glib_source.cpp (+12/-21)
To merge this branch: bzr merge lp:~sil2100/unity/tests_glib_timeout_modifications
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+135883@code.launchpad.net

Commit message

Change some test_glib_source unit tests. Those tests are measuring times of execution of timeouts, which is not really suitable for unit testing. Those tests are also failing sometimes on ARM machines, as the timeouts are longer than expected. We're dropping time measurement from these tests, only testing if the timeouts actually happen, because that seems enough.

Description of the change

Change for comment.

- Problem:

3 tests from the test_glib_source.cpp (TestGLibTimeout) suite are failing on most ARM devices. Those tests measure time of the glib::Timeout executions, which are slower on ARM. Also, we shouldn't be really doing tests like this in the unit test suite.

- Fix:

Remove time measurement in the glib::Timeout failing test functions. Instead, all that we need is actually just making sure that the one-shot and multiple-shots just work (i.e. the callbacks are executed). We don't really care if the timeouts happen a bit later, since we can't do anything about that really if the hardware has issues.

- Tests:

N/A

To post a comment you must log in.
Revision history for this message
Francis Ginther (fginther) wrote :

The MultipleShotsRun test doesn't look very useful now as it waits until the callback count is 6, then checks that it is 6. Also, what happens if the callback count never increments? The other test changes look appropriate.

Perhaps it should test that callback count is within a given range, but I'm unsure of the appropriate tolerance. Just a suggestion:
TEST(TestGLibTimeout, MultipleShotsRun)
{
  callback_called = false;
  callback_call_count = 0;
  {
    Timeout timeout(100, &OnSourceCallbackContinue);
    Utils::WaitForTimeoutMSec(650);
    EXPECT_TRUE(timeout.IsRunning());
  }
  EXPECT_TRUE(callback_called);
  EXPECT_GE(callback_call_count, 5);
  EXPECT_LT(callback_call_count, 7);
}

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

The test, as it is right now, works in the following way. We wait until the callback_call_count is 6 OR when the timeout happens (I think the default is 10 seconds? Or something like that). That is why there is that callback_call_count check at the end actually. Since if the timeout happens, we check how many times the callback_call_count happened. Actually, EXPECT_GE() is better there!

I would prefer not to measure time in a test like this. Since when this test fails, the number of callback calls is sometimes 3-4, so we would have to be REALLY tolerant. This would make such testing a bit pointless... That's why I wanted to actually just make sure that it can timeout more than once (6 times).

Anyway, I still wonder about this test though, since you're right, maybe we could make it more useful somehow. Also, there are many other tests MultipleShotsRun in this source file which in fact also measure time. So maybe I would have to change those as well.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Of course we lose some checks, but we can survive without them... However probably you can use:

Utils::WaitUntil(check_function, true, 1); instead...

53 - timeout.removed.connect([&] (unsigned int id) { clock_gettime(CLOCK_MONOTONIC, &post); });

Replace it with
timeout.removed.connect([&] (unsigned int id) { removed_called = true; });});

And check for removed_called value at the end...

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

I changed it as suggested. Do you think this would be a sufficient workaround for now?

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Yeah, it should... Let's see :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_glib_source.cpp'
2--- tests/test_glib_source.cpp 2012-10-11 01:44:15 +0000
3+++ tests/test_glib_source.cpp 2012-11-28 12:28:20 +0000
4@@ -131,55 +131,46 @@
5 {
6 callback_called = false;
7 callback_call_count = 0;
8- struct timespec pre, post;
9+ bool removed_called = false;
10
11 Timeout timeout(100, &OnSourceCallbackStop);
12- clock_gettime(CLOCK_MONOTONIC, &pre);
13- timeout.removed.connect([&] (unsigned int id) { clock_gettime(CLOCK_MONOTONIC, &post); });
14+ timeout.removed.connect([&] (unsigned int id) { removed_called = true; });
15
16 Utils::WaitForTimeoutMSec(500);
17 EXPECT_FALSE(timeout.IsRunning());
18 EXPECT_TRUE(callback_called);
19 EXPECT_EQ(callback_call_count, 1);
20- int time_delta = unity::TimeUtil::TimeDelta(&post, &pre);
21- EXPECT_GE(time_delta, 100);
22- EXPECT_LT(time_delta, 110);
23+ EXPECT_TRUE(removed_called);
24 }
25
26 TEST(TestGLibTimeout, MultipleShotsRun)
27 {
28 callback_called = false;
29 callback_call_count = 0;
30- struct timespec pre, post;
31+ bool removed_called = false;
32
33 {
34+ auto check_function = []() { return (callback_call_count < 6) ? false : true; };
35 Timeout timeout(100, &OnSourceCallbackContinue);
36- clock_gettime(CLOCK_MONOTONIC, &pre);
37- timeout.removed.connect([&] (unsigned int id) { clock_gettime(CLOCK_MONOTONIC, &post); });
38-
39- Utils::WaitForTimeoutMSec(650);
40+ timeout.removed.connect([&] (unsigned int id) { removed_called = true; });
41+ Utils::WaitUntil(check_function, true, 1);
42 EXPECT_TRUE(timeout.IsRunning());
43 }
44
45 EXPECT_TRUE(callback_called);
46- EXPECT_EQ(callback_call_count, 6);
47- int time_delta = unity::TimeUtil::TimeDelta(&post, &pre);
48- EXPECT_GE(time_delta, 600);
49- EXPECT_LT(time_delta, 700);
50+ EXPECT_GE(callback_call_count, 6);
51+ EXPECT_TRUE(removed_called);
52 }
53
54 TEST(TestGLibTimeout, OneShotRunWithEmptyCallback)
55 {
56- struct timespec pre, post;
57+ bool removed_called = false;
58 Timeout timeout(100, Source::Callback());
59- clock_gettime(CLOCK_MONOTONIC, &pre);
60- timeout.removed.connect([&] (unsigned int id) { clock_gettime(CLOCK_MONOTONIC, &post); });
61+ timeout.removed.connect([&] (unsigned int id) { removed_called = true; });
62
63 Utils::WaitForTimeoutMSec(500);
64 EXPECT_FALSE(timeout.IsRunning());
65- int time_delta = unity::TimeUtil::TimeDelta(&post, &pre);
66- EXPECT_GE(time_delta, 100);
67- EXPECT_LT(time_delta, 110);
68+ EXPECT_TRUE(removed_called);
69 }
70
71 TEST(TestGLibTimeout, Removal)