File: run-basic-tests.pl

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (283 lines) | stat: -rwxr-xr-x 11,724 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

# This script runs one abinit built-in test in background mode while
# periodically displaying the status file till the end of the process.

# Copyright (C) 1999-2022 ABINIT group (LSi,XG)
# This file is distributed under the terms of the
# GNU General Public License, see ~ABINIT/COPYING
# or http://www.gnu.org/copyleft/gpl.txt .
# For the initials of contributors, see ~ABINIT/Infos/contributors .
#
# Usage :
# This script is intended to be called from Makefile (unix) or make.bat
# (DOS/Windows). Execute "make help" for details. It can also be called
# directly:
# unix shell: run-basic-tests machine_name [ 1 | 2 | 3 | 4 | 5 | 6] srcDir
# Windows DOS box: perl run-basic-tests.pl machine_name [ 1 | 2 | 3 | 4 | 5 | 6] srcDir
# MacOS (likely...) : perl -f run-basic-tests.pl machine_name [ 1 | 2 | 3 | 4 | 5 | 6] srcDir
#
$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator
#
$DELAY = 3;		# delay in seconds between 2 verifications of the STATUS file
$NCHECKS = 10;		# max number of times to check
$MAXLOOP = '50';	# maximum count for STATUS file checking loop
%PspFiles=('in_fast','01h.pspgth',
	 'in_v1','70yb.pspnc',
	 'in_v5','01h.pspgth:04be.pspgth',
	 'in_bigdft','01h.pspgth',
	 'in_etsf_io','20ca.paw',
	 'in_libxc','83bi.psphgh',
	 'in_wannier90','31ga.pspnc:33as.pspnc');
#
$debug = 0;		# Debug level ???
if ($ARGV[1] eq '') {
  print 'Missing argument';
	print "Usage is: run-basic-tests machine_name [ in_fast | in_v1 | in_v5 | in_bigdft | in_etsf_io | in_libxc | in_wannier90 ] srcDir";
	exit 16;
	}
$MACH = $ARGV[0];
$TestN = $ARGV[1];
$srcDir = $ARGV[2];

$TMPfile = 'Test_in.tmp';	# multi usage temporary file
$UNIXSLASH = '/';	# unix subdirectory delimitor in file paths (octal 057)
$DOSSLASH = '\\';	# subdirectory delimitor in DOS file paths (\ escaped)
$MACSLASH = ':';  # subdirectory delimitor in MAC file paths
$MULTI = '*';
# fetch some environment variables and try unix 'uname' command (Bourne shell)
$OSname = $ENV{'OS'};		# OS name on Windows systems
$OStype = $ENV{'OSTYPE'};	# defined on some systems as OPENVMS, mingw/msys
# Use internal variable of Perl $^O
if ($^O eq 'MacOS') {
  $OStype = 'MacOS'; $rc = 0;
	$MULTI = "\xc5";
  }
elsif ($OStype ne 'OPENVMS') {
  $unamerc = open(IP,"uname -a |");
  $_ = <IP>;
  chop $_;
  ($UNkernel,$wd2,$wd3,$wd4,$wd5,$wd6,$wd7,$wd8,$wd9) = split(' ',$_);
  close IP;
  }
print "uname: =$OSname=$OStype=$UNkernel=$unamerc= " if ($debug >= 1);
# Check for Windows 2000/XP (DOS box, cygwin, mingw, PGI Workstation, ...)
# cygwin, mingw, PGI Workstation are unix bash shells. However, older versions
# of the latter behave as a DOS one on some aspects
if ($OSname eq 'Windows_NT') {	# check Windows environmental variable
# When 'uname' command is unknown, the return code is undetermined.
# drop version code from kernel name
# by JMB : add support of mixed env cygwin + mingw compilation : MINGW64_NT
    $UNkernel = 'MINGW64_NT' if ( $UNkernel eq 'CYGWIN_NT-6.1-WOW64');
    $UNkernel = 'MINGW64_NT' if ( $UNkernel eq 'CYGWIN_NT-5.2-WOW64');
    $UNkernel =~ m/(.*)(-)([0-9]+\.[0-9]+)/;
    $UNkernel = $1 if ($& ne '');
    if ($OStype eq '' && $UNkernel eq '') {
	$OStype = 'DOS';	# set OStype
# since unlink <file*> fails on some versions of perl for DOS, let's use del
	$SLASH = $DOSSLASH;	# subdirectory delimitor for file paths
	$COPY_COMMAND = 'copy';         # DOS copy file command
	$ERASE_COMMAND = 'del /q';	# DOS delete file command
	$TYPE_COMMAND = 'type';		# DOS type file command
# Define the DOS conventions to call the dotest perl script by means of the
# "system" function
# NOTE: perl.exe is a DOS module that MUST be accessible through the DOS PATH
	$SUFXstyle = 'DOS';	# use DOS-style suffixes for binaries
	$PLSUFX = '.pl';	# DOS suffix for perl script
	$PRLPFX = 'start /min perl ';	# DOS command for background
	$BGSUFX = '';		# no special DOS suffix for new task
	$ENDtest = $MAXLOOP;	# loop limit in case dotest fails early
	print "File test$TestN.end will be checked to test end of abinit execution";
	print "The wait loop of this script is limited to $ENDtest cycles";
	}
    elsif ( $UNkernel eq 'CYGWIN_NT' || $UNkernel eq 'MINGW32_NT' || $UNkernel eq 'MINGW64_NT' ) {
# unix-like environment under Windows
	$OStype = $UNkernel; 	# set OStype for cygwin/mingw
# subdirectory delimitor for file paths is DOS \ under cygwin and standard /
# under other unices
	$SLASH = $UNkernel eq 'CYGWIN_NT' ? $DOSSLASH : $UNIXSLASH;
	$COPY_COMMAND = 'cp -p';  # unix copy file command
	$ERASE_COMMAND = 'rm -f';	# unix delete file command
	$TYPE_COMMAND = 'cat';		# unix type file command
	$SUFXstyle = 'unix';	# use unix-style suffixes for binaries,.
	$PLSUFX = '.pl';	# no special suffix for perl script under unix
	$PRLPFX = 'perl ';	# perl path ??? should use $(PERL)
	$BGSUFX = '&';		# special suffix for background task
	$ENDtest = 'ps';	# use unix ps command to check end of test
	}
    else {
	print "unrecognized Windows Subsystem =$OStype=$UNkernel=";
	exit (99);
	}
    }
