1 /* Copyright (C) 2007, 2009 Free Software Foundation, Inc.
2 
3    This file is free software; you can redistribute it and/or modify it under
4    the terms of the GNU General Public License as published by the Free
5    Software Foundation; either version 3 of the License, or (at your option)
6    any later version.
7 
8    This file is distributed in the hope that it will be useful, but WITHOUT
9    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11    for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this file; see the file COPYING3.  If not see
15    <http://www.gnu.org/licenses/>.  */
16 
17 /* { dg-do run } */
18 
19 #include <spu_mfcio.h>
20 #include <stdlib.h>
21 
22 /* This test directly accesses the internal table used
23    by the MFC tag manager.  */
24 extern vector unsigned int __mfc_tag_table;
25 
26 
27 /* This tag tests invalid tag release.  Invalid tag release does
28    nothing to the tag table.  */
29 void
test_tag_release01(void)30 test_tag_release01 (void)
31 {
32   unsigned int copy;
33   copy = spu_extract (__mfc_tag_table, 0);
34 
35   mfc_tag_release (35);
36   if (copy != spu_extract (__mfc_tag_table, 0))
37     abort ();
38 }
39 
40 /* More invalid release tests.  */
41 void
test_tag_release_invalid(void)42 test_tag_release_invalid (void)
43 {
44   unsigned int copy;
45   copy = spu_extract (__mfc_tag_table, 0);
46 
47   if (mfc_tag_release (32) != MFC_TAG_INVALID)
48     abort ();
49   if (copy != spu_extract (__mfc_tag_table, 0))
50     abort ();
51 
52   if (mfc_tag_release (17) != MFC_TAG_INVALID)
53     abort ();
54   if (copy != spu_extract (__mfc_tag_table, 0))
55     abort ();
56 }
57 
58 /* Invalid multiple-tag release tests.  */
59 void
test_tag_group_release_invalid(void)60 test_tag_group_release_invalid (void)
61 {
62   unsigned int copy;
63   copy = spu_extract (__mfc_tag_table, 0);
64 
65   if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
66     abort ();
67   if (copy != spu_extract (__mfc_tag_table, 0))
68     abort ();
69 
70   if (mfc_multi_tag_release (28, 10) != MFC_TAG_INVALID)
71     abort ();
72   if (copy != spu_extract (__mfc_tag_table, 0))
73     abort ();
74 
75   if (mfc_multi_tag_release (17, 10) != MFC_TAG_INVALID)
76     abort ();
77   if (copy != spu_extract (__mfc_tag_table, 0))
78     abort ();
79 
80   if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
81     abort ();
82   if (copy != spu_extract (__mfc_tag_table, 0))
83     abort ();
84 }
85 
86 /* The tag table should be in a pristine mode to run this test.  */
87 void
test_tag_reserve01(void)88 test_tag_reserve01 (void)
89 {
90   unsigned int correct_table[32] =
91     {
92 		  0x80000000, 0xC0000000, 0xE0000000,
93       0xF0000000, 0xF8000000, 0xFC000000, 0xFE000000,
94       0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
95       0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000,
96       0xFFFF0000, 0xFFFF8000, 0xFFFFC000, 0xFFFFE000,
97       0xFFFFF000, 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00,
98       0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0,
99       0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE,
100       0xFFFFFFFF
101     };
102 
103   unsigned int tag;
104   unsigned int i;
105 
106   for (i = 0; i < 32; i++)
107     {
108       tag = mfc_tag_reserve ();
109       if (tag != i)
110 	abort ();
111     }
112 
113   for (i = 0; i < 32; i++)
114     {
115       tag = mfc_tag_reserve ();
116       if (tag != MFC_TAG_INVALID)
117 	abort ();
118     }
119 
120   for (i = 0; i < 32; i++)
121     {
122       mfc_tag_release (i);
123       if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
124 	abort ();
125     }
126 }
127 
128 /* The tag table should be in a pristine mode to run this test.  */
129 void
test_tag_reserve02(void)130 test_tag_reserve02 (void)
131 {
132   unsigned int correct_table[32] =
133     {
134       0x80000000, 0xC0000000, 0xA0000000, 0xF0000000,
135       0xA8000000, 0xFC000000, 0xAA000000, 0xFF000000,
136       0xAA800000, 0xFFC00000, 0xAAA00000, 0xFFF00000,
137       0xAAA80000, 0xFFFC0000, 0xAAAA0000, 0xFFFF0000,
138       0xAAAA8000, 0xFFFFC000, 0xAAAAA000, 0xFFFFF000,
139       0xAAAAA800, 0xFFFFFC00, 0xAAAAAA00, 0xFFFFFF00,
140       0xAAAAAA80, 0xFFFFFFC0, 0xAAAAAAA0, 0xFFFFFFF0,
141       0xAAAAAAA8, 0xFFFFFFFC, 0xAAAAAAAA, 0xFFFFFFFF
142     };
143 
144   unsigned int correct_table2[32] =
145     {
146       0x80000000, 0xEAAAAAAA, 0xA0000000, 0xFAAAAAAA,
147       0xA8000000, 0xFEAAAAAA, 0xAA000000, 0xFFAAAAAA,
148       0xAA800000, 0xFFEAAAAA, 0xAAA00000, 0xFFFAAAAA,
149       0xAAA80000, 0xFFFEAAAA, 0xAAAA0000, 0xFFFFAAAA,
150       0xAAAA8000, 0xFFFFEAAA, 0xAAAAA000, 0xFFFFFAAA,
151       0xAAAAA800, 0xFFFFFEAA, 0xAAAAAA00, 0xFFFFFFAA,
152       0xAAAAAA80, 0xFFFFFFEA, 0xAAAAAAA0, 0xFFFFFFFA,
153       0xAAAAAAA8, 0xFFFFFFFE, 0xAAAAAAAA, 0xFFFFFFFF
154     };
155 
156   unsigned int tag;
157   unsigned int i;
158 
159   /* Reserve all 32 tags.  */
160   for (i = 0; i < 32; i++)
161     {
162       tag = mfc_tag_reserve();
163       if (tag != i)
164 	abort ();
165     }
166 
167   for (i = 0; i < 32; i++)
168     {
169       tag = mfc_tag_reserve();
170       if (tag != MFC_TAG_INVALID)
171 	abort ();
172     }
173 
174   /* Release only 16 tags with a stride of 2.  */
175   for (i = 0; i < 32; i += 2)
176     {
177       mfc_tag_release (i);
178       if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
179 	abort ();
180     }
181 
182   /* Release the other 16 tags with a stride of 2.  */
183   for (i = 1; i < 32; i += 2)
184     {
185       mfc_tag_release (i);
186       if (spu_extract (__mfc_tag_table, 0) != correct_table2[i])
187 	abort ();
188     }
189 }
190 
191 /* The tag table should be in a pristine mode to run this test.  */
192 void
test_tag_reserve03(void)193 test_tag_reserve03 (void)
194 {
195   unsigned int tag;
196   unsigned int i;
197 
198   /* Reserve all 32 tags.  */
199   for (i = 0; i < 32; i++)
200     {
201       tag = mfc_tag_reserve ();
202       if (tag != i)
203 	abort ();
204     }
205 
206   for (i = 0; i < 32; i++)
207     {
208       tag = mfc_tag_reserve ();
209       if (tag != MFC_TAG_INVALID)
210 	abort ();
211     }
212 
213   /* Release only 16 tags with a stride of 2.  */
214   for (i = 0; i < 32; i += 2)
215     mfc_tag_release (i);
216 
217   /* Now let's re-reserve those tags.  */
218   for (i = 0; i < 32; i += 2)
219     {
220       tag = mfc_tag_reserve ();
221       if (tag != i)
222 	abort ();
223     }
224 
225   /* Release all tags.  */
226   for (i = 0; i < 32; i++)
227     mfc_tag_release (i);
228 
229   if (spu_extract (__mfc_tag_table,0) != 0xFFFFFFFF)
230     abort ();
231 }
232 
233 
234 void
test_tag_group_reserve(void)235 test_tag_group_reserve (void)
236 {
237   unsigned int tag;
238   unsigned int i;
239   unsigned int copy;
240 
241   /* Reserve all tags.  */
242   for (i = 0; i < 32; i++)
243     mfc_tag_reserve();
244 
245   /* Release the first 4. */
246   for (i = 0; i < 4; i++)
247     mfc_tag_release (i);
248 
249   /* Release tag 5 to 7.  */
250   for (i = 5; i < 8; i++)
251     mfc_tag_release (i);
252 
253   /* Release tag 9 to 19.  */
254   for (i = 9; i < 20; i++)
255     mfc_tag_release (i);
256 
257   /* Tag table should be 0xF77FF000.  */
258   if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
259     abort ();
260 
261 
262   /* Verify invalid release is detected.  */
263   copy = spu_extract (__mfc_tag_table, 0);
264   if (mfc_multi_tag_release (1, 5) != MFC_TAG_INVALID)
265     abort ();
266   if (copy != spu_extract (__mfc_tag_table, 0))
267     abort ();
268 
269 
270   /* Reserve multiple tags.  */
271   tag = mfc_multi_tag_reserve (5);
272   if (tag != 9)
273     abort ();
274 
275   /* Tag table should be 0xF703F000.  */
276   if (spu_extract (__mfc_tag_table, 0) != 0xF703F000)
277     abort ();
278 
279 
280   /* Release 5 tags in the group.  */
281   mfc_multi_tag_release (tag, 5);
282 
283   /* Tag table should be 0xF77FF000.  */
284   if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
285     abort ();
286 
287 
288   /* This call should not do anything.  */
289   mfc_multi_tag_release (32, 5);
290 
291   /* Tag table should be 0xF77FF000.  */
292   if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
293     abort ();
294 }
295 
296 
297 int
main(void)298 main (void)
299 {
300   test_tag_release01 ();
301   test_tag_release_invalid ();
302   test_tag_group_release_invalid ();
303 
304   test_tag_reserve01 ();
305   test_tag_reserve02 ();
306   test_tag_reserve03 ();
307 
308   test_tag_group_reserve ();
309 
310   return 0;
311 }
312 
313