[v16,6/6] test/memarea: support dump API test

Message ID 20230710064923.19849-7-fengchengwen@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series introduce memarea library |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-abi-testing success Testing PASS
ci/iol-aarch-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

fengchengwen July 10, 2023, 6:49 a.m. UTC
  This patch supports rte_memarea_dump() API test.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 app/test/test_memarea.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
  

Comments

Anatoly Burakov July 19, 2023, 12:09 p.m. UTC | #1
On 7/10/2023 7:49 AM, Chengwen Feng wrote:
> This patch supports rte_memarea_dump() API test.
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> ---
>   app/test/test_memarea.c | 40 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 40 insertions(+)
> 
> diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c
> index 4053cdcac9..6511a86699 100644
> --- a/app/test/test_memarea.c
> +++ b/app/test/test_memarea.c
> @@ -320,6 +320,45 @@ test_memarea_alloc_free(void)
>   
>   	TEST_ASSERT(rte_errno == 0, "Expected Zero");
>   
> +	fprintf(stderr, "There should have no allocated object.\n");
> +	rte_memarea_dump(ma, stderr, true);
> +
> +	rte_memarea_destroy(ma);
> +
> +	return 0;
> +}
> +
> +static int
> +test_memarea_dump(void)
> +{
> +	struct rte_memarea_param init;
> +	struct rte_memarea *ma;
> +	int ret;
> +
> +	test_memarea_init_param(&init);
> +	init.source = RTE_MEMAREA_SOURCE_LIBC;
> +	init.total_sz = MEMAREA_TEST_DEFAULT_SIZE;
> +	ma = rte_memarea_create(&init);
> +	TEST_ASSERT(ma != NULL, "Expected Non-NULL");

Here and in other places: I feel it's better to say *why* we expect 
non-NULL, or make the error message otherwise more meaningful, such as 
"Memarea creation failed".

> +
> +	/* test for invalid parameters */
> +	ret = rte_memarea_dump(NULL, stderr, false);
> +	TEST_ASSERT(ret == -1, "Expected -1");
> +	TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
> +	ret = rte_memarea_dump(ma, NULL, false);
> +	TEST_ASSERT(ret == -1, "Expected -1");
> +	TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
> +
> +	/* test for dump */
> +	(void)rte_memarea_alloc(ma, 1);
> +	(void)rte_memarea_alloc(ma, 1);
> +	(void)rte_memarea_alloc(ma, 1);
> +	(void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
> +	(void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
> +	fprintf(stderr, "There should have three allocated object.\n");

I question the value of this printout.

> +	ret = rte_memarea_dump(ma, stderr, true);
> +	TEST_ASSERT(ret == 0, "Expected ZERO");
> +
>   	rte_memarea_destroy(ma);
>   
>   	return 0;
> @@ -337,6 +376,7 @@ static struct unit_test_suite memarea_test_suite  = {
>   		TEST_CASE(test_memarea_alloc_fail),
>   		TEST_CASE(test_memarea_free_fail),
>   		TEST_CASE(test_memarea_alloc_free),
> +		TEST_CASE(test_memarea_dump),
>   
>   		TEST_CASES_END() /**< NULL terminate unit test array */
>   	}
  
fengchengwen July 20, 2023, 9:35 a.m. UTC | #2
Hi Anatoly,

On 2023/7/19 20:09, Burakov, Anatoly wrote:
> On 7/10/2023 7:49 AM, Chengwen Feng wrote:
>> This patch supports rte_memarea_dump() API test.
>>
>> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
>> Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
>> Acked-by: Morten Brørup <mb@smartsharesystems.com>
>> ---
>>   app/test/test_memarea.c | 40 ++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 40 insertions(+)
>>
>> diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c
>> index 4053cdcac9..6511a86699 100644
>> --- a/app/test/test_memarea.c
>> +++ b/app/test/test_memarea.c
>> @@ -320,6 +320,45 @@ test_memarea_alloc_free(void)
>>         TEST_ASSERT(rte_errno == 0, "Expected Zero");
>>   +    fprintf(stderr, "There should have no allocated object.\n");
>> +    rte_memarea_dump(ma, stderr, true);
>> +
>> +    rte_memarea_destroy(ma);
>> +
>> +    return 0;
>> +}
>> +
>> +static int
>> +test_memarea_dump(void)
>> +{
>> +    struct rte_memarea_param init;
>> +    struct rte_memarea *ma;
>> +    int ret;
>> +
>> +    test_memarea_init_param(&init);
>> +    init.source = RTE_MEMAREA_SOURCE_LIBC;
>> +    init.total_sz = MEMAREA_TEST_DEFAULT_SIZE;
>> +    ma = rte_memarea_create(&init);
>> +    TEST_ASSERT(ma != NULL, "Expected Non-NULL");
> 
> Here and in other places: I feel it's better to say *why* we expect non-NULL, or make the error message otherwise more meaningful, such as "Memarea creation failed".

It already fix in v19.

> 
>> +
>> +    /* test for invalid parameters */
>> +    ret = rte_memarea_dump(NULL, stderr, false);
>> +    TEST_ASSERT(ret == -1, "Expected -1");
>> +    TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
>> +    ret = rte_memarea_dump(ma, NULL, false);
>> +    TEST_ASSERT(ret == -1, "Expected -1");
>> +    TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
>> +
>> +    /* test for dump */
>> +    (void)rte_memarea_alloc(ma, 1);
>> +    (void)rte_memarea_alloc(ma, 1);
>> +    (void)rte_memarea_alloc(ma, 1);
>> +    (void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
>> +    (void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
>> +    fprintf(stderr, "There should have three allocated object.\n");
> 
> I question the value of this printout.

I have change the implemention (in v19): so it will depend on the rte_memarea_alloc result.

> 
>> +    ret = rte_memarea_dump(ma, stderr, true);
>> +    TEST_ASSERT(ret == 0, "Expected ZERO");
>> +
>>       rte_memarea_destroy(ma);
>>         return 0;
>> @@ -337,6 +376,7 @@ static struct unit_test_suite memarea_test_suite  = {
>>           TEST_CASE(test_memarea_alloc_fail),
>>           TEST_CASE(test_memarea_free_fail),
>>           TEST_CASE(test_memarea_alloc_free),
>> +        TEST_CASE(test_memarea_dump),
>>             TEST_CASES_END() /**< NULL terminate unit test array */
>>       }
> 

Thanks.
  

Patch

diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c
index 4053cdcac9..6511a86699 100644
--- a/app/test/test_memarea.c
+++ b/app/test/test_memarea.c
@@ -320,6 +320,45 @@  test_memarea_alloc_free(void)
 
 	TEST_ASSERT(rte_errno == 0, "Expected Zero");
 
+	fprintf(stderr, "There should have no allocated object.\n");
+	rte_memarea_dump(ma, stderr, true);
+
+	rte_memarea_destroy(ma);
+
+	return 0;
+}
+
+static int
+test_memarea_dump(void)
+{
+	struct rte_memarea_param init;
+	struct rte_memarea *ma;
+	int ret;
+
+	test_memarea_init_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_LIBC;
+	init.total_sz = MEMAREA_TEST_DEFAULT_SIZE;
+	ma = rte_memarea_create(&init);
+	TEST_ASSERT(ma != NULL, "Expected Non-NULL");
+
+	/* test for invalid parameters */
+	ret = rte_memarea_dump(NULL, stderr, false);
+	TEST_ASSERT(ret == -1, "Expected -1");
+	TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
+	ret = rte_memarea_dump(ma, NULL, false);
+	TEST_ASSERT(ret == -1, "Expected -1");
+	TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL");
+
+	/* test for dump */
+	(void)rte_memarea_alloc(ma, 1);
+	(void)rte_memarea_alloc(ma, 1);
+	(void)rte_memarea_alloc(ma, 1);
+	(void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
+	(void)rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE);
+	fprintf(stderr, "There should have three allocated object.\n");
+	ret = rte_memarea_dump(ma, stderr, true);
+	TEST_ASSERT(ret == 0, "Expected ZERO");
+
 	rte_memarea_destroy(ma);
 
 	return 0;
@@ -337,6 +376,7 @@  static struct unit_test_suite memarea_test_suite  = {
 		TEST_CASE(test_memarea_alloc_fail),
 		TEST_CASE(test_memarea_free_fail),
 		TEST_CASE(test_memarea_alloc_free),
+		TEST_CASE(test_memarea_dump),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}