mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-23 09:57:08 +03:00
gpu: nvgpu: unit: Shuffle the paths of tests around a bit
We will need to organize the unit tests in order to keep the units/ directory managable. The basic idea here is to mirror the common/ structure in nvgpu proper under units/. There's one additrion at the moment though: posix. This is for posix environment related tests. Also added a fix for the runlist unit test. Add it to the tmake sources and move the nvgpu-runlist/ directory to just runlist/. Change-Id: I1f4163d0e33c3af70376cfeb3441d277d559e05a Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1935710 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
1023c6af14
commit
63da5366a6
28
userspace/units/posix/fault-injection/Makefile
Normal file
28
userspace/units/posix/fault-injection/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright (c) 2018, 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 = posix-fault-injection.o \
|
||||
posix-fault-injection-kmem.o \
|
||||
posix-fault-injection-dma-alloc.o
|
||||
MODULE = posix-fault-injection
|
||||
|
||||
include ../../Makefile.units
|
||||
23
userspace/units/posix/fault-injection/Makefile.interface.tmk
Normal file
23
userspace/units/posix/fault-injection/Makefile.interface.tmk
Normal file
@@ -0,0 +1,23 @@
|
||||
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||
#
|
||||
# Copyright (c) 2018, NVIDIA CORPORATION. All Rights Reserved.
|
||||
#
|
||||
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
||||
# and proprietary rights in and to this software, related documentation
|
||||
# and any modifications thereto. Any use, reproduction, disclosure or
|
||||
# distribution of this software and related documentation without an express
|
||||
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
||||
#
|
||||
# tmake for SW Mobile component makefile
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
NVGPU_UNIT_NAME=posix-fault-injection
|
||||
|
||||
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.interface.tmk
|
||||
|
||||
# Local Variables:
|
||||
# indent-tabs-mode: t
|
||||
# tab-width: 8
|
||||
# End:
|
||||
# vi: set tabstop=8 noexpandtab:
|
||||
26
userspace/units/posix/fault-injection/Makefile.tmk
Normal file
26
userspace/units/posix/fault-injection/Makefile.tmk
Normal file
@@ -0,0 +1,26 @@
|
||||
################################### tell Emacs this is a -*- makefile-gmake -*-
|
||||
#
|
||||
# Copyright (c) 2018 NVIDIA CORPORATION. All Rights Reserved.
|
||||
#
|
||||
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
||||
# and proprietary rights in and to this software, related documentation
|
||||
# and any modifications thereto. Any use, reproduction, disclosure or
|
||||
# distribution of this software and related documentation without an express
|
||||
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
||||
#
|
||||
# tmake for SW Mobile component makefile
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
NVGPU_UNIT_NAME=posix-fault-injection
|
||||
NVGPU_UNIT_SRCS=posix-fault-injection.c \
|
||||
posix-fault-injection-kmem.c \
|
||||
posix-fault-injection-dma-alloc.c
|
||||
|
||||
include $(NV_COMPONENT_DIR)/../../Makefile.units.common.tmk
|
||||
|
||||
# Local Variables:
|
||||
# indent-tabs-mode: t
|
||||
# tab-width: 8
|
||||
# End:
|
||||
# vi: set tabstop=8 noexpandtab:
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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/dma.h>
|
||||
#include <nvgpu/nvgpu_mem.h>
|
||||
#include <nvgpu/posix/posix-fault-injection.h>
|
||||
|
||||
#include "posix-fault-injection-dma-alloc.h"
|
||||
|
||||
#define TEST_DEFAULT_SIZE 4096
|
||||
|
||||
static struct nvgpu_posix_fault_inj *dma_fi;
|
||||
|
||||
/*
|
||||
* Used to make sure fault injection is disabled before running test
|
||||
* If already enabled, prints warning and disables
|
||||
*
|
||||
* Returns false if unable to guarantee fault injection is disabled
|
||||
*/
|
||||
static bool verify_fi_disabled(struct unit_module *m)
|
||||
{
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_info(m, "Unexpected fault injection enabled\n");
|
||||
}
|
||||
|
||||
/* force disabled in case it was in "delay" mode */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "Unable to disable fault injection\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* This test is for test environment initialization */
|
||||
int test_dma_alloc_init(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
dma_fi = nvgpu_dma_alloc_get_fault_injection();
|
||||
if (dma_fi == NULL) {
|
||||
return UNIT_FAIL;
|
||||
} else {
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This test verifies the default case for dma_alloc operations when fault
|
||||
* injection is disabled.
|
||||
*/
|
||||
int test_dma_alloc_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_mem mem;
|
||||
int result;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* check default case, no fault injection */
|
||||
result = nvgpu_dma_alloc(g, TEST_DEFAULT_SIZE, &mem);
|
||||
if (result != 0) {
|
||||
unit_err(m, "nvgpu_dma_alloc returned error when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* good housekeeping */
|
||||
nvgpu_dma_free(g, &mem);
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "dma alloc fault injection test "
|
||||
"failure\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test enables fault injection for dma_alloc immediately then verifies the
|
||||
* first call to a dma_alloc fails.
|
||||
*/
|
||||
int test_dma_alloc_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_mem mem;
|
||||
int result;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable fault injection immediately */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, true, 0);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "unable to enable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
result = nvgpu_dma_alloc(g, TEST_DEFAULT_SIZE, &mem);
|
||||
if (result == 0) {
|
||||
unit_err(m, "nvgpu_dma_alloc returned success when fault "
|
||||
"injection enabled\n");
|
||||
nvgpu_dma_free(g, &mem);
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "dma alloc fault injection test "
|
||||
"failure\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This is a test of delayed fault injection enabling for dma_alloc */
|
||||
int test_dma_alloc_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
const unsigned int fail_after = 2;
|
||||
unsigned int call_count = 0;
|
||||
struct nvgpu_mem mem[fail_after+1];
|
||||
int result = 0;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable fault injection after delay */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, true, fail_after);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "Fault injection errantly enabled too soon\n");
|
||||
ret = UNIT_FAIL;
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
call_count = 1;
|
||||
while (call_count <= (fail_after+1)){
|
||||
result = nvgpu_dma_alloc(g, TEST_DEFAULT_SIZE,
|
||||
&mem[call_count-1]);
|
||||
|
||||
if ((call_count <= fail_after) && (result != 0U)) {
|
||||
unit_err(m, "nvgpu_dma_alloc returned error when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
} else if ((call_count > fail_after) && (result == 0U)) {
|
||||
unit_err(m, "nvgpu_dma_alloc returned success when "
|
||||
"fault injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
}
|
||||
call_count++;
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* free allocations */
|
||||
if (result != 0) {
|
||||
/* the last alloc failed, so decrement before we start
|
||||
* freeing
|
||||
*/
|
||||
call_count--;
|
||||
}
|
||||
while (call_count > 1) {
|
||||
nvgpu_dma_free(g, &mem[call_count-1]);
|
||||
call_count--;
|
||||
}
|
||||
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(dma_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(dma_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "dma alloc fault injection test "
|
||||
"failure\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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_FAULT_INJECTION_DMA_ALLOC_H__
|
||||
#define __UNIT_FAULT_INJECTION_DMA_ALLOC_H__
|
||||
|
||||
int test_dma_alloc_init(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_dma_alloc_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_dma_alloc_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_dma_alloc_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
#endif /* __UNIT_FAULT_INJECTION_DMA_ALLOC_H__ */
|
||||
@@ -0,0 +1,545 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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/kmem.h>
|
||||
#include <nvgpu/posix/posix-fault-injection.h>
|
||||
#include "posix-fault-injection-kmem.h"
|
||||
|
||||
|
||||
#define TEST_DEFAULT_CACHE_SIZE 1024
|
||||
#define TEST_DEFAULT_KMALLOC_SIZE 1024
|
||||
|
||||
static struct nvgpu_posix_fault_inj *kmem_fi;
|
||||
|
||||
/*
|
||||
* Used to make sure fault injection is disabled before running test
|
||||
* If already enabled, prints warning and disables
|
||||
*
|
||||
* Returns false if unable to guarantee fault injection is disabled
|
||||
*/
|
||||
static bool verify_fi_disabled(struct unit_module *m)
|
||||
{
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_info(m, "Unexpected fault injection enabled\n");
|
||||
}
|
||||
|
||||
/* force disabled in case it was in "delay" mode */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Unable to disable fault injection\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* This test is for test environment initialization */
|
||||
int test_kmem_init(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
kmem_fi = nvgpu_kmem_get_fault_injection();
|
||||
if (kmem_fi == NULL) {
|
||||
return UNIT_FAIL;
|
||||
} else {
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This test simply tests the default case of fault injection disabled for
|
||||
* calling kmem cache routines.
|
||||
*/
|
||||
int test_kmem_cache_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_kmem_cache *kmem_cache;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* check default case */
|
||||
kmem_cache = nvgpu_kmem_cache_create(g, TEST_DEFAULT_CACHE_SIZE);
|
||||
if (kmem_cache == NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_create returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
nvgpu_kmem_cache_destroy(kmem_cache);
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test "
|
||||
"failure\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test enables fault injection for kmem immediately then verifies the
|
||||
* first call to a kmem cache API (in this case nvgpu_kmem_cache_create())
|
||||
* fails.
|
||||
*/
|
||||
int test_kmem_cache_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_kmem_cache *kmem_cache;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Unable to enable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* create cache and verify error */
|
||||
kmem_cache = nvgpu_kmem_cache_create(g, TEST_DEFAULT_CACHE_SIZE);
|
||||
if (kmem_cache != NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_create returned pointer when "
|
||||
"fault injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This is a test of delayed fault injection for kmem_cache APIs */
|
||||
int test_kmem_cache_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_kmem_cache *kmem_cache;
|
||||
int *ptr1, *ptr2;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults after 2 calls */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, 2);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Fault injection errantly enabled too soon\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* first call should pass */
|
||||
kmem_cache = nvgpu_kmem_cache_create(g, TEST_DEFAULT_CACHE_SIZE);
|
||||
if (kmem_cache == NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_create returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* second call should pass */
|
||||
ptr1 = (int *)nvgpu_kmem_cache_alloc(kmem_cache);
|
||||
if (ptr1 == NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_alloc returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* third call should fail */
|
||||
ptr2 = (int *)nvgpu_kmem_cache_alloc(kmem_cache);
|
||||
if (ptr2 != NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_alloc returned pointer when "
|
||||
"fault injection enabled\n");
|
||||
nvgpu_kmem_cache_free(kmem_cache, ptr2);
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* good housekeeping */
|
||||
nvgpu_kmem_cache_free(kmem_cache, ptr1);
|
||||
nvgpu_kmem_cache_destroy(kmem_cache);
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test validates delayed disabling of fault injection for calling kmem
|
||||
* cache routines.
|
||||
*/
|
||||
int test_kmem_cache_fi_delayed_disable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
struct nvgpu_kmem_cache *kmem_cache;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults now */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Unable to enable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* disable faults after 1 call */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 1);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Fault injection errantly disabled too soon\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* first call should fail */
|
||||
kmem_cache = nvgpu_kmem_cache_create(g, TEST_DEFAULT_CACHE_SIZE);
|
||||
if (kmem_cache != NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_create returned pointer when "
|
||||
"fault injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* second call should pass */
|
||||
kmem_cache = nvgpu_kmem_cache_create(g, TEST_DEFAULT_CACHE_SIZE);
|
||||
if (kmem_cache == NULL) {
|
||||
unit_err(m, "nvgpu_kmem_cache_create returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
/* good housekeeping */
|
||||
nvgpu_kmem_cache_destroy(kmem_cache);
|
||||
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test validates the default case for kmem kmalloc routines when fault
|
||||
* injection is disabled.
|
||||
*/
|
||||
int test_kmem_kmalloc_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
int *ptr;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* check default case */
|
||||
ptr = (int *)nvgpu_kmalloc(g, TEST_DEFAULT_KMALLOC_SIZE);
|
||||
if (ptr == NULL) {
|
||||
unit_err(m, "nvgpu_kmalloc returned NULL when fault injection "
|
||||
"disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
/* good housekeeping */
|
||||
nvgpu_kfree(g, ptr);
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test verifies that kmalloc routines return errors after fault
|
||||
* injection is enabled immediately.
|
||||
*/
|
||||
int test_kmem_kmalloc_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
int *ptr;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Unable to enable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* call kmalloc and verify error */
|
||||
ptr = (int *)nvgpu_kmalloc(g, TEST_DEFAULT_KMALLOC_SIZE);
|
||||
if (ptr != NULL) {
|
||||
unit_err(m, "nvgpu_kmalloc returned pointer when fault "
|
||||
"injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test validates that when a fault injection is enabled with a delayed
|
||||
* number of calls, the kmem kmalloc routines only report errors after the
|
||||
* delayed number of calls have been made.
|
||||
*/
|
||||
int test_kmem_kmalloc_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
const unsigned int fail_after = 2;
|
||||
int *ptrs[fail_after+1];
|
||||
unsigned int call_count;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults after "fail_after" calls */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, fail_after);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Fault injection errantly enabled too soon\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
call_count = 1;
|
||||
while (call_count <= (fail_after + 1)) {
|
||||
ptrs[call_count-1] = nvgpu_kmalloc(g,
|
||||
TEST_DEFAULT_KMALLOC_SIZE);
|
||||
if ((call_count <= fail_after) &&
|
||||
(ptrs[call_count-1] == NULL)) {
|
||||
unit_err(m, "nvgpu_kmalloc returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
} else if ((call_count > fail_after) &&
|
||||
(ptrs[call_count-1] != NULL)) {
|
||||
unit_err(m, "nvgpu_kmalloc returned pointer when fault "
|
||||
"injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
}
|
||||
call_count++;
|
||||
}
|
||||
|
||||
/* good housekeeping */
|
||||
while (--call_count >= 1) {
|
||||
if (ptrs[call_count-1] != NULL) {
|
||||
nvgpu_kfree(g, ptrs[call_count-1]);
|
||||
}
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This test verifies that if fault injection is enabled and then set to be
|
||||
* disabled after a delayed number of calls, the kmalloc routines return errors
|
||||
* until the number of calls have been made, then they return valid results.
|
||||
*/
|
||||
int test_kmem_kmalloc_fi_delayed_disable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
const unsigned int pass_after = 2;
|
||||
int *ptrs[pass_after+1];
|
||||
unsigned int call_count;
|
||||
int ret = UNIT_SUCCESS;
|
||||
|
||||
if (!verify_fi_disabled(m)) {
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* enable faults now */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, true, 0);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Unable to enable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
/* disable faults after "pass_after" calls */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, pass_after);
|
||||
if (!nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "Fault injection errantly disabled too soon\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
goto test_exit;
|
||||
}
|
||||
|
||||
call_count = 1;
|
||||
while (call_count <= (pass_after + 1)) {
|
||||
ptrs[call_count-1] = nvgpu_kmalloc(g,
|
||||
TEST_DEFAULT_KMALLOC_SIZE);
|
||||
if ((call_count <= pass_after) &&
|
||||
(ptrs[call_count-1] != NULL)) {
|
||||
unit_err(m, "nvgpu_kmalloc returned pointer when fault "
|
||||
"injection enabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
} else if ((call_count > pass_after) &&
|
||||
(ptrs[call_count-1] == NULL)) {
|
||||
unit_err(m, "nvgpu_kmalloc returned NULL when fault "
|
||||
"injection disabled\n");
|
||||
ret = UNIT_FAIL;
|
||||
/* no reason to go on */
|
||||
break;
|
||||
}
|
||||
call_count++;
|
||||
}
|
||||
|
||||
/* good housekeeping */
|
||||
while (--call_count >= 1) {
|
||||
if (ptrs[call_count-1] != NULL) {
|
||||
nvgpu_kfree(g, ptrs[call_count-1]);
|
||||
}
|
||||
}
|
||||
|
||||
test_exit:
|
||||
/* disable faults upon exit */
|
||||
nvgpu_posix_enable_fault_injection(kmem_fi, false, 0);
|
||||
if (nvgpu_posix_is_fault_injection_triggered(kmem_fi)) {
|
||||
unit_err(m, "unable to disable fault injection\n");
|
||||
ret = UNIT_FAIL;
|
||||
}
|
||||
|
||||
if (ret != UNIT_SUCCESS) {
|
||||
unit_return_fail(m, "kmem cache fault injection test failure"
|
||||
"\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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_FAULT_INJECTION_KMEM_H__
|
||||
#define __UNIT_FAULT_INJECTION_KMEM_H__
|
||||
|
||||
int test_kmem_init(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
|
||||
int test_kmem_cache_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_cache_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_cache_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_cache_fi_delayed_disable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
|
||||
int test_kmem_kmalloc_fi_default(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_kmalloc_fi_enabled(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_kmalloc_fi_delayed_enable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
int test_kmem_kmalloc_fi_delayed_disable(struct unit_module *m,
|
||||
struct gk20a *g, void *__args);
|
||||
|
||||
#endif /* __UNIT_FAULT_INJECTION_KMEM_H__ */
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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 <nvgpu/enabled.h>
|
||||
#include <unit/unit.h>
|
||||
#include <unit/io.h>
|
||||
#include "posix-fault-injection-kmem.h"
|
||||
#include "posix-fault-injection-dma-alloc.h"
|
||||
|
||||
static int test_fault_injection_init(struct unit_module *m,
|
||||
struct gk20a *g, void *__args)
|
||||
{
|
||||
__nvgpu_set_enabled(g, NVGPU_MM_UNIFIED_MEMORY, true);
|
||||
return UNIT_SUCCESS;
|
||||
}
|
||||
|
||||
struct unit_module_test fault_injection_tests[] = {
|
||||
UNIT_TEST(fault_injection_init, test_fault_injection_init, NULL),
|
||||
|
||||
UNIT_TEST(init, test_kmem_init, NULL),
|
||||
|
||||
UNIT_TEST(cache_default, test_kmem_cache_fi_default, NULL),
|
||||
UNIT_TEST(cache_enabled, test_kmem_cache_fi_enabled, NULL),
|
||||
UNIT_TEST(cache_delayed_enable, test_kmem_cache_fi_delayed_enable,
|
||||
NULL),
|
||||
UNIT_TEST(cache_delayed_disable, test_kmem_cache_fi_delayed_disable,
|
||||
NULL),
|
||||
|
||||
UNIT_TEST(kmalloc_default, test_kmem_kmalloc_fi_default, NULL),
|
||||
UNIT_TEST(kmalloc_enabled, test_kmem_kmalloc_fi_enabled, NULL),
|
||||
UNIT_TEST(kmalloc_delayed_enable,
|
||||
test_kmem_kmalloc_fi_delayed_enable, NULL),
|
||||
UNIT_TEST(kmalloc_delayed_disable,
|
||||
test_kmem_kmalloc_fi_delayed_disable, NULL),
|
||||
|
||||
UNIT_TEST(dma_alloc_init, test_dma_alloc_init, NULL),
|
||||
|
||||
UNIT_TEST(dma_alloc_default, test_dma_alloc_fi_default, NULL),
|
||||
UNIT_TEST(dma_alloc_enabled, test_dma_alloc_fi_enabled, NULL),
|
||||
UNIT_TEST(dma_alloc_delayed_enable, test_dma_alloc_fi_delayed_enable,
|
||||
NULL),
|
||||
};
|
||||
|
||||
UNIT_MODULE(fault_injection, fault_injection_tests, UNIT_PRIO_POSIX_TEST);
|
||||
Reference in New Issue
Block a user