Skip to content

Commit

Permalink
make sleep test automated check with system_clock
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 8, 2020
1 parent c8974dc commit 0ea0ee1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/tests/system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_executable(test_sleep test_sleep.f90)
target_link_libraries(test_sleep fortran_stdlib)

add_test(NAME Sleep COMMAND $<TARGET_FILE:test_sleep> 650)
set_tests_properties(Sleep PROPERTIES TIMEOUT 5)
add_test(NAME Sleep COMMAND $<TARGET_FILE:test_sleep> 350)
set_tests_properties(Sleep PROPERTIES TIMEOUT 1)
17 changes: 16 additions & 1 deletion src/tests/system/test_sleep.f90
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
program test_sleep

use, intrinsic :: iso_fortran_env, only : int64, real64
use stdlib_experimental_system, only : sleep

implicit none

integer :: ierr, millisec
character(8) :: argv
integer(int64) :: tic, toc, trate
real(real64) :: t_ms

call system_clock(count_rate=trate)

millisec = 780
call get_command_argument(1, argv, status=ierr)
if (ierr==0) read(argv,*) millisec

if (millisec<0) millisec=0

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

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

if (millisec > 0) then
if (t_ms < 0.5 * millisec) error stop 'actual sleep time was too short'
if (t_ms > 2 * millisec) error stop 'actual sleep time was too long'
endif

print '(A,F8.3)', 'OK: test_sleep: slept for (ms): ',t_ms

end program

0 comments on commit 0ea0ee1

Please sign in to comment.