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 * NOTE! This is the libU77 version, so it should be a bit more
7 * "interactive" than the testsuite version, which is in
8 * gcc/testsuite/g77.f-torture/execute/u77-test.f.
9 * This version purposely exits with a "failure" status, to test
10 * returning of non-zero status, and it doesn't call the ABORT
11 * intrinsic (it substitutes an EXTERNAL stub, so the code can be
12 * kept nearly the same in both copies). Also, it goes ahead and
13 * tests the HOSTNM intrinsic. Please keep the other copy up-to-date when
14 * you modify this one.
22 integer i, j, k, ltarray (9), idat (3), count, rate, count_max,
24 real tarray1(2), tarray2(2), r1, r2
26 intrinsic getpid, getuid, getgid, ierrno, gerror,
27 + fnum, isatty, getarg, access, unlink, fstat,
28 + stat, lstat, getcwd, gmtime, etime, chmod,
29 + chdir, fgetc, fputc, system_clock, second, idate, secnds,
30 + time, ctime, fdate, ttynam, date_and_time
31 external lenstr, ctrlc
34 character gerr*80, c*1
35 character ctim*25, line*80, lognam*20, wd*100, line2*80, ddate*8,
37 integer fstatb (13), statb (13)
40 integer(kind=7) sigret
43 WRITE (6,'(A/)') '1 GNU libU77 test at: ' // ctim
44 write (6,'(A,I3,'', '',I3)')
45 + ' Logical units 5 and 6 correspond (FNUM) to'
46 + // ' Unix i/o units ', fnum(5), fnum(6)
47 if (lnblnk('foo ').ne.3 .or. len_trim('foo ').ne.3) then
48 print *, 'LNBLNK or LEN_TRIM failed'
54 line = 'and 6 is a tty device (ISATTY) named '//line2
56 line = 'and 6 isn''t a tty device (ISATTY)'
58 write (6,'(1X,A)') line(:lenstr(line))
60 * regression test for compiler crash fixed by JCB 1998-08-04 com.c
61 sigret = signal(2, ctrlc)
64 WRITE (6,'(A,I10)') ' Process id (GETPID): ', pid
65 WRITE (6,'(A,I10)') ' User id (GETUID): ', GETUID ()
66 WRITE (6,'(A,I10)') ' Group id (GETGID): ', GETGID ()
67 WRITE (6, *) 'If you have the `id'' program, the following call'
68 write (6, *) 'of SYSTEM should agree with the above:'
70 CALL SYSTEM ('echo " " `id`')
72 lognam = 'blahblahblah'
74 write (6,*) 'Login name (GETLOG): ', lognam
76 write(6,*) 'UMASK returns', mask
80 write (6,*) 'FDATE returns: ', ctim
82 call ltime (j, ltarray)
83 write (6,'(1x,a,9i4)') 'LTIME returns:', ltarray
84 call gmtime (j, ltarray)
85 write (6,'(1x,a,9i4)') 'GMTIME returns:', ltarray
86 call system_clock(count) ! omitting optional args
87 call system_clock(count, rate, count_max)
88 write(6,*) 'SYSTEM_CLOCK returns: ', count, rate, count_max
89 call date_and_time(ddate) ! omitting optional args
90 call date_and_time(ddate, ttime, zone, values)
91 write(6, *) 'DATE_AND_TIME returns: ', ddate, ' ', ttime, ' ',
94 write (6,*) 'Sleeping for 1 second (SLEEP) ...'
97 c consistency-check etime vs. dtime for first call
100 if (abs (r1-r2).gt.1.0) then
102 + 'Results of ETIME and DTIME differ by more than a second:',
106 if (.not. issum (r1, tarray1(1), tarray1(2))) then
107 write (6,*) '*** ETIME didn''t return sum of the array: ',
108 + r1, ' /= ', tarray1(1), '+', tarray1(2)
111 if (.not. issum (r2, tarray2(1), tarray2(2))) then
112 write (6,*) '*** DTIME didn''t return sum of the array: ',
113 + r2, ' /= ', tarray2(1), '+', tarray2(2)
116 write (6, '(A,3F10.3)')
117 + ' Elapsed total, user, system time (ETIME): ',
120 c now try to get times to change enough to see in etime/dtime
121 write (6,*) 'Looping until clock ticks at least once...'
126 if (tarray2(1) .ne. 0. .or. tarray2(2) .ne. 0.) exit
129 if (.not. issum (r1, tarray1(1), tarray1(2))) then
130 write (6,*) '*** ETIME didn''t return sum of the array: ',
131 + r1, ' /= ', tarray1(1), '+', tarray1(2)
134 if (.not. issum (r2, tarray2(1), tarray2(2))) then
135 write (6,*) '*** DTIME didn''t return sum of the array: ',
136 + r2, ' /= ', tarray2(1), '+', tarray2(2)
139 write (6, '(A,3F10.3)')
140 + ' Differences in total, user, system time (DTIME): ',
142 write (6, '(A,3F10.3)')
143 + ' Elapsed total, user, system time (ETIME): ',
145 write (6, *) '(Clock-tick detected after ', i, ' 1K loops.)'
149 write (6,*) 'IDATE (date,month,year): ',idat
150 print *, '... and the VXT version (month,date,year): ', i,j,k
151 if (i/=idat(2) .or. j/=idat(1) .or. k/=mod(idat(3),100)) then
152 print *, '*** VXT and U77 versions don''t agree'
156 print *, 'TIME: ', line(:8)
157 write (6,*) 'SECNDS(0.0) returns: ',secnds(0.0)
158 write (6,*) 'SECOND returns: ', second()
161 write (6,*) 'CALL SECOND returns: ', r1
162 * compiler crash fixed by 1998-10-01 com.c change
163 if (rand(0).lt.0.0 .or. rand(0).gt.1.0) then
164 write (6,*) '*** rand(0) error'
169 call perror ('*** getcwd')
172 write (6,*) 'Current directory is "'//wd(:lenstr(wd))//'"'
176 write (6,*) '***CHDIR to ".": ', i
181 call perror ('*** hostnm')
184 write (6,*) 'Host name is ', wd(:lenstr(wd))
186 i = access('/dev/null ', 'rw')
187 if (i.ne.0) write (6,*) '***Read/write ACCESS to /dev/null: ', i
188 write (6,*) 'Creating file "foo" for testing...'
189 open (3,file='foo',status='UNKNOWN')
193 if (i+j.ne.0) write(6,*) '***FPUTC: ', i
194 C why is it necessary to reopen? (who wrote this?)
195 C the better to test with, my dear! (-- burley)
197 open(3,file='foo',status='old')
198 call fseek(3,0,0,*10)
200 10 write(6,*) '***FSEEK failed'
202 20 call fgetc(3, c,i)
204 write(6,*) '***FGETC: ', i
208 write(6,*) '***FGETC read the wrong thing: ', ichar(c)
213 write(6,*) '***FTELL offset: ', i
216 call chmod ('foo', 'a+w',i)
218 write (6,*) '***CHMOD of "foo": ', i
221 i = fstat (3, fstatb)
223 write (6,*) '***FSTAT of "foo": ', i
226 i = stat ('foo', statb)
228 write (6,*) '***STAT of "foo": ', i
231 write (6,*) ' with stat array ', statb
232 if (statb(5).ne.getuid () .or. statb(6).ne.getgid() .or. statb(4)
234 write (6,*) '*** FSTAT uid, gid or nlink is wrong'
238 if (fstatb (i) .ne. statb (i)) then
239 write (6,*) '*** FSTAT and STAT don''t agree on '// '
240 + array element ', i, ' value ', fstatb (i), statb (i)
244 i = lstat ('foo', fstatb)
246 if (fstatb (i) .ne. statb (i)) then
247 write (6,*) '*** LSTAT and STAT don''t agree on '//
248 + 'array element ', i, ' value ', fstatb (i), statb (i)
253 C in case it exists already:
254 call unlink ('bar',i)
255 call link ('foo ', 'bar ',i)
257 write (6,*) '***LINK "foo" to "bar" failed: ', i
260 call unlink ('foo',i)
262 write (6,*) '***UNLINK "foo" failed: ', i
265 call unlink ('foo',i)
267 write (6,*) '***UNLINK "foo" again: ', i
272 write (6,'(A,I3,A/1X,A)') ' The current error number is: ',
274 + ' and the corresponding message is:', gerr(:lenstr(gerr))
275 write (6,*) 'This is sent to stderr prefixed by the program name'
276 call getarg (0, line)
277 call perror (line (:lenstr (line)))
279 WRITE (6,*) 'You should see exit status 1'
283 * Return length of STR not including trailing blanks, but always > 0.
284 integer function lenstr (str)
289 lenstr = lnblnk (str)
293 * Just make sure SECOND() doesn't "magically" work the second time.
298 * Test whether sum is approximately left+right.
299 logical function issum (sum, left, right)
301 real sum, left, right
302 real mysum, delta, width
304 delta = abs (mysum - sum)
305 width = abs (left) + abs (right)
306 issum = (delta .le. .0001 * width)
315 * A problem has been noticed, so maybe abort the test.
317 * For this version, print out all problems noticed.