@@ -9,23 +9,51 @@ class Programs
99 PROGRAMS_ROOT = File . join ( LKP_SRC , 'programs' ) . freeze
1010
1111 class << self
12+ def collect_programs ( lkp_src_pattern , programs_pattern , executable_only : false )
13+ lkp_files = Dir [ "#{ LKP_SRC } /#{ lkp_src_pattern } " ]
14+ prog_files = Dir [ "#{ PROGRAMS_ROOT } /#{ programs_pattern } " ]
15+
16+ if executable_only
17+ lkp_files . select! { |p | File . file? ( p ) && File . executable? ( p ) }
18+ prog_files . select! { |p | File . file? ( p ) && File . executable? ( p ) }
19+ end
20+
21+ ( lkp_files || [ ] ) . map { |path | File . basename ( path ) } + ( prog_files || [ ] ) . map { |path | path . split ( '/' ) [ -2 ] }
22+ end
23+
24+ def find_executable ( program , lkp_dir , *prog_names )
25+ [
26+ *prog_names . map { |n | "#{ PROGRAMS_ROOT } /#{ program } /#{ n } " } ,
27+ "#{ LKP_SRC } /#{ lkp_dir } /#{ program } "
28+ ] . find { |file | File . exist? ( file ) }
29+ end
30+
1231 def all_stats
13- Dir [ "#{ LKP_SRC } /stats/**/*" ] . map { |path | File . basename path } +
14- Dir [ "#{ PROGRAMS_ROOT } /*/parse" ] . map { |path | path . split ( '/' ) [ -2 ] }
32+ collect_programs ( 'stats/**/*' , '*/parse' )
1533 end
1634
1735 alias all_parser_names all_stats
1836
1937 def all_tests
20- Dir [ "#{ LKP_SRC } /tests/**/*" ] . map { |path | File . basename path } +
21- Dir [ "#{ PROGRAMS_ROOT } /*/run" ] . map { |path | path . split ( '/' ) [ -2 ] }
38+ collect_programs ( 'tests/**/*' , '*/run' )
2239 end
2340
2441 alias all_runner_names all_tests
2542
43+ def all_monitors
44+ collect_programs ( 'monitors/*' , '*/{monitor,no-stdout-monitor,one-shot-monitor}' , executable_only : true )
45+ end
46+
47+ def all_setups
48+ collect_programs ( 'setup/**/*' , '*/setup' , executable_only : true )
49+ end
50+
51+ def all_daemons
52+ collect_programs ( 'daemon/**/*' , '*/daemon' , executable_only : true )
53+ end
54+
2655 def all_tests_and_daemons
27- all_tests + Dir [ "#{ LKP_SRC } /daemon/**/*" ] . map { |path | File . basename path } +
28- Dir [ "#{ PROGRAMS_ROOT } /*/daemon" ] . map { |path | path . split ( '/' ) [ -2 ] }
56+ all_tests + all_daemons
2957 end
3058
3159 def all_tests_set
@@ -36,18 +64,31 @@ def all_metas
3664 Dir [ "#{ LKP_SRC } /tests/*.yaml" ] + Dir [ "#{ PROGRAMS_ROOT } /*/meta.yaml" ]
3765 end
3866
39- def find_parser ( program )
67+ def find_meta ( program )
4068 [
41- "#{ PROGRAMS_ROOT } /#{ program } /parse" ,
42- "#{ LKP_SRC } /stats/#{ program } "
43- ] . find { |file | File . exist? file }
69+ "#{ PROGRAMS_ROOT } /#{ program } /meta.yaml" ,
70+ "#{ LKP_SRC } /tests/#{ program } .yaml"
71+ ] . find { |file | File . exist? ( file ) }
72+ end
73+
74+ def find_parser ( program )
75+ find_executable ( program , 'stats' , 'parse' )
76+ end
77+
78+ def find_setup ( program )
79+ find_executable ( program , 'setup' , 'setup' )
80+ end
81+
82+ def find_monitor ( program )
83+ find_executable ( program , 'monitors' , 'monitor' , 'no-stdout-monitor' , 'one-shot-monitor' )
84+ end
85+
86+ def find_daemon ( program )
87+ find_executable ( program , 'daemon' , 'daemon' )
4488 end
4589
4690 def find_runner ( program )
47- [
48- "#{ PROGRAMS_ROOT } /#{ program } /run" ,
49- "#{ LKP_SRC } /tests/#{ program } "
50- ] . find { |file | File . exist? file }
91+ find_executable ( program , 'tests' , 'run' )
5192 end
5293
5394 # program: turbostat, turbostat-dev
0 commit comments