mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
gpu: nvgpu: unit: add negative tests for common.gr.global_ctx
Add negative tests that inject memory allocation failures and verify error handling path in common.gr.global_ctx unit. Jira NVGPU-4373 Change-Id: Ic180f5eda0d25d5a713bdd513a617dc7c3a29d53 Signed-off-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2255770 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
Alex Waterman
parent
1eaa2f3d35
commit
83ef099d19
@@ -108,6 +108,7 @@ NV_REPOSITORY_COMPONENTS += userspace/units/gr/config
|
|||||||
NV_REPOSITORY_COMPONENTS += userspace/units/gr/init
|
NV_REPOSITORY_COMPONENTS += userspace/units/gr/init
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/gr/setup
|
NV_REPOSITORY_COMPONENTS += userspace/units/gr/setup
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/gr/fs_state
|
NV_REPOSITORY_COMPONENTS += userspace/units/gr/fs_state
|
||||||
|
NV_REPOSITORY_COMPONENTS += userspace/units/gr/global_ctx
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/gr/intr
|
NV_REPOSITORY_COMPONENTS += userspace/units/gr/intr
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/acr
|
NV_REPOSITORY_COMPONENTS += userspace/units/acr
|
||||||
NV_REPOSITORY_COMPONENTS += userspace/units/ce
|
NV_REPOSITORY_COMPONENTS += userspace/units/ce
|
||||||
|
|||||||
@@ -291,6 +291,19 @@ nvgpu_gr_obj_ctx_is_golden_image_ready
|
|||||||
nvgpu_gr_ctx_get_tsgid
|
nvgpu_gr_ctx_get_tsgid
|
||||||
nvgpu_gr_get_config_ptr
|
nvgpu_gr_get_config_ptr
|
||||||
nvgpu_gr_fs_state_init
|
nvgpu_gr_fs_state_init
|
||||||
|
nvgpu_gr_global_ctx_desc_alloc
|
||||||
|
nvgpu_gr_global_ctx_desc_free
|
||||||
|
nvgpu_gr_global_ctx_buffer_alloc
|
||||||
|
nvgpu_gr_global_ctx_buffer_free
|
||||||
|
nvgpu_gr_global_ctx_set_size
|
||||||
|
nvgpu_gr_global_ctx_buffer_map
|
||||||
|
nvgpu_gr_global_ctx_buffer_unmap
|
||||||
|
nvgpu_gr_global_ctx_buffer_get_mem
|
||||||
|
nvgpu_gr_global_ctx_buffer_ready
|
||||||
|
nvgpu_gr_global_ctx_init_local_golden_image
|
||||||
|
nvgpu_gr_global_ctx_load_local_golden_image
|
||||||
|
nvgpu_gr_global_ctx_compare_golden_images
|
||||||
|
nvgpu_gr_global_ctx_deinit_local_golden_image
|
||||||
nvgpu_hr_timestamp
|
nvgpu_hr_timestamp
|
||||||
nvgpu_init_ltc_support
|
nvgpu_init_ltc_support
|
||||||
nvgpu_ltc_ecc_free
|
nvgpu_ltc_ecc_free
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ UNITS := \
|
|||||||
$(UNIT_SRC)/gr/config \
|
$(UNIT_SRC)/gr/config \
|
||||||
$(UNIT_SRC)/gr/init \
|
$(UNIT_SRC)/gr/init \
|
||||||
$(UNIT_SRC)/gr/fs_state \
|
$(UNIT_SRC)/gr/fs_state \
|
||||||
|
$(UNIT_SRC)/gr/global_ctx \
|
||||||
$(UNIT_SRC)/gr/intr \
|
$(UNIT_SRC)/gr/intr \
|
||||||
$(UNIT_SRC)/gr/setup \
|
$(UNIT_SRC)/gr/setup \
|
||||||
$(UNIT_SRC)/acr \
|
$(UNIT_SRC)/acr \
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
* - @ref SWUTS-gr-intr
|
* - @ref SWUTS-gr-intr
|
||||||
* - @ref SWUTS-gr-falcon
|
* - @ref SWUTS-gr-falcon
|
||||||
* - @ref SWUTS-gr-fs-state
|
* - @ref SWUTS-gr-fs-state
|
||||||
|
* - @ref SWUTS-gr-global-ctx
|
||||||
* - @ref SWUTS-gr-config
|
* - @ref SWUTS-gr-config
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -66,4 +66,5 @@ INPUT += ../../../userspace/units/gr/setup/nvgpu-gr-setup.h
|
|||||||
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-intr.h
|
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-intr.h
|
||||||
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-falcon.h
|
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-falcon.h
|
||||||
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-fs-state.h
|
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-fs-state.h
|
||||||
|
INPUT += ../../../userspace/units/gr/intr/nvgpu-gr-global-ctx.h
|
||||||
INPUT += ../../../userspace/units/gr/config/nvgpu-gr-config.h
|
INPUT += ../../../userspace/units/gr/config/nvgpu-gr-config.h
|
||||||
|
|||||||
@@ -1991,6 +1991,30 @@
|
|||||||
"unit": "nvgpu_gr_fs_state",
|
"unit": "nvgpu_gr_fs_state",
|
||||||
"test_level": 0
|
"test_level": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"test": "test_gr_init_setup",
|
||||||
|
"case": "gr_global_ctx_setup",
|
||||||
|
"unit": "nvgpu_gr_global_ctx",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": "test_gr_global_ctx_alloc_error_injection",
|
||||||
|
"case": "gr_global_ctx_alloc_errors",
|
||||||
|
"unit": "nvgpu_gr_global_ctx",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": "test_gr_global_ctx_local_ctx_error_injection",
|
||||||
|
"case": "gr_global_ctx_local_ctx_errors",
|
||||||
|
"unit": "nvgpu_gr_global_ctx",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"test": "test_gr_remove_setup",
|
||||||
|
"case": "gr_global_ctx_cleanup",
|
||||||
|
"unit": "nvgpu_gr_global_ctx",
|
||||||
|
"test_level": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"test": "test_nvgpu_mem_create_from_phys",
|
"test": "test_nvgpu_mem_create_from_phys",
|
||||||
"case": "mem_create_from_phys",
|
"case": "mem_create_from_phys",
|
||||||
|
|||||||
33
userspace/units/gr/global_ctx/Makefile
Normal file
33
userspace/units/gr/global_ctx/Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
|
OBJS = nvgpu-gr-global-ctx.o
|
||||||
|
MODULE = nvgpu-gr-global-ctx
|
||||||
|
|
||||||
|
LIB_PATHS += -lnvgpu-gr
|
||||||
|
include ../../Makefile.units
|
||||||
|
|
||||||
|
lib$(MODULE).so: nvgpu-gr
|
||||||
|
|
||||||
|
nvgpu-gr:
|
||||||
|
$(MAKE) -C ..
|
||||||
|
|
||||||
35
userspace/units/gr/global_ctx/Makefile.interface.tmk
Normal file
35
userspace/units/gr/global_ctx/Makefile.interface.tmk
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
#
|
||||||
|
# tmake for SW Mobile component makefile
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
NVGPU_UNIT_NAME=nvgpu-gr-global-ctx
|
||||||
|
|
||||||
|
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# indent-tabs-mode: t
|
||||||
|
# tab-width: 8
|
||||||
|
# End:
|
||||||
|
# vi: set tabstop=8 noexpandtab:
|
||||||
40
userspace/units/gr/global_ctx/Makefile.tmk
Normal file
40
userspace/units/gr/global_ctx/Makefile.tmk
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
#
|
||||||
|
# tmake for SW Mobile component makefile
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
NVGPU_UNIT_NAME = nvgpu-gr-global-ctx
|
||||||
|
NVGPU_UNIT_SRCS = nvgpu-gr-global-ctx.c
|
||||||
|
|
||||||
|
NVGPU_UNIT_INTERFACE_DIRS := \
|
||||||
|
$(NV_COMPONENT_DIR)/.. \
|
||||||
|
$(NV_SOURCE)/kernel/nvgpu/drivers/gpu/nvgpu
|
||||||
|
|
||||||
|
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# indent-tabs-mode: t
|
||||||
|
# tab-width: 8
|
||||||
|
# End:
|
||||||
|
# vi: set tabstop=8 noexpandtab:
|
||||||
290
userspace/units/gr/global_ctx/nvgpu-gr-global-ctx.c
Normal file
290
userspace/units/gr/global_ctx/nvgpu-gr-global-ctx.c
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 AUTHORS OR COPYRIGHT HOLDERS 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 <stdlib.h>
|
||||||
|
|
||||||
|
#include <unit/unit.h>
|
||||||
|
#include <unit/io.h>
|
||||||
|
|
||||||
|
#include <nvgpu/posix/io.h>
|
||||||
|
#include <nvgpu/gk20a.h>
|
||||||
|
#include <nvgpu/dma.h>
|
||||||
|
#include <nvgpu/gr/gr.h>
|
||||||
|
#include <nvgpu/gr/global_ctx.h>
|
||||||
|
|
||||||
|
#include <nvgpu/posix/posix-fault-injection.h>
|
||||||
|
#include <nvgpu/posix/dma.h>
|
||||||
|
|
||||||
|
#include "common/gr/gr_priv.h"
|
||||||
|
#include "common/gr/global_ctx_priv.h"
|
||||||
|
|
||||||
|
#include "../nvgpu-gr.h"
|
||||||
|
#include "nvgpu-gr-global-ctx.h"
|
||||||
|
|
||||||
|
#define DUMMY_SIZE 0xF0U
|
||||||
|
|
||||||
|
static int dummy_l2_flush(struct gk20a *g, bool invalidate)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_gr_global_ctx_alloc_error_injection(struct unit_module *m,
|
||||||
|
struct gk20a *g, void *args)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
u64 gpu_va;
|
||||||
|
bool valid;
|
||||||
|
struct nvgpu_mem *mem;
|
||||||
|
struct nvgpu_gr_global_ctx_buffer_desc *desc;
|
||||||
|
struct nvgpu_posix_fault_inj *dma_fi =
|
||||||
|
nvgpu_dma_alloc_get_fault_injection();
|
||||||
|
|
||||||
|
desc = nvgpu_gr_global_ctx_desc_alloc(g);
|
||||||
|
if (!desc) {
|
||||||
|
unit_return_fail(m, "failed to allocate desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No size is set in desc, should fail */
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
nvgpu_gr_global_ctx_set_size(desc, NVGPU_GR_GLOBAL_CTX_CIRCULAR,
|
||||||
|
DUMMY_SIZE);
|
||||||
|
/* Size of pagepool buffer is not set, should fail */
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
nvgpu_gr_global_ctx_set_size(desc, NVGPU_GR_GLOBAL_CTX_PAGEPOOL,
|
||||||
|
DUMMY_SIZE);
|
||||||
|
/* Size of attribute buffer is not set, should fail */
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
nvgpu_gr_global_ctx_set_size(desc, NVGPU_GR_GLOBAL_CTX_ATTRIBUTE,
|
||||||
|
DUMMY_SIZE);
|
||||||
|
/* Size of access map buffer is not set, should fail */
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
nvgpu_gr_global_ctx_set_size(desc, NVGPU_GR_GLOBAL_CTX_PRIV_ACCESS_MAP,
|
||||||
|
DUMMY_SIZE);
|
||||||
|
/* Now, all the sizes are set in desc */
|
||||||
|
|
||||||
|
/* Ensure mapping fails before buffers are allocated */
|
||||||
|
gpu_va = nvgpu_gr_global_ctx_buffer_map(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_CIRCULAR, NULL, 0, false);
|
||||||
|
if (gpu_va != 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure unmapping fails before buffers are allocated */
|
||||||
|
nvgpu_gr_global_ctx_buffer_unmap(desc, NVGPU_GR_GLOBAL_CTX_CIRCULAR,
|
||||||
|
NULL, 0);
|
||||||
|
|
||||||
|
/* Ensure no memory handle is returned before buffers are allocated */
|
||||||
|
mem = nvgpu_gr_global_ctx_buffer_get_mem(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_CIRCULAR);
|
||||||
|
if (mem != NULL) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure buffer ready status is false before they are allocated */
|
||||||
|
valid = nvgpu_gr_global_ctx_buffer_ready(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_CIRCULAR);
|
||||||
|
if (valid) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail circular ctx buffer allocation */
|
||||||
|
nvgpu_posix_enable_fault_injection(dma_fi, true, 0);
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail pagepool ctx buffer allocation */
|
||||||
|
nvgpu_posix_enable_fault_injection(dma_fi, true, 1);
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail attribute ctx buffer allocation */
|
||||||
|
nvgpu_posix_enable_fault_injection(dma_fi, true, 2);
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail access map ctx buffer allocation */
|
||||||
|
nvgpu_posix_enable_fault_injection(dma_fi, true, 3);
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err == 0) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finally, verify successful context buffer allocation */
|
||||||
|
nvgpu_posix_enable_fault_injection(dma_fi, false, 0);
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err != 0) {
|
||||||
|
unit_return_fail(m,
|
||||||
|
"failed to allocate global context buffers");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to allocate them one more time and ensure no error */
|
||||||
|
err = nvgpu_gr_global_ctx_buffer_alloc(g, desc);
|
||||||
|
if (err != 0) {
|
||||||
|
unit_return_fail(m, "failed double allocation");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check buffer ready status again, should be set */
|
||||||
|
valid = nvgpu_gr_global_ctx_buffer_ready(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_CIRCULAR);
|
||||||
|
if (!valid) {
|
||||||
|
unit_return_fail(m, "global buffer is not ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
valid = nvgpu_gr_global_ctx_buffer_ready(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_PAGEPOOL);
|
||||||
|
if (!valid) {
|
||||||
|
unit_return_fail(m, "global buffer is not ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
valid = nvgpu_gr_global_ctx_buffer_ready(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_ATTRIBUTE);
|
||||||
|
if (!valid) {
|
||||||
|
unit_return_fail(m, "global buffer is not ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
valid = nvgpu_gr_global_ctx_buffer_ready(desc,
|
||||||
|
NVGPU_GR_GLOBAL_CTX_PRIV_ACCESS_MAP);
|
||||||
|
if (!valid) {
|
||||||
|
unit_return_fail(m, "global buffer is not ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup */
|
||||||
|
nvgpu_gr_global_ctx_buffer_free(g, desc);
|
||||||
|
nvgpu_gr_global_ctx_desc_free(g, desc);
|
||||||
|
|
||||||
|
return UNIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_gr_global_ctx_local_ctx_error_injection(struct unit_module *m,
|
||||||
|
struct gk20a *g, void *args)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
bool valid;
|
||||||
|
struct nvgpu_mem mem;
|
||||||
|
struct nvgpu_gr_global_ctx_local_golden_image *local_golden_image;
|
||||||
|
struct nvgpu_gr_global_ctx_local_golden_image *local_golden_image_bk;
|
||||||
|
struct nvgpu_posix_fault_inj *kmem_fi =
|
||||||
|
nvgpu_kmem_get_fault_injection();
|
||||||
|
|
||||||
|
/* Allocate dummy memory */
|
||||||
|
err = nvgpu_dma_alloc(g, DUMMY_SIZE, &mem);
|
||||||
|
if (err) {
|
||||||
|
unit_return_fail(m, "failed to allocate dummy memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail allocation of nvgpu_gr_global_ctx_local_golden_image struct */
|
||||||
|
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
|
||||||
|
local_golden_image = nvgpu_gr_global_ctx_init_local_golden_image(g,
|
||||||
|
&mem, DUMMY_SIZE);
|
||||||
|
if (local_golden_image != NULL) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fail allocation of local_golden_image->context */
|
||||||
|
nvgpu_posix_enable_fault_injection(kmem_fi, true, 1);
|
||||||
|
local_golden_image = nvgpu_gr_global_ctx_init_local_golden_image(g,
|
||||||
|
&mem, DUMMY_SIZE);
|
||||||
|
if (local_golden_image != NULL) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Successful allocation of local golden context */
|
||||||
|
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||||
|
local_golden_image = nvgpu_gr_global_ctx_init_local_golden_image(g,
|
||||||
|
&mem, DUMMY_SIZE);
|
||||||
|
if (local_golden_image == NULL) {
|
||||||
|
unit_return_fail(m, "failed to initialize local golden image");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Trigger flush error during context load */
|
||||||
|
g->ops.mm.cache.l2_flush = dummy_l2_flush;
|
||||||
|
nvgpu_gr_global_ctx_load_local_golden_image(g,
|
||||||
|
local_golden_image, &mem);
|
||||||
|
|
||||||
|
/* Allocate dummy local golden context image */
|
||||||
|
local_golden_image_bk = nvgpu_gr_global_ctx_init_local_golden_image(g,
|
||||||
|
&mem, DUMMY_SIZE);
|
||||||
|
if (local_golden_image_bk == NULL) {
|
||||||
|
unit_return_fail(m, "failed to initialize local golden image");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compare two images, they should match since both have zero's only */
|
||||||
|
valid = nvgpu_gr_global_ctx_compare_golden_images(g, true, local_golden_image,
|
||||||
|
local_golden_image_bk, DUMMY_SIZE);
|
||||||
|
if (!valid) {
|
||||||
|
unit_return_fail(m, "images do not match");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to match them in vidmem, should fail */
|
||||||
|
valid = nvgpu_gr_global_ctx_compare_golden_images(g, false, local_golden_image,
|
||||||
|
local_golden_image_bk, DUMMY_SIZE);
|
||||||
|
if (valid) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update dummy image and compare, now comparison should fail */
|
||||||
|
*(local_golden_image_bk->context) = 0xFFU;
|
||||||
|
valid = nvgpu_gr_global_ctx_compare_golden_images(g, true, local_golden_image,
|
||||||
|
local_golden_image_bk, DUMMY_SIZE);
|
||||||
|
if (valid) {
|
||||||
|
unit_return_fail(m, "unexpected success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup */
|
||||||
|
nvgpu_gr_global_ctx_deinit_local_golden_image(g, local_golden_image);
|
||||||
|
nvgpu_gr_global_ctx_deinit_local_golden_image(g, local_golden_image_bk);
|
||||||
|
nvgpu_dma_free(g, &mem);
|
||||||
|
|
||||||
|
return UNIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct unit_module_test nvgpu_gr_global_ctx_tests[] = {
|
||||||
|
UNIT_TEST(gr_global_ctx_setup, test_gr_init_setup, NULL, 0),
|
||||||
|
UNIT_TEST(gr_global_ctx_alloc_errors, test_gr_global_ctx_alloc_error_injection, NULL, 0),
|
||||||
|
UNIT_TEST(gr_global_ctx_local_ctx_errors, test_gr_global_ctx_local_ctx_error_injection, NULL, 0),
|
||||||
|
UNIT_TEST(gr_global_ctx_cleanup, test_gr_remove_setup, NULL, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
UNIT_MODULE(nvgpu_gr_global_ctx, nvgpu_gr_global_ctx_tests, UNIT_PRIO_NVGPU_TEST);
|
||||||
120
userspace/units/gr/global_ctx/nvgpu-gr-global-ctx.h
Normal file
120
userspace/units/gr/global_ctx/nvgpu-gr-global-ctx.h
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||||
|
*/
|
||||||
|
#ifndef UNIT_NVGPU_GR_GLOBAL_CTX_H
|
||||||
|
#define UNIT_NVGPU_GR_GLOBAL_CTX_H
|
||||||
|
|
||||||
|
#include <nvgpu/types.h>
|
||||||
|
|
||||||
|
struct gk20a;
|
||||||
|
struct unit_module;
|
||||||
|
|
||||||
|
/** @addtogroup SWUTS-gr-global-ctx
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* Software Unit Test Specification for common.gr.global_ctx
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test specification for: test_gr_global_ctx_alloc_error_injection.
|
||||||
|
*
|
||||||
|
* Description: Verify error handling in global context allocation path.
|
||||||
|
*
|
||||||
|
* Test Type: Feature based, Error guessing.
|
||||||
|
*
|
||||||
|
* Targets: #nvgpu_gr_global_ctx_buffer_alloc,
|
||||||
|
* #nvgpu_gr_global_ctx_buffer_free,
|
||||||
|
* #nvgpu_gr_global_ctx_desc_alloc,
|
||||||
|
* #nvgpu_gr_global_ctx_desc_free,
|
||||||
|
* #nvgpu_gr_global_ctx_set_size,
|
||||||
|
* #nvgpu_gr_global_ctx_buffer_map,
|
||||||
|
* #nvgpu_gr_global_ctx_buffer_unmap,
|
||||||
|
* #nvgpu_gr_global_ctx_buffer_get_mem,
|
||||||
|
* #nvgpu_gr_global_ctx_buffer_ready.
|
||||||
|
*
|
||||||
|
* Input: gr_global_ctx_setup must have been executed successfully.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* - Trigger nvgpu_gr_global_ctx_buffer_alloc() to allocate global context
|
||||||
|
* buffers before sizes of all the buffers are set. This step should fail.
|
||||||
|
* - Trigger map/unmap calls for global context buffers before buffers are
|
||||||
|
* allocated. This step should fail.
|
||||||
|
* - Check if valid memory handle is returned or "ready" status is returned
|
||||||
|
* before context buffers are allocated. This step should fail.
|
||||||
|
* - Inject dma allocation errors for each context buffer and ensure
|
||||||
|
* nvgpu_gr_global_ctx_buffer_alloc() returns error in each case.
|
||||||
|
* - Ensure nvgpu_gr_global_ctx_buffer_alloc() is successful after all sizes
|
||||||
|
* are set and no error is injected.
|
||||||
|
* - Call nvgpu_gr_global_ctx_buffer_alloc() one more time to ensure API
|
||||||
|
* does not fail for double allocation.
|
||||||
|
* - Cleanup all the local resources.
|
||||||
|
*
|
||||||
|
* Output: Returns PASS if the steps above were executed successfully. FAIL
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
int test_gr_global_ctx_alloc_error_injection(struct unit_module *m,
|
||||||
|
struct gk20a *g, void *args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test specification for: test_gr_global_ctx_local_ctx_error_injection.
|
||||||
|
*
|
||||||
|
* Description: Verify error handling in local golden context image
|
||||||
|
* creation and comparison.
|
||||||
|
*
|
||||||
|
* Test Type: Feature based, Error guessing.
|
||||||
|
*
|
||||||
|
* Targets: #nvgpu_gr_global_ctx_init_local_golden_image,
|
||||||
|
* #nvgpu_gr_global_ctx_load_local_golden_image,
|
||||||
|
* #nvgpu_gr_global_ctx_compare_golden_images,
|
||||||
|
* #nvgpu_gr_global_ctx_deinit_local_golden_image.
|
||||||
|
*
|
||||||
|
* Input: gr_global_ctx_setup must have been executed successfully.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* - Allocate a dummy buffer for local use.
|
||||||
|
* - Inject memory allocation failures and ensure
|
||||||
|
* #nvgpu_gr_global_ctx_init_local_golden_image returns error in
|
||||||
|
* each case.
|
||||||
|
* - Trigger #nvgpu_gr_global_ctx_init_local_golden_image without any
|
||||||
|
* error injection and ensure it returns success.
|
||||||
|
* - Trigger memory flush errors and execute
|
||||||
|
* #nvgpu_gr_global_ctx_load_local_golden_image to cover error
|
||||||
|
* handling code.
|
||||||
|
* - Allocate another dummy local golden context image and compare
|
||||||
|
* the contents. This step should pass.
|
||||||
|
* - Trigger the comparison with vidmem flag set to true, this step
|
||||||
|
* should fail.
|
||||||
|
* - Change the contents of dummy local context image and compare.
|
||||||
|
* This step should fail.
|
||||||
|
* - Cleanup all the local resources.
|
||||||
|
*
|
||||||
|
* Output: Returns PASS if the steps above were executed successfully. FAIL
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
int test_gr_global_ctx_local_ctx_error_injection(struct unit_module *m,
|
||||||
|
struct gk20a *g, void *args);
|
||||||
|
|
||||||
|
#endif /* UNIT_NVGPU_GR_GLOBAL_CTX_H */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
Reference in New Issue
Block a user