mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 13:58:04 +02:00
util: Add multi-threaded test for util/u_debug.h and util/perf/u_trace.h
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18764>
This commit is contained in:
parent
2c1c87f76f
commit
7753e80219
3 changed files with 70 additions and 0 deletions
|
|
@ -345,6 +345,7 @@ if with_tests
|
|||
'tests/half_float_test.cpp',
|
||||
'tests/int_min_max.cpp',
|
||||
'tests/mesa-sha1_test.cpp',
|
||||
'tests/perf/u_trace_test.cpp',
|
||||
'tests/rb_tree_test.cpp',
|
||||
'tests/register_allocate_test.cpp',
|
||||
'tests/roundeven_test.cpp',
|
||||
|
|
|
|||
32
src/util/tests/perf/u_trace_test.cpp
Normal file
32
src/util/tests/perf/u_trace_test.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "c11/threads.h"
|
||||
#include "util/perf/u_trace.h"
|
||||
|
||||
#define NUM_DEBUG_TEST_THREAD 8
|
||||
|
||||
static int
|
||||
test_thread(void *_state)
|
||||
{
|
||||
struct u_trace_context ctx = { 0 };
|
||||
u_trace_context_init(&ctx, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
u_trace_context_fini(&ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(UtilPerfTraceTest, Multithread)
|
||||
{
|
||||
static char env_tracefile[] = "GPU_TRACEFILE=tracefile_for_test-b5ba5a0c-6ed1-4901-a38d-755991182663";
|
||||
thrd_t threads[NUM_DEBUG_TEST_THREAD];
|
||||
putenv(env_tracefile);
|
||||
for (unsigned i = 0; i < NUM_DEBUG_TEST_THREAD; i++) {
|
||||
thrd_create(&threads[i], test_thread, NULL);
|
||||
}
|
||||
for (unsigned i = 0; i < NUM_DEBUG_TEST_THREAD; i++) {
|
||||
int ret;
|
||||
thrd_join(threads[i], &ret);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,46 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "c11/threads.h"
|
||||
#include "util/u_debug.h"
|
||||
|
||||
#define NUM_DEBUG_TEST_THREAD 8
|
||||
|
||||
DEBUG_GET_ONCE_BOOL_OPTION(bool_test,"X_TEST_ENV_BOOL", false);
|
||||
|
||||
static int
|
||||
test_thread(void *_state)
|
||||
{
|
||||
EXPECT_STREQ(debug_get_option("X_TEST_GALLIUM_DRIVER", ""), "test_driver");
|
||||
EXPECT_EQ(debug_get_option_bool_test(), true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(u_debug, DEBUG_GET_ONCE_BOOL_Multithread)
|
||||
{
|
||||
{
|
||||
static char env_str[] = "X_TEST_ENV_BOOL=true";
|
||||
putenv(env_str);
|
||||
}
|
||||
|
||||
{
|
||||
static char env_str[] = "X_TEST_GALLIUM_DRIVER=test_driver";
|
||||
putenv(env_str);
|
||||
}
|
||||
|
||||
thrd_t threads[NUM_DEBUG_TEST_THREAD];
|
||||
for (unsigned i = 0; i < NUM_DEBUG_TEST_THREAD; i++) {
|
||||
thrd_create(&threads[i], test_thread, NULL);
|
||||
}
|
||||
for (unsigned i = 0; i < NUM_DEBUG_TEST_THREAD; i++) {
|
||||
int ret;
|
||||
thrd_join(threads[i], &ret);
|
||||
}
|
||||
}
|
||||
|
||||
/* When testing, the environment variable name should not be the same */
|
||||
|
||||
TEST(u_debug, debug_get_bool_option)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue