Skip to content

Commit 9a433f9

Browse files
committed
cleanup python test
1 parent ce1e5ab commit 9a433f9

File tree

5 files changed

+23
-61
lines changed

5 files changed

+23
-61
lines changed

openmp/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22
timeprec = executable('timeprec', 'timeprec.f90', dependencies : openmp)
33
test('OpenMP:TimeMeasure', timeprec,
4+
is_parallel: false,
45
timeout: 30)

system/CMakeLists.txt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,25 @@ project(F18system Fortran)
33
enable_testing()
44

55
add_executable(color color_text.f90)
6-
add_test(NAME Color COMMAND color)
6+
add_test(NAME system:Color COMMAND color)
77

88
add_library(osdet OBJECT os_detect.f90)
99

1010
add_executable(gitrev gitrev.f90)
11-
add_test(NAME Git COMMAND gitrev)
11+
add_test(NAME system:Git COMMAND gitrev)
1212

1313
add_executable(complog compiler_log.f90)
14-
add_test(NAME Compiler COMMAND complog)
14+
add_test(NAME system:Compiler COMMAND complog)
1515

1616
find_package(Python3 COMPONENTS Interpreter)
1717
if(Python3_FOUND)
18-
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import psutil" RESULT_VARIABLE _ret)
19-
if(_ret EQUAL 0)
20-
set(Python_OK true)
21-
else()
22-
set(Python_OK false)
23-
endif()
24-
endif()
25-
if(Python_OK)
2618
add_executable(callpython call_python_script.f90)
27-
target_link_libraries(callpython osdet)
28-
add_test(NAME CallPython COMMAND callpython)
29-
else()
30-
message(STATUS "SKIP: Python test ${Python3_EXECUTABLE} ${_ret}")
19+
add_test(NAME system:CallPython COMMAND callpython)
3120
endif()
3221

3322
find_program(FFPLAY NAMES ffplay)
34-
add_executable(playsound play_sound.f90)
3523
if(FFPLAY)
36-
add_test(NAME PlaySound COMMAND $<TARGET_FILE:playsound> ${CMAKE_CURRENT_SOURCE_DIR}/bell.aac)
37-
endif()
24+
add_executable(playsound play_sound.f90)
25+
add_test(NAME system:PlaySound COMMAND $<TARGET_FILE:playsound> ${CMAKE_CURRENT_SOURCE_DIR}/bell.aac)
26+
set_tests_properties(system:PlaySound PROPERTIES TIMEOUT 15)
27+
endif()

system/call_python_script.f90

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,13 @@ program call_python
33
!! this technique works in general, as Fortran will crash if calling a non-existant program
44
!! without exitstat= and/or cmdstat= parameter
55

6-
use os_detect, only: getos
7-
use, intrinsic:: iso_fortran_env, only: stderr=>error_unit
8-
96
implicit none (type, external)
107

8+
character(:), allocatable :: cmd
9+
character(*), parameter :: exe='python'
1110

12-
integer :: ierr, istat
13-
character(:), allocatable :: cmd, oscmd
14-
character(*), parameter :: exe='python3'
15-
16-
cmd = "import psutil; print(f'{psutil.virtual_memory().available} MB RAM free')"
17-
18-
select case (getos())
19-
case('windows')
20-
oscmd = 'where '//exe
21-
case('unix')
22-
oscmd = 'which '//exe
23-
case default
24-
error stop 'unknown os'
25-
end select
26-
27-
call execute_command_line(oscmd, cmdstat=ierr, exitstat=istat)
28-
if (ierr/=0 .or. istat /= 0) error stop 'python not found'
11+
cmd = "import os; print(f'{os.cpu_count()} CPUs detected')"
2912

30-
call execute_command_line(exe//' -c "'//cmd//'"', cmdstat=ierr, exitstat=istat)
31-
if (ierr/=0 .or. istat/=0) write(stderr,*) 'Python psutil not available'
13+
call execute_command_line(exe//' -c "'//cmd//'"')
3214

33-
end program
15+
end program

system/meson.build

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ test('Compiler version logging', complog,
1515
suite: 'system',
1616
timeout: 15)
1717

18-
playsound_exe = executable('playsound', 'play_sound.f90')
1918
if find_program('ffplay', required: false).found()
20-
test('PlaySound', playsound_exe,
19+
test('PlaySound',
20+
executable('playsound', 'play_sound.f90'),
2121
args: files('bell.aac'),
2222
suite: 'system',
2323
timeout: 15)
2424
endif
2525

26-
if run_command(['python', '-c', 'import psutil']).returncode() == 0
27-
callpython_exe = executable('callpython', 'call_python_script.f90',
28-
link_with : osdet)
29-
test('call python', callpython_exe,
30-
suite: 'system',
31-
timeout: 10)
32-
endif
26+
test('call python',
27+
executable('callpython', 'call_python_script.f90'),
28+
suite: 'system', timeout: 15)

system/os_detect.f90

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@ module os_detect
22

33
implicit none (type, external)
44

5-
65
contains
76

87
function getos()
9-
!! heuristic detection of operating system based on de factor environment variables
8+
!! heuristic detection of operating system based on de facto environment variables
109
character(256) :: buf
1110
character(:), allocatable :: getos
1211

1312
call get_environment_variable("HOME", buf)
14-
if (len_trim(buf) > 0) then
15-
getos = "unix"
16-
return
17-
endif
13+
if (len_trim(buf) > 0) getos = "unix"
1814

1915
call get_environment_variable("USERPROFILE", buf)
20-
if (len_trim(buf) > 0) then
21-
getos = "windows"
22-
return
23-
endif
16+
if (len_trim(buf) > 0) getos = "windows"
2417

2518
end function getos
2619

27-
end module os_detect
20+
end module os_detect

0 commit comments

Comments
 (0)