From 7753e80219c7afa932f7f7466e682a89a0562607 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Fri, 4 Nov 2022 01:56:34 +0800 Subject: [PATCH] util: Add multi-threaded test for util/u_debug.h and util/perf/u_trace.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yonggang Luo Acked-by: Marek Olšák Part-of: --- src/util/meson.build | 1 + src/util/tests/perf/u_trace_test.cpp | 32 ++++++++++++++++++++++++ src/util/tests/u_debug_test.cpp | 37 ++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 src/util/tests/perf/u_trace_test.cpp diff --git a/src/util/meson.build b/src/util/meson.build index e8d4eb9e379..3bdaffb7b40 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -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', diff --git a/src/util/tests/perf/u_trace_test.cpp b/src/util/tests/perf/u_trace_test.cpp new file mode 100644 index 00000000000..decfe2cb7cb --- /dev/null +++ b/src/util/tests/perf/u_trace_test.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#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); + } +} diff --git a/src/util/tests/u_debug_test.cpp b/src/util/tests/u_debug_test.cpp index 7168986a586..4dcac245af2 100644 --- a/src/util/tests/u_debug_test.cpp +++ b/src/util/tests/u_debug_test.cpp @@ -24,9 +24,46 @@ * */ +#include + #include +#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)