Lumiera  0.pre.03
»edit your freedom«
sync-timedwait-test.cpp
Go to the documentation of this file.
1 /*
2  SyncTimedwait(Test) - check the monitor object based timed condition wait
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/error.hpp"
21 #include "lib/sync.hpp"
22 
23 #include <chrono>
24 
25 using test::Test;
26 using std::chrono::system_clock;
27 using std::chrono::milliseconds;
28 
29 
30 namespace lib {
31 namespace test{
32 
33  namespace { // test parameters...
34 
35  const uint WAIT_mSec = 20;
36  const milliseconds TIMEOUT{WAIT_mSec};
37 
38  using CLOCK_SCALE = std::milli; // Results are in ms
39  using Dur = std::chrono::duration<double, CLOCK_SCALE>;
40 
41  }//(End) parameters
42 
43 
44 
45 
46 
47 
48  /****************************************************************************/
57  : public Test,
58  Sync<NonrecursiveLock_Waitable>
59  {
60 
61  friend class Lock; // allows inheriting privately from Sync
62 
63 
64  virtual void
65  run (Arg)
66  {
67  Lock lock{this};
68 
69  auto start = system_clock::now();
70 
71  auto salvation = []{ return false; };
72  bool fulfilled = lock.wait_for (TIMEOUT, salvation);
73 
74  CHECK (not fulfilled); // condition not fulfilled, but timeout
75 
76  Dur duration = system_clock::now () - start;
77  CHECK (WAIT_mSec <= duration.count());
78  CHECK (duration.count() < 2*WAIT_mSec);
79  }
80  };
81 
82 
83 
85  LAUNCHER (SyncTimedwait_test, "unit common");
86 
87 
88 
89 }} // namespace lib::test
Facility for monitor object based locking.
Definition: sync.hpp:209
Definition: run.hpp:40
scoped guard to control the actual locking.
Definition: sync.hpp:226
Implementation namespace for support and library code.
Object Monitor based synchronisation.
Abstract Base Class for all testcases.
Definition: run.hpp:53
Simplistic test class runner.
const uint WAIT_mSec
milliseconds to wait before timeout
Lumiera error handling (C++ interface).