summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests/lldeadmantimer_test.cpp
blob: 7fd2dde6e09390da48bc894b33e8c272376c2038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
/** 
 * @file lldeadmantimer_test.cpp
 * @brief Tests for the LLDeadmanTimer class.
 *
 * $LicenseInfo:firstyear=2013&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2013, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "../lldeadmantimer.h"
#include "../llsd.h"
#include "../lltimer.h"

#include "../test/lltut.h"

// Convert between floating point time deltas and U64 time deltas.
// Reflects an implementation detail inside lldeadmantimer.cpp

static LLDeadmanTimer::time_type float_time_to_u64(F64 delta)
{
	return LLDeadmanTimer::time_type(delta * gClockFrequency);
}

static F64 u64_time_to_float(LLDeadmanTimer::time_type delta)
{
	return delta * gClockFrequencyInv;
}


namespace tut
{

struct deadmantimer_test
{
	deadmantimer_test()
		{
			// LLTimer internals updating
			update_clock_frequencies();
		}
};

typedef test_group<deadmantimer_test> deadmantimer_group_t;
typedef deadmantimer_group_t::object deadmantimer_object_t;
tut::deadmantimer_group_t deadmantimer_instance("LLDeadmanTimer");

// Basic construction test and isExpired() call
template<> template<>
void deadmantimer_object_t::test<1>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(10.0, false);

		ensure_equals("WOCM isExpired() returns false after ctor()", timer.isExpired(0, started, stopped, count), false);
		ensure_approximately_equals("WOCM t1 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WOCM t1 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WOCM t1 - isExpired() does not modify count", count, U64L(8));
	}

	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(10.0, true);

		ensure_equals("WCM isExpired() returns false after ctor()", timer.isExpired(0, started, stopped, count, user_cpu, sys_cpu), false);
		ensure_approximately_equals("WCM t1 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WCM t1 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WCM t1 - isExpired() does not modify count", count, U64L(8));
		ensure_equals("WCM t1 - isExpired() does not modify user_cpu", user_cpu, U64L(29000));
		ensure_equals("WCM t1 - isExpired() does not modify sys_cpu", sys_cpu, U64L(57000));
	}
}


// Construct with zero horizon - not useful generally but will be useful in testing
template<> template<>
void deadmantimer_object_t::test<2>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(0.0, false);			// Zero is pre-expired
		
		ensure_equals("WOCM isExpired() still returns false with 0.0 time ctor()",
					  timer.isExpired(0, started, stopped, count), false);
	}

	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(0.0, true);			// Zero is pre-expired
		
		ensure_equals("WCM isExpired() still returns false with 0.0 time ctor()",
					  timer.isExpired(0, started, stopped, count, user_cpu, sys_cpu), false);
	}
}


// "pre-expired" timer - starting a timer with a 0.0 horizon will result in
// expiration on first test.
template<> template<>
void deadmantimer_object_t::test<3>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(0.0, false);

		timer.start(0);
		ensure_equals("WOCM isExpired() returns true with 0.0 horizon time",
					  timer.isExpired(0, started, stopped, count), true);
 		ensure_approximately_equals("WOCM expired timer with no bell ringing has stopped == started", started, stopped, 8);
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(0.0, true);

		timer.start(0);
		ensure_equals("WCM isExpired() returns true with 0.0 horizon time",
					  timer.isExpired(0, started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WCM expired timer with no bell ringing has stopped == started", started, stopped, 8);
	}
}


// "pre-expired" timer - bell rings are ignored as we're already expired.
template<> template<>
void deadmantimer_object_t::test<4>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(0.0, false);
	
		timer.start(0);
		timer.ringBell(LLDeadmanTimer::getNow() + float_time_to_u64(1000.0), 1);
		ensure_equals("WOCM isExpired() returns true with 0.0 horizon time after bell ring",
					  timer.isExpired(0, started, stopped, count), true);
		ensure_approximately_equals("WOCM ringBell has no impact on expired timer leaving stopped == started", started, stopped, 8);
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(0.0, true);
	
		timer.start(0);
		timer.ringBell(LLDeadmanTimer::getNow() + float_time_to_u64(1000.0), 1);
		ensure_equals("WCM isExpired() returns true with 0.0 horizon time after bell ring",
					  timer.isExpired(0, started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WCM ringBell has no impact on expired timer leaving stopped == started", started, stopped, 8);
	}
}


// start(0) test - unexpired timer reports unexpired
template<> template<>
void deadmantimer_object_t::test<5>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(10.0, false);
	
		timer.start(0);
		ensure_equals("WOCM isExpired() returns false after starting with 10.0 horizon time",
					  timer.isExpired(0, started, stopped, count), false);
		ensure_approximately_equals("WOCM t5 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WOCM t5 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WOCM t5 - isExpired() does not modify count", count, U64L(8));
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(10.0, true);
	
		timer.start(0);
		ensure_equals("WCM isExpired() returns false after starting with 10.0 horizon time",
					  timer.isExpired(0, started, stopped, count, user_cpu, sys_cpu), false);
		ensure_approximately_equals("WCM t5 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WCM t5 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WCM t5 - isExpired() does not modify count", count, U64L(8));
		ensure_equals("WCM t5 - isExpired() does not modify user_cpu", user_cpu, U64L(29000));
		ensure_equals("WCM t5 - isExpired() does not modify sys_cpu", sys_cpu, U64L(57000));
	}
}


// start() test - start in the past but not beyond 1 horizon
template<> template<>
void deadmantimer_object_t::test<6>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(10.0, false);

		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(5.0));
		timer.start(the_past);
		ensure_equals("WOCM t6 - isExpired() returns false with 10.0 horizon time starting 5.0 in past",
					  timer.isExpired(now, started, stopped, count), false);
		ensure_approximately_equals("WOCM t6 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WOCM t6 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WOCM t6 - isExpired() does not modify count", count, U64L(8));
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(10.0, true);

		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(5.0));
		timer.start(the_past);
		ensure_equals("WCM t6 - isExpired() returns false with 10.0 horizon time starting 5.0 in past",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
		ensure_approximately_equals("WCM t6 - isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WCM t6 - isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("t6 - isExpired() does not modify count", count, U64L(8));
		ensure_equals("WCM t6 - isExpired() does not modify user_cpu", user_cpu, U64L(29000));
		ensure_equals("WCM t6 - isExpired() does not modify sys_cpu", sys_cpu, U64L(57000));
	}
}


// start() test - start in the past but well beyond 1 horizon
template<> template<>
void deadmantimer_object_t::test<7>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(10.0, false);
		
		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(20.0));
		timer.start(the_past);
		ensure_equals("WOCM t7 - isExpired() returns true with 10.0 horizon time starting 20.0 in past",
					  timer.isExpired(now,started, stopped, count), true);
		ensure_approximately_equals("WOCM t7 - starting before horizon still gives equal started / stopped", started, stopped, 8);
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(10.0, true);
		
		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(20.0));
		timer.start(the_past);
		ensure_equals("WCM t7 - isExpired() returns true with 10.0 horizon time starting 20.0 in past",
					  timer.isExpired(now,started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WOCM t7 - starting before horizon still gives equal started / stopped", started, stopped, 8);
	}
}


// isExpired() test - results are read-once.  Probes after first true are false.
template<> template<>
void deadmantimer_object_t::test<8>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(10.0, false);

		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(20.0));
		timer.start(the_past);
		ensure_equals("WOCM t8 - isExpired() returns true with 10.0 horizon time starting 20.0 in past",
					  timer.isExpired(now, started, stopped, count), true);
		
		started = 42.0;
		stopped = 97.0;
		count = U64L(8);
		ensure_equals("WOCM t8 - second isExpired() returns false after true",
					  timer.isExpired(now, started, stopped, count), false);
		ensure_approximately_equals("WOCM t8 - 2nd isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WOCM t8 - 2nd isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WOCM t8 - 2nd isExpired() does not modify count", count, U64L(8));
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(10.0, true);

		// Would like to do subtraction on current time but can't because
		// the implementation on Windows is zero-based.  We wrap around
		// the backside resulting in a large U64 number.
	
		LLDeadmanTimer::time_type the_past(LLDeadmanTimer::getNow());
		LLDeadmanTimer::time_type now(the_past + float_time_to_u64(20.0));
		timer.start(the_past);
		ensure_equals("WCM t8 - isExpired() returns true with 10.0 horizon time starting 20.0 in past",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), true);
		
		started = 42.0;
		stopped = 97.0;
		count = U64L(8);
		user_cpu = 29000;
		sys_cpu = 57000;
		ensure_equals("WCM t8 - second isExpired() returns false after true",
					  timer.isExpired(now, started, stopped, count), false);
		ensure_approximately_equals("WCM t8 - 2nd isExpired() does not modify started", started, F64(42.0), 2);
		ensure_approximately_equals("WCM t8 - 2nd isExpired() does not modify stopped", stopped, F64(97.0), 2);
		ensure_equals("WCM t8 - 2nd isExpired() does not modify count", count, U64L(8));
		ensure_equals("WCM t8 - 2nd isExpired() does not modify user_cpu", user_cpu, U64L(29000));
		ensure_equals("WCM t8 - 2nd isExpired() does not modify sys_cpu", sys_cpu, U64L(57000));
	}
}


// ringBell() test - see that we can keep a timer from expiring
template<> template<>
void deadmantimer_object_t::test<9>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(5.0, false);

		LLDeadmanTimer::time_type now(LLDeadmanTimer::getNow());
		F64 real_start(u64_time_to_float(now));
		timer.start(0);

		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WOCM t9 - 5.0 horizon timer has not timed out after 10 1-second bell rings",
					  timer.isExpired(now, started, stopped, count), false);
		F64 last_good_ring(u64_time_to_float(now));

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WOCM t9 - 5.0 horizon timer expires on 10-second jump",
					  timer.isExpired(now, started, stopped, count), true);
		ensure_approximately_equals("WOCM t9 - started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WOCM t9 - stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WOCM t9 - 10 good ringBell()s", count, U64L(10));
		ensure_equals("WOCM t9 - single read only", timer.isExpired(now, started, stopped, count), false);
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);
		LLDeadmanTimer timer(5.0, true);

		LLDeadmanTimer::time_type now(LLDeadmanTimer::getNow());
		F64 real_start(u64_time_to_float(now));
		timer.start(0);

		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WCM t9 - 5.0 horizon timer has not timed out after 10 1-second bell rings",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
		F64 last_good_ring(u64_time_to_float(now));

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WCM t9 - 5.0 horizon timer expires on 10-second jump",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WCM t9 - started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WCM t9 - stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WCM t9 - 10 good ringBell()s", count, U64L(10));
		ensure_equals("WCM t9 - single read only", timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
	}
}


// restart after expiration test - verify that restarts behave well
template<> template<>
void deadmantimer_object_t::test<10>()
{
	{
		// Without cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8));
		LLDeadmanTimer timer(5.0, false);

		LLDeadmanTimer::time_type now(LLDeadmanTimer::getNow());
		F64 real_start(u64_time_to_float(now));
		timer.start(0);

		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WOCM t10 - 5.0 horizon timer has not timed out after 10 1-second bell rings",
					  timer.isExpired(now, started, stopped, count), false);
		F64 last_good_ring(u64_time_to_float(now));

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WOCM t10 - 5.0 horizon timer expires on 10-second jump",
					  timer.isExpired(now, started, stopped, count), true);
		ensure_approximately_equals("WOCM t10 - started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WOCM t10 - stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WOCM t10 - 10 good ringBell()s", count, U64L(10));
		ensure_equals("WOCM t10 - single read only", timer.isExpired(now, started, stopped, count), false);
		
		// Jump forward and restart
		now += float_time_to_u64(1.0);
		real_start = u64_time_to_float(now);
		timer.start(now);
		
		// Run a modified bell ring sequence
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WOCM t10 - 5.0 horizon timer has not timed out after 8 1-second bell rings",
					  timer.isExpired(now, started, stopped, count), false);
		last_good_ring = u64_time_to_float(now);

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WOCM t10 - 5.0 horizon timer expires on 8-second jump",
					  timer.isExpired(now, started, stopped, count), true);
		ensure_approximately_equals("WOCM t10 - 2nd started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WOCM t10 - 2nd stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WOCM t10 - 8 good ringBell()s", count, U64L(8));
		ensure_equals("WOCM t10 - single read only - 2nd start",
					  timer.isExpired(now, started, stopped, count), false);
	}
	{
		// With cpu metrics
		F64 started(42.0), stopped(97.0);
		U64 count(U64L(8)), user_cpu(29000), sys_cpu(57000);

		LLDeadmanTimer timer(5.0, true);

		LLDeadmanTimer::time_type now(LLDeadmanTimer::getNow());
		F64 real_start(u64_time_to_float(now));
		timer.start(0);

		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WCM t10 - 5.0 horizon timer has not timed out after 10 1-second bell rings",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
		F64 last_good_ring(u64_time_to_float(now));

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WCM t10 - 5.0 horizon timer expires on 10-second jump",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WCM t10 - started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WCM t10 - stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WCM t10 - 10 good ringBell()s", count, U64L(10));
		ensure_equals("WCM t10 - single read only", timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
		
		// Jump forward and restart
		now += float_time_to_u64(1.0);
		real_start = u64_time_to_float(now);
		timer.start(now);
		
		// Run a modified bell ring sequence
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		now += float_time_to_u64(1.0);
		timer.ringBell(now, 1);
		ensure_equals("WCM t10 - 5.0 horizon timer has not timed out after 8 1-second bell rings",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
		last_good_ring = u64_time_to_float(now);

		// Jump forward and expire
		now += float_time_to_u64(10.0);
		ensure_equals("WCM t10 - 5.0 horizon timer expires on 8-second jump",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), true);
		ensure_approximately_equals("WCM t10 - 2nd started matches start() time", started, real_start, 4);
		ensure_approximately_equals("WCM t10 - 2nd stopped matches last ringBell() time", stopped, last_good_ring, 4);
		ensure_equals("WCM t10 - 8 good ringBell()s", count, U64L(8));
		ensure_equals("WCM t10 - single read only - 2nd start",
					  timer.isExpired(now, started, stopped, count, user_cpu, sys_cpu), false);
	}
}



} // end namespace tut