diff options
author | Teravus Ovares (Dan Olivares) | 2009-10-30 19:13:57 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-10-30 19:13:57 -0400 |
commit | 5101f688ee887d5fa67a573591ec3b6a43c4e50b (patch) | |
tree | ce7ccf37f96563f0019b59cb7a2ce0c05aa726b2 /OpenSim | |
parent | * Adding Tests for OpenSim.Framework.Cache. Some test cases disabled until m... (diff) | |
download | opensim-SC-5101f688ee887d5fa67a573591ec3b6a43c4e50b.zip opensim-SC-5101f688ee887d5fa67a573591ec3b6a43c4e50b.tar.gz opensim-SC-5101f688ee887d5fa67a573591ec3b6a43c4e50b.tar.bz2 opensim-SC-5101f688ee887d5fa67a573591ec3b6a43c4e50b.tar.xz |
* Add LocklessQueueTests. One Test is commented out because it fails. It should probably work.. but I'm awaiting clarification.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/ACL.cs | 32 | ||||
-rw-r--r-- | OpenSim/Framework/Tests/LocklessQueueTests.cs | 147 |
2 files changed, 148 insertions, 31 deletions
diff --git a/OpenSim/Framework/ACL.cs b/OpenSim/Framework/ACL.cs index 3b1c0f0..f76e8b7 100644 --- a/OpenSim/Framework/ACL.cs +++ b/OpenSim/Framework/ACL.cs | |||
@@ -248,35 +248,5 @@ namespace OpenSim.Framework | |||
248 | 248 | ||
249 | #endregion | 249 | #endregion |
250 | 250 | ||
251 | #region Tests | 251 | |
252 | |||
253 | /// <summary> | ||
254 | /// ACL Test class | ||
255 | /// </summary> | ||
256 | internal class ACLTester | ||
257 | { | ||
258 | public ACLTester() | ||
259 | { | ||
260 | ACL acl = new ACL(); | ||
261 | |||
262 | Role Guests = new Role("Guests"); | ||
263 | acl.AddRole(Guests); | ||
264 | |||
265 | Role[] parents = new Role[0]; | ||
266 | parents[0] = Guests; | ||
267 | |||
268 | Role JoeGuest = new Role("JoeGuest", parents); | ||
269 | acl.AddRole(JoeGuest); | ||
270 | |||
271 | Resource CanBuild = new Resource("CanBuild"); | ||
272 | acl.AddResource(CanBuild); | ||
273 | |||
274 | |||
275 | acl.GrantPermission("Guests", "CanBuild"); | ||
276 | |||
277 | acl.HasPermission("JoeGuest", "CanBuild"); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | #endregion | ||
282 | } \ No newline at end of file | 252 | } \ No newline at end of file |
diff --git a/OpenSim/Framework/Tests/LocklessQueueTests.cs b/OpenSim/Framework/Tests/LocklessQueueTests.cs new file mode 100644 index 0000000..e34f767 --- /dev/null +++ b/OpenSim/Framework/Tests/LocklessQueueTests.cs | |||
@@ -0,0 +1,147 @@ | |||
1 | using System; | ||
2 | using NUnit.Framework; | ||
3 | using System.Threading; | ||
4 | |||
5 | namespace OpenSim.Framework.Tests | ||
6 | { | ||
7 | [TestFixture] | ||
8 | public class LocklessQueueTests | ||
9 | { | ||
10 | public LocklessQueue<int> sharedQueue; | ||
11 | [SetUp] | ||
12 | public void build() | ||
13 | { | ||
14 | sharedQueue = new LocklessQueue<int>(); | ||
15 | |||
16 | } | ||
17 | |||
18 | [Test] | ||
19 | public void EnqueueDequeueTest() | ||
20 | { | ||
21 | sharedQueue.Enqueue(1); | ||
22 | int dequeue; | ||
23 | sharedQueue.Dequeue(out dequeue); | ||
24 | Assert.That(dequeue == 1, "Enqueued 1. Dequeue should also be 1"); | ||
25 | Assert.That(sharedQueue.Count == 0, "We Dequeued the last item, count should be 0"); | ||
26 | |||
27 | } | ||
28 | |||
29 | [Test] | ||
30 | public void ThreadedSimpleEnqueueDequeueTest() | ||
31 | { | ||
32 | int loopamountA = 5000; | ||
33 | int loopamountB = 5000; | ||
34 | int loopamountC = 5000; | ||
35 | int loopamountD = 5000; | ||
36 | |||
37 | threadObject1 obj1 = new threadObject1(this, loopamountA); | ||
38 | threadObject1 obj2 = new threadObject1(this, loopamountB); | ||
39 | threadObject1 obj3 = new threadObject1(this, loopamountC); | ||
40 | threadObject1 obj4 = new threadObject1(this, loopamountD); | ||
41 | for (int i=0;i<1;i++) | ||
42 | { | ||
43 | sharedQueue.Enqueue(i); | ||
44 | } | ||
45 | |||
46 | Thread thr = new Thread(obj1.thread1Action); | ||
47 | Thread thr2 = new Thread(obj2.thread1Action); | ||
48 | Thread thr3 = new Thread(obj3.thread1Action); | ||
49 | Thread thr4 = new Thread(obj4.thread1Action); | ||
50 | thr.Start(); | ||
51 | thr2.Start(); | ||
52 | thr3.Start(); | ||
53 | thr4.Start(); | ||
54 | |||
55 | thr.Join(); | ||
56 | thr2.Join(); | ||
57 | thr3.Join(); | ||
58 | thr4.Join(); | ||
59 | |||
60 | Assert.That(sharedQueue.Count == 1); | ||
61 | int result = 0; | ||
62 | sharedQueue.Dequeue(out result); | ||
63 | Assert.That(result == loopamountD + loopamountC + loopamountB + loopamountA, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountD + loopamountC + loopamountB + loopamountA); | ||
64 | |||
65 | } | ||
66 | |||
67 | /* This test fails. Need clarification if this should work | ||
68 | [Test] | ||
69 | public void ThreadedAdvancedEnqueueDequeueTest() | ||
70 | { | ||
71 | int loopamountA = 5000; | ||
72 | int loopamountB = 5000; | ||
73 | int loopamountC = 5000; | ||
74 | int loopamountD = 5000; | ||
75 | |||
76 | threadObject1 obj1 = new threadObject1(this, loopamountA); | ||
77 | threadObject2 obj2 = new threadObject2(this, loopamountB); | ||
78 | threadObject1 obj3 = new threadObject1(this, loopamountC); | ||
79 | threadObject2 obj4 = new threadObject2(this, loopamountD); | ||
80 | for (int i = 0; i < 1; i++) | ||
81 | { | ||
82 | sharedQueue.Enqueue(i); | ||
83 | } | ||
84 | |||
85 | Thread thr = new Thread(obj1.thread1Action); | ||
86 | Thread thr2 = new Thread(obj2.thread1Action); | ||
87 | Thread thr3 = new Thread(obj3.thread1Action); | ||
88 | Thread thr4 = new Thread(obj4.thread1Action); | ||
89 | thr.Start(); | ||
90 | thr2.Start(); | ||
91 | thr3.Start(); | ||
92 | thr4.Start(); | ||
93 | |||
94 | thr.Join(); | ||
95 | thr2.Join(); | ||
96 | thr3.Join(); | ||
97 | thr4.Join(); | ||
98 | |||
99 | Assert.That(sharedQueue.Count == 1); | ||
100 | int result = 0; | ||
101 | sharedQueue.Dequeue(out result); | ||
102 | Assert.That(result == loopamountA - loopamountB + loopamountC - loopamountD, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountA - loopamountB + loopamountC - loopamountD); | ||
103 | |||
104 | } | ||
105 | */ | ||
106 | } | ||
107 | // Dequeue one from the locklessqueue add one to it and enqueue it again. | ||
108 | public class threadObject1 | ||
109 | { | ||
110 | private LocklessQueueTests m_tests; | ||
111 | private int m_loopamount = 0; | ||
112 | public threadObject1(LocklessQueueTests tst, int loopamount) | ||
113 | { | ||
114 | m_tests = tst; | ||
115 | m_loopamount = loopamount; | ||
116 | } | ||
117 | public void thread1Action(object o) | ||
118 | { | ||
119 | for (int i=0;i<m_loopamount;i++) | ||
120 | { | ||
121 | int j = 0; | ||
122 | m_tests.sharedQueue.Dequeue(out j); | ||
123 | m_tests.sharedQueue.Enqueue(++j); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | // Dequeue one from the locklessqueue subtract one from it and enqueue it again. | ||
128 | public class threadObject2 | ||
129 | { | ||
130 | private LocklessQueueTests m_tests; | ||
131 | private int m_loopamount = 0; | ||
132 | public threadObject2(LocklessQueueTests tst, int loopamount) | ||
133 | { | ||
134 | m_tests = tst; | ||
135 | m_loopamount = loopamount; | ||
136 | } | ||
137 | public void thread1Action(object o) | ||
138 | { | ||
139 | for (int i = 0; i < m_loopamount; i++) | ||
140 | { | ||
141 | int j = 0; | ||
142 | m_tests.sharedQueue.Dequeue(out j); | ||
143 | m_tests.sharedQueue.Enqueue(--j); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||