# if not Windows NT check other environment variables and uname output
elsif ($OStype eq 'OPENVMS') {
    $SLASH = $UNIXSLASH;		# subdirectory delimitor in file paths
    $COPY_COMMAND = 'copy';     # OpenVMS copy file command
    $ERASE_COMMAND = 'delete ';	# OpenVMS delete file command
    $TYPE_COMMAND = 'type ';		# OpenVMS type file command
# for perl under normal unix systems:
    $SUFXstyle = 'vms';	# use unix-style suffixes for binaries, ...
    $PLSUFX = '.pl';		# no special suffix for perl script under unix
    $PRLPFX = 'perl ';		# perl path defined in first line of script
    $BGSUFX = '';		# special suffix for background task
    $ENDtest = 'vms';	# use gnv ps command to check end of test
    }
# MacOS section
elsif ($OStype eq 'MacOS') {
    $SLASH = $MACSLASH;             # subdirectory delimitor in file paths
    $COPY_COMMAND = 'Duplicate -c'; # copy file command
    $ERASE_COMMAND = 'Delete -y';   # delete file command
    $SUFXstyle = $OStype;        # use unix commands but MAC-style suffixes
    $PLSUFX = '.pl'; 	       # suffix for perl script
    }
# normal unix/linux section
elsif ($OSname eq '' && $UNkernel ne '') {
    $OStype = $UNkernel;	# set OStype for *ux
    $SLASH = $UNIXSLASH;	# subdirectory delimitor in file paths
    $COPY_COMMAND = '\cp ';      # copy file command
    $ERASE_COMMAND = '\rm -f';	# unix delete file command
    $TYPE_COMMAND = 'cat';	# unix type file command
# for perl under normal unix systems:
    $SUFXstyle = 'unix';	# use unix-style suffixes for binaries, ...
    $PLSUFX = '.pl';		# XG060708 : .pl is needed ... ?? no special suffix for perl script under unix
    $PRLPFX = 'perl ' ;		# XG060708 : perl is needed ... ?? perl path defined in first line of script
    $BGSUFX = '&';		# special suffix for background task
    $ENDtest = 'ps';	# use unix ps command to check end of test
    }
else {
    print "unrecognized Operating System -$OSname=$OStype=$UNkernel-";
    exit (99);
    }
# make sure "files" file exist
$inputfile = &transpath("$srcDir/built-in/Input/test$TestN.in");
print "$OStype $SLASH $SUFXstyle $inputfile" if ($debug >=2);
if (! -e &transpath("$inputfile") ) {
	print "Invalid test number: $TestN";
	print "Expected input file $inputfile not found";
	print "Usage is: run-basic-tests machine_name [ in_fast | in_v1 | in_v5 | in_bigdft | in_etsf_io | in_libxc | in_wannier90 ] srcDir ";
	exit (8);
	}
#
print "Built-in test $TestN will be run through run-basic-dotest$PLSUFX script" if ($debug >= 1);
# set a date flag to make a new directory today #
($sec,$min,$hour,$mday,$ymon,$yyear,$wday,$yday,$isdst)=localtime(time);
$ymon++;        # ymon was 0-11
$yyear +=1900;  # yyear was relative to 1900
$YYYYMMDD = sprintf("%4.4d",$yyear).sprintf("%2.2d",$ymon).sprintf("%2.2d",$mday);
$WORK_DIR = 'built-in';
if (! -e $WORK_DIR || ! -d $WORK_DIR) {
  mkdir ($WORK_DIR,0755);         # Mode 0755 ignored under DOS-Windows
  }
