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 integer i, j, k, ltarray (9), idat (3), count, rate, count_max,
8 real tarray1(2), tarray2(2), r1, r2, etime
9 intrinsic getpid, getuid, getgid, ierrno, gerror,
10 + fnum, isatty, getarg, access, unlink, fstat,
11 + stat, lstat, getcwd, gmtime, hostnm, etime, chmod,
12 + chdir, fgetc, fputc, system_clock, second, idate, secnds,
13 + time, ctime, fdate, ttynam
16 character gerr*80, c*1
17 character ctim*25, line*80, lognam*20, wd*100, line2*80
18 integer fstatb (13), statb (13)
22 WRITE (6,'(A/)') '1 GNU libU77 test at: ' // ctim
23 write (6,'(A,I3,'', '',I3)')
24 + ' Logical units 5 and 6 correspond (FNUM) to'
25 + // ' Unix i/o units ', fnum(5), fnum(6)
26 if (lnblnk('foo ').ne.3 .or. len_trim('foo ').ne.3) then
27 print *, 'LNBLNK or LEN_TRIM failed'
33 line = 'and 6 is a tty device (ISATTY) named '//line2
35 line = 'and 6 isn''t a tty device (ISATTY)'
37 write (6,'(1X,A)') line(:lenstr(line))
39 WRITE (6,'(A,I10)') ' Process id (GETPID): ', pid
40 WRITE (6,'(A,I10)') ' User id (GETUID): ', GETUID ()
41 WRITE (6,'(A,I10)') ' Group id (GETGID): ', GETGID ()
42 WRITE (6,*) 'If you have the `id'' program, the following call of'
43 + // ' SYSTEM should agree with the above'
45 CALL SYSTEM ('echo " " `id`')
48 write (6,*) 'Login name (GETLOG): ', lognam
50 write(6,*) 'UMASK returns', mask
53 write (6,*) 'FDATE returns: ', ctim
55 call ltime (j, ltarray)
56 write (6,'(1x,a,9i4)') 'LTIME returns:', ltarray
57 call gmtime (j, ltarray)
58 write (6,'(1x,a,9i4)') 'GMTIME returns:', ltarray
59 call system_clock(count, rate, count_max)
60 write(6,*) 'SYSTEM_CLOCK returns: ', count, rate, count_max
61 write (6,*) 'Sleeping for 1 second (SLEEP) ...'
63 write (6,*) 'Looping 10,000,000 times ...'
67 if (r1.ne.tarray1(1)+tarray1(2))
68 + write (6,*) '*** ETIME didn''t return sum of the array: ',
71 if (abs (r1-r2).gt.1.0) write (6,*)
72 + 'Results of ETIME and DTIME differ by more than a second:',
74 write (6,'(A,3F10.3)')
75 + ' Elapsed total, user, system time (ETIME): ',
79 write (6,*) 'IDATE d,m,y: ',idat
80 print *, '... and the VXT version: ', i,j,k
83 write (6,*) 'SECNDS(0.0) returns: ',secnds(0.0)
84 write (6,*) 'SECOND returns: ', second()
87 write (6,*) 'CALL SECOND returns: ', r1
90 call perror ('*** getcwd')
92 write (6,*) 'Current directory is "'//wd(:lenstr(wd))//'"'
95 if (i.ne.0) write (6,*) '***CHDIR to ".": ', i
98 call perror ('*** hostnm')
100 write (6,*) 'Host name is ', wd(:lenstr(wd))
102 i = access('/dev/null ', 'rw')
103 if (i.ne.0) write (6,*) '***Read/write ACCESS to /dev/null: ', i
104 write (6,*) 'Creating file "foo" for testing...'
105 open (3,file='foo',status='UNKNOWN')
109 if (i+j.ne.0) write(6,*) '***FPUTC: ', i
110 C why is it necessary to reopen?
112 open(3,file='foo',status='old')
113 call fseek(3,0,0,*10)
115 10 write(6,*) '***FSEEK failed'
116 20 call fgetc(3, c,i)
117 if (i.ne.0) write(6,*) '***FGETC: ', i
118 if (c.ne.'c') write(6,*) '***FGETC read the wrong thing: ',
121 if (i.ne.1) write(6,*) '***FTELL offset: ', i
122 call chmod ('foo', 'a+w',i)
123 if (i.ne.0) write (6,*) '***CHMOD of "foo": ', i
124 i = fstat (3, fstatb)
125 if (i.ne.0) write (6,*) '***FSTAT of "foo": ', i
126 i = stat ('foo', statb)
127 if (i.ne.0) write (6,*) '***STAT of "foo": ', i
128 write (6,*) ' with stat array ', statb
129 if (statb(5).ne.getuid () .or. statb(6).ne.getgid() .or. statb(4)
130 + .ne. 1) write (6,*) '*** FSTAT uid, gid or nlink is wrong'
132 if (fstatb (i) .ne. statb (i))
133 + write (6,*) '*** FSTAT and STAT don''t agree on '// '
134 + array element ', i, ' value ', fstatb (i), statb (i)
136 i = lstat ('foo', fstatb)
138 if (fstatb (i) .ne. statb (i))
139 + write (6,*) '*** LSTAT and STAT don''t agree on '// '
140 + array element ', i, ' value ', fstatb (i), statb (i)
143 C in case it exists already:
144 call unlink ('bar',i)
145 call link ('foo ', 'bar ',i)
147 + write (6,*) '***LINK "foo" to "bar" failed: ', i
148 call unlink ('foo',i)
149 if (i.ne.0) write (6,*) '***UNLINK "foo" failed: ', i
150 call unlink ('foo',i)
151 if (i.eq.0) write (6,*) '***UNLINK "foo" again: ', i
154 write (6,'(A,I3,A/1X,A)') ' The current error number is: ',
156 + ' and the corresponding message is:', gerr(:lenstr(gerr))
157 write (6,*) 'This is sent to stderr prefixed by the program name'
158 call getarg (0, line)
159 call perror (line (:lenstr (line)))
161 WRITE (6,*) 'You should see exit status 1'
165 integer function lenstr (str)
166 C return length of STR not including trailing blanks, but always
172 lenstr = lnblnk (str)
175 * just make sure SECOND() doesn't "magically" work the second time.