Skip to content

Commit 25ce9e2

Browse files
committed
make sleep test automated check with system_clock
1 parent 7dcbff9 commit 25ce9e2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/tests/system/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_executable(test_sleep test_sleep.f90)
22
target_link_libraries(test_sleep fortran_stdlib)
33

4-
add_test(NAME Sleep COMMAND $<TARGET_FILE:test_sleep> 650)
5-
set_tests_properties(Sleep PROPERTIES TIMEOUT 5)
4+
add_test(NAME Sleep COMMAND $<TARGET_FILE:test_sleep> 350)
5+
set_tests_properties(Sleep PROPERTIES TIMEOUT 1)

src/tests/system/test_sleep.f90

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
program test_sleep
2-
2+
use, intrinsic :: iso_fortran_env, only : int64, real64
33
use stdlib_experimental_system, only : sleep
44

55
implicit none
66

77
integer :: ierr, millisec
88
character(8) :: argv
9+
integer(int64) :: tic, toc, trate
10+
real(real64) :: t_ms
11+
12+
call system_clock(count_rate=trate)
913

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

1418
if (millisec<0) millisec=0
1519

20+
call system_clock(count=tic)
1621
call sleep(millisec)
22+
call system_clock(count=toc)
23+
24+
t_ms = (toc-tic) * 1000._real64 / trate
25+
26+
if (millisec > 0) then
27+
if (t_ms < 0.5 * millisec) error stop 'actual sleep time was too short'
28+
if (t_ms > 2 * millisec) error stop 'actual sleep time was too long'
29+
endif
30+
31+
print '(A,F8.3)', 'OK: test_sleep: slept for (ms): ',t_ms
1732

1833
end program

0 commit comments

Comments
 (0)