-
Izzard, Robert Dr (Maths & Physics) authoredIzzard, Robert Dr (Maths & Physics) authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test_random.pl 7.28 KiB
#!/usr/bin/env perl
$|=1;
use strict;
use IO::Select;
use rob_misc;
use robqueue;
use threads;
use threads::shared;
use 5.16.0;
use Term::ReadKey;
use Term::ANSIScreen qw(cls :cursor);
use Text::ANSITable;
binmode(STDOUT, ":utf8");
use Term::ANSIColor;
#
# Script to run binary_c across many CPUs
# perhaps through valgrind. Can be set to exit on error.
# NB to do this it must run each system individually,
# which is a little slow.
#
my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
my $args = "@ARGV";
check_ps() unless($args=~/skip_valgrind_check/);
$SIG{INT} = \&reaper;
my $valgrind = ($args=~/valgrind/) ? 'valgrind' : ''; # valgrind or ''
my $nice = ($args=~/nice=(\d+)/) ? "nice -n +$1" : 'nice';
my $timeout = ($args=~/timeout=(\d+)/) ? "timeout $1" : '';
my $repeat = ($args=~/repeat=(\d+)/)[0] // 1;
my $logtimes = ($args=~/logtimes/) ? 1 : 0;
my $ignore_time = ($args=~/ignore_time=(\S+)/)[0] // 2.0; # do not log time if < this
my $exit_on_error = ($args=~/exit_on_error/) // 0;
my $newlogs = ($args=~/newlogs/) ? 1 : 0;
my $opener = $newlogs ? '>' : '>>';
open(my $log,$opener,"$ENV{HOME}/binary_c_test_random.log")||die;
open(my $logtimes_file,$opener,"$ENV{HOME}/binary_c_test_random.logtimes")||die;
my $locklog :shared;
$log->autoflush(1);
my @screenlog : shared;
my $settle = ($args=~/(settle)/)[0] // 10; # wait this many seconds before output
my $sleeptime = ($args=~/sleeptime=(\S+)/)[0] // 0.25; # number of s to wait between checking for binary_c output
my $twarn = ($args=~/twarn=(\S+)/)[0] // 180.0; # warn if no output for this time
my $warn_every = ($args=~/warn_every=(\S+)/)[0] // 10.0; # warn every this many seconds
my $n_binary_c_threads = ($args=~/threads=cpu/i) ? (rob_misc::ncpus()-1) : ($args=~/threads=(\d+)/)[0] // 1;
my $nstore = ($args=~/nstore=(\d+)/)[0] // 1000;# store this many lines of output
print "Options :
valgrind $valgrind
nice : $nice
timeout : $timeout
repeat : $repeat
logtimes : $logtimes
ignore_time : $ignore_time
settle : $settle
sleeptime : $sleeptime
twarn : $twarn
warn_every : $warn_every
n_binary_c_threads : $n_binary_c_threads
nstore : $nstore
Files: log = $log, logtimes_file = $logtimes_file
\n";
my $q = robqueue->new(
nthreads=>$n_binary_c_threads+1,
subr=>\&runsystem,
prepend_thread_number_to_subroutine=>1
);