basic tests (done on one core) */
| 74 | |
| 75 | /* basic tests (done on one core) */ |
| 76 | static int |
| 77 | test_mempool_basic(struct rte_mempool *mp, int use_external_cache) |
| 78 | { |
| 79 | uint32_t *objnum; |
| 80 | void **objtable; |
| 81 | void *obj, *obj2; |
| 82 | char *obj_data; |
| 83 | int ret = 0; |
| 84 | unsigned i, j; |
| 85 | int offset; |
| 86 | struct rte_mempool_cache *cache; |
| 87 | |
| 88 | if (use_external_cache) { |
| 89 | /* Create a user-owned mempool cache. */ |
| 90 | cache = rte_mempool_cache_create(RTE_MEMPOOL_CACHE_MAX_SIZE, |
| 91 | SOCKET_ID_ANY); |
| 92 | if (cache == NULL) |
| 93 | RET_ERR(); |
| 94 | } else { |
| 95 | /* May be NULL if cache is disabled. */ |
| 96 | cache = rte_mempool_default_cache(mp, rte_lcore_id()); |
| 97 | } |
| 98 | |
| 99 | /* dump the mempool status */ |
| 100 | rte_mempool_dump(stdout, mp); |
| 101 | |
| 102 | printf("get an object\n"); |
| 103 | if (rte_mempool_generic_get(mp, &obj, 1, cache) < 0) |
| 104 | GOTO_ERR(ret, out); |
| 105 | rte_mempool_dump(stdout, mp); |
| 106 | |
| 107 | /* tests that improve coverage */ |
| 108 | printf("get object count\n"); |
| 109 | /* We have to count the extra caches, one in this case. */ |
| 110 | offset = use_external_cache ? 1 * cache->len : 0; |
| 111 | if (rte_mempool_avail_count(mp) + offset != MEMPOOL_SIZE - 1) |
| 112 | GOTO_ERR(ret, out); |
| 113 | |
| 114 | printf("get private data\n"); |
| 115 | if (rte_mempool_get_priv(mp) != (char *)mp + |
| 116 | RTE_MEMPOOL_HEADER_SIZE(mp, mp->cache_size)) |
| 117 | GOTO_ERR(ret, out); |
| 118 | |
| 119 | #ifndef RTE_EXEC_ENV_FREEBSD /* rte_mem_virt2iova() not supported on bsd */ |
| 120 | printf("get physical address of an object\n"); |
| 121 | if (rte_mempool_virt2iova(obj) != rte_mem_virt2iova(obj)) |
| 122 | GOTO_ERR(ret, out); |
| 123 | #endif |
| 124 | |
| 125 | printf("put the object back\n"); |
| 126 | rte_mempool_generic_put(mp, &obj, 1, cache); |
| 127 | rte_mempool_dump(stdout, mp); |
| 128 | |
| 129 | printf("get 2 objects\n"); |
| 130 | if (rte_mempool_generic_get(mp, &obj, 1, cache) < 0) |
| 131 | GOTO_ERR(ret, out); |
| 132 | if (rte_mempool_generic_get(mp, &obj2, 1, cache) < 0) { |
| 133 | rte_mempool_generic_put(mp, &obj, 1, cache); |
no test coverage detected