script/p2-scheduler.pl untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 #===============================================================================
3 #
4 # FILE: schedule-of-month.pl
5 #
6 # DESCRIPTION: an experiments scheduler for P2.
7 #
8 # OPTIONS: ---
9 # REQUIREMENTS: ---
10 # BUGS: ---
11 # NOTES: ---
12 # AUTHOR: Marco Masetti (), marco.masetti@sky.uk
13 # ORGANIZATION: SKY uk
14 # VERSION: 1.0
15 # CREATED: 05/05/2020 23:57:20
16 # REVISION: ---
17 #===============================================================================
18 use strict;
19 use warnings;
20 use Getopt::Long qw( GetOptions );
21 use P2::Scheduler;
22 use YAML::Syck qw(Dump LoadFile);
23  
24 my ( $month, $year, @experiments_files, $spare_days_per_month);
25 my $starting_from = 1;
26 my $weights = "2,1,1";
27 my $num_week_days = 5;
28 my $selected_week_days_str="1,2,3,4,5";
29 my $hour_slots_str="1,2,3,4,5";
30 my $context;
31 my $fixed_intervals;
32  
33 GetOptions(
34 "month=i" => \$month,
35 "year=i" => \$year,
36 "exp_files=s" => \@experiments_files,
37 "spare_days=i" => \$spare_days_per_month,
38 "starting_from=i" => \$starting_from,
39 "weights=s" => \$weights,
40 "num_week_days=i" => \$num_week_days,
41 "selected_week_days=s" => \$selected_week_days_str,
42 "hour_slots=s" => \$hour_slots_str,
43 "fixed_intervals" => \$fixed_intervals,
44 "context=s" => \$context
45 );
46  
47 die "------------------------------------------------------------------------------
48 Usage: $0
49 -month [1..12] :not mandatory
50 -year <year> :mandatory
51 -context <context> :K8s context (mandatory)
52 -exp_files :yaml-encoded files with experiments sorted by priority
53 -spare_days <#> :number of business days to leave free per month
54 -starting_from <#> :day of each month to start with
55 -weights 'x,y,z' :a comma-separated string with the 3 weights for the
56 priorities starting from highest.
57 -num_week_days :number of business days to consider starting from Monday
58 defauts to 5
59 -selected_week_days :list of business days ids to consider:
60 1 => Monday,..., 5 => Friday
61 for example the string '2,3,4' would set tests to run only
62 between Tuesdays and Thursdays
63 -hour_slots :list of hours of the test shift, separate by commas
64 -fixed_intervals :if experiments times should be strictly scheduled in
65 fixed intervals or randomly allocated
66 -------------------------------------------------------------------------------"
67 unless $year && scalar @experiments_files;
68  
69 my @selected_week_days = split(/,/, $selected_week_days_str);
70 my @hour_slots = split(/,/, $hour_slots_str);
71  
72 foreach (@experiments_files) {
73 die "experiments file $_ not found or not readable" unless -f $_;
74 }
75  
76 my $experiments = [];
77  
78 foreach my $file ( @experiments_files ) {
79 my $exp = LoadFile ( $file );
80 for (my $priority=0;$priority<=2;$priority++) {
81 next unless $exp->[$priority];
82 push @{$experiments->[$priority]}, @{$exp->[$priority]};
83 }
84 }
85  
86 my $schedule = P2::Scheduler->new(
87 experiments => $experiments,
88 weight => [split(',',$weights)],
89 spare_days_per_month=> $spare_days_per_month,
90 starting_from => $starting_from,
91 year => $year,
92 num_week_days => $num_week_days,
93 selected_week_days => \@selected_week_days,
94 hour_slots => \@hour_slots,
95 fixed_intervals => $fixed_intervals,
96 context => $context
97 );
98  
99 my @report = ( $month ) ? $schedule->month_schedule( $month ) : $schedule->year_schedule();
100 print Dump ( [ @report ] );