tile: fix build
[dpdk.git] / app / test / test_memzone.c
index 6934eee..7ae31cf 100644 (file)
@@ -432,7 +432,6 @@ test_memzone_reserve_max(void)
                printf("Expected size = %zu, actual size = %zu\n", maxlen, mz->len);
                rte_dump_physmem_layout(stdout);
                rte_memzone_dump(stdout);
-
                return -1;
        }
        return 0;
@@ -472,7 +471,6 @@ test_memzone_reserve_max_aligned(void)
                                maxlen, mz->len);
                rte_dump_physmem_layout(stdout);
                rte_memzone_dump(stdout);
-
                return -1;
        }
        return 0;
@@ -611,36 +609,36 @@ check_memzone_bounded(const char *name, uint32_t len,  uint32_t align,
                        align, bound)) == NULL) {
                printf("%s(%s): memzone creation failed\n",
                        __func__, name);
-               return (-1);
+               return -1;
        }
 
        if ((mz->phys_addr & ((phys_addr_t)align - 1)) != 0) {
                printf("%s(%s): invalid phys addr alignment\n",
                        __func__, mz->name);
-               return (-1);
+               return -1;
        }
 
        if (((uintptr_t) mz->addr & ((uintptr_t)align - 1)) != 0) {
                printf("%s(%s): invalid virtual addr alignment\n",
                        __func__, mz->name);
-               return (-1);
+               return -1;
        }
 
        if ((mz->len & RTE_CACHE_LINE_MASK) != 0 || mz->len < len ||
                        mz->len < RTE_CACHE_LINE_SIZE) {
                printf("%s(%s): invalid length\n",
                        __func__, mz->name);
-               return (-1);
+               return -1;
        }
 
        if ((mz->phys_addr & bmask) !=
                        ((mz->phys_addr + mz->len - 1) & bmask)) {
                printf("%s(%s): invalid memzone boundary %u crossed\n",
                        __func__, mz->name, bound);
-               return (-1);
+               return -1;
        }
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -656,7 +654,7 @@ test_memzone_bounded(void)
                        100, SOCKET_ID_ANY, 0, 32, UINT32_MAX)) != NULL) {
                printf("%s(%s)created a memzone with invalid boundary "
                        "conditions\n", __func__, memzone_err->name);
-               return (-1);
+               return -1;
        }
 
        /* should fail as len is greater then boundary */
@@ -665,20 +663,96 @@ test_memzone_bounded(void)
                        100, SOCKET_ID_ANY, 0, 32, 32)) != NULL) {
                printf("%s(%s)created a memzone with invalid boundary "
                        "conditions\n", __func__, memzone_err->name);
-               return (-1);
+               return -1;
        }
 
        if ((rc = check_memzone_bounded("bounded_128", 100, 128, 128)) != 0)
-               return (rc);
+               return rc;
 
        if ((rc = check_memzone_bounded("bounded_256", 100, 256, 128)) != 0)
-               return (rc);
+               return rc;
 
        if ((rc = check_memzone_bounded("bounded_1K", 100, 64, 1024)) != 0)
-               return (rc);
+               return rc;
 
        if ((rc = check_memzone_bounded("bounded_1K_MAX", 0, 64, 1024)) != 0)
-               return (rc);
+               return rc;
+
+       return 0;
+}
+
+static int
+test_memzone_free(void)
+{
+       const struct rte_memzone *mz[RTE_MAX_MEMZONE];
+       int i;
+       char name[20];
+
+       mz[0] = rte_memzone_reserve("tempzone0", 2000, SOCKET_ID_ANY, 0);
+       mz[1] = rte_memzone_reserve("tempzone1", 4000, SOCKET_ID_ANY, 0);
+
+       if (mz[0] > mz[1])
+               return -1;
+       if (!rte_memzone_lookup("tempzone0"))
+               return -1;
+       if (!rte_memzone_lookup("tempzone1"))
+               return -1;
+
+       if (rte_memzone_free(mz[0])) {
+               printf("Fail memzone free - tempzone0\n");
+               return -1;
+       }
+       if (rte_memzone_lookup("tempzone0")) {
+               printf("Found previously free memzone - tempzone0\n");
+               return -1;
+       }
+       mz[2] = rte_memzone_reserve("tempzone2", 2000, SOCKET_ID_ANY, 0);
+
+       if (mz[2] > mz[1]) {
+               printf("tempzone2 should have gotten the free entry from tempzone0\n");
+               return -1;
+       }
+       if (rte_memzone_free(mz[2])) {
+               printf("Fail memzone free - tempzone2\n");
+               return -1;
+       }
+       if (rte_memzone_lookup("tempzone2")) {
+               printf("Found previously free memzone - tempzone2\n");
+               return -1;
+       }
+       if (rte_memzone_free(mz[1])) {
+               printf("Fail memzone free - tempzone1\n");
+               return -1;
+       }
+       if (rte_memzone_lookup("tempzone1")) {
+               printf("Found previously free memzone - tempzone1\n");
+               return -1;
+       }
+
+       i = 0;
+       do {
+               snprintf(name, sizeof(name), "tempzone%u", i);
+               mz[i] = rte_memzone_reserve(name, 1, SOCKET_ID_ANY, 0);
+       } while (mz[i++] != NULL);
+
+       if (rte_memzone_free(mz[0])) {
+               printf("Fail memzone free - tempzone0\n");
+               return -1;
+       }
+       mz[0] = rte_memzone_reserve("tempzone0new", 0, SOCKET_ID_ANY, 0);
+
+       if (mz[0] == NULL) {
+               printf("Fail to create memzone - tempzone0new - when MAX memzones were "
+                               "created and one was free\n");
+               return -1;
+       }
+
+       for (i = i - 2; i >= 0; i--) {
+               if (rte_memzone_free(mz[i])) {
+                       printf("Fail memzone free - tempzone%d\n", i);
+                       return -1;
+               }
+       }
 
        return 0;
 }
@@ -763,6 +837,10 @@ test_memzone(void)
        if (mz != NULL)
                return -1;
 
+       printf("test free memzone\n");
+       if (test_memzone_free() < 0)
+               return -1;
+
        printf("test reserving memzone with bigger size than the maximum\n");
        if (test_memzone_reserving_zone_size_bigger_than_the_maximum() < 0)
                return -1;
@@ -794,8 +872,4 @@ test_memzone(void)
        return 0;
 }
 
-static struct test_command memzone_cmd = {
-       .command = "memzone_autotest",
-       .callback = test_memzone,
-};
-REGISTER_TEST_COMMAND(memzone_cmd);
+REGISTER_TEST_COMMAND(memzone_autotest, test_memzone);