OSDN Git Service

* Previous contents of gcc/f/runtime moved into toplevel
[pf3gnuchains/gcc-fork.git] / libf2c / libU77 / u77-test.f
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 
4 *     starred messages.
5
6       integer i, j, k, ltarray (9), idat (3), count, rate, count_max,
7      +     pid
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
14       external lenstr
15       logical l
16       character gerr*80, c*1
17       character ctim*25, line*80, lognam*20, wd*100, line2*80
18       integer fstatb (13), statb (13)
19       integer *2 i2zero
20
21       ctim = ctime(time())
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'
28         call exit(1)
29       end if
30       l= isatty(6)
31       line2 = ttynam(6)
32       if (l) then
33         line = 'and 6 is a tty device (ISATTY) named '//line2
34       else
35         line = 'and 6 isn''t a tty device (ISATTY)'
36       end if
37       write (6,'(1X,A)') line(:lenstr(line))
38       pid = getpid()
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'
44       call flush(6)
45       CALL SYSTEM ('echo " " `id`')
46       call flush
47       call getlog (lognam)
48       write (6,*) 'Login name (GETLOG): ', lognam
49       call umask(0, mask)
50       write(6,*) 'UMASK returns', mask
51       call umask(mask)
52       ctim = fdate()
53       write (6,*) 'FDATE returns: ', ctim
54       j=time()
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) ...'
62       call sleep (1)
63       write (6,*) 'Looping 10,000,000 times ...'
64       do i=1,10*1000*1000
65       end do
66       r1= etime (tarray1)
67       if (r1.ne.tarray1(1)+tarray1(2))
68      +     write (6,*) '*** ETIME didn''t return sum of the array: ',
69      +     r1, ' /= ', tarray1
70       r2= dtime (tarray2)
71       if (abs (r1-r2).gt.1.0) write (6,*)
72      +     'Results of ETIME and DTIME differ by more than a second:',
73      +     i, j
74       write (6,'(A,3F10.3)')
75      +     ' Elapsed total, user, system time (ETIME): ',
76      +     r1, tarray1
77       call idate(i,j,k)
78       call idate (idat)
79       write (6,*) 'IDATE d,m,y: ',idat
80       print *,  '... and the VXT version: ', i,j,k
81       call time(line(:8))
82       print *, line(:8)
83       write (6,*) 'SECNDS(0.0) returns: ',secnds(0.0)
84       write (6,*) 'SECOND returns: ', second()
85       call dumdum(r1)
86       call second(r1)
87       write (6,*) 'CALL SECOND returns: ', r1
88       i = getcwd(wd)
89       if (i.ne.0) then
90         call perror ('*** getcwd')
91       else
92         write (6,*) 'Current directory is "'//wd(:lenstr(wd))//'"'
93       end if
94       call chdir ('.',i)
95       if (i.ne.0) write (6,*) '***CHDIR to ".": ', i
96       i=hostnm(wd)
97       if(i.ne.0) then
98         call perror ('*** hostnm')
99       else
100         write (6,*) 'Host name is ', wd(:lenstr(wd))
101       end if
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')
106       rewind 3
107       call fputc(3, 'c',i)
108       call fputc(3, 'd',j)      
109       if (i+j.ne.0) write(6,*) '***FPUTC: ', i
110 C     why is it necessary to reopen?
111       close(3)
112       open(3,file='foo',status='old')
113       call fseek(3,0,0,*10)
114       go to 20
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: ',
119      +     ichar(c)
120       i= ftell(3)
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'
131       do i=1,13
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)
135       end do
136       i = lstat ('foo', fstatb)
137       do i=1,13
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)
141       end do
142
143 C     in case it exists already:
144       call unlink ('bar',i)
145       call link ('foo ', 'bar ',i)
146       if (i.ne.0)
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
152       call gerror (gerr)
153       i = ierrno()
154       write (6,'(A,I3,A/1X,A)') ' The current error number is: ',
155      +     i,
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)))
160       call unlink ('bar')
161       WRITE (6,*) 'You should see exit status 1'
162       CALL EXIT(1)
163  99   END
164
165       integer function lenstr (str)
166 C     return length of STR not including trailing blanks, but always
167 C     return >0
168       character *(*) str
169       if (str.eq.' ') then
170         lenstr=1
171       else
172         lenstr = lnblnk (str)
173       end if
174       end
175 * just make sure SECOND() doesn't "magically" work the second time.
176       subroutine dumdum(r)
177       r = 3.14159
178       end