[dpdk-dev,1/2] test/memzone: add test for memzone count in eal mem config

Message ID ec8bf2436653ce9dbbe9e83a364ca44c41bd2a8a.1516988093.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Anatoly Burakov Jan. 26, 2018, 5:40 p.m. UTC
  Ensure that memzone count in eal mem config is incremented and
decremented whenever memzones are allocated and freed.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 test/test/test_memzone.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Comments

Radoslaw Biernacki Jan. 27, 2018, 2:53 p.m. UTC | #1
Looks OK.

Following note is aside from the patch.
Might be beneficial (in some rare cases) to add bailout recovery with
goto's in test_memzone_basic()
Just in case one of the rte_memzone_reserve() we should not make return -1,
but instead a goto to below section where we call rte_memzone_free().
This way we would be able to free only the allocated memzones and prevent
leaking out those memzones to other tests.

Reviewed-by: Radoslaw Biernacki <r <ferruh.yigit@intel.com>
adoslaw.biernacki@linaro.com>

On 26 January 2018 at 18:40, Anatoly Burakov <anatoly.burakov@intel.com>
wrote:

> Ensure that memzone count in eal mem config is incremented and
> decremented whenever memzones are allocated and freed.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
>  test/test/test_memzone.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/test/test/test_memzone.c b/test/test/test_memzone.c
> index f6c9b56..00d340f 100644
> --- a/test/test/test_memzone.c
> +++ b/test/test/test_memzone.c
> @@ -841,6 +841,9 @@ test_memzone_basic(void)
>         const struct rte_memzone *memzone3;
>         const struct rte_memzone *memzone4;
>         const struct rte_memzone *mz;
> +       int memzone_cnt_after, memzone_cnt_expected;
> +       int memzone_cnt_before =
> +                       rte_eal_get_configuration()->
> mem_config->memzone_cnt;
>
>         memzone1 = rte_memzone_reserve("testzone1", 100,
>                                 SOCKET_ID_ANY, 0);
> @@ -858,6 +861,18 @@ test_memzone_basic(void)
>         if (memzone1 == NULL || memzone2 == NULL || memzone4 == NULL)
>                 return -1;
>
> +       /* check how many memzones we are expecting */
> +       memzone_cnt_expected = memzone_cnt_before +
> +                       (memzone1 != NULL) + (memzone2 != NULL) +
> +                       (memzone3 != NULL) + (memzone4 != NULL);
> +
> +       memzone_cnt_after =
> +                       rte_eal_get_configuration()->
> mem_config->memzone_cnt;
> +
> +       if (memzone_cnt_after != memzone_cnt_expected)
> +               return -1;
> +
> +
>         rte_memzone_dump(stdout);
>
>         /* check cache-line alignments */
> @@ -930,6 +945,11 @@ test_memzone_basic(void)
>                 return -1;
>         }
>
> +       memzone_cnt_after =
> +                       rte_eal_get_configuration()->
> mem_config->memzone_cnt;
> +       if (memzone_cnt_after != memzone_cnt_before)
> +               return -1;
> +
>         return 0;
>  }
>
> --
> 2.7.4
>
  
Anatoly Burakov Jan. 29, 2018, 9:40 a.m. UTC | #2
On 27-Jan-18 2:53 PM, Radoslaw Biernacki wrote:
> Looks OK.
> 
> Following note is aside from the patch.
> Might be beneficial (in some rare cases) to add bailout recovery with
> goto's in test_memzone_basic()
> Just in case one of the rte_memzone_reserve() we should not make return -1,
> but instead a goto to below section where we call rte_memzone_free().
> This way we would be able to free only the allocated memzones and prevent
> leaking out those memzones to other tests.

Thanks, and yep, it's on my todo list :) didn't get around to it yet.

> 
> Reviewed-by: Radoslaw Biernacki <r <ferruh.yigit@intel.com>
> adoslaw.biernacki@linaro.com>
>
  

Patch

diff --git a/test/test/test_memzone.c b/test/test/test_memzone.c
index f6c9b56..00d340f 100644
--- a/test/test/test_memzone.c
+++ b/test/test/test_memzone.c
@@ -841,6 +841,9 @@  test_memzone_basic(void)
 	const struct rte_memzone *memzone3;
 	const struct rte_memzone *memzone4;
 	const struct rte_memzone *mz;
+	int memzone_cnt_after, memzone_cnt_expected;
+	int memzone_cnt_before =
+			rte_eal_get_configuration()->mem_config->memzone_cnt;
 
 	memzone1 = rte_memzone_reserve("testzone1", 100,
 				SOCKET_ID_ANY, 0);
@@ -858,6 +861,18 @@  test_memzone_basic(void)
 	if (memzone1 == NULL || memzone2 == NULL || memzone4 == NULL)
 		return -1;
 
+	/* check how many memzones we are expecting */
+	memzone_cnt_expected = memzone_cnt_before +
+			(memzone1 != NULL) + (memzone2 != NULL) +
+			(memzone3 != NULL) + (memzone4 != NULL);
+
+	memzone_cnt_after =
+			rte_eal_get_configuration()->mem_config->memzone_cnt;
+
+	if (memzone_cnt_after != memzone_cnt_expected)
+		return -1;
+
+
 	rte_memzone_dump(stdout);
 
 	/* check cache-line alignments */
@@ -930,6 +945,11 @@  test_memzone_basic(void)
 		return -1;
 	}
 
+	memzone_cnt_after =
+			rte_eal_get_configuration()->mem_config->memzone_cnt;
+	if (memzone_cnt_after != memzone_cnt_before)
+		return -1;
+
 	return 0;
 }