[PATCH 3/3] tests/amd_uvd: Introduce additional test instance for UVD dec.& enc.

vitaly.prosyak at amd.com vitaly.prosyak at amd.com
Tue Nov 26 17:29:23 UTC 2024


From: Vitaly Prosyak <vitaly.prosyak at amd.com>

Added another process instance to simulate stressful conditions for
UVD decoding and encoding tests, increasing test coverage and
robustness.

Cc: Jesse Zhang  <jesse.zhang at amd.com>
Cc: Christian Koenig <christian.koenig at amd.com>
Cc: Alexander Deucher <alexander.deucher at amd.com>
Cc: Leo Liu <leo.liu at amd.com>
Cc: Boyuan Zhang <boyuan.zhang at amd.com>
Signed-off-by: Vitaly Prosyak <vitaly.prosyak at amd.com>
---
 tests/amdgpu/amd_uvd_dec.c | 82 +++++++++++++++++++++++++++++++++-----
 tests/amdgpu/amd_uvd_enc.c | 60 ++++++++++++++++++++++++----
 2 files changed, 124 insertions(+), 18 deletions(-)

diff --git a/tests/amdgpu/amd_uvd_dec.c b/tests/amdgpu/amd_uvd_dec.c
index 3ec411aac..4b82549cc 100644
--- a/tests/amdgpu/amd_uvd_dec.c
+++ b/tests/amdgpu/amd_uvd_dec.c
@@ -2,7 +2,11 @@
 // Copyright 2023 Advanced Micro Devices, Inc.
 // Copyright 2014 Advanced Micro Devices, Inc.
 
+#include <spawn.h>
+#include <sys/wait.h>
+
 #include "lib/amdgpu/amd_mmd_shared.h"
