Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
make sleep test automated check with system_clock
  • Loading branch information
scivision committed Jan 8, 2020
commit 0ea0ee17a60898c24e8d386a170eb5a87245165f
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