Skip to content
Snippets Groups Projects
Commit ad0ac818 authored by Petri Latvala's avatar Petri Latvala
Browse files

WIP: lib/tests: Add test for handling asserts in threads


Triggering an assert in a thread leads to calling siglongjmp to a
jmpbuf created from another thread (the main thread). That's undefined
behaviour and breaks all kinds of things.

Other issues with threads currently: Interleaved backtrace printing,
stack corruption because the longjmp succeeds in another thread and
continuing execution modifies the stack for the other threads that are
still running and triggering their asserts, no good automatic way of
propagating failures to main thread otherwise.

We probably need a whole framework for igt_thread á la igt_fork to
handle all that.

Signed-off-by: default avatarPetri Latvala <petri.latvala@intel.com>
parent 7b7189e9
No related branches found
No related tags found
No related merge requests found
Pipeline #85326 failed
/*
* Copyright © 2019 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include <pthread.h>
#include "igt_core.h"
#include "igt_tests_common.h"
#define NUM_THREADS 1024
pthread_t thread[NUM_THREADS];
pthread_mutex_t mutex;
pthread_cond_t cond;
bool go = false;
static void *thread_func(void *data)
{
pthread_mutex_lock(&mutex);
while (!go)
pthread_cond_wait(&cond, &mutex);
pthread_mutex_unlock(&mutex);
igt_assert(false);
return NULL;
}
igt_main
{
int i;
igt_subtest("subtest") {
pthread_mutex_init(&mutex, 0);
pthread_cond_init(&cond, 0);
for (i = 0; i < NUM_THREADS; i++)
pthread_create(&thread[i], 0, thread_func, NULL);
pthread_mutex_lock(&mutex);
go = true;
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
for (i = 0; i < NUM_THREADS; i++)
pthread_join(thread[i], NULL);
igt_success();
}
igt_fixture {
igt_info("Still alive\n");
}
}
...@@ -16,6 +16,7 @@ lib_tests = [ ...@@ -16,6 +16,7 @@ lib_tests = [
'igt_simulation', 'igt_simulation',
'igt_stats', 'igt_stats',
'igt_subtest_group', 'igt_subtest_group',
'igt_threads',
] ]
lib_fail_tests = [ lib_fail_tests = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment