Merge pull request #53 from t2-kob/environment_settings

Added change directories and filename via Environment variables.
This commit is contained in:
Kelly Lucas 2018-01-13 20:05:29 -08:00 committed by GitHub
commit 5734fb362d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 9 deletions

View File

@ -5,6 +5,7 @@ use strict;
use POSIX qw(strftime);
use Time::HiRes;
use IO::Handle;
use File::Path;
use FindBin;
@ -569,17 +570,33 @@ sub getCmdOutput {
sub getDir {
my ( $var, $def ) = @_;
# If Environment variables(e.g. UB_RESULTDIR) is unset, use default value.
my $val = $ENV{$var} || $def;
# Canonicalise the value.
my $wd;
chomp($wd = `pwd`);
chdir($val);
chomp($val = `pwd`);
chdir($wd);
# Only "execl.c" test needs the Environment variable(UB_BINDIR).
$ENV{$var} = $val;
$val;
return $val;
}
# Create direcotry(0755) if not exists.
sub createDirrectoriesIfNotExists {
foreach my $path (@_) {
my $isDirectoryNotExists = ! -d $path;
if ( $isDirectoryNotExists ) {
mkpath($path, {chmod => 0755});
}
}
}
# Show use directories.
sub printUsingDirectories {
printf "------------------------------------------------------------------------------\n";
printf " Use directories for:\n";
printf " * File I/O tests (named fs***) = ${TMPDIR}\n";
printf " * Results = ${RESULTDIR}\n";
printf "------------------------------------------------------------------------------\n";
printf "\n";
}
@ -588,11 +605,18 @@ sub getDir {
sub logFile {
my ( $sysInfo ) = @_;
my $count = 1;
# If supplied output file name via Environment variable(UB_OUTPUT_FILE_NAME), then use it.
# * If exists same file, it will be overwrite completly.
my $output_file_name_supplied_by_environment = $ENV{"UB_OUTPUT_FILE_NAME"};
if ( defined($output_file_name_supplied_by_environment) && $output_file_name_supplied_by_environment ne "" ) {
return ${RESULTDIR} . "/" . $output_file_name_supplied_by_environment;
}
# Use the date in the base file name.
my $ymd = strftime "%Y-%m-%d", localtime;
my $count = 1;
while (1) {
my $log = sprintf "%s/%s-%s-%02d",
${RESULTDIR}, $sysInfo->{'name'}, $ymd, $count;
@ -1872,6 +1896,10 @@ sub main {
$tests = $index;
}
# Create directories.
my @creatingDirectories = ( ${TMPDIR}, ${RESULTDIR} );
createDirrectoriesIfNotExists(@creatingDirectories);
preChecks();
my $systemInfo = getSystemInfo();
@ -1888,6 +1916,11 @@ sub main {
# Display the program banner.
system("cat \"${BINDIR}/unixbench.logo\"");
# Show output output directories, if not in quiet mode.
if ($verbose > 0) {
printUsingDirectories();
}
if ($verbose > 1) {
printf "\n", join(", ", @$tests);
printf "Tests to run: %s\n", join(", ", @$tests);

View File

@ -65,7 +65,11 @@ so that randomly-churning background processes don't randomise the results
too much. This is particularly true for the graphics tests.
If you need to change the directories, use "Environment variables" about below.
Output can be specified by setting the following environment variables:
* "UB_RESULTDIR" : Absolute path of output directory of result files.
* "UB_TMPDIR" : Absolute path of temporary files for IO tests.
* "UB_OUTPUT_FILE_NAME" : Output file name. If exists it will be overwritten.
* "UB_OUTPUT_CSV" : If set "true", output results(score only) to .csv.
============================================================================