<ahref="testdyn_8c.html">Go to the documentation of this file.</a><divclass="fragment"><preclass="fragment"><aname="l00001"></a>00001 <spanclass="comment">/*</span>
<aname="l00027"></a>00027 <spanclass="preprocessor">#include "<aclass="code"href="ch_8h.html"title="ChibiOS/RT main include file.">ch.h</a>"</span>
<aname="l00028"></a>00028 <spanclass="preprocessor">#include "<aclass="code"href="test_8h.html"title="Tests support header.">test.h</a>"</span>
<aname="l00067"></a>00067 <spanclass="preprocessor"></span><spanclass="keyword">static</span><aclass="code"href="struct_memory_pool.html"title="Memory pool descriptor.">MemoryPool</a> mp1;
<aname="l00081"></a>00081 <spanclass="keyword">static</span><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> thread(<spanclass="keywordtype">void</span> *p) {
<aname="l00082"></a>00082
<aname="l00083"></a>00083 <aclass="code"href="group__test.html#gab3d9527d7616b3f9f8cba60cda0211a8"title="Emits a token into the tokens buffer.">test_emit_token</a>(*(<spanclass="keywordtype">char</span> *)p);
<aname="l00095"></a>00095 <aclass="code"href="group__heaps.html#ga7135c9ddbd1402a4a36ce44df948f4e4"title="Initializes a memory heap from a static memory area.">chHeapInit</a>(&heap1, test.buffer, <spanclass="keyword">sizeof</span>(<spanclass="keyword">union</span> test_buffers));
<aname="l00101"></a>00101 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio = <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>();
<aname="l00102"></a>00102
<aname="l00103"></a>00103 (void)<aclass="code"href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b"title="Reports the heap status.">chHeapStatus</a>(&heap1, &sz);
<aname="l00104"></a>00104 <spanclass="comment">/* Starting threads from the heap. */</span>
<aname="l00105"></a>00105 threads[0] = <aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(&heap1, <aclass="code"href="group__core.html#gaf7a83c1c8bde96b77299c36dc598d33d"title="Computes the thread working area global size.">THD_WA_SIZE</a>(THREADS_STACK_SIZE),
<aname="l00107"></a>00107 threads[1] = <aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(&heap1, <aclass="code"href="group__core.html#gaf7a83c1c8bde96b77299c36dc598d33d"title="Computes the thread working area global size.">THD_WA_SIZE</a>(THREADS_STACK_SIZE),
<aname="l00109"></a>00109 <spanclass="comment">/* Allocating the whole heap in order to make the thread creation fail.*/</span>
<aname="l00110"></a>00110 (void)<aclass="code"href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b"title="Reports the heap status.">chHeapStatus</a>(&heap1, &n);
<aname="l00111"></a>00111 p1 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&heap1, n);
<aname="l00112"></a>00112 threads[2] = <aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(&heap1, <aclass="code"href="group__core.html#gaf7a83c1c8bde96b77299c36dc598d33d"title="Computes the thread working area global size.">THD_WA_SIZE</a>(THREADS_STACK_SIZE),
<aname="l00123"></a>00123 <spanclass="comment">/* Claiming the memory from terminated threads. */</span>
<aname="l00124"></a>00124 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00129"></a>00129 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(4, n == sz, <spanclass="stringliteral">"heap size changed"</span>);
<aname="l00130"></a>00130 }
<aname="l00131"></a>00131
<aname="l00132"></a>00132 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testdyn1 = {
<aname="l00158"></a>00158 <aclass="code"href="group__pools.html#ga9c53c25a5ae60930534cde8620775781"title="Initializes an empty memory pool.">chPoolInit</a>(&mp1, <aclass="code"href="group__core.html#gaf7a83c1c8bde96b77299c36dc598d33d"title="Computes the thread working area global size.">THD_WA_SIZE</a>(THREADS_STACK_SIZE), NULL);
<aname="l00163"></a>00163 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio = <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>();
<aname="l00164"></a>00164
<aname="l00165"></a>00165 <spanclass="comment">/* Adding the WAs to the pool. */</span>
<aname="l00166"></a>00166 <spanclass="keywordflow">for</span> (i = 0; i < 4; i++)
<aname="l00167"></a>00167 <aclass="code"href="group__pools.html#ga978f8d038e8e981bf9e5a104b81c6cb6"title="Releases (or adds) an object into (to) a memory pool.">chPoolFree</a>(&mp1, wa[i]);
<aname="l00168"></a>00168
<aname="l00169"></a>00169 <spanclass="comment">/* Starting threads from the memory pool. */</span>
<aname="l00170"></a>00170 threads[0] = <aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(&mp1, prio-1, thread, <spanclass="stringliteral">"A"</span>);
<aname="l00171"></a>00171 threads[1] = <aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(&mp1, prio-2, thread, <spanclass="stringliteral">"B"</span>);
<aname="l00172"></a>00172 threads[2] = <aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(&mp1, prio-3, thread, <spanclass="stringliteral">"C"</span>);
<aname="l00173"></a>00173 threads[3] = <aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(&mp1, prio-4, thread, <spanclass="stringliteral">"D"</span>);
<aname="l00174"></a>00174 threads[4] = <aclass="code"href="group__threads.html#gad3ccc1a6f054c543258ed2fe97ed2f58"title="Creates a new thread allocating the memory from the specified memory pool.">chThdCreateFromMemoryPool</a>(&mp1, prio-5, thread, <spanclass="stringliteral">"E"</span>);
<aname="l00183"></a>00183 <spanclass="comment">/* Claiming the memory from terminated threads. */</span>
<aname="l00184"></a>00184 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00187"></a>00187 <spanclass="comment">/* Now the pool must be full again. */</span>
<aname="l00188"></a>00188 <spanclass="keywordflow">for</span> (i = 0; i < 4; i++)
<aname="l00189"></a>00189 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(3, <aclass="code"href="group__pools.html#gab86190d70893fe708c75570af6720bd5"title="Allocates an object from a memory pool.">chPoolAlloc</a>(&mp1) != NULL, <spanclass="stringliteral">"pool list empty"</span>);
<aname="l00190"></a>00190 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(4, <aclass="code"href="group__pools.html#gab86190d70893fe708c75570af6720bd5"title="Allocates an object from a memory pool.">chPoolAlloc</a>(&mp1) == NULL, <spanclass="stringliteral">"pool list not empty"</span>);
<aname="l00191"></a>00191 }
<aname="l00192"></a>00192
<aname="l00193"></a>00193 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testdyn2 = {
<aname="l00211"></a>00211 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp;
<aname="l00212"></a>00212 <spanclass="keywordtype">unsigned</span> i = 0;
<aname="l00213"></a>00213
<aname="l00214"></a>00214 tp = <aclass="code"href="group__registry.html#ga55c0a485b40cf4acbfce0dd333f28513"title="Returns the first thread in the system.">chRegFirstThread</a>();
<aname="l00217"></a>00217 tp = <aclass="code"href="group__registry.html#gaefff43a49fb7888a596319d67cf01dab"title="Returns the thread next to the specified one.">chRegNextThread</a>(tp);
<aname="l00229"></a>00229 <aclass="code"href="group__heaps.html#ga7135c9ddbd1402a4a36ce44df948f4e4"title="Initializes a memory heap from a static memory area.">chHeapInit</a>(&heap1, test.buffer, <spanclass="keyword">sizeof</span>(<spanclass="keyword">union</span> test_buffers));
<aname="l00234"></a>00234 <aclass="code"href="struct_thread.html"title="Structure representing a thread.">Thread</a> *tp;
<aname="l00235"></a>00235 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio = <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>();
<aname="l00236"></a>00236
<aname="l00237"></a>00237 <spanclass="comment">/* Current number of threads in the system, two times just in case some</span>
<aname="l00242"></a>00242 <spanclass="comment">/* Testing references increase/decrease and final detach.*/</span>
<aname="l00243"></a>00243 tp = <aclass="code"href="group__threads.html#ga50b84e3e82a4e09c1066e1d422e4c780"title="Creates a new thread allocating the memory from the heap.">chThdCreateFromHeap</a>(&heap1, WA_SIZE, prio-1, thread, <spanclass="stringliteral">"A"</span>);
<aname="l00244"></a>00244 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(1, tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a> == 1, <spanclass="stringliteral">"wrong initial reference counter"</span>);
<aname="l00245"></a>00245 <aclass="code"href="group__threads.html#gabefc5734beaf29ae0bcd52cd41744930"title="Adds a reference to a thread object.">chThdAddRef</a>(tp);
<aname="l00246"></a>00246 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(2, tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a> == 2, <spanclass="stringliteral">"references increase failure"</span>);
<aname="l00247"></a>00247 <aclass="code"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80"title="Releases a reference to a thread object.">chThdRelease</a>(tp);
<aname="l00248"></a>00248 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(3, tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a> == 1, <spanclass="stringliteral">"references decrease failure"</span>);
<aname="l00249"></a>00249
<aname="l00250"></a>00250 <spanclass="comment">/* Verify the new threads count.*/</span>
<aname="l00254"></a>00254 <spanclass="comment">/* Detach and let the thread execute and terminate.*/</span>
<aname="l00255"></a>00255 <aclass="code"href="group__threads.html#gaa22f80040cf192015be4607f31a0ac80"title="Releases a reference to a thread object.">chThdRelease</a>(tp);
<aname="l00256"></a>00256 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(5, tp-><aclass="code"href="struct_thread.html#af86d1da435197d113bc42fe8139a21c5"title="References to this thread.">p_refs</a> == 0, <spanclass="stringliteral">"detach failure"</span>);
<aname="l00257"></a>00257 <aclass="code"href="group__threads.html#ga5aebc25e053a0094714abce4cad9f56f"title="Delays the invoking thread for the specified number of milliseconds.">chThdSleepMilliseconds</a>(50); <spanclass="comment">/* The thread just terminates. */</span>
<aname="l00265"></a>00265 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testdyn3 = {
<aname="l00277"></a><aclass="code"href="testdyn_8h.html#aa966c6562a3e1df7afe28c8311c20af3">00277</a><spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> * <spanclass="keyword">const</span><aclass="code"href="testdyn_8c.html#a52d5578e94aaa419c9687076097472e3"title="Test sequence for dynamic APIs.">patterndyn</a>[] = {
Generated on Sun Oct 24 2010 09:40:38 for ChibiOS/RT by <ahref="http://www.doxygen.org/index.html"><imgsrc="doxygen.png"alt="doxygen"align="middle"border="0"></a> 1.7.1</small></address>