diff mbox

[API-NEXT,PATCHv3,4/9] validation: cpumask: def_worker and def_control fixes

Message ID 1437485540-4862-5-git-send-email-stuart.haslam@linaro.org
State Superseded
Headers show

Commit Message

Stuart Haslam July 21, 2015, 1:32 p.m. UTC
The odp_cpumask_def_worker() and odp_cpumask_def_control() APIs are used
to populate a mask with the CPUs available for running threads of the
same type. This does not necessarily mean those CPUs are dedicated to
running threads of that type, on a particular platform the same CPU may
appear in both the control and worker set.

The test now verifies that the APIs;

 - populate the mask with at least 1 CPU
 - return a value that matches the number of CPUs set in the mask
 - don't return a value greater than the total available CPUsa
 - don't return a value greater than the requested number of CPUs

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 test/validation/cpumask/cpumask.c | 44 +++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 11 deletions(-)

Comments

Christophe Milard July 22, 2015, 11:12 a.m. UTC | #1
On 2015-07-21 14:32, Stuart Haslam wrote:
> The odp_cpumask_def_worker() and odp_cpumask_def_control() APIs are used
> to populate a mask with the CPUs available for running threads of the
> same type. This does not necessarily mean those CPUs are dedicated to
> running threads of that type, on a particular platform the same CPU may
> appear in both the control and worker set.
> 
> The test now verifies that the APIs;
> 
>  - populate the mask with at least 1 CPU
>  - return a value that matches the number of CPUs set in the mask
>  - don't return a value greater than the total available CPUsa
>  - don't return a value greater than the requested number of CPUs
> 
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>

Reviewed-by: Christophe Milard <christophe.milard@linaro.org>

