glx-multithread-clearbuffer: Check pthread_join return value.

Submitted by Vinson Lee on July 25, 2017, 12:42 a.m.

Details

Message ID 1500943365-3771-1-git-send-email-vlee@freedesktop.org
State New
Headers show
Series "glx-multithread-clearbuffer: Check pthread_join return value." ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Vinson Lee July 25, 2017, 12:42 a.m.
Fix Coverity unchecked return value defect.

CID: 1415101
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
---
 tests/glx/glx-multithread-clearbuffer.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/glx/glx-multithread-clearbuffer.c b/tests/glx/glx-multithread-clearbuffer.c
index 577fde842435..da301089f2a6 100644
--- a/tests/glx/glx-multithread-clearbuffer.c
+++ b/tests/glx/glx-multithread-clearbuffer.c
@@ -82,6 +82,7 @@  main(int argc, char **argv)
 {
 	/* Need at least 16 contexts to congest the thread queue. */
 	pthread_t thread[16];
+	bool pass = true;
 
 	XInitThreads();
 
@@ -90,11 +91,15 @@  main(int argc, char **argv)
 	for (int i = 0; i < ARRAY_SIZE(thread); i++)
 		pthread_create(&thread[i], NULL, thread_func, NULL);
 
-	for (int i = 0; i < ARRAY_SIZE(thread); i++)
-		pthread_join(thread[i], NULL);
+	for (int i = 0; i < ARRAY_SIZE(thread); i++) {
+		int err = pthread_join(thread[i], NULL);
+
+		if (err)
+			pass = false;
+	}
 
 	pthread_mutex_destroy(&mutex);
 
-	piglit_report_result(PIGLIT_PASS);
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
 	return 0;
 }

Comments

On 07/24/2017 06:42 PM, Vinson Lee wrote:
> Fix Coverity unchecked return value defect.
>
> CID: 1415101
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>
> ---
>   tests/glx/glx-multithread-clearbuffer.c | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/tests/glx/glx-multithread-clearbuffer.c b/tests/glx/glx-multithread-clearbuffer.c
> index 577fde842435..da301089f2a6 100644
> --- a/tests/glx/glx-multithread-clearbuffer.c
> +++ b/tests/glx/glx-multithread-clearbuffer.c
> @@ -82,6 +82,7 @@ main(int argc, char **argv)
>   {
>   	/* Need at least 16 contexts to congest the thread queue. */
>   	pthread_t thread[16];
> +	bool pass = true;
>
>   	XInitThreads();
>
> @@ -90,11 +91,15 @@ main(int argc, char **argv)
>   	for (int i = 0; i < ARRAY_SIZE(thread); i++)
>   		pthread_create(&thread[i], NULL, thread_func, NULL);
>
> -	for (int i = 0; i < ARRAY_SIZE(thread); i++)
> -		pthread_join(thread[i], NULL);
> +	for (int i = 0; i < ARRAY_SIZE(thread); i++) {
> +		int err = pthread_join(thread[i], NULL);
> +
> +		if (err)
> +			pass = false;

Normally, I'd probably write it as:

	if (pthread_join(thread[i], NULL) != 0)
		pass = false;

but if one were debugging with gdb, the err var would be helpful.


> +	}
>
>   	pthread_mutex_destroy(&mutex);
>
> -	piglit_report_result(PIGLIT_PASS);
> +	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
>   	return 0;
>   }
>

Reviewed-by: Brian Paul <brianp@vmware.com>
If you do what Brian said:

Reviewed-by: Marek Olšák <marek.olsak@amd.com>

Marek

On Tue, Jul 25, 2017 at 2:42 AM, Vinson Lee <vlee@freedesktop.org> wrote:
> Fix Coverity unchecked return value defect.
>
> CID: 1415101
> Signed-off-by: Vinson Lee <vlee@freedesktop.org>
> ---
>  tests/glx/glx-multithread-clearbuffer.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/tests/glx/glx-multithread-clearbuffer.c b/tests/glx/glx-multithread-clearbuffer.c
> index 577fde842435..da301089f2a6 100644
> --- a/tests/glx/glx-multithread-clearbuffer.c
> +++ b/tests/glx/glx-multithread-clearbuffer.c
> @@ -82,6 +82,7 @@ main(int argc, char **argv)
>  {
>         /* Need at least 16 contexts to congest the thread queue. */
>         pthread_t thread[16];
> +       bool pass = true;
>
>         XInitThreads();
>
> @@ -90,11 +91,15 @@ main(int argc, char **argv)
>         for (int i = 0; i < ARRAY_SIZE(thread); i++)
>                 pthread_create(&thread[i], NULL, thread_func, NULL);
>
> -       for (int i = 0; i < ARRAY_SIZE(thread); i++)
> -               pthread_join(thread[i], NULL);
> +       for (int i = 0; i < ARRAY_SIZE(thread); i++) {
> +               int err = pthread_join(thread[i], NULL);
> +
> +               if (err)
> +                       pass = false;
> +       }
>
>         pthread_mutex_destroy(&mutex);
>
> -       piglit_report_result(PIGLIT_PASS);
> +       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
>         return 0;
>  }
> --
> 2.11.0
>
> _______________________________________________
> Piglit mailing list
> Piglit@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit