/[eiffelstudio]/trunk/eweasel/tests/scoop061/test.e
ViewVC logotype

Contents of /trunk/eweasel/tests/scoop061/test.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97323 - (show annotations)
Tue May 19 13:33:49 2015 UTC (4 years, 8 months ago) by alexk
File size: 2935 byte(s)
Added an example that demonstrates that reads and writes to tuple fields are not performed in an exclusive mode.
1 class TEST
2
3 inherit
4 EXECUTION_ENVIRONMENT
5
6 create
7 make,
8 make_other,
9 make_tuple
10
11 feature {NONE} -- Creation
12
13 make
14 -- Run the test.
15 local
16 other: separate TEST
17 do
18 create flag
19 separate create {separate TEST}.make_tuple (3) as t do
20 tuple := t.tuple
21 end
22 create other.make_other (flag, tuple)
23 separate other as o do
24 o.test_read
25 end
26 write (flag)
27 separate other as o do
28 o.test_write
29 end
30 read (flag)
31 end
32
33 make_other (f: like flag; t: like tuple)
34 do
35 flag := f
36 tuple := t
37 ensure
38 flag = f
39 tuple = t
40 end
41
42 make_tuple (v: INTEGER)
43 do
44 value := v
45 create flag
46 tuple := [v, Current, create {E}.make (Current)]
47 end
48
49 feature -- Access
50
51 value: INTEGER
52
53 feature -- Test
54
55 write (f: like flag)
56 require
57 f.is_ready
58 local
59 x: separate TEST
60 do
61 create x.make_tuple (5)
62 separate tuple as t do
63 t.i := 5
64 t.x := x
65 t.e := create {E}.make (x)
66 end
67 f.reset
68 end
69
70 test_read
71 do
72 separate tuple as t do
73 -- Test expected values.
74 report_i (1, t.i, 3)
75 report_x (2, t.x, 3)
76 report_x (3, t.e.t, 3)
77 -- Indicate that one reading operation has been completed.
78 separate flag as f do f.set end
79 -- Delay execution to let other processors update `t' if locking is not done for tuples.
80 sleep (1_000_000_000)
81 -- Re-test expected values.
82 report_i (4, t.i, 3)
83 report_x (5, t.x, 3)
84 report_x (6, t.e.t, 3)
85 end
86 end
87
88 read (f: like flag)
89 require
90 f.is_ready
91 do
92 separate tuple as t do
93 -- Test expected values.
94 report_i (7, t.i, 7)
95 report_x (8, t.x, 7)
96 report_x (9, t.e.t, 7)
97 end
98 end
99
100 test_write
101 local
102 x: separate TEST
103 do
104 separate tuple as t do
105 -- Write some values.
106 create x.make_tuple (8)
107 t.i := 8
108 t.x := x
109 t.e := create {E}.make (x)
110 -- Indicate that one writing operation has been completed.
111 separate flag as f do f.set end
112 -- Delay execution to let other processors read `t' if locking is not done for tuples.
113 sleep (1_000_000_000)
114 -- Write expected values.
115 create x.make_tuple (7)
116 t.i := 7
117 t.x := x
118 t.e := create {E}.make (x)
119 end
120 end
121
122 tuple: separate TUPLE [i: INTEGER; x: separate TEST; e: E]
123
124 feature -- Output
125
126 report_i (n: INTEGER; v: INTEGER; e: INTEGER)
127 -- Report whether for test #`n' the value `v' matches `e'.
128 do
129 io.put_string ("Test ")
130 io.put_integer (n)
131 if v = e then
132 io.put_string (": OK")
133 else
134 io.put_string (": FAILED (expected ")
135 io.put_integer (e)
136 io.put_string (" but got ")
137 io.put_integer (v)
138 io.put_string (")")
139 end
140 io.put_new_line
141 end
142
143 report_x (n: INTEGER; t: detachable separate TEST; e: INTEGER)
144 -- Report whether for test #`n' the value `t.value' matches `e'.
145 do
146 if attached t then
147 report_i (n, t.value, e)
148 else
149 report_i (n, 0, e)
150 end
151 end
152
153 feature -- Synchronization
154
155 flag: separate FLAG
156
157 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23