<ahref="testthd_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="l00070"></a>00070 <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="l00071"></a>00071
<aname="l00072"></a>00072 <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="l00083"></a>00083 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, thread, <spanclass="stringliteral">"E"</span>);
<aname="l00084"></a>00084 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>()-4, thread, <spanclass="stringliteral">"D"</span>);
<aname="l00085"></a>00085 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, thread, <spanclass="stringliteral">"C"</span>);
<aname="l00086"></a>00086 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>()-2, thread, <spanclass="stringliteral">"B"</span>);
<aname="l00087"></a>00087 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>()-1, thread, <spanclass="stringliteral">"A"</span>);
<aname="l00088"></a>00088 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00092"></a>00092 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testthd1 = {
<aname="l00116"></a>00116 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>()-4, thread, <spanclass="stringliteral">"D"</span>);
<aname="l00117"></a>00117 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, thread, <spanclass="stringliteral">"E"</span>);
<aname="l00118"></a>00118 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>()-1, thread, <spanclass="stringliteral">"A"</span>);
<aname="l00119"></a>00119 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>()-2, thread, <spanclass="stringliteral">"B"</span>);
<aname="l00120"></a>00120 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, thread, <spanclass="stringliteral">"C"</span>);
<aname="l00121"></a>00121 <aclass="code"href="group__test.html#ga361d9d2685d79754206ae8af370a303c"title="Waits for the completion of all the test-spawned threads.">test_wait_threads</a>();
<aname="l00125"></a>00125 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testthd2 = {
<aname="l00148"></a>00148 <aclass="code"href="group__types.html#ga5f2488ba73e5969cbc0f7033735374ee"title="Priority, use the fastest unsigned type.">tprio_t</a> prio, p1;
<aname="l00149"></a>00149
<aname="l00150"></a>00150 prio = <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>();
<aname="l00151"></a>00151 p1 = <aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe"title="Changes the running thread priority level then reschedules if necessary.">chThdSetPriority</a>(prio + 1);
<aname="l00156"></a>00156 p1 = <aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe"title="Changes the running thread priority level then reschedules if necessary.">chThdSetPriority</a>(p1);
<aname="l00158"></a>00158 <spanclass="stringliteral">"unexpected returned priority level"</span>);
<aname="l00159"></a>00159 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(4, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>() == prio,
<aname="l00163"></a>00163 <spanclass="preprocessor"></span><spanclass="comment">/* Simulates a priority boost situation (p_prio > p_realprio).*/</span>
<aname="l00164"></a>00164 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00165"></a>00165 <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_prio += 2;
<aname="l00166"></a>00166 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<aname="l00167"></a>00167 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(5, <aclass="code"href="group__threads.html#gac71903de6268d886ff58022854b8b6dd"title="Returns the current thread priority.">chThdGetPriority</a>() == prio + 2,
<aname="l00170"></a>00170 <spanclass="comment">/* Tries to raise but below the boost level. */</span>
<aname="l00171"></a>00171 p1 = <aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe"title="Changes the running thread priority level then reschedules if necessary.">chThdSetPriority</a>(prio + 1);
<aname="l00173"></a>00173 <spanclass="stringliteral">"unexpected returned priority level"</span>);
<aname="l00174"></a>00174 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(7, <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_prio == prio + 2,
<aname="l00176"></a>00176 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(8, <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_realprio == prio + 1,
<aname="l00177"></a>00177 <spanclass="stringliteral">"unexpected returned real priority level"</span>);
<aname="l00178"></a>00178
<aname="l00179"></a>00179 <spanclass="comment">/* Tries to raise above the boost level. */</span>
<aname="l00180"></a>00180 p1 = <aclass="code"href="group__threads.html#ga5a5d9388c64e4c1a3aec129d2831eefe"title="Changes the running thread priority level then reschedules if necessary.">chThdSetPriority</a>(prio + 3);
<aname="l00182"></a>00182 <spanclass="stringliteral">"unexpected returned priority level"</span>);
<aname="l00183"></a>00183 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(10, <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_prio == prio + 3,
<aname="l00185"></a>00185 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(11, <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_realprio == prio + 3,
<aname="l00186"></a>00186 <spanclass="stringliteral">"unexpected real priority level"</span>);
<aname="l00187"></a>00187
<aname="l00188"></a>00188 <aclass="code"href="group__system.html#ga9f6573c0763d1e4e97c63c62edad6e42"title="Enters the kernel lock mode.">chSysLock</a>();
<aname="l00189"></a>00189 <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_prio = prio;
<aname="l00190"></a>00190 <aclass="code"href="group__threads.html#gaa36662628234799d205ff8c0cc6745c5"title="Returns a pointer to the current Thread.">chThdSelf</a>()->p_realprio = prio;
<aname="l00191"></a>00191 <aclass="code"href="group__system.html#ga5a257fa58a09815eb64a45e2dfbdc22e"title="Leaves the kernel lock mode.">chSysUnlock</a>();
<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> testthd3 = {
<aname="l00216"></a>00216 <aclass="code"href="group__types.html#gae3e32a98d431a02106616da3071832dd"title="System Time, recommended fastest unsigned.">systime_t</a> time;
<aname="l00217"></a>00217
<aname="l00218"></a>00218 <aclass="code"href="group__test.html#gac067dd7ee03b2c56d4d26ce9815ed3f7"title="Delays execution until next system time tick.">test_wait_tick</a>();
<aname="l00219"></a>00219
<aname="l00220"></a>00220 <spanclass="comment">/* Timeouts in microseconds.*/</span>
<aname="l00221"></a>00221 time = <aclass="code"href="group__time.html#ga137c8f67c450f34416a786d169be90e2"title="Current system time.">chTimeNow</a>();
<aname="l00222"></a>00222 <aclass="code"href="group__threads.html#ga596f4015871a919694911bc50ba8bd94"title="Delays the invoking thread for the specified number of microseconds.">chThdSleepMicroseconds</a>(100000);
<aname="l00223"></a>00223 <aclass="code"href="group__test.html#gabb18a77859d6fc0972a35d88f11a90e1"title="Test time window assertion.">test_assert_time_window</a>(1, time + <aclass="code"href="group__time.html#ga093b2a96d7a52eb5988739fff1b5a995"title="Time conversion utility.">US2ST</a>(100000), time + <aclass="code"href="group__time.html#ga093b2a96d7a52eb5988739fff1b5a995"title="Time conversion utility.">US2ST</a>(100000) + 1);
<aname="l00224"></a>00224
<aname="l00225"></a>00225 <spanclass="comment">/* Timeouts in milliseconds.*/</span>
<aname="l00226"></a>00226 time = <aclass="code"href="group__time.html#ga137c8f67c450f34416a786d169be90e2"title="Current system time.">chTimeNow</a>();
<aname="l00227"></a>00227 <aclass="code"href="group__threads.html#ga5aebc25e053a0094714abce4cad9f56f"title="Delays the invoking thread for the specified number of milliseconds.">chThdSleepMilliseconds</a>(100);
<aname="l00228"></a>00228 <aclass="code"href="group__test.html#gabb18a77859d6fc0972a35d88f11a90e1"title="Test time window assertion.">test_assert_time_window</a>(2, time + <aclass="code"href="group__time.html#ga0a7e7bc6c6225bd9652c4f1567f1bc6a"title="Time conversion utility.">MS2ST</a>(100), time + <aclass="code"href="group__time.html#ga0a7e7bc6c6225bd9652c4f1567f1bc6a"title="Time conversion utility.">MS2ST</a>(100) + 1);
<aname="l00229"></a>00229
<aname="l00230"></a>00230 <spanclass="comment">/* Timeouts in seconds.*/</span>
<aname="l00231"></a>00231 time = <aclass="code"href="group__time.html#ga137c8f67c450f34416a786d169be90e2"title="Current system time.">chTimeNow</a>();
<aname="l00232"></a>00232 <aclass="code"href="group__threads.html#ga5fc3d014124e558bc59c423a74668c8d"title="Delays the invoking thread for the specified number of seconds.">chThdSleepSeconds</a>(1);
<aname="l00233"></a>00233 <aclass="code"href="group__test.html#gabb18a77859d6fc0972a35d88f11a90e1"title="Test time window assertion.">test_assert_time_window</a>(3, time + <aclass="code"href="group__time.html#gab64090e53ca84e2179acbbf61aa9c71f"title="Time conversion utility.">S2ST</a>(1), time + <aclass="code"href="group__time.html#gab64090e53ca84e2179acbbf61aa9c71f"title="Time conversion utility.">S2ST</a>(1) + 1);
<aname="l00236"></a>00236 time = <aclass="code"href="group__time.html#ga137c8f67c450f34416a786d169be90e2"title="Current system time.">chTimeNow</a>() + <aclass="code"href="group__time.html#ga0a7e7bc6c6225bd9652c4f1567f1bc6a"title="Time conversion utility.">MS2ST</a>(100);
<aname="l00237"></a>00237 <aclass="code"href="group__threads.html#ga9e6e2f8d46d415e8f0862daf0be1d984"title="Suspends the invoking thread until the system time arrives to the specified value.">chThdSleepUntil</a>(time);
<aname="l00238"></a>00238 <aclass="code"href="group__test.html#gabb18a77859d6fc0972a35d88f11a90e1"title="Test time window assertion.">test_assert_time_window</a>(4, time, time + 1);
<aname="l00239"></a>00239 }
<aname="l00240"></a>00240
<aname="l00241"></a>00241 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testthd4 = {
<aname="l00251"></a><aclass="code"href="testthd_8h.html#ac80ba06e004412a51e767d05fcb5d412">00251</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="testthd_8c.html#a0e03ba3eab1184efc52f1ecb594042ca"title="Test sequence for threads.">patternthd</a>[] = {
Generated on Sun Nov 28 2010 14:09:49 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>