> ---
>  test/validation/cpumask/cpumask.c | 44 +++++++++++++++++++++++++++++----------
>  1 file changed, 33 insertions(+), 11 deletions(-)
> 
> diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c
> index 933ee97..d72569e 100644
> --- a/test/validation/cpumask/cpumask.c
> +++ b/test/validation/cpumask/cpumask.c
> @@ -476,39 +476,61 @@ static void cpumask_test_odp_cpumask_setall(void)
>  
>  static void cpumask_test_odp_cpumask_def_control(void)
>  {
> -	int num;
> -	int max_cpus = mask_capacity();
> +	unsigned num;
> +	unsigned mask_count;
> +	unsigned max_cpus = mask_capacity();
>  	odp_cpumask_t mask;
>  
>  	num = odp_cpumask_def_control(&mask, ALL_AVAILABLE);
> +	mask_count = odp_cpumask_count(&mask);
>  
> -	CU_ASSERT(num >= 0);
> +	CU_ASSERT(mask_count == num);
> +	CU_ASSERT(num > 0);
>  	CU_ASSERT(num <= max_cpus);
>  }
>  
>  static void cpumask_test_odp_cpumask_def_worker(void)
>  {
> -	int num;
> -	int max_cpus = mask_capacity();
> +	unsigned num;
> +	unsigned mask_count;
> +	unsigned max_cpus = mask_capacity();
>  	odp_cpumask_t mask;
>  
>  	num = odp_cpumask_def_worker(&mask, ALL_AVAILABLE);
> +	mask_count = odp_cpumask_count(&mask);
>  
> -	CU_ASSERT(num >= 0);
> +	CU_ASSERT(mask_count == num);
> +	CU_ASSERT(num > 0);
>  	CU_ASSERT(num <= max_cpus);
>  }
>  
>  static void cpumask_test_odp_cpumask_def(void)
>  {
> -	int num_worker;
> -	int num_control;
> -	int max_cpus = mask_capacity();
> +	unsigned mask_count;
> +	unsigned num_worker;
> +	unsigned num_control;
> +	unsigned max_cpus = mask_capacity();
> +	unsigned available_cpus = odp_cpu_count();
> +	unsigned requested_cpus;
>  	odp_cpumask_t mask;
>  
> -	num_worker = odp_cpumask_def_worker(&mask, max_cpus - 1);
> +	CU_ASSERT(available_cpus <= max_cpus);
> +
> +	if (available_cpus > 1)
> +		requested_cpus = available_cpus - 1;
> +	else
> +		requested_cpus = available_cpus;
> +	num_worker = odp_cpumask_def_worker(&mask, requested_cpus);
> +	mask_count = odp_cpumask_count(&mask);
> +	CU_ASSERT(mask_count == num_worker);
> +
>  	num_control = odp_cpumask_def_control(&mask, 1);
> +	mask_count = odp_cpumask_count(&mask);
> +	CU_ASSERT(mask_count == num_control);
>  
> -	CU_ASSERT((num_control + num_worker) <= max_cpus);
> +	CU_ASSERT(num_control == 1);
> +	CU_ASSERT(num_worker <= available_cpus);
> +	CU_ASSERT(num_worker > 0);
>  }
>  
>  static CU_TestInfo cpumask_suite[] = {
> -- 
> 2.1.1
> 
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/test/validation/cpumask/cpumask.c b/test/validation/cpumask/cpumask.c
index 933ee97..d72569e 100644
--- a/test/validation/cpumask/cpumask.c
+++ b/test/validation/cpumask/cpumask.c
@@ -476,39 +476,61 @@  static void cpumask_test_odp_cpumask_setall(void)
 
 static void cpumask_test_odp_cpumask_def_control(void)
 {
-	int num;
-	int max_cpus = mask_capacity();
+	unsigned num;
+	unsigned mask_count;
+	unsigned max_cpus = mask_capacity();
 	odp_cpumask_t mask;
 
 	num = odp_cpumask_def_control(&mask, ALL_AVAILABLE);
+	mask_count = odp_cpumask_count(&mask);
 
-	CU_ASSERT(num >= 0);
+	CU_ASSERT(mask_count == num);
+	CU_ASSERT(num > 0);
 	CU_ASSERT(num <= max_cpus);
 }
 
 static void cpumask_test_odp_cpumask_def_worker(void)
 {
-	int num;
-	int max_cpus = mask_capacity();
+	unsigned num;
+	unsigned mask_count;
+	unsigned max_cpus = mask_capacity();
 	odp_cpumask_t mask;
 
 	num = odp_cpumask_def_worker(&mask, ALL_AVAILABLE);
+	mask_count = odp_cpumask_count(&mask);
 
-	CU_ASSERT(num >= 0);
+	CU_ASSERT(mask_count == num);
+	CU_ASSERT(num > 0);
 	CU_ASSERT(num <= max_cpus);
 }
 
 static void cpumask_test_odp_cpumask_def(void)
 {
-	int num_worker;
-	int num_control;
-	int max_cpus = mask_capacity();
+	unsigned mask_count;
+	unsigned num_worker;
+	unsigned num_control;
+	unsigned max_cpus = mask_capacity();
+	unsigned available_cpus = odp_cpu_count();
+	unsigned requested_cpus;
 	odp_cpumask_t mask;
 
-	num_worker = odp_cpumask_def_worker(&mask, max_cpus - 1);
+	CU_ASSERT(available_cpus <= max_cpus);
+
+	if (available_cpus > 1)
+		requested_cpus = available_cpus - 1;
+	else
+		requested_cpus = available_cpus;
+	num_worker = odp_cpumask_def_worker(&mask, requested_cpus);
+	mask_count = odp_cpumask_count(&mask);
+	CU_ASSERT(mask_count == num_worker);
+
 	num_control = odp_cpumask_def_control(&mask, 1);
+	mask_count = odp_cpumask_count(&mask);
+	CU_ASSERT(mask_count == num_control);
 
-	CU_ASSERT((num_control + num_worker) <= max_cpus);
+	CU_ASSERT(num_control == 1);
+	CU_ASSERT(num_worker <= available_cpus);
+	CU_ASSERT(num_worker > 0);
 }
 
 static CU_TestInfo cpumask_suite[] = {