1 *** Some random stuff
for testing libU77
. Should be done better
. It
's
2 * hard to test things where you can't guarantee the result
. Have a
3 * good squint at what it prints
, though detected errors will cause
6 * Currently not tested
:
29 * NOTE
! This is the libU77 version
, so it should be a bit more
30 * "interactive" than the testsuite version
, which is in
31 * gcc
/testsuite
/g77
.f
-torture
/execute
/u77
-test
.f
.
32 * This version purposely exits with a
"failure" status
, to test
33 * returning of non
-zero status
, and it doesn
't call the ABORT
34 * intrinsic (it substitutes an EXTERNAL stub, so the code can be
35 * kept nearly the same in both copies). Also, it goes ahead and
36 * tests the HOSTNM intrinsic. Please keep the other copy up-to-date when
37 * you modify this one.
45 integer i, j, k, ltarray (9), idat (3), count, rate, count_max,
47 real tarray1(2), tarray2(2), r1, r2
51 intrinsic getpid, getuid, getgid, ierrno, gerror, time8,
52 + fnum, isatty, getarg, access, unlink, fstat, iargc,
53 + stat, lstat, getcwd, gmtime, etime, chmod, itime, date,
54 + chdir, fgetc, fputc, system_clock, second, idate, secnds,
55 + time, ctime, fdate, ttynam, date_and_time, mclock, mclock8,
56 + cpu_time, dtime, ftell, abort
57 external lenstr, ctrlc
60 character gerr*80, c*1
61 character ctim*25, line*80, lognam*20, wd*1000, line2*80,
62 + ddate*8, ttime*10, zone*5, ctim2*25
63 integer fstatb (13), statb (13)
66 integer(kind=7) sigret
70 WRITE (6,'(A
/)') '1 GNU libU77 test at
: ' // ctim(:lenstr (ctim))
71 write (6,'(A
,I3
,'', '',I3
)')
72 + ' Logical units
5 and
6 correspond
(FNUM
) to'
73 + // ' Unix i
/o units
', fnum(5), fnum(6)
74 if (lnblnk('foo
').ne.3 .or. len_trim('foo
').ne.3) then
75 print *, 'LNBLNK or LEN_TRIM failed
'
82 if (ctim .ne. ctim2) then
83 write (6, *) '*** CALL CTIME disagrees with CTIME
(): ',
84 + ctim2(:lenstr (ctim2)), ' vs
. ', ctim(:lenstr (ctim))
89 if (i .gt. bigi .or. bigi .gt. j) then
90 write (6, *) '*** TIME
/TIME8
/TIME sequence failures
: ',
95 print *, 'Command
-line arguments
: ', iargc ()
98 print *, 'Arg
', i, ' is
: ', line(:lenstr (line))
104 line = 'and
6 is a tty device
(ISATTY
) named
'//line2
106 line = 'and
6 isn
''t a tty device
(ISATTY
)'
108 write (6,'(1X
,A
)') line(:lenstr(line))
109 call ttynam (6, line)
110 if (line .ne. line2) then
111 print *, '*** CALL TTYNAM disagrees with TTYNAM
: ',
112 + line(:lenstr (line))
116 * regression test for compiler crash fixed by JCB 1998-08-04 com.c
117 sigret = signal(2, ctrlc)
120 WRITE (6,'(A
,I10
)') ' Process id
(GETPID
): ', pid
121 WRITE (6,'(A
,I10
)') ' User id
(GETUID
): ', GETUID ()
122 WRITE (6,'(A
,I10
)') ' Group id
(GETGID
): ', GETGID ()
123 WRITE (6, *) 'If you have the `id
'' program, the following
call'
124 write (6, *) 'of SYSTEM should agree with the above
:'
126 CALL SYSTEM ('echo
" " `id`
')
129 lognam = 'blahblahblah
'
131 write (6,*) 'Login name
(GETLOG
): ', lognam(:lenstr (lognam))
134 call getenv ('LOGNAME
', wd)
135 write (6,*) 'Login name
(GETENV of LOGNAME
): ', wd(:lenstr (wd))
138 write(6,*) 'UMASK returns
', mask
142 write (6,*) 'FDATE returns
: ', ctim(:lenstr (ctim))
144 write (6,*) 'CALL FDATE returns
: ', ctim(:lenstr (ctim))
147 call ltime (j, ltarray)
148 write (6,'(1x
,a
,9i4
)') 'LTIME returns
:', ltarray
149 call gmtime (j, ltarray)
150 write (6,'(1x
,a
,9i4
)') 'GMTIME returns
:', ltarray
152 call system_clock(count) ! omitting optional args
153 call system_clock(count, rate, count_max)
154 write(6,*) 'SYSTEM_CLOCK returns
: ', count, rate, count_max
156 call date_and_time(ddate) ! omitting optional args
157 call date_and_time(ddate, ttime, zone, values)
158 write(6, *) 'DATE_AND_TIME returns
: ', ddate, ' ', ttime, ' ',
161 write (6,*) 'Sleeping
for 1 second
(SLEEP
) ...'
164 c consistency-check etime vs. dtime for first call
167 if (abs (r1-r2).gt.1.0) then
169 + 'Results of ETIME and DTIME differ by more than a second
:',
173 if (.not. issum (r1, tarray1(1), tarray1(2))) then
174 write (6,*) '*** ETIME didn
''t
return sum of the array
: ',
175 + r1, ' /= ', tarray1(1), '+', tarray1(2)
178 if (.not. issum (r2, tarray2(1), tarray2(2))) then
179 write (6,*) '*** DTIME didn
''t
return sum of the array
: ',
180 + r2, ' /= ', tarray2(1), '+', tarray2(2)
183 write (6, '(A
,3F10
.3
)')
184 + ' Elapsed total
, user
, system time
(ETIME
): ',
187 c now try to get times to change enough to see in etime/dtime
188 write (6,*) 'Looping until clock ticks at least once
...'
192 call dtime (tarray2, r2)
193 if (tarray2(1) .ne. 0. .or. tarray2(2) .ne. 0.) exit
195 call etime (tarray1, r1)
196 if (.not. issum (r1, tarray1(1), tarray1(2))) then
197 write (6,*) '*** ETIME didn
''t
return sum of the array
: ',
198 + r1, ' /= ', tarray1(1), '+', tarray1(2)
201 if (.not. issum (r2, tarray2(1), tarray2(2))) then
202 write (6,*) '*** DTIME didn
''t
return sum of the array
: ',
203 + r2, ' /= ', tarray2(1), '+', tarray2(2)
206 write (6, '(A
,3F10
.3
)')
207 + ' Differences in total
, user
, system time
(DTIME
): ',
209 write (6, '(A
,3F10
.3
)')
210 + ' Elapsed total
, user
, system time
(ETIME
): ',
212 write (6, *) '(Clock
-tick detected after
', i, ' 1K loops
.)'
216 write (6,*) 'IDATE
(date,month
,year
): ',idat
217 print *, '... and the VXT version
(month
,date,year
): ', i,j,k
218 if (i/=idat(2) .or. j/=idat(1) .or. k/=mod(idat(3),100)) then
219 print *, '*** VXT and U77 versions don
''t agree
'
224 write (6,*) 'DATE (dd
-mmm
-yy
): ', ctim(:lenstr (ctim))
227 write (6,*) 'ITIME
(hour
,minutes
,seconds
): ', idat
230 print *, 'TIME
: ', line(:8)
232 write (6,*) 'SECNDS
(0.0) returns
: ',secnds(0.0)
234 write (6,*) 'SECOND returns
: ', second()
237 write (6,*) 'CALL SECOND returns
: ', r1
239 * compiler crash fixed by 1998-10-01 com.c change
240 if (rand(0).lt.0.0 .or. rand(0).gt.1.0) then
241 write (6,*) '*** rand
(0) error
'
247 call perror ('*** getcwd
')
250 write (6,*) 'Current directory is
"'//wd(:lenstr(wd))//'"'
254 write (6,*) '***CHDIR
to ".": ', i
260 call perror ('*** hostnm
')
263 write (6,*) 'Host name is
', wd(:lenstr(wd))
266 i = access('/dev
/null
', 'rw
')
267 if (i.ne.0) write (6,*) '***Read/write ACCESS
to /dev
/null
: ', i
268 write (6,*) 'Creating file
"foo" for testing
...'
269 open (3,file='foo
',status='UNKNOWN
')
273 if (i+j.ne.0) write(6,*) '***FPUTC
: ', i
274 C why is it necessary to reopen? (who wrote this?)
275 C the better to test with, my dear! (-- burley)
277 open(3,file='foo
',status='old
')
278 call fseek(3,0,0,*10)
280 10 write(6,*) '***FSEEK failed
'
282 20 call fgetc(3, c,i)
284 write(6,*) '***FGETC
: ', i
288 write(6,*) '***FGETC
read the wrong thing
: ', ichar(c)
293 write(6,*) '***FTELL offset
: ', i
298 write(6,*) '***CALL FTELL offset
: ', i
301 call chmod ('foo
', 'a
+w
',i)
303 write (6,*) '***CHMOD of
"foo": ', i
306 i = fstat (3, fstatb)
308 write (6,*) '***FSTAT of
"foo": ', i
311 i = stat ('foo
', statb)
313 write (6,*) '***STAT of
"foo": ', i
316 write (6,*) ' with stat array
', statb
317 if (statb(6) .ne. getgid ()) then
318 write (6,*) 'Note
: FSTAT gid wrong
(happens on some systems
).'
320 if (statb(5) .ne. getuid () .or. statb(4) .ne. 1) then
321 write (6,*) '*** FSTAT uid or nlink is wrong
'
325 if (fstatb (i) .ne. statb (i)) then
326 write (6,*) '*** FSTAT and STAT don
''t agree on
'// '
327 + array element
', i, ' value
', fstatb (i), statb (i)
331 i = lstat ('foo
', fstatb)
333 if (fstatb (i) .ne. statb (i)) then
334 write (6,*) '*** LSTAT and STAT don
''t agree on
'//
335 + 'array element
', i, ' value
', fstatb (i), statb (i)
340 C in case it exists already:
341 call unlink ('bar
',i)
342 call link ('foo
', 'bar
',i)
344 write (6,*) '***LINK
"foo" to "bar" failed
: ', i
347 call unlink ('foo
',i)
349 write (6,*) '***UNLINK
"foo" failed
: ', i
352 call unlink ('foo
',i)
354 write (6,*) '***UNLINK
"foo" again
: ', i
360 write (6,'(A
,I3
,A
/1X
,A
)') ' The current error number is
: ',
362 + ' and the corresponding message is
:', gerr(:lenstr(gerr))
363 write (6,*) 'This is sent
to stderr prefixed by the
program name
'
364 call getarg (0, line)
365 call perror (line (:lenstr (line)))
368 print *, 'MCLOCK returns
', mclock ()
369 print *, 'MCLOCK8 returns
', mclock8 ()
372 print *, 'CPU_TIME returns
', d1
374 WRITE (6,*) 'You should see exit status
1'
378 * Return length of STR not including trailing blanks, but always > 0.
379 integer function lenstr (str)
384 lenstr = lnblnk (str)
388 * Just make sure SECOND() doesn't
"magically" work the second time
.
393 * Test whether sum is approximately left
+right
.
394 logical function issum
(sum
, left
, right
)
396 real sum
, left
, right
397 real mysum
, delta
, width
399 delta
= abs
(mysum
- sum
)
400 width
= abs
(left
) + abs
(right
)
401 issum
= (delta
.le
. .0001 * width
)
410 * A problem has been noticed
, so maybe abort the test
.
412 * For this version
, print out all problems noticed
.