anv/tests: Link a single anv_tests binary using gtest
authorCaio Oliveira <caio.oliveira@intel.com>
Thu, 27 Jul 2023 21:18:43 +0000 (14:18 -0700)
committerCaio Oliveira <caio.oliveira@intel.com>
Fri, 25 Aug 2023 19:08:26 +0000 (12:08 -0700)
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24355>

src/intel/vulkan/meson.build
src/intel/vulkan/tests/anv_tests.cpp [new file with mode: 0644]
src/intel/vulkan/tests/block_pool_grow_first.c
src/intel/vulkan/tests/block_pool_no_free.c
src/intel/vulkan/tests/state_pool.c
src/intel/vulkan/tests/state_pool_free_list_only.c
src/intel/vulkan/tests/state_pool_no_free.c
src/intel/vulkan/tests/state_pool_padding.c

index 26f658b..0cc6fdd 100644 (file)
@@ -291,26 +291,34 @@ if with_tests
     gnu_symbol_visibility : 'hidden',
   )
 
-  foreach t : ['block_pool_no_free', 'block_pool_grow_first',
-               'state_pool_no_free', 'state_pool_free_list_only',
-               'state_pool', 'state_pool_padding']
-    test(
-      'anv_@0@'.format(t),
-      executable(
-        t,
-        ['tests/@0@.c'.format(t), anv_entrypoints[0]],
-        c_args : [ sse2_args ],
-        link_with : libvulkan_intel_test,
-        dependencies : [
-          dep_libdrm, dep_thread, dep_m, dep_valgrind,
-          idep_vulkan_util, idep_vulkan_wsi_headers,
-          idep_vulkan_runtime, idep_intel_driver_ds, idep_intel_dev,
-        ],
-        include_directories : [
-          inc_include, inc_src, inc_intel, inc_compiler,
-        ],
-      ),
-      suite : ['intel'],
-    )
-  endforeach
+  files_anv_tests = files(
+    'tests/anv_tests.cpp',
+
+    'tests/state_pool.c',
+    'tests/state_pool_free_list_only.c',
+    'tests/state_pool_no_free.c',
+    'tests/state_pool_padding.c',
+    'tests/block_pool_no_free.c',
+    'tests/block_pool_grow_first.c',
+  )
+
+  test(
+    'anv_tests',
+    executable(
+      'anv_tests',
+      [files_anv_tests, anv_entrypoints[0]],
+      c_args : [ sse2_args ],
+      link_with : libvulkan_intel_test,
+      dependencies : [
+        idep_gtest, dep_libdrm, dep_thread, dep_m, dep_valgrind,
+        idep_vulkan_util, idep_vulkan_wsi_headers,
+        idep_vulkan_runtime, idep_intel_driver_ds, idep_intel_dev,
+      ],
+      include_directories : [
+        inc_include, inc_src, inc_intel, inc_compiler,
+      ],
+    ),
+    suite : ['intel'],
+    protocol : 'gtest',
+  )
 endif
diff --git a/src/intel/vulkan/tests/anv_tests.cpp b/src/intel/vulkan/tests/anv_tests.cpp
new file mode 100644 (file)
index 0000000..1763177
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright © 2023 Intel Corporation
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <gtest/gtest.h>
+
+#define ANV_C_TEST(S, N, C) extern "C" void C(void); TEST(S, N) { C(); }
+
+ANV_C_TEST(StatePool, Regular, state_pool_test);
+ANV_C_TEST(StatePool, FreeListOnly, state_pool_free_list_only_test);
+ANV_C_TEST(StatePool, NoFree, state_pool_no_free_test);
+ANV_C_TEST(StatePool, Padding, state_pool_padding_test);
+
+ANV_C_TEST(BlockPool, NoFree, block_pool_no_free_test);
+ANV_C_TEST(BlockPool, GrowFirst, block_pool_grow_first_test);
index 5ad2303..629d1df 100644 (file)
@@ -24,7 +24,9 @@
 #include "anv_private.h"
 #include "test_common.h"
 
-int main(void)
+void block_pool_grow_first_test(void);
+
+void block_pool_grow_first_test(void)
 {
    struct anv_physical_device physical_device = {};
    struct anv_device device = {};
index 849e7eb..cdf8c62 100644 (file)
@@ -30,7 +30,7 @@
 #define BLOCKS_PER_THREAD 1024
 #define NUM_RUNS 64
 
-struct job {
+static struct job {
    pthread_t thread;
    unsigned id;
    struct anv_block_pool *pool;
@@ -131,7 +131,9 @@ static void run_test()
    pthread_mutex_destroy(&device.mutex);
 }
 
-int main(void)
+void block_pool_no_free_test(void);
+
+void block_pool_no_free_test(void)
 {
    for (unsigned i = 0; i < NUM_RUNS; i++)
       run_test();
index 65685ca..c54e6c9 100644 (file)
@@ -28,7 +28,9 @@
 
 #include "state_pool_test_helper.h"
 
-int main(void)
+void state_pool_test(void);
+
+void state_pool_test(void)
 {
    const unsigned num_threads = 8;
    const unsigned states_per_thread = 1 << 10;
index 4bd8fdd..287384c 100644 (file)
 #include "anv_private.h"
 #include "test_common.h"
 
-#define STATES_PER_THREAD_LOG2 12
-#define STATES_PER_THREAD (1 << STATES_PER_THREAD_LOG2)
-
 #include "state_pool_test_helper.h"
 
-int main(void)
+void state_pool_free_list_only_test(void);
+
+void state_pool_free_list_only_test(void)
 {
    const unsigned num_threads = 8;
    const unsigned states_per_thread = 1 << 12;
index 9182ba3..8777dfe 100644 (file)
 #define STATES_PER_THREAD 1024
 #define NUM_RUNS 64
 
-struct job {
+static struct job {
    pthread_t thread;
    unsigned id;
    struct anv_state_pool *pool;
    uint32_t offsets[STATES_PER_THREAD];
 } jobs[NUM_THREADS];
 
-pthread_barrier_t barrier;
+static pthread_barrier_t barrier;
 
 static void *alloc_states(void *_job)
 {
@@ -114,7 +114,9 @@ static void run_test()
    pthread_mutex_destroy(&device.mutex);
 }
 
-int main(void)
+void state_pool_no_free_test(void);
+
+void state_pool_no_free_test(void)
 {
    for (unsigned i = 0; i < NUM_RUNS; i++)
       run_test();
index 845767a..61a4c28 100644 (file)
@@ -24,7 +24,9 @@
 #include "anv_private.h"
 #include "test_common.h"
 
-int main(void)
+void state_pool_padding_test(void);
+
+void state_pool_padding_test(void)
 {
    struct anv_physical_device physical_device = {};
    struct anv_device device = {};