Skip to content

Commit

Permalink
Clamp synthesized script from evemu format to non-negative delays
Browse files Browse the repository at this point in the history
Fixes eternal (well, 49 days..) hang due to negative delays when playing back
evemu scripts with timestamps that go backwards.
  • Loading branch information
martinpitt committed Mar 25, 2014
1 parent fb30730 commit f70d31a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.8.1 (UNRELEASED)
------------------
- Fix eternal hang due to negative delays when playing back evemu scripts with
timestamps that go backwards.

0.8 (2014-03-20)
----------------
New features:
Expand Down
2 changes: 2 additions & 0 deletions src/umockdev.vala
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ public class Testbed: GLib.Object {
first = false;
} else {
delay = (int) (ev_sec - ev.time.tv_sec) * 1000 + (int) (ev_usec - ev.time.tv_usec) / 1000;
if (delay < 0)
delay = 0;
}
ev.time.tv_sec = ev_sec;
ev.time.tv_usec = ev_usec;
Expand Down
5 changes: 3 additions & 2 deletions tests/test-umockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,8 @@ t_testbed_replay_evemu_events(UMockdevTestbedFixture * fixture, gconstpointer da
static const char* test_data = "E: 1234.500000 0000 0000 0\n" /* SYN */
"E: 1234.650000 0002 0000 5 # comment\n" /* REL X */
"# some comment\n"
"E: 1234.650000 0002 0001 -11 # comment #2\n" /* REL Y */
/* slightly go back in time here */
"E: 1234.649000 0002 0001 -11 # comment #2\n" /* REL Y */
"E: 1235.200000 0001 0174 1\n"; /* KEY_ZOOM */

umockdev_testbed_add_from_string(fixture->testbed,
Expand Down Expand Up @@ -1552,7 +1553,7 @@ t_testbed_replay_evemu_events(UMockdevTestbedFixture * fixture, gconstpointer da
g_assert_cmpint(read(fd, &ev, sizeof(ev)), ==, sizeof(ev));
g_assert_cmpint(gettimeofday(&tv_end, NULL), ==, 0);
g_assert_cmpint(ev.time.tv_sec, ==, 1234);
g_assert_cmpint(ev.time.tv_usec, ==, 650000);
g_assert_cmpint(ev.time.tv_usec, ==, 649000);
g_assert_cmpint(ev.type, ==, 2);
g_assert_cmpint(ev.code, ==, 1);
g_assert_cmpint(ev.value, ==, -11);
Expand Down

0 comments on commit f70d31a

Please sign in to comment.