4eccbd6acefc627aacf46fa59de28150fc35a5e0
[dpdk.git] / app / test / test_memzone.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  * 
7  *   Redistribution and use in source and binary forms, with or without 
8  *   modification, are permitted provided that the following conditions 
9  *   are met:
10  * 
11  *     * Redistributions of source code must retain the above copyright 
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright 
14  *       notice, this list of conditions and the following disclaimer in 
15  *       the documentation and/or other materials provided with the 
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its 
18  *       contributors may be used to endorse or promote products derived 
19  *       from this software without specific prior written permission.
20  * 
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * 
33  */
34
35 #include <stdio.h>
36 #include <stdint.h>
37 #include <inttypes.h>
38 #include <sys/queue.h>
39
40 #include <cmdline_parse.h>
41
42 #include <rte_random.h>
43 #include <rte_cycles.h>
44 #include <rte_memory.h>
45 #include <rte_memzone.h>
46 #include <rte_tailq.h>
47 #include <rte_eal.h>
48 #include <rte_eal_memconfig.h>
49 #include <rte_common.h>
50
51 #include "test.h"
52
53 /*
54  * Memzone
55  * =======
56  *
57  * - Search for three reserved zones or reserve them if they do not exist:
58  *
59  *   - One is on any socket id.
60  *   - The second is on socket 0.
61  *   - The last one is on socket 1 (if socket 1 exists).
62  *
63  * - Check that the zones exist.
64  *
65  * - Check that the zones are cache-aligned.
66  *
67  * - Check that zones do not overlap.
68  *
69  * - Check that the zones are on the correct socket id.
70  *
71  * - Check that a lookup of the first zone returns the same pointer.
72  *
73  * - Check that it is not possible to create another zone with the
74  *   same name as an existing zone.
75  *
76  * - Check flags for specific huge page size reservation
77  */
78
79 /* Test if memory overlaps: return 1 if true, or 0 if false. */
80 static int
81 is_memory_overlap(phys_addr_t ptr1, size_t len1, phys_addr_t ptr2, size_t len2)
82 {
83         if (ptr2 >= ptr1 && (ptr2 - ptr1) < len1)
84                 return 1;
85         else if (ptr2 < ptr1 && (ptr1 - ptr2) < len2)
86                 return 1;
87         return 0;
88 }
89
90 static int
91 test_memzone_invalid_alignment(void)
92 {
93         const struct rte_memzone * mz;
94
95         mz = rte_memzone_lookup("invalid_alignment");
96         if (mz != NULL) {
97                 printf("Zone with invalid alignment has been reserved\n");
98                 return -1;
99         }
100
101         mz = rte_memzone_reserve_aligned("invalid_alignment", 100,
102                         SOCKET_ID_ANY, 0, 100);
103         if (mz != NULL) {
104                 printf("Zone with invalid alignment has been reserved\n");
105                 return -1;
106         }
107         return 0;
108 }
109
110 static int
111 test_memzone_reserving_zone_size_bigger_than_the_maximum(void)
112 {
113         const struct rte_memzone * mz;
114
115         mz = rte_memzone_lookup("zone_size_bigger_than_the_maximum");
116         if (mz != NULL) {
117                 printf("zone_size_bigger_than_the_maximum has been reserved\n");
118                 return -1;
119         }
120
121         mz = rte_memzone_reserve("zone_size_bigger_than_the_maximum", (size_t)-1,
122                         SOCKET_ID_ANY, 0);
123         if (mz != NULL) {
124                 printf("It is impossible to reserve such big a memzone\n");
125                 return -1;
126         }
127
128         return 0;
129 }
130
131 static int
132 test_memzone_reserve_flags(void)
133 {
134         const struct rte_memzone *mz;
135         const struct rte_memseg *ms;
136         int hugepage_2MB_avail = 0;
137         int hugepage_1GB_avail = 0;
138         const int size = 100;
139         int i = 0;
140         ms = rte_eal_get_physmem_layout();
141         for (i = 0; i < RTE_MAX_MEMSEG; i++) {
142                 if (ms[i].hugepage_sz == RTE_PGSIZE_2M)
143                         hugepage_2MB_avail = 1;
144                 if (ms[i].hugepage_sz == RTE_PGSIZE_1G)
145                         hugepage_1GB_avail = 1;
146         }
147         /* Display the availability of 2MB and 1GB pages */
148         if (hugepage_2MB_avail)
149                 printf("2MB Huge pages available\n");
150         if (hugepage_1GB_avail)
151                 printf("1GB Huge pages available\n");
152         /*
153          * If 2MB pages available, check that a small memzone is correctly
154          * reserved from 2MB huge pages when requested by the RTE_MEMZONE_2MB flag.
155          * Also check that RTE_MEMZONE_SIZE_HINT_ONLY flag only defaults to an
156          * available page size (i.e 1GB ) when 2MB pages are unavailable.
157          */
158         if (hugepage_2MB_avail) {
159                 mz = rte_memzone_reserve("flag_zone_2M", size, SOCKET_ID_ANY,
160                                 RTE_MEMZONE_2MB);
161                 if (mz == NULL) {
162                         printf("MEMZONE FLAG 2MB\n");
163                         return -1;
164                 }
165                 if (mz->hugepage_sz != RTE_PGSIZE_2M) {
166                         printf("hugepage_sz not equal 2M\n");
167                         return -1;
168                 }
169
170                 mz = rte_memzone_reserve("flag_zone_2M_HINT", size, SOCKET_ID_ANY,
171                                 RTE_MEMZONE_2MB|RTE_MEMZONE_SIZE_HINT_ONLY);
172                 if (mz == NULL) {
173                         printf("MEMZONE FLAG 2MB\n");
174                         return -1;
175                 }
176                 if (mz->hugepage_sz != RTE_PGSIZE_2M) {
177                         printf("hugepage_sz not equal 2M\n");
178                         return -1;
179                 }
180
181                 /* Check if 1GB huge pages are unavailable, that function fails unless
182                  * HINT flag is indicated
183                  */
184                 if (!hugepage_1GB_avail) {
185                         mz = rte_memzone_reserve("flag_zone_1G_HINT", size, SOCKET_ID_ANY,
186                                         RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY);
187                         if (mz == NULL) {
188                                 printf("MEMZONE FLAG 1GB & HINT\n");
189                                 return -1;
190                         }
191                         if (mz->hugepage_sz != RTE_PGSIZE_2M) {
192                                 printf("hugepage_sz not equal 2M\n");
193                                 return -1;
194                         }
195
196                         mz = rte_memzone_reserve("flag_zone_1G", size, SOCKET_ID_ANY,
197                                         RTE_MEMZONE_1GB);
198                         if (mz != NULL) {
199                                 printf("MEMZONE FLAG 1GB\n");
200                                 return -1;
201                         }
202                 }
203         }
204
205         /*As with 2MB tests above for 1GB huge page requests*/
206         if (hugepage_1GB_avail) {
207                 mz = rte_memzone_reserve("flag_zone_1G", size, SOCKET_ID_ANY,
208                                 RTE_MEMZONE_1GB);
209                 if (mz == NULL) {
210                         printf("MEMZONE FLAG 1GB\n");
211                         return -1;
212                 }
213                 if (mz->hugepage_sz != RTE_PGSIZE_1G) {
214                         printf("hugepage_sz not equal 1G\n");
215                         return -1;
216                 }
217
218                 mz = rte_memzone_reserve("flag_zone_1G_HINT", size, SOCKET_ID_ANY,
219                                 RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY);
220                 if (mz == NULL) {
221                         printf("MEMZONE FLAG 1GB\n");
222                         return -1;
223                 }
224                 if (mz->hugepage_sz != RTE_PGSIZE_1G) {
225                         printf("hugepage_sz not equal 1G\n");
226                         return -1;
227                 }
228
229                 /* Check if 1GB huge pages are unavailable, that function fails unless
230                  * HINT flag is indicated
231                  */
232                 if (!hugepage_2MB_avail) {
233                         mz = rte_memzone_reserve("flag_zone_2M_HINT", size, SOCKET_ID_ANY,
234                                         RTE_MEMZONE_2MB|RTE_MEMZONE_SIZE_HINT_ONLY);
235                         if (mz == NULL){
236                                 printf("MEMZONE FLAG 2MB & HINT\n");
237                                 return -1;
238                         }
239                         if (mz->hugepage_sz != RTE_PGSIZE_1G) {
240                                 printf("hugepage_sz not equal 1G\n");
241                                 return -1;
242                         }
243                         mz = rte_memzone_reserve("flag_zone_2M", size, SOCKET_ID_ANY,
244                                         RTE_MEMZONE_2MB);
245                         if (mz != NULL) {
246                                 printf("MEMZONE FLAG 2MB\n");
247                                 return -1;
248                         }
249                 }
250
251                 if (hugepage_2MB_avail && hugepage_1GB_avail) {
252                         mz = rte_memzone_reserve("flag_zone_2M_HINT", size, SOCKET_ID_ANY,
253                                                                 RTE_MEMZONE_2MB|RTE_MEMZONE_1GB);
254                         if (mz != NULL) {
255                                 printf("BOTH SIZES SET\n");
256                                 return -1;
257                         }
258                 }
259         }
260         return 0;
261 }
262
263 static int
264 test_memzone_reserve_max(void)
265 {
266         const struct rte_memzone *mz;
267         const struct rte_config *config;
268         const struct rte_memseg *ms;
269         int memseg_idx = 0;
270         int memzone_idx = 0;
271         size_t len = 0;
272         void* last_addr;
273         size_t maxlen = 0;
274
275         /* get pointer to global configuration */
276         config = rte_eal_get_configuration();
277
278         ms = rte_eal_get_physmem_layout();
279
280         for (memseg_idx = 0; memseg_idx < RTE_MAX_MEMSEG; memseg_idx++){
281                 /* ignore smaller memsegs as they can only get smaller */
282                 if (ms[memseg_idx].len < maxlen)
283                         continue;
284
285                 /* align everything */
286                 last_addr = RTE_PTR_ALIGN_CEIL(ms[memseg_idx].addr, CACHE_LINE_SIZE);
287                 len = ms[memseg_idx].len - RTE_PTR_DIFF(last_addr, ms[memseg_idx].addr);
288                 len &= ~((size_t) CACHE_LINE_MASK);
289
290                 /* cycle through all memzones */
291                 for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
292
293                         /* stop when reaching last allocated memzone */
294                         if (config->mem_config->memzone[memzone_idx].addr == NULL)
295                                 break;
296
297                         /* check if the memzone is in our memseg and subtract length */
298                         if ((config->mem_config->memzone[memzone_idx].addr >=
299                                         ms[memseg_idx].addr) &&
300                                         (config->mem_config->memzone[memzone_idx].addr <=
301                                         (RTE_PTR_ADD(ms[memseg_idx].addr, ms[memseg_idx].len)))) {
302                                 /* since the zones can now be aligned and occasionally skip
303                                  * some space, we should calculate the length based on
304                                  * reported length and start addresses difference. Addresses
305                                  * are allocated sequentially so we don't need to worry about
306                                  * them being in the right order.
307                                  */
308                                 len -= RTE_PTR_DIFF(
309                                                 config->mem_config->memzone[memzone_idx].addr,
310                                                 last_addr);
311                                 len -= config->mem_config->memzone[memzone_idx].len;
312                                 last_addr = RTE_PTR_ADD(config->mem_config->memzone[memzone_idx].addr,
313                                                 (size_t) config->mem_config->memzone[memzone_idx].len);
314                         }
315                 }
316
317                 /* we don't need to calculate offset here since length
318                  * is always cache-aligned */
319                 if (len > maxlen)
320                         maxlen = len;
321         }
322
323         if (maxlen == 0) {
324                 printf("There is no space left!\n");
325                 return 0;
326         }
327
328         mz = rte_memzone_reserve("max_zone", 0, SOCKET_ID_ANY, 0);
329         if (mz == NULL){
330                 printf("Failed to reserve a big chunk of memory\n");
331                 rte_dump_physmem_layout();
332                 rte_memzone_dump();
333                 return -1;
334         }
335
336         if (mz->len != maxlen) {
337                 printf("Memzone reserve with 0 size did not return bigest block\n");
338                 printf("Expected size = %zu, actual size = %zu\n",
339                                 maxlen, mz->len);
340                 rte_dump_physmem_layout();
341                 rte_memzone_dump();
342
343                 return -1;
344         }
345         return 0;
346 }
347
348 static int
349 test_memzone_reserve_max_aligned(void)
350 {
351         const struct rte_memzone *mz;
352         const struct rte_config *config;
353         const struct rte_memseg *ms;
354         int memseg_idx = 0;
355         int memzone_idx = 0;
356         uintptr_t addr_offset;
357         size_t len = 0;
358         void* last_addr;
359         size_t maxlen = 0;
360
361         /* random alignment */
362         rte_srand((unsigned)rte_rdtsc());
363         const unsigned align = 1 << ((rte_rand() % 8) + 5); /* from 128 up to 4k alignment */
364
365         /* get pointer to global configuration */
366         config = rte_eal_get_configuration();
367
368         ms = rte_eal_get_physmem_layout();
369
370         addr_offset = 0;
371
372         for (memseg_idx = 0; memseg_idx < RTE_MAX_MEMSEG; memseg_idx++){
373
374                 /* ignore smaller memsegs as they can only get smaller */
375                 if (ms[memseg_idx].len < maxlen)
376                         continue;
377
378                 /* align everything */
379                 last_addr = RTE_PTR_ALIGN_CEIL(ms[memseg_idx].addr, CACHE_LINE_SIZE);
380                 len = ms[memseg_idx].len - RTE_PTR_DIFF(last_addr, ms[memseg_idx].addr);
381                 len &= ~((size_t) CACHE_LINE_MASK);
382
383                 /* cycle through all memzones */
384                 for (memzone_idx = 0; memzone_idx < RTE_MAX_MEMZONE; memzone_idx++) {
385
386                         /* stop when reaching last allocated memzone */
387                         if (config->mem_config->memzone[memzone_idx].addr == NULL)
388                                 break;
389
390                         /* check if the memzone is in our memseg and subtract length */
391                         if ((config->mem_config->memzone[memzone_idx].addr >=
392                                         ms[memseg_idx].addr) &&
393                                         (config->mem_config->memzone[memzone_idx].addr <=
394                                         (RTE_PTR_ADD(ms[memseg_idx].addr, ms[memseg_idx].len)))) {
395                                 /* since the zones can now be aligned and occasionally skip
396                                  * some space, we should calculate the length based on
397                                  * reported length and start addresses difference.
398                                  */
399                                 len -= (uintptr_t) RTE_PTR_SUB(
400                                                 config->mem_config->memzone[memzone_idx].addr,
401                                                 (uintptr_t) last_addr);
402                                 len -= config->mem_config->memzone[memzone_idx].len;
403                                 last_addr =
404                                                 RTE_PTR_ADD(config->mem_config->memzone[memzone_idx].addr,
405                                                 (size_t) config->mem_config->memzone[memzone_idx].len);
406                         }
407                 }
408
409                 /* make sure we get the alignment offset */
410                 if (len > maxlen) {
411                         addr_offset = RTE_PTR_ALIGN_CEIL((uintptr_t) last_addr, align) - (uintptr_t) last_addr;
412                         maxlen = len;
413                 }
414         }
415
416         if (maxlen == 0 || maxlen == addr_offset) {
417                 printf("There is no space left for biggest %u-aligned memzone!\n", align);
418                 return 0;
419         }
420
421         maxlen -= addr_offset;
422
423         mz = rte_memzone_reserve_aligned("max_zone_aligned", 0,
424                         SOCKET_ID_ANY, 0, align);
425         if (mz == NULL){
426                 printf("Failed to reserve a big chunk of memory\n");
427                 rte_dump_physmem_layout();
428                 rte_memzone_dump();
429                 return -1;
430         }
431
432         if (mz->len != maxlen) {
433                 printf("Memzone reserve with 0 size and alignment %u did not return"
434                                 " bigest block\n", align);
435                 printf("Expected size = %zu, actual size = %zu\n",
436                                 maxlen, mz->len);
437                 rte_dump_physmem_layout();
438                 rte_memzone_dump();
439
440                 return -1;
441         }
442         return 0;
443 }
444
445 static int
446 test_memzone_aligned(void)
447 {
448         const struct rte_memzone *memzone_aligned_32;
449         const struct rte_memzone *memzone_aligned_128;
450         const struct rte_memzone *memzone_aligned_256;
451         const struct rte_memzone *memzone_aligned_512;
452         const struct rte_memzone *memzone_aligned_1024;
453
454         /* memzone that should automatically be adjusted to align on 64 bytes */
455         memzone_aligned_32 = rte_memzone_lookup("aligned_32");
456         if (memzone_aligned_32 == NULL)
457                 memzone_aligned_32 = rte_memzone_reserve_aligned("aligned_32", 100,
458                                 SOCKET_ID_ANY, 0, 32);
459
460         /* memzone that is supposed to be aligned on a 128 byte boundary */
461         memzone_aligned_128 = rte_memzone_lookup("aligned_128");
462         if (memzone_aligned_128 == NULL)
463                 memzone_aligned_128 = rte_memzone_reserve_aligned("aligned_128", 100,
464                                 SOCKET_ID_ANY, 0, 128);
465
466         /* memzone that is supposed to be aligned on a 256 byte boundary */
467         memzone_aligned_256 = rte_memzone_lookup("aligned_256");
468         if (memzone_aligned_256 == NULL)
469                 memzone_aligned_256 = rte_memzone_reserve_aligned("aligned_256", 100,
470                                 SOCKET_ID_ANY, 0, 256);
471
472         /* memzone that is supposed to be aligned on a 512 byte boundary */
473         memzone_aligned_512 = rte_memzone_lookup("aligned_512");
474         if (memzone_aligned_512 == NULL)
475                 memzone_aligned_512 = rte_memzone_reserve_aligned("aligned_512", 100,
476                                 SOCKET_ID_ANY, 0, 512);
477
478         /* memzone that is supposed to be aligned on a 1024 byte boundary */
479         memzone_aligned_1024 = rte_memzone_lookup("aligned_1024");
480         if (memzone_aligned_1024 == NULL)
481                 memzone_aligned_1024 = rte_memzone_reserve_aligned("aligned_1024", 100,
482                                 SOCKET_ID_ANY, 0, 1024);
483
484         printf("check alignments and lengths\n");
485         if (memzone_aligned_32 == NULL) {
486                 printf("Unable to reserve 64-byte aligned memzone!\n");
487                 return -1;
488         }
489         if ((memzone_aligned_32->phys_addr & CACHE_LINE_MASK) != 0)
490                 return -1;
491         if (((uintptr_t) memzone_aligned_32->addr & CACHE_LINE_MASK) != 0)
492                 return -1;
493         if ((memzone_aligned_32->len & CACHE_LINE_MASK) != 0)
494                 return -1;
495         if (memzone_aligned_128 == NULL) {
496                 printf("Unable to reserve 128-byte aligned memzone!\n");
497                 return -1;
498         }
499         if ((memzone_aligned_128->phys_addr & 127) != 0)
500                 return -1;
501         if (((uintptr_t) memzone_aligned_128->addr & 127) != 0)
502                 return -1;
503         if ((memzone_aligned_128->len & CACHE_LINE_MASK) != 0)
504                 return -1;
505         if (memzone_aligned_256 == NULL) {
506                 printf("Unable to reserve 256-byte aligned memzone!\n");
507                 return -1;
508         }
509         if ((memzone_aligned_256->phys_addr & 255) != 0)
510                 return -1;
511         if (((uintptr_t) memzone_aligned_256->addr & 255) != 0)
512                 return -1;
513         if ((memzone_aligned_256->len & CACHE_LINE_MASK) != 0)
514                 return -1;
515         if (memzone_aligned_512 == NULL) {
516                 printf("Unable to reserve 512-byte aligned memzone!\n");
517                 return -1;
518         }
519         if ((memzone_aligned_512->phys_addr & 511) != 0)
520                 return -1;
521         if (((uintptr_t) memzone_aligned_512->addr & 511) != 0)
522                 return -1;
523         if ((memzone_aligned_512->len & CACHE_LINE_MASK) != 0)
524                 return -1;
525         if (memzone_aligned_1024 == NULL) {
526                 printf("Unable to reserve 1024-byte aligned memzone!\n");
527                 return -1;
528         }
529         if ((memzone_aligned_1024->phys_addr & 1023) != 0)
530                 return -1;
531         if (((uintptr_t) memzone_aligned_1024->addr & 1023) != 0)
532                 return -1;
533         if ((memzone_aligned_1024->len & CACHE_LINE_MASK) != 0)
534                 return -1;
535
536         /* check that zones don't overlap */
537         printf("check overlapping\n");
538         if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
539                                         memzone_aligned_128->phys_addr, memzone_aligned_128->len))
540                 return -1;
541         if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
542                                         memzone_aligned_256->phys_addr, memzone_aligned_256->len))
543                 return -1;
544         if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
545                                         memzone_aligned_512->phys_addr, memzone_aligned_512->len))
546                 return -1;
547         if (is_memory_overlap(memzone_aligned_32->phys_addr, memzone_aligned_32->len,
548                                         memzone_aligned_1024->phys_addr, memzone_aligned_1024->len))
549                 return -1;
550         if (is_memory_overlap(memzone_aligned_128->phys_addr, memzone_aligned_128->len,
551                                         memzone_aligned_256->phys_addr, memzone_aligned_256->len))
552                 return -1;
553         if (is_memory_overlap(memzone_aligned_128->phys_addr, memzone_aligned_128->len,
554                                         memzone_aligned_512->phys_addr, memzone_aligned_512->len))
555                 return -1;
556         if (is_memory_overlap(memzone_aligned_128->phys_addr, memzone_aligned_128->len,
557                                         memzone_aligned_1024->phys_addr, memzone_aligned_1024->len))
558                 return -1;
559         if (is_memory_overlap(memzone_aligned_256->phys_addr, memzone_aligned_256->len,
560                                         memzone_aligned_512->phys_addr, memzone_aligned_512->len))
561                 return -1;
562         if (is_memory_overlap(memzone_aligned_256->phys_addr, memzone_aligned_256->len,
563                                         memzone_aligned_1024->phys_addr, memzone_aligned_1024->len))
564                 return -1;
565         if (is_memory_overlap(memzone_aligned_512->phys_addr, memzone_aligned_512->len,
566                                         memzone_aligned_1024->phys_addr, memzone_aligned_1024->len))
567                 return -1;
568         return 0;
569 }
570
571 int
572 test_memzone(void)
573 {
574         const struct rte_memzone *memzone1;
575         const struct rte_memzone *memzone2;
576         const struct rte_memzone *memzone3;
577         const struct rte_memzone *mz;
578
579         memzone1 = rte_memzone_lookup("testzone1");
580         if (memzone1 == NULL)
581                 memzone1 = rte_memzone_reserve("testzone1", 100,
582                                 SOCKET_ID_ANY, 0);
583
584         memzone2 = rte_memzone_lookup("testzone2");
585         if (memzone2 == NULL)
586                 memzone2 = rte_memzone_reserve("testzone2", 1000,
587                                 0, 0);
588
589         memzone3 = rte_memzone_lookup("testzone3");
590         if (memzone3 == NULL)
591                 memzone3 = rte_memzone_reserve("testzone3", 1000,
592                                 1, 0);
593
594         /* memzone3 may be NULL if we don't have NUMA */
595         if (memzone1 == NULL || memzone2 == NULL)
596                 return -1;
597
598         rte_memzone_dump();
599
600         /* check cache-line alignments */
601         printf("check alignments and lengths\n");
602
603         if ((memzone1->phys_addr & CACHE_LINE_MASK) != 0)
604                 return -1;
605         if ((memzone2->phys_addr & CACHE_LINE_MASK) != 0)
606                 return -1;
607         if (memzone3 != NULL && (memzone3->phys_addr & CACHE_LINE_MASK) != 0)
608                 return -1;
609         if ((memzone1->len & CACHE_LINE_MASK) != 0 || memzone1->len == 0)
610                 return -1;
611         if ((memzone2->len & CACHE_LINE_MASK) != 0 || memzone2->len == 0)
612                 return -1;
613         if (memzone3 != NULL && ((memzone3->len & CACHE_LINE_MASK) != 0 ||
614                         memzone3->len == 0))
615                 return -1;
616
617         /* check that zones don't overlap */
618         printf("check overlapping\n");
619
620         if (is_memory_overlap(memzone1->phys_addr, memzone1->len,
621                         memzone2->phys_addr, memzone2->len))
622                 return -1;
623         if (memzone3 != NULL &&
624                         is_memory_overlap(memzone1->phys_addr, memzone1->len,
625                                         memzone3->phys_addr, memzone3->len))
626                 return -1;
627         if (memzone3 != NULL &&
628                         is_memory_overlap(memzone2->phys_addr, memzone2->len,
629                                         memzone3->phys_addr, memzone3->len))
630                 return -1;
631
632         printf("check socket ID\n");
633
634         /* memzone2 must be on socket id 0 and memzone3 on socket 1 */
635         if (memzone2->socket_id != 0)
636                 return -1;
637         if (memzone3 != NULL && memzone3->socket_id != 1)
638                 return -1;
639
640         printf("test zone lookup\n");
641         mz = rte_memzone_lookup("testzone1");
642         if (mz != memzone1)
643                 return -1;
644
645         printf("test duplcate zone name\n");
646         mz = rte_memzone_reserve("testzone1", 100,
647                         SOCKET_ID_ANY, 0);
648         if (mz != NULL)
649                 return -1;
650
651         printf("test reserving memzone with bigger size than the maximum\n");
652         if (test_memzone_reserving_zone_size_bigger_than_the_maximum() < 0)
653                 return -1;
654
655         printf("test memzone_reserve flags\n");
656         if (test_memzone_reserve_flags() < 0)
657                 return -1;
658
659         printf("test alignment for memzone_reserve\n");
660         if (test_memzone_aligned() < 0)
661                 return -1;
662
663         printf("test invalid alignment for memzone_reserve\n");
664         if (test_memzone_invalid_alignment() < 0)
665                 return -1;
666
667         printf("test reserving the largest size memzone possible\n");
668         if (test_memzone_reserve_max() < 0)
669                 return -1;
670
671         printf("test reserving the largest size aligned memzone possible\n");
672         if (test_memzone_reserve_max_aligned() < 0)
673                 return -1;
674
675         return 0;
676 }