Open source GPL/LGPL release

This commit is contained in:
svcmobrel-release
2025-12-19 15:25:44 -08:00
commit 9fc87a7ec7
2261 changed files with 576825 additions and 0 deletions

View 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

View File

@@ -0,0 +1,35 @@
################################### tell Emacs this is a -*- makefile-gmake -*-
#
# Copyright (c) 2018-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=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:

View File

@@ -0,0 +1,38 @@
################################### tell Emacs this is a -*- makefile-gmake -*-
#
# Copyright (c) 2018-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=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:

View File

@@ -0,0 +1,224 @@
/*
* Copyright (c) 2018-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/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;
}
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;
}
}
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;
}
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;
}
int test_dma_alloc_fi_delayed_enable(struct unit_module *m,
struct gk20a *g, void *__args)
{
#define 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;
}

View File

@@ -0,0 +1,116 @@
/*
* Copyright (c) 2018-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_FAULT_INJECTION_DMA_ALLOC_H__
#define __UNIT_FAULT_INJECTION_DMA_ALLOC_H__
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-posix-fault-injection
* @{
*/
/**
* Test specification for: test_dma_alloc_init
*
* Description: Initialization required for dma alloc fault injection tests.
*
* Test Type: Other (Setup)
*
* Input: test_fault_injection_init() must have been called prior to this test.
*
* Steps:
* - Get the pointer to the dma alloc fault injection object.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_dma_alloc_init(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_dma_alloc_fi_default
*
* Description: This test simply tests the default case of fault injection
* disabled for calling dma alloc routines.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_dma_alloc_init() must have been
* called prior to this test.
*
* Steps:
* - Verify the dma alloc fault injection is disabled.
* - Call nvgpu_dma_alloc() verify the call succeeded.
* - Free the dma allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_dma_alloc_fi_default(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_dma_alloc_fi_enabled
*
* Description: This test validates immediate fault injection for dma alloc
* routines.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_dma_alloc_init() must have been
* called prior to this test.
*
* Steps:
* - Enable dma alloc fault injection immediately.
* - Call nvgpu_dma_alloc() and verify an error is returned.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_dma_alloc_fi_enabled(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_dma_alloc_fi_delayed_enable
*
* Description: This test validates delayed enable of fault injection for dma
* alloc APIs.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_dma_alloc_init() must have been
* called prior to this test.
*
* Steps:
* - Enable dma alloc fault injection for after 2 calls.
* - Loop calling nvgpu_dma_alloc() and verify success until the 3rd call.
* - Cleanup the dma allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_dma_alloc_fi_delayed_enable(struct unit_module *m,
struct gk20a *g, void *__args);
#endif /* __UNIT_FAULT_INJECTION_DMA_ALLOC_H__ */

View File

