forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sleep test automated check with system_clock
- Loading branch information
Showing
2 changed files
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |