net/sfc/base: remove unused defined for WPTR alignment
[dpdk.git] / test / test / test_memzone.c
index c9394c4..6e80977 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 
 #include <stdio.h>
@@ -176,6 +147,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 2M\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                mz = rte_memzone_reserve("flag_zone_2M_HINT", size, SOCKET_ID_ANY,
                                RTE_MEMZONE_2MB|RTE_MEMZONE_SIZE_HINT_ONLY);
@@ -187,6 +162,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 2M\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                /* Check if 1GB huge pages are unavailable, that function fails unless
                 * HINT flag is indicated
@@ -202,6 +181,10 @@ test_memzone_reserve_flags(void)
                                printf("hugepage_sz not equal 2M\n");
                                return -1;
                        }
+                       if (rte_memzone_free(mz)) {
+                               printf("Fail memzone free\n");
+                               return -1;
+                       }
 
                        mz = rte_memzone_reserve("flag_zone_1G", size, SOCKET_ID_ANY,
                                        RTE_MEMZONE_1GB);
@@ -224,6 +207,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 1G\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                mz = rte_memzone_reserve("flag_zone_1G_HINT", size, SOCKET_ID_ANY,
                                RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY);
@@ -235,6 +222,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 1G\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                /* Check if 1GB huge pages are unavailable, that function fails unless
                 * HINT flag is indicated
@@ -250,12 +241,20 @@ test_memzone_reserve_flags(void)
                                printf("hugepage_sz not equal 1G\n");
                                return -1;
                        }
+                       if (rte_memzone_free(mz)) {
+                               printf("Fail memzone free\n");
+                               return -1;
+                       }
                        mz = rte_memzone_reserve("flag_zone_2M", size, SOCKET_ID_ANY,
                                        RTE_MEMZONE_2MB);
                        if (mz != NULL) {
                                printf("MEMZONE FLAG 2MB\n");
                                return -1;
                        }
+                       if (rte_memzone_free(mz)) {
+                               printf("Fail memzone free\n");
+                               return -1;
+                       }
                }
 
                if (hugepage_2MB_avail && hugepage_1GB_avail) {
@@ -285,6 +284,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 16M\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                mz = rte_memzone_reserve("flag_zone_16M_HINT", size,
                SOCKET_ID_ANY, RTE_MEMZONE_16MB|RTE_MEMZONE_SIZE_HINT_ONLY);
@@ -296,6 +299,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 16M\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                /* Check if 1GB huge pages are unavailable, that function fails
                 * unless HINT flag is indicated
@@ -312,6 +319,10 @@ test_memzone_reserve_flags(void)
                                printf("hugepage_sz not equal 16M\n");
                                return -1;
                        }
+                       if (rte_memzone_free(mz)) {
+                               printf("Fail memzone free\n");
+                               return -1;
+                       }
 
                        mz = rte_memzone_reserve("flag_zone_16G", size,
                                SOCKET_ID_ANY, RTE_MEMZONE_16GB);
@@ -333,6 +344,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 16G\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                mz = rte_memzone_reserve("flag_zone_16G_HINT", size,
                SOCKET_ID_ANY, RTE_MEMZONE_16GB|RTE_MEMZONE_SIZE_HINT_ONLY);
@@ -344,6 +359,10 @@ test_memzone_reserve_flags(void)
                        printf("hugepage_sz not equal 16G\n");
                        return -1;
                }
+               if (rte_memzone_free(mz)) {
+                       printf("Fail memzone free\n");
+                       return -1;
+               }
 
                /* Check if 1GB huge pages are unavailable, that function fails
                 * unless HINT flag is indicated
@@ -360,6 +379,10 @@ test_memzone_reserve_flags(void)
                                printf("hugepage_sz not equal 16G\n");
                                return -1;
                        }
+                       if (rte_memzone_free(mz)) {
+                               printf("Fail memzone free\n");
+                               return -1;
+                       }
                        mz = rte_memzone_reserve("flag_zone_16M", size,
                                SOCKET_ID_ANY, RTE_MEMZONE_16MB);
                        if (mz != NULL) {
@@ -434,6 +457,12 @@ test_memzone_reserve_max(void)
                rte_memzone_dump(stdout);
                return -1;
        }
+
+       if (rte_memzone_free(mz)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+
        return 0;
 }
 
@@ -473,6 +502,12 @@ test_memzone_reserve_max_aligned(void)
                rte_memzone_dump(stdout);
                return -1;
        }
+
+       if (rte_memzone_free(mz)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+
        return 0;
 }
 
@@ -593,6 +628,28 @@ test_memzone_aligned(void)
        if (is_memory_overlap(memzone_aligned_512->iova, memzone_aligned_512->len,
                                        memzone_aligned_1024->iova, memzone_aligned_1024->len))
                return -1;
+
+       /* free all used zones */
+       if (rte_memzone_free(memzone_aligned_32)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone_aligned_128)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone_aligned_256)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone_aligned_512)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone_aligned_1024)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
        return 0;
 }
 
@@ -638,6 +695,11 @@ check_memzone_bounded(const char *name, uint32_t len,  uint32_t align,
                return -1;
        }
 
+       if (rte_memzone_free(mz)) {
+               printf("Fail memzone free\n");
+               return -1;
+       }
+
        return 0;
 }
 
@@ -758,7 +820,7 @@ test_memzone_free(void)
 }
 
 static int
-test_memzone(void)
+test_memzone_basic(void)
 {
        const struct rte_memzone *memzone1;
        const struct rte_memzone *memzone2;
@@ -837,6 +899,40 @@ test_memzone(void)
        if (mz != NULL)
                return -1;
 
+       if (rte_memzone_free(memzone1)) {
+               printf("Fail memzone free - memzone1\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone2)) {
+               printf("Fail memzone free - memzone2\n");
+               return -1;
+       }
+       if (memzone3 && rte_memzone_free(memzone3)) {
+               printf("Fail memzone free - memzone3\n");
+               return -1;
+       }
+       if (rte_memzone_free(memzone4)) {
+               printf("Fail memzone free - memzone4\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+static int memzone_calk_called;
+static void memzone_walk_clb(const struct rte_memzone *mz __rte_unused,
+                            void *arg __rte_unused)
+{
+       memzone_calk_called = 1;
+}
+
+static int
+test_memzone(void)
+{
+       printf("test basic memzone API\n");
+       if (test_memzone_basic() < 0)
+               return -1;
+
        printf("test free memzone\n");
        if (test_memzone_free() < 0)
                return -1;
@@ -869,6 +965,14 @@ test_memzone(void)
        if (test_memzone_reserve_max_aligned() < 0)
                return -1;
 
+       printf("check memzone cleanup\n");
+       rte_memzone_walk(memzone_walk_clb, NULL);
+       if (memzone_calk_called) {
+               printf("there are some memzones left after test\n");
+               rte_memzone_dump(stdout);
+               return -1;
+       }
+
        return 0;
 }