@@ -0,0 +1,512 @@
/*
* Copyright (c) 2018-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/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;
}
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;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}

View File

@@ -0,0 +1,234 @@
/*
* Copyright (c) 2018-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_FAULT_INJECTION_KMEM_H__
#define __UNIT_FAULT_INJECTION_KMEM_H__
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-posix-fault-injection
* @{
*/
/**
* Test specification for: test_kmem_init
*
* Description: Initialization required for kmem fault injection tests.
*
* Test Type: Other (Setup)
*
* Input: test_fault_injection_init() must have been called prior to this test.
*
* Steps:
* - Get the pointer to the kmem fault injection object.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_init(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_cache_fi_default
*
* Description: This test simply tests the default case of fault injection
* disabled for calling kmem cache routines.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Verify the kmem fault injection is disabled.
* - Create a kmem cache object and verify the return is non-NULL.
* - Destroy the kmem cache object.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_cache_fi_default(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_cache_fi_enabled
*
* Description: This test validates immediate fault injection for kmem cache
* create.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection immediately.
* - Create a kmem cache object and verify the return is NULL, indicating
* failure.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_cache_fi_enabled(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_cache_fi_delayed_enable
*
* Description: This test validates delayed enable of fault injection for kmem
* cache APIs.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection for after 2 calls.
* - Create a kmem cache object and verify the return is non-NULL, indicating
* pass.
* - Allocate from the kmem cache object and verify the 1st call passes.
* - Allocate from the kmem cache object and verify the 2nd call fails.
* - Cleanup the allocated cache.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_cache_fi_delayed_enable(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_cache_fi_delayed_disable
*
* Description: This test validates delayed disable of fault injection for kmem
* cache APIs.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection immediately.
* - Disable fault injection for after 1 call.
* - Create a kmem cache object and verify the return is NULL, indicating fail.
* - Create a kmem cache object and verify the return is non-NULL for the 2nd
* call, indicating pass and the fault injection was disabled.
* - Cleanup the allocated cache.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_cache_fi_delayed_disable(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_kmalloc_fi_default
*
* Description: This test simply tests the default case of fault injection
* disabled for calling kmem kmalloc routines.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Verify the kmem fault injection is disabled.
* - Allocate memory with nvgpu_kmalloc() and verify the call passed.
* - Free the kmem kmalloc memory.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_kmalloc_fi_default(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_kmalloc_fi_enabled
*
* Description: This test validates immediate fault injection for kmem kmalloc.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection immediately.
* - Allocate memory with nvgpu_kmalloc() and verify the result is NULL,
* indicating fail.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_kmalloc_fi_enabled(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_kmalloc_fi_delayed_enable
*
* Description: This test validates delayed enable of fault injection for kmem
* kmalloc APIs.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection for after 2 calls.
* - Call nvgpu_kmalloc() 3 times and verify it fails only on the 3rd call.
* - Cleanup the allocated memory.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_kmalloc_fi_delayed_enable(struct unit_module *m,
struct gk20a *g, void *__args);
/**
* Test specification for: test_kmem_kmalloc_fi_delayed_disable
*
* Description: This test validates delayed disable of fault injection for kmem
* kalloc APIs.
*
* Test Type: Feature Based
*
* Input: test_fault_injection_init() & test_kmem_init() must have been called
* prior to this test.
*
* Steps:
* - Enable kmem fault injection immediately.
* - Disable fault injection for after 2 calls.
* - Call nvgpu_kmalloc() in a loop and verify it fails until the 3rd call.
* - Cleanup the allocated cache.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_kmem_kmalloc_fi_delayed_disable(struct unit_module *m,
struct gk20a *g, void *__args);
#endif /* __UNIT_FAULT_INJECTION_KMEM_H__ */

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2018-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 <nvgpu/enabled.h>
#include <unit/unit.h>
#include <unit/io.h>
#include "posix-fault-injection.h"
#include "posix-fault-injection-kmem.h"
#include "posix-fault-injection-dma-alloc.h"
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, 0),
UNIT_TEST(init, test_kmem_init, NULL, 0),
UNIT_TEST(cache_default, test_kmem_cache_fi_default, NULL, 0),
UNIT_TEST(cache_enabled, test_kmem_cache_fi_enabled, NULL, 0),
UNIT_TEST(cache_delayed_enable, test_kmem_cache_fi_delayed_enable,
NULL, 0),
UNIT_TEST(cache_delayed_disable, test_kmem_cache_fi_delayed_disable,
NULL, 0),
UNIT_TEST(kmalloc_default, test_kmem_kmalloc_fi_default, NULL, 0),
UNIT_TEST(kmalloc_enabled, test_kmem_kmalloc_fi_enabled, NULL, 0),
UNIT_TEST(kmalloc_delayed_enable,
test_kmem_kmalloc_fi_delayed_enable, NULL, 0),
UNIT_TEST(kmalloc_delayed_disable,
test_kmem_kmalloc_fi_delayed_disable, NULL, 0),
UNIT_TEST(dma_alloc_init, test_dma_alloc_init, NULL, 0),
UNIT_TEST(dma_alloc_default, test_dma_alloc_fi_default, NULL, 0),
UNIT_TEST(dma_alloc_enabled, test_dma_alloc_fi_enabled, NULL, 0),
UNIT_TEST(dma_alloc_delayed_enable, test_dma_alloc_fi_delayed_enable,
NULL, 0),
};
UNIT_MODULE(fault_injection, fault_injection_tests, UNIT_PRIO_POSIX_TEST);

View File

@@ -0,0 +1,54 @@
/*
* 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_FAULT_INJECTION_H
#define UNIT_FAULT_INJECTION_H
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-posix-fault-injection
* @{
*
* Software Unit Test Specification for posix-fault-injection
*/
/**
* Test specification for: test_fault_injection_init
*
* Description: General initialization required for posix fault injection tests.
*
* Test Type: Other (Setup)
*
* Input: None
*
* Steps:
* - Set the enabled flag NVGPU_MM_UNIFIED_MEMORY flag required for the mm unit
* to function properly for these tests.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_fault_injection_init(struct unit_module *m,
struct gk20a *g, void *__args);
#endif /* UNIT_FAULT_INJECTION_H */