<ahref="testsem_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="l00087"></a>00087 <aclass="code"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value.">chSemInit</a>(&sem1, 0);
<aname="l00088"></a>00088 }
<aname="l00089"></a>00089
<aname="l00090"></a>00090 <spanclass="keyword">static</span><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> thread1(<spanclass="keywordtype">void</span> *p) {
<aname="l00091"></a>00091
<aname="l00092"></a>00092 <aclass="code"href="group__semaphores.html#gabc8f7e509870e9b0527a6a68fad71425"title="Performs a wait operation on a semaphore.">chSemWait</a>(&sem1);
<aname="l00093"></a>00093 <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="l00099"></a>00099 threads[0] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[0], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+5, thread1, <spanclass="stringliteral">"A"</span>);
<aname="l00100"></a>00100 threads[1] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[1], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+1, thread1, <spanclass="stringliteral">"B"</span>);
<aname="l00101"></a>00101 threads[2] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[2], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+3, thread1, <spanclass="stringliteral">"C"</span>);
<aname="l00102"></a>00102 threads[3] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[3], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+4, thread1, <spanclass="stringliteral">"D"</span>);
<aname="l00103"></a>00103 threads[4] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[4], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+2, thread1, <spanclass="stringliteral">"E"</span>);
<aname="l00104"></a>00104 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00105"></a>00105 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00106"></a>00106 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00107"></a>00107 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00108"></a>00108 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00109"></a>00109 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00127"></a>00127 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testsem1 = {
<aname="l00141"></a>00141 <aclass="code"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value.">chSemInit</a>(&sem1, 0);
<aname="l00142"></a>00142 }
<aname="l00143"></a>00143
<aname="l00144"></a>00144 <spanclass="keyword">static</span><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> thread2(<spanclass="keywordtype">void</span> *p) {
<aname="l00145"></a>00145
<aname="l00146"></a>00146 (void)p;
<aname="l00147"></a>00147 <aclass="code"href="group__threads.html#ga5aebc25e053a0094714abce4cad9f56f"title="Delays the invoking thread for the specified number of milliseconds.">chThdSleepMilliseconds</a>(50);
<aname="l00148"></a>00148 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00149"></a>00149 <aclass="code"href="group__semaphores.html#gaca0b70cf495a9cb7569e1cf5b07e2b3d"title="Performs a signal operation on a semaphore.">chSemSignalI</a>(&sem1); <spanclass="comment">/* For coverage reasons */</span>
<aname="l00150"></a>00150 <aclass="code"href="group__scheduler.html#ga4e38b4bee3d2330f6a0f1cdb7660af20"title="Performs a reschedule if a higher priority thread is runnable.">chSchRescheduleS</a>();
<aname="l00151"></a>00151 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00157"></a>00157 <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> target_time;
<aname="l00158"></a>00158 <aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> msg;
<aname="l00163"></a>00163 msg = <aclass="code"href="group__semaphores.html#ga0bc227311e5be3e3b6e3aee6a68169da"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeout</a>(&sem1, <aclass="code"href="group__scheduler.html#gad1ac15e9e5fc17810a94a779257f3d29"title="Zero time specification for some syscalls with a timeout specification.">TIME_IMMEDIATE</a>);
<aname="l00164"></a>00164 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(1, msg == <aclass="code"href="group__scheduler.html#gaf28d5427eeeb8f737cc7db495157780c"title="Low level message sent to a thread awakened by a timeout.">RDY_TIMEOUT</a>, <spanclass="stringliteral">"wrong wake-up message"</span>);
<aname="l00165"></a>00165 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(2, <aclass="code"href="group__internals.html#gadf402c10356566d82a6631c102b7f656"title="Evaluates to TRUE if the specified threads queue or list is empty.">isempty</a>(&sem1.s_queue), <spanclass="stringliteral">"queue not empty"</span>);
<aname="l00166"></a>00166 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(3, sem1.s_cnt == 0, <spanclass="stringliteral">"counter not zero"</span>);
<aname="l00171"></a>00171 threads[0] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[0], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>() - 1,
<aname="l00172"></a>00172 thread2, 0);
<aname="l00173"></a>00173 msg = <aclass="code"href="group__semaphores.html#ga0bc227311e5be3e3b6e3aee6a68169da"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeout</a>(&sem1, <aclass="code"href="group__time.html#ga0a7e7bc6c6225bd9652c4f1567f1bc6a"title="Time conversion utility.">MS2ST</a>(500));
<aname="l00174"></a>00174 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00176"></a>00176 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(5, <aclass="code"href="group__internals.html#gadf402c10356566d82a6631c102b7f656"title="Evaluates to TRUE if the specified threads queue or list is empty.">isempty</a>(&sem1.s_queue), <spanclass="stringliteral">"queue not empty"</span>);
<aname="l00177"></a>00177 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(6, sem1.s_cnt == 0, <spanclass="stringliteral">"counter not zero"</span>);
<aname="l00182"></a>00182 <aclass="code"href="group__test.html#gac067dd7ee03b2c56d4d26ce9815ed3f7"title="Delays execution until next system time tick.">test_wait_tick</a>();
<aname="l00184"></a>00184 <spanclass="keywordflow">for</span> (i = 0; i < 5; i++) {
<aname="l00185"></a>00185 <aclass="code"href="group__test.html#gab3d9527d7616b3f9f8cba60cda0211a8"title="Emits a token into the tokens buffer.">test_emit_token</a>(<spanclass="charliteral">'A'</span> + i);
<aname="l00186"></a>00186 msg = <aclass="code"href="group__semaphores.html#ga0bc227311e5be3e3b6e3aee6a68169da"title="Performs a wait operation on a semaphore with timeout specification.">chSemWaitTimeout</a>(&sem1, <aclass="code"href="group__time.html#ga0a7e7bc6c6225bd9652c4f1567f1bc6a"title="Time conversion utility.">MS2ST</a>(500));
<aname="l00187"></a>00187 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(7, msg == <aclass="code"href="group__scheduler.html#gaf28d5427eeeb8f737cc7db495157780c"title="Low level message sent to a thread awakened by a timeout.">RDY_TIMEOUT</a>, <spanclass="stringliteral">"wrong wake-up message"</span>);
<aname="l00188"></a>00188 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(8, <aclass="code"href="group__internals.html#gadf402c10356566d82a6631c102b7f656"title="Evaluates to TRUE if the specified threads queue or list is empty.">isempty</a>(&sem1.s_queue), <spanclass="stringliteral">"queue not empty"</span>);
<aname="l00189"></a>00189 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(9, sem1.s_cnt == 0, <spanclass="stringliteral">"counter not zero"</span>);
<aname="l00192"></a>00192 <aclass="code"href="group__test.html#gabb18a77859d6fc0972a35d88f11a90e1"title="Test time window assertion.">test_assert_time_window</a>(11, target_time, target_time + ALLOWED_DELAY);
<aname="l00193"></a>00193 }
<aname="l00194"></a>00194
<aname="l00195"></a>00195 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testsem2 = {
<aname="l00222"></a>00222 <aclass="code"href="group__semaphores.html#gafe8fc6155a871074e8017efd908b2c58"title="Initializes a semaphore with the specified counter value.">chSemInit</a>(&sem1, 0);
<aname="l00223"></a>00223 }
<aname="l00224"></a>00224
<aname="l00225"></a>00225 <spanclass="keyword">static</span><aclass="code"href="group__types.html#ga35bcb0c321cd7bc45bf1a11fa17ebdd3"title="Message, use signed pointer equivalent.">msg_t</a> thread3(<spanclass="keywordtype">void</span> *p) {
<aname="l00226"></a>00226
<aname="l00227"></a>00227 (void)p;
<aname="l00228"></a>00228 <aclass="code"href="group__semaphores.html#gabc8f7e509870e9b0527a6a68fad71425"title="Performs a wait operation on a semaphore.">chSemWait</a>(&sem1);
<aname="l00229"></a>00229 <aclass="code"href="group__semaphores.html#ga7ec0cbda23e49e2370e0b91f20baf05e"title="Performs a signal operation on a semaphore.">chSemSignal</a>(&sem1);
<aname="l00235"></a>00235 threads[0] = <aclass="code"href="group__threads.html#ga048e588238dd336c6059133b3d0c3435"title="Creates a new thread into a static memory area.">chThdCreateStatic</a>(wa[0], WA_SIZE, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>()+1, thread3, 0);
<aname="l00236"></a>00236 <aclass="code"href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44"title="Performs atomic signal and wait operations on two semaphores.">chSemSignalWait</a>(&sem1, &sem1);
<aname="l00237"></a>00237 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(1, <aclass="code"href="group__internals.html#gadf402c10356566d82a6631c102b7f656"title="Evaluates to TRUE if the specified threads queue or list is empty.">isempty</a>(&sem1.s_queue), <spanclass="stringliteral">"queue not empty"</span>);
<aname="l00238"></a>00238 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(2, sem1.s_cnt == 0, <spanclass="stringliteral">"counter not zero"</span>);
<aname="l00239"></a>00239
<aname="l00240"></a>00240 <aclass="code"href="group__semaphores.html#ga0dc7b4339506de346d67b4560b271e44"title="Performs atomic signal and wait operations on two semaphores.">chSemSignalWait</a>(&sem1, &sem1);
<aname="l00241"></a>00241 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(3, <aclass="code"href="group__internals.html#gadf402c10356566d82a6631c102b7f656"title="Evaluates to TRUE if the specified threads queue or list is empty.">isempty</a>(&sem1.s_queue), <spanclass="stringliteral">"queue not empty"</span>);
<aname="l00242"></a>00242 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(4, sem1.s_cnt == 0, <spanclass="stringliteral">"counter not zero"</span>);
<aname="l00243"></a>00243 }
<aname="l00244"></a>00244
<aname="l00245"></a>00245 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testsem3 = {
<aname="l00257"></a><aclass="code"href="testsem_8h.html#a1aa3461c413ffccaca1c33f5fc3e72bd">00257</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="testsem_8c.html#a775d46d7f42a35bff0a0e9ff4ea52235"title="Test sequence for semaphores.">patternsem</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>