From: Huang Rui <ray.hu...@amd.com>

This patch is to add a new test suite to store security tests.
In Raven+ asics, it will support TMZ (trust memory zone), and it is
page-based protection feature.

v2: remove tests/amdgpu/Makefile.am and update to
tests/amdgpu/meson.build

Signed-off-by: Huang Rui <ray.hu...@amd.com>
Signed-off-by: Aaron Liu <aaron....@amd.com>
Reviewed-by: Alex Deucher <alexander.deuc...@amd.com>
---
 tests/amdgpu/amdgpu_test.c    |  7 ++++
 tests/amdgpu/amdgpu_test.h    | 21 ++++++++++
 tests/amdgpu/meson.build      |  2 +-
 tests/amdgpu/security_tests.c | 96 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 125 insertions(+), 1 deletion(-)
 create mode 100644 tests/amdgpu/security_tests.c

diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c
index 94bc305..f6ea23a 100644
--- a/tests/amdgpu/amdgpu_test.c
+++ b/tests/amdgpu/amdgpu_test.c
@@ -58,6 +58,7 @@
 #define VM_TESTS_STR "VM Tests"
 #define RAS_TESTS_STR "RAS Tests"
 #define SYNCOBJ_TIMELINE_TESTS_STR "SYNCOBJ TIMELINE Tests"
+#define SECURITY_TESTS_STR "Security Tests"
 
 /**
  *  Open handles for amdgpu devices
@@ -130,6 +131,12 @@ static CU_SuiteInfo suites[] = {
                .pCleanupFunc = suite_syncobj_timeline_tests_clean,
                .pTests = syncobj_timeline_tests,
        },
+       {
+               .pName = SECURITY_TESTS_STR,
+               .pInitFunc = suite_security_tests_init,
+               .pCleanupFunc = suite_security_tests_clean,
+               .pTests = security_tests,
+       },
 
        CU_SUITE_INFO_NULL,
 };
diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h
index 0cb6ee9..b7f8de2 100644
--- a/tests/amdgpu/amdgpu_test.h
+++ b/tests/amdgpu/amdgpu_test.h
@@ -243,6 +243,27 @@ extern CU_TestInfo syncobj_timeline_tests[];
 
 
 /**
+ * Initialize security test suite
+ */
+int suite_security_tests_init();
+
+/**
+ * Deinitialize security test suite
+ */
+int suite_security_tests_clean();
+
+/**
+ * Decide if the suite is enabled by default or not.
+ */
+CU_BOOL suite_security_tests_enable(void);
+
+/**
+ * Tests in security test suite
+ */
+extern CU_TestInfo security_tests[];
+
+
+/**
  * Helper functions
  */
 static inline amdgpu_bo_handle gpu_mem_alloc(
diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build
index 1726cb4..2a48b43 100644
--- a/tests/amdgpu/meson.build
+++ b/tests/amdgpu/meson.build
@@ -24,7 +24,7 @@ if dep_cunit.found()
     files(
       'amdgpu_test.c', 'basic_tests.c', 'bo_tests.c', 'cs_tests.c',
       'vce_tests.c', 'uvd_enc_tests.c', 'vcn_tests.c', 'deadlock_tests.c',
-      'vm_tests.c', 'ras_tests.c', 'syncobj_tests.c',
+      'vm_tests.c', 'ras_tests.c', 'syncobj_tests.c', 'security_tests.c',
     ),
     dependencies : [dep_cunit, dep_threads],
     include_directories : [inc_root, inc_drm, 
include_directories('../../amdgpu')],
diff --git a/tests/amdgpu/security_tests.c b/tests/amdgpu/security_tests.c
new file mode 100644
index 0000000..182b03d
--- /dev/null
+++ b/tests/amdgpu/security_tests.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2019 Advanced Micro Devices, Inc.
+ *
+ * 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 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 "CUnit/Basic.h"
+
+#include "amdgpu_test.h"
+#include "amdgpu_drm.h"
+#include "amdgpu_internal.h"
+
+static amdgpu_device_handle device_handle;
+static uint32_t major_version;
+static uint32_t minor_version;
+
+static void amdgpu_security_alloc_buf_test(void);
+
+CU_BOOL suite_security_tests_enable(void)
+{
+       CU_BOOL enable = CU_TRUE;
+
+       if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
+                                    &minor_version, &device_handle))
+               return CU_FALSE;
+
+       if (device_handle->info.family_id < AMDGPU_FAMILY_RV) {
+               printf("\n\nDon't support TMZ (trust memory zone), security 
suite disabled\n");
+               enable = CU_FALSE;
+       }
+
+       if (amdgpu_device_deinitialize(device_handle))
+               return CU_FALSE;
+
+       return enable;
+}
+
+int suite_security_tests_init(void)
+{
+       if (amdgpu_device_initialize(drm_amdgpu[0], &major_version,
+                                    &minor_version, &device_handle))
+               return CUE_SINIT_FAILED;
+
+       return CUE_SUCCESS;
+}
+
+int suite_security_tests_clean(void)
+{
+       int r;
+
+       r = amdgpu_device_deinitialize(device_handle);
+       if (r)
+               return CUE_SCLEAN_FAILED;
+
+       return CUE_SUCCESS;
+}
+
+
+CU_TestInfo security_tests[] = {
+       { "allocate secure buffer test", amdgpu_security_alloc_buf_test },
+       CU_TEST_INFO_NULL,
+};
+
+static void amdgpu_security_alloc_buf_test(void)
+{
+       amdgpu_bo_handle bo;
+       amdgpu_va_handle va_handle;
+       uint64_t bo_mc;
+       int r;
+
+       /* Test secure buffer allocation in VRAM */
+       bo = gpu_mem_alloc(device_handle, 4096, 4096,
+                          AMDGPU_GEM_DOMAIN_VRAM,
+                          AMDGPU_GEM_CREATE_ENCRYPTED,
+                          &bo_mc, &va_handle);
+
+       r = gpu_mem_free(bo, va_handle, bo_mc, 4096);
+       CU_ASSERT_EQUAL(r, 0);
+}
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to