else {
  print "Do not create directory, $WORK_DIR already exists" if ($debug >= 1);
  }
print ('cd built-in') if ($debug >= 1);
chdir ('built-in');
$WORK_DIR = 'tmp-'.$MACH.'_'.$OStype.'_'.$YYYYMMDD;
if (! -e $WORK_DIR || ! -d $WORK_DIR) {
  mkdir ($WORK_DIR,0755);         # Mode 0755 ignored under DOS-Windows
  }
else {
  print "Do not create directory, $WORK_DIR already exists" if ($debug >= 1);
  }
print "cd $WORK_DIR" if ($debug >= 1);
chdir ("$WORK_DIR");

# suppress old files
unlink("test$TestN.end") if (-e "test$TestN.end");
unlink("test$TestN.log") if (-e "test$TestN.log");
unlink("test$TestN.out") if (-e "test$TestN.out");
unlink("test$TestN".'.o_WFK') if (-e "test$TestN".'.o_WFK');
if ($OStype eq 'OPENVMS') {
  $statfile = "test$TestN".'_STATUS.dat';	# name of STATUS file
  }
else {
  $statfile = "test$TestN".'_STATUS';	# name of STATUS file
  }
unlink($statfile) if (-e $statfile);
# Write input files for test
system("$COPY_COMMAND ".&transpath("$srcDir/built-in/Input/test$TestN.in")." test$TestN.in");
if ($TestN eq 'in_wannier90') {
  system("$COPY_COMMAND ".&transpath("$srcDir/built-in/Input/testin_wannier90o_w90.win")." testin_wannier90o_w90.win");
  }
# Write abinit.files for test
$rc = open (FILES,">test$TestN.files");
print FILES "test$TestN.in";
print FILES "test$TestN.out";
print FILES "test$TestN".'i';
print FILES "test$TestN".'o';
print FILES "test$TestN";
@PsP = split(':', $PspFiles{"$TestN"} );
print "Psp files: @PsP" if ($debug >=1);

if( $UNkernel eq 'MINGW64_NT') {
   print FILES &transpath("/cygwin$srcDir/Psps_for_tests/$PsP[0]");
   print FILES &transpath("/cygwin$srcDir/Psps_for_tests/$PsP[1]") if ($PsP[1] ne '');
} else {
   print FILES &transpath("$srcDir/Psps_for_tests/$PsP[0]");
   print FILES &transpath("$srcDir/Psps_for_tests/$PsP[1]") if ($PsP[1] ne '');
}

print FILES &transpath("$srcDir/Psps_for_tests/$PsP[0]");
print FILES &transpath("$srcDir/Psps_for_tests/$PsP[1]") if ($PsP[1] ne '');
close (FILES);
# abinit will be started through a dotest perl script
# this is necessary under DOS/Windows because of file redirections
$cmd = $PRLPFX.&transpath("$srcDir/Scripts/run-basic-dotest$PLSUFX")." $TestN $ENDtest $SLASH $SUFXstyle $BGSUFX";
print $cmd if ($debug >= 2);
$rc = system($cmd);
die "Error $rc starting run-basic-dotest" if ($rc != 0);
# loop waiting end of abinit execution
$ichk = $NCHECKS;
while ($ichk > 0) {
	sleep($DELAY);		# take a few seconds rest

	if ($ENDtest eq 'ps') {
# check abinit process using unix ps
		$cmd = 'ps | grep abinit | grep -v grep > '.$TMPfile;
		print $cmd if ($debug >= 2);
		$rc = system($cmd);
		last if (-z $TMPfile);	# no abinit process was found
		}
	elsif ($ENDtest eq 'vms') {
# always end for VMS
    last;
		}
	else {
# check presence of file "test$Test0N.end"  (like test1.end)
		last if (-e "test$TestN.end");	# dotest has completed
		$ENDtest --;	# decrement loop counter
		if ($ENDtest <= 0) {
			print 'Wait loop limit reached, run-basic-dotest not yet finished';
			exit;		# loop limit reached
			}
		}
	$cmd = "$TYPE_COMMAND $statfile";
	system($cmd) if (-e $statfile);	# type status file if it exists
	$ichk--;
	}
#
$cmd = "$TYPE_COMMAND $statfile";
system($cmd) if (-e $statfile);	# type status file if it exists
unlink ("$TMPfile") if (-e $TMPfile);
exit (0);

# ****************************************
sub transpath {
  local($path) = @_;
#
# purpose: translate unix-like path of file to DOS-like according to $SLASH
# argument:
#       $path = path to be translated
# output: this subroutine acts as a function and returns the path
# according to host conventions

  $path =~ tr/\057/\\/ if ($SLASH eq '\\');
  if ($OStype eq 'MacOS') {
    $path =~ tr/\057/:/;
    $path =~ s/\.\.//g;
    $path =~ s/:/::/ ;
    }
  return $path;
  }