+#include "lib/amdgpu/amd_shared_process.h"
 
 static void
 uvd_cmd(uint32_t family_id, uint64_t addr, uint32_t cmd, uint32_t *idx,
@@ -21,6 +25,7 @@ uvd_cmd(uint32_t family_id, uint64_t addr, uint32_t cmd, uint32_t *idx,
 
 static void
 amdgpu_uvd_dec_create(amdgpu_device_handle device_handle,
+		struct shmbuf *sh_mem,
 		struct mmd_shared_context *shared_context,
 		struct mmd_context *context)
 {
@@ -35,6 +40,8 @@ amdgpu_uvd_dec_create(amdgpu_device_handle device_handle,
 	req.alloc_size = 4*1024;
 	req.preferred_heap = AMDGPU_GEM_DOMAIN_GTT;
 
+	sync_point_enter(sh_mem);
+
 	r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
 	igt_assert_eq(r, 0);
 
@@ -88,11 +95,16 @@ amdgpu_uvd_dec_create(amdgpu_device_handle device_handle,
 
 	r = amdgpu_bo_free(buf_handle);
 	igt_assert_eq(r, 0);
+
+	sync_point_exit(sh_mem);
+
 }
 
 static void
 amdgpu_uvd_decode(amdgpu_device_handle device_handle,
-		struct mmd_context *context, struct mmd_shared_context *shared_context)
+		struct shmbuf *sh_mem,
+		struct mmd_shared_context *shared_context,
+		struct mmd_context *context)
 {
 	const unsigned int dpb_size = 15923584, dt_size = 737280;
 	uint64_t msg_addr, fb_addr, bs_addr, dpb_addr, ctx_addr, dt_addr, it_addr;
@@ -115,6 +127,8 @@ amdgpu_uvd_decode(amdgpu_device_handle device_handle,
 
 	req.preferred_heap = AMDGPU_GEM_DOMAIN_GTT;
 
+	sync_point_enter(sh_mem);
+
 	r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
 	igt_assert_eq(r, 0);
 
@@ -232,11 +246,15 @@ amdgpu_uvd_decode(amdgpu_device_handle device_handle,
 
 	r = amdgpu_bo_free(buf_handle);
 	igt_assert_eq(r, 0);
+
+	sync_point_exit(sh_mem);
 }
 
 static void
-amdgpu_uvd_dec_destroy(amdgpu_device_handle device_handle, struct mmd_context *context,
-		 struct mmd_shared_context *shared_context)
+amdgpu_uvd_dec_destroy(amdgpu_device_handle device_handle,
+		struct shmbuf *sh_mem,
+		struct mmd_shared_context *shared_context,
+		struct mmd_context *context)
 {
 	struct amdgpu_bo_alloc_request req = {0};
 	amdgpu_bo_handle buf_handle;
@@ -249,6 +267,8 @@ amdgpu_uvd_dec_destroy(amdgpu_device_handle device_handle, struct mmd_context *c
 	req.alloc_size = 4 * 1024;
 	req.preferred_heap = AMDGPU_GEM_DOMAIN_GTT;
 
+	sync_point_enter(sh_mem);
+
 	r = amdgpu_bo_alloc(device_handle, &req, &buf_handle);
 	igt_assert_eq(r, 0);
 
@@ -292,6 +312,8 @@ amdgpu_uvd_dec_destroy(amdgpu_device_handle device_handle, struct mmd_context *c
 
 	r = amdgpu_bo_free(buf_handle);
 	igt_assert_eq(r, 0);
+
+	sync_point_exit(sh_mem);
 }
 
 igt_main
@@ -301,37 +323,77 @@ igt_main
 	struct mmd_shared_context shared_context = {};
 	int fd = -1;
 
+	int r;
+	char cmdline[2048];
+	char shm_name[256] = {};
+	int argc = 0;
+	char **argv = NULL;
+	char *path = NULL;
+	enum  process_type process = PROCESS_UNKNOWN;
+	int fd_shm = -1;
+	struct shmbuf *sh_mem = NULL;
+	posix_spawn_file_actions_t action;
+
+	pid_t pid_brother;
+	uint32_t major, minor;
+	int err;
+
 	igt_fixture {
-		uint32_t major, minor;
-		int err;
+
+		posix_spawn_file_actions_init(&action);
+
+		if (get_command_line(cmdline, &argc, &argv, &path) != 0)
+			igt_fail(IGT_EXIT_FAILURE);
+
+		r = is_run_device_parameter_found(argc, argv, ONDEVICE);
+		snprintf(shm_name, sizeof(shm_name), "/uvd_dec_shm_%d", r);
 
 		fd = drm_open_driver(DRIVER_AMDGPU);
 		err = amdgpu_device_initialize(fd, &major, &minor, &device);
 		igt_require(err == 0);
-		igt_info("Initialized amdgpu, driver version %d.%d\n",
-			 major, minor);
 		err = mmd_shared_context_init(device, &shared_context);
 		igt_require(err == 0);
 		err = mmd_context_init(device, &context);
 		igt_require(err == 0);
 		igt_skip_on(!is_uvd_tests_enable(shared_context.family_id, shared_context.chip_id,
 				shared_context.chip_rev));
+
+		if (is_brother_parameter_found(argc, argv, BROTHER) == 0) {
+			add_brother_parameter(&argc, argv, BROTHER);
+			fd_shm = shared_mem_create(&sh_mem, shm_name);
+			igt_require(fd_shm != -1);
+			launch_brother_process(argc, argv, path, &pid_brother, fd_shm);
+			process = PROCESS_TEST;
+
+		} else {
+			process = PROCESS_BROTHER;
+			pid_brother = getpid();
+		}
+		if (process == PROCESS_BROTHER)
+			fd_shm = shared_mem_open(&sh_mem);
+
 	}
 	igt_describe("Test whether uvd dec is created");
 	igt_subtest("amdgpu_uvd_dec_create")
-	amdgpu_uvd_dec_create(device, &shared_context, &context);
+	amdgpu_uvd_dec_create(device, sh_mem, &shared_context, &context);
 
 	igt_describe("Test whether uvd dec can decode");
 	igt_subtest("amdgpu_uvd_decode")
-	amdgpu_uvd_decode(device, &context, &shared_context);
+	amdgpu_uvd_decode(device, sh_mem, &shared_context, &context);
 
 	igt_describe("Test whether uvd dec is destroyed");
 	igt_subtest("amdgpu_uvd_dec_destroy")
-	amdgpu_uvd_dec_destroy(device, &context, &shared_context);
+	amdgpu_uvd_dec_destroy(device, sh_mem, &shared_context, &context);
 
 	igt_fixture {
 		mmd_context_clean(device, &context);
+		if (process == PROCESS_TEST)
+			waitpid(pid_brother, NULL, 0);
+
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
+		shared_mem_destroy(sh_mem, fd_shm, true, shm_name);
+		posix_spawn_file_actions_destroy(&action);
+		free_command_line(argc, argv, path);
 	}
 }
diff --git a/tests/amdgpu/amd_uvd_enc.c b/tests/amdgpu/amd_uvd_enc.c
index 15fb11fa3..fecda249a 100644
--- a/tests/amdgpu/amd_uvd_enc.c
+++ b/tests/amdgpu/amd_uvd_enc.c
@@ -1,8 +1,11 @@
 // SPDX-License-Identifier: MIT
 // Copyright 2023 Advanced Micro Devices, Inc.
 // Copyright 2017 Advanced Micro Devices, Inc.
+#include <spawn.h>
+#include <sys/wait.h>
 
 #include "lib/amdgpu/amd_mmd_shared.h"
+#include "lib/amdgpu/amd_shared_process.h"
 
 static bool
 is_uvd_enc_enable(amdgpu_device_handle device_handle)
@@ -293,20 +296,24 @@ amdgpu_uvd_enc_destroy(amdgpu_device_handle device_handle,
 }
 
 static void
-amdgpu_uvd_enc_test(amdgpu_device_handle device, struct mmd_shared_context *shared_context)
+amdgpu_uvd_enc_test(amdgpu_device_handle device,
+		struct shmbuf *sh_mem,
+		struct mmd_shared_context *shared_context)
 {
 	struct uvd_enc_context context = {0};
 	int r;
 
+	sync_point_enter(sh_mem);
+
 	r = mmd_context_init(device, &context.uvd);
-	igt_require(r == 0);
+	igt_require(r);
 	amdgpu_uvd_enc_create(device, &context);
 	amdgpu_uvd_enc_session_init(device, &context);
 	amdgpu_uvd_enc_encode(device, &context, shared_context);
 	amdgpu_uvd_enc_destroy(device, &context);
-
 	mmd_context_clean(device, &context.uvd);
 
+	sync_point_exit(sh_mem);
 }
 
 igt_main
@@ -315,28 +322,65 @@ igt_main
 	struct mmd_shared_context shared_context = {};
 	int fd = -1;
 
+	int r;
+	char cmdline[2048];
+	char shm_name[256] = {};
+	int argc = 0;
+	char **argv = NULL;
+	char *path = NULL;
+	enum  process_type process = PROCESS_UNKNOWN;
+	int fd_shm = -1;
+	struct shmbuf *sh_mem = NULL;
+	posix_spawn_file_actions_t action;
+
+	pid_t pid_brother;
+	uint32_t major, minor;
+	int err;
 	igt_fixture {
-		uint32_t major, minor;
-		int err;
+
+		posix_spawn_file_actions_init(&action);
+
+		if (get_command_line(cmdline, &argc, &argv, &path) != 0)
+			igt_fail(IGT_EXIT_FAILURE);
+
+		r = is_run_device_parameter_found(argc, argv, ONDEVICE);
+		snprintf(shm_name, sizeof(shm_name), "/uvd_enc_shm_%d", r);
 
 		fd = drm_open_driver(DRIVER_AMDGPU);
 		err = amdgpu_device_initialize(fd, &major, &minor, &device);
 		igt_require(err == 0);
-		igt_info("Initialized amdgpu, driver version %d.%d\n",
-			 major, minor);
 		memset(&shared_context, 0, sizeof(shared_context));
 		err = mmd_shared_context_init(device, &shared_context);
 		igt_require(err == 0);
 
 		igt_skip_on(!is_uvd_enc_enable(device));
+		if (is_brother_parameter_found(argc, argv, BROTHER) == 0) {
+			add_brother_parameter(&argc, argv, BROTHER);
+			fd_shm = shared_mem_create(&sh_mem, shm_name);
+			igt_require(fd_shm != -1);
+			launch_brother_process(argc, argv, path, &pid_brother, fd_shm);
+			process = PROCESS_TEST;
+
+		} else {
+			process = PROCESS_BROTHER;
+			pid_brother = getpid();
+		}
+		if (process == PROCESS_BROTHER)
+			fd_shm = shared_mem_open(&sh_mem);
 	}
 
 	igt_describe("Test uvd session, encode, destroy");
 	igt_subtest("uvd_encoder")
-		amdgpu_uvd_enc_test(device, &shared_context);
+		amdgpu_uvd_enc_test(device, sh_mem, &shared_context);
 
 	igt_fixture {
+		if (process == PROCESS_TEST)
+			waitpid(pid_brother, NULL, 0);
+
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
+		shared_mem_destroy(sh_mem, fd_shm, true, shm_name);
+		posix_spawn_file_actions_destroy(&action);
+		free_command_line(argc, argv, path);
 	}
 }
-- 
2.25.1



More information about the igt-dev mailing list