<ahref="testheap_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="l00081"></a>00081 <aclass="code"href="group__heaps.html#ga7135c9ddbd1402a4a36ce44df948f4e4"title="Initializes a memory heap from a static memory area.">chHeapInit</a>(&test_heap, test.buffer, <spanclass="keyword">sizeof</span>(<spanclass="keyword">union</span> test_buffers));
<aname="l00095"></a>00095 (void)<aclass="code"href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b"title="Reports the heap status.">chHeapStatus</a>(NULL, &sz);
<aname="l00096"></a>00096 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>(NULL, SIZE);
<aname="l00098"></a>00098 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1);
<aname="l00099"></a>00099 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>(NULL, (<spanclass="keywordtype">size_t</span>)-256);
<aname="l00100"></a>00100 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(2, p1 == NULL, <spanclass="stringliteral">"allocation not failed"</span>);
<aname="l00101"></a>00101
<aname="l00102"></a>00102 <spanclass="comment">/* Initial local heap state.*/</span>
<aname="l00103"></a>00103 (void)<aclass="code"href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b"title="Reports the heap status.">chHeapStatus</a>(&test_heap, &sz);
<aname="l00104"></a>00104
<aname="l00105"></a>00105 <spanclass="comment">/* Same order.*/</span>
<aname="l00106"></a>00106 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>(&test_heap, SIZE);
<aname="l00107"></a>00107 p2 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00108"></a>00108 p3 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00109"></a>00109 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1); <spanclass="comment">/* Does not merge.*/</span>
<aname="l00110"></a>00110 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p2); <spanclass="comment">/* Merges backward.*/</span>
<aname="l00111"></a>00111 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p3); <spanclass="comment">/* Merges both sides.*/</span>
<aname="l00115"></a>00115 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>(&test_heap, SIZE);
<aname="l00116"></a>00116 p2 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00117"></a>00117 p3 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00118"></a>00118 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p3); <spanclass="comment">/* Merges forward.*/</span>
<aname="l00119"></a>00119 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p2); <spanclass="comment">/* Merges forward.*/</span>
<aname="l00120"></a>00120 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1); <spanclass="comment">/* Merges forward.*/</span>
<aname="l00123"></a>00123 <spanclass="comment">/* Small fragments handling.*/</span>
<aname="l00124"></a>00124 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>(&test_heap, SIZE + 1);
<aname="l00125"></a>00125 p2 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00126"></a>00126 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1);
<aname="l00128"></a>00128 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>(&test_heap, SIZE);
<aname="l00129"></a>00129 <spanclass="comment">/* Note, the first situation happens when the alignment size is smaller</span>
<aname="l00130"></a>00130 <spanclass="comment"> than the header size, the second in the other cases.*/</span>
<aname="l00137"></a>00137 <spanclass="comment">/* Skip fragment handling.*/</span>
<aname="l00138"></a>00138 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>(&test_heap, SIZE);
<aname="l00139"></a>00139 p2 = <aclass="code"href="group__heaps.html#ga3d364eec0bef8b1986f63b3288ebbd5f"title="Allocates a block of memory from the heap by using the first-fit algorithm.">chHeapAlloc</a>(&test_heap, SIZE);
<aname="l00140"></a>00140 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1);
<aname="l00142"></a>00142 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>(&test_heap, SIZE * 2); <spanclass="comment">/* Skips first fragment.*/</span>
<aname="l00143"></a>00143 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p1);
<aname="l00144"></a>00144 <aclass="code"href="group__heaps.html#ga0fc553df0138f02e0b233be91e413c79"title="Frees a previously allocated memory block.">chHeapFree</a>(p2);
<aname="l00147"></a>00147 <spanclass="comment">/* Allocate all handling.*/</span>
<aname="l00148"></a>00148 (void)<aclass="code"href="group__heaps.html#ga944ffb8c5b83c26b984e6a072d871a8b"title="Reports the heap status.">chHeapStatus</a>(&test_heap, &n);
<aname="l00149"></a>00149 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>(&test_heap, n);
<aname="l00154"></a>00154 <aclass="code"href="group__test.html#ga835cb17ca3869922b49435d95324a68b"title="Test assertion.">test_assert</a>(12, n == sz, <spanclass="stringliteral">"size changed"</span>);
<aname="l00155"></a>00155 }
<aname="l00156"></a>00156
<aname="l00157"></a>00157 <spanclass="keyword">const</span><spanclass="keyword">struct </span><aclass="code"href="structtestcase.html"title="Structure representing a test case.">testcase</a> testheap1 = {
<aname="l00169"></a><aclass="code"href="testheap_8h.html#a5fbd0631733f8927ec129d234461d7ff">00169</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="testheap_8c.html#a5573379e505168afe49bf5d440911438"title="Test sequence for heap.">patternheap</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>