! Macro to test "TIMER" intrinsic
!
! 2009-04-16 - Updated upper bounds check to be 3 times (vs 2x) expected elapsed
!      time, since when running on a loaded system I have seen elapsed time of
!      .48 seconds or higher in the first test case, which trickles down to the
!      subsequent test cases.
! 2013-10-07 - To remove false positives from this test case: 
!      1. Made upper bounds check changeable via arg1 (toleranceMultipler=)
!      2. increased the pause time slightly (i.e. +0.1 for t1, +0.2 for t2, +0.3 for t3).
!      3. added additional processing time to account non pause commands (e.g. do, enddo, etc.)
!         on the upper bounds check. This is changeable via arg2 (additionalProcessTime=)
!
! @version $Id: test_timer.mm,v 1.10 2013/10/08 13:35:09 ntn Exp $
startmacro F:toleranceMultipler[3] F:additionalProcessingTime[0.111]

  ! TIMER SET/ELAPSED  (expected to be .3 seconds or higher)
  timer set
  pause 0.1
  pause 0.2
  timer elapsed t1
  calc F:upperBound1 0.3 toleranceMultipler *
  assert/text="^reg.main.name: SET/ELAPSED, time1 = ^t1 < ^{upperBound1}" t1 GE 0.29 AND t1 LT upperBound1

  ! Continue timing... (expected to be t1 + .4 seconds or higher)
  do i 1 2
    pause 0.2
  enddo
  timer elapsed t2
  calc F:upperBound2 0.4 toleranceMultipler * t1 + additionalProcessingTime +
  assert/text="^reg.main.name: ELAPSED (continued), time2 = ^t2 < ^{upperBound2}" t2 GE 0.7 AND t2 LT upperBound2

  ! Reset timer... (expected to be .5 seconds or higher)
  timer set
  do i 1 2
    pause 0.25
  enddo
  timer elapsed t3
  calc F:upperBound3 0.5 toleranceMultipler * additionalProcessingTime +
  assert/text="^reg.main.name: rate, (re)SET/ELAPSED, time3 = ^t3 < ^{upperBound3}" t3 GE 0.5 AND t3 LT upperBound3

endmacro
