Fix build on sparc64-linux-gnu.
[official-gcc.git] / libgomp / testsuite / libgomp.fortran / async_io_5.f90
blob916e78aa001da3c94e73ec483d38628c5b5dbb7c
1 ! { dg-do run }
2 !TODO: Move these testcases to gfortran testsuite
3 ! once compilation with pthreads is supported there
4 ! PR55818 Reading a REAL from a file which doesn't end in a new line fails
5 ! Test case from PR reporter.
6 implicit none
7 integer :: stat
8 !integer :: var ! << works
9 real :: var ! << fails
10 character(len=10) :: cvar ! << fails
11 complex :: cval
12 logical :: lvar
14 open(99, file="test.dat", access="stream", form="unformatted", status="new")
15 write(99) "1", new_line("")
16 write(99) "2", new_line("")
17 write(99) "3"
18 close(99)
20 ! Test character kind
21 open(99, file="test.dat")
22 read (99,*, iostat=stat) cvar
23 if (stat /= 0 .or. cvar /= "1") STOP 1
24 read (99,*, iostat=stat) cvar
25 if (stat /= 0 .or. cvar /= "2") STOP 2
26 read (99,*, iostat=stat) cvar ! << FAILS: stat /= 0
27 if (stat /= 0 .or. cvar /= "3") STOP 3 ! << aborts here
29 ! Test real kind
30 rewind(99)
31 read (99,*, iostat=stat) var
32 if (stat /= 0 .or. var /= 1.0) STOP 4
33 read (99,*, iostat=stat) var
34 if (stat /= 0 .or. var /= 2.0) STOP 5
35 read (99,*, iostat=stat) var ! << FAILS: stat /= 0
36 if (stat /= 0 .or. var /= 3.0) STOP 6
37 close(99, status="delete")
39 ! Test real kind with exponents
40 open(99, file="test.dat", access="stream", form="unformatted", status="new")
41 write(99) "1.0e3", new_line("")
42 write(99) "2.0e-03", new_line("")
43 write(99) "3.0e2"
44 close(99)
46 open(99, file="test.dat")
47 read (99,*, iostat=stat) var
48 if (stat /= 0) STOP 7
49 read (99,*, iostat=stat) var
50 if (stat /= 0) STOP 8
51 read (99,*) var ! << FAILS: stat /= 0
52 if (stat /= 0) STOP 9
53 close(99, status="delete")
55 ! Test logical kind
56 open(99, file="test.dat", access="stream", form="unformatted", status="new")
57 write(99) "Tru", new_line("")
58 write(99) "fal", new_line("")
59 write(99) "t"
60 close(99)
62 open(99, file="test.dat")
63 read (99,*, iostat=stat) lvar
64 if (stat /= 0 .or. (.not.lvar)) STOP 10
65 read (99,*, iostat=stat) lvar
66 if (stat /= 0 .or. lvar) STOP 11
67 read (99,*) lvar ! << FAILS: stat /= 0
68 if (stat /= 0 .or. (.not.lvar)) STOP 12
69 close(99, status="delete")
71 ! Test combinations of Inf and Nan
72 open(99, file="test.dat", access="stream", form="unformatted", status="new")
73 write(99) "infinity", new_line("")
74 write(99) "nan", new_line("")
75 write(99) "infinity"
76 close(99)
78 open(99, file="test.dat")
79 read (99,*, iostat=stat) var
80 if (stat /= 0) STOP 13
81 read (99,*, iostat=stat) var
82 if (stat /= 0) STOP 14
83 read (99,*) var ! << FAILS: stat /= 0
84 if (stat /= 0) STOP 1! << aborts here
85 close(99, status="delete")
87 open(99, file="test.dat", access="stream", form="unformatted", status="new")
88 write(99) "infinity", new_line("")
89 write(99) "inf", new_line("")
90 write(99) "nan"
91 close(99)
93 open(99, file="test.dat")
94 read (99,*, iostat=stat) var
95 if (stat /= 0) STOP 15
96 read (99,*, iostat=stat) var
97 if (stat /= 0) STOP 16
98 read (99,*) var ! << FAILS: stat /= 0
99 if (stat /= 0) STOP 2! << aborts here
100 close(99, status="delete")
102 open(99, file="test.dat", access="stream", form="unformatted", status="new")
103 write(99) "infinity", new_line("")
104 write(99) "nan", new_line("")
105 write(99) "inf"
106 close(99)
108 open(99, file="test.dat")
109 read (99,*, iostat=stat) var
110 if (stat /= 0) STOP 17
111 read (99,*, iostat=stat) var
112 if (stat /= 0) STOP 18
113 read (99,*) var ! << FAILS: stat /= 0
114 if (stat /= 0) STOP 3! << aborts here
115 close(99, status="delete")
117 ! Test complex kind
118 open(99, file="test.dat", access="stream", form="unformatted", status="new")
119 write(99) "(1,2)", new_line("")
120 write(99) "(2,3)", new_line("")
121 write(99) "(4,5)"
122 close(99)
124 open(99, file="test.dat")
125 read (99,*, iostat=stat) cval
126 if (stat /= 0 .or. cval /= cmplx(1,2)) STOP 19
127 read (99,*, iostat=stat) cval
128 if (stat /= 0 .or. cval /= cmplx(2,3)) STOP 20
129 read (99,*, iostat=stat) cval ! << FAILS: stat /= 0, value is okay
130 if (stat /= 0 .or. cval /= cmplx(4,5)) STOP 21
131 close(99, status="delete")