File: test_sleep.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (73 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download | duplicates (2)
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
module test_sleep
  use, intrinsic :: iso_fortran_env, only : int64, real64
  use stdlib_system, only : sleep
  use testdrive, only: new_unittest, unittest_type, error_type, check
  implicit none

  private
  public :: collect_sleep

  integer, parameter :: millisec = 100

contains

  !> Collect all exported unit tests
  subroutine collect_sleep(testsuite)
    !> Collection of tests
    type(unittest_type), allocatable, intent(out) :: testsuite(:)

    testsuite = [ &
      new_unittest('sleep', test_sleep_) &
    ]

  end subroutine collect_sleep


  subroutine test_sleep_(error)
    !> Error handling
    type(error_type), allocatable, intent(out) :: error

    integer(int64) :: tic, toc, trate
    real(real64) :: t_ms

    call system_clock(count_rate=trate)

    call system_clock(count=tic)
    call sleep(millisec)
    call system_clock(count=toc)

    t_ms = (toc - tic) * 1000._real64 / trate

    call check(error, t_ms, real(millisec, real64), thr=1.5_real64, rel=.true.)

  end subroutine test_sleep_

end module test_sleep


program tester
  use, intrinsic :: iso_fortran_env, only: error_unit
  use testdrive, only: run_testsuite, new_testsuite, testsuite_type
  use test_sleep, only: collect_sleep
  implicit none
  integer :: stat, is
  type(testsuite_type), allocatable :: testsuites(:)
  character(len=*), parameter :: fmt = '("#", *(1x, a))'

  stat = 0

  testsuites = [ &
    new_testsuite('sleep', collect_sleep) &
  ]

  do is = 1, size(testsuites)
    write(error_unit, fmt) "Testing:", testsuites(is)%name
    call run_testsuite(testsuites(is)%collect, error_unit, stat)
  end do

  if (stat > 0) then
    write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
    error stop
  end if

end program tester