[PATCH v2 26/40] test: Use a local variable for test state

Alex G. mr.nuke.me at gmail.com
Mon Feb 1 17:47:34 CET 2021


Hi Simon,

On 1/30/21 9:32 PM, Simon Glass wrote:
[snip]
>   
> +static struct unit_test_state *cur_test_state;
> +
> +struct unit_test_state *test_get_state(void)
> +{
> +	return cur_test_state;
> +}
> +
> +void test_set_state(struct unit_test_state *uts)
> +{
> +	cur_test_state = uts;
> +}
> +
>   /**
>    * dm_test_pre_run() - Get ready to run a driver model test
>    *
> @@ -180,6 +192,9 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
>   		note = " (flat tree)";
>   	printf("Test: %s: %s%s\n", test_name, fname, note);
>   
> +	/* Allow access to test state from drivers */
> +	cur_test_state = uts;
> +
Is there a reason for setting 'cur_test_state' directly instead of 
through test_set_state() ?

>   	ret = test_pre_run(uts, test);
>   	if (ret == -EAGAIN)
>   		return -EAGAIN;
> @@ -192,6 +207,8 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
>   	if (ret)
>   		return ret;
>   
> +	cur_test_state = NULL;
> +
ditto

>   	return 0;
>   }
>   
> 


More information about the U-Boot mailing list