gpu: nvgpu: unit: mm: add coverage & traceability

This patch adds new tests to improve test coverage. Also, updating test
target tags to increase traceability.

Jira NVGPU-4780

Change-Id: I87341efa3fa7d741f7abb611ff28ad6d5e1c6880
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2279644
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Vedashree Vidwans
2019-12-31 11:00:24 -08:00
committed by Alex Waterman
parent 4bcd419a0b
commit f46c3064ed
27 changed files with 934 additions and 240 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2020, 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"),
@@ -37,7 +37,10 @@ struct unit_module;
*
* Description: Initialize bitmap allocator.
*
* Test Type: Feature
* Test Type: Feature, Error injection
*
* Targets: nvgpu_bitmap_allocator_init, nvgpu_bitmap_check_argument_limits,
* nvgpu_allocator.ops.fini, nvgpu_alloc_to_gpu
*
* Input: None
*
@@ -61,6 +64,9 @@ int test_nvgpu_bitmap_allocator_init(struct unit_module *m,
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.base, nvgpu_allocator.ops.length,
* nvgpu_allocator.ops.end, nvgpu_allocator.ops.inited
*
* Input: test_nvgpu_bitmap_allocator_init
*
* Steps:
@@ -80,7 +86,12 @@ int test_nvgpu_bitmap_allocator_ops(struct unit_module *m,
*
* Description: Allocate various sizes of memory to test different scenarios.
*
* Test Type: Feature
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator.ops.alloc, nvgpu_allocator.ops.free_alloc,
* nvgpu_allocator.ops.alloc_fixed, nvgpu_allocator.ops.free_fixed,
* nvgpu_bitmap_alloc_from_rbtree_node, bitmap_allocator,
* alloc_loc, alloc_unlock
*
* Input: test_nvgpu_bitmap_allocator_init
*
@@ -109,6 +120,8 @@ int test_nvgpu_bitmap_allocator_alloc(struct unit_module *m,
*
* Test Type: Other (clean up)
*
* Targets: nvgpu_allocator.ops.fini
*
* Input: test_nvgpu_bitmap_allocator_init
*
* Steps:
@@ -128,6 +141,11 @@ int test_nvgpu_bitmap_allocator_destroy(struct unit_module *m,
*
* Test Type: Feature
*
* Targets: nvgpu_allocator_init, nvgpu_bitmap_allocator_init,
* nvgpu_bitmap_check_argument_limits, nvgpu_allocator.ops.alloc
* nvgpu_allocator.ops.free_alloc, nvgpu_allocator.ops.alloc_fixed,
* nvgpu_allocator.ops.free_fixed, nvgpu_allocator.ops.fini
*
* Input: None
*
* Steps:

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2020, 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"),
@@ -39,6 +39,7 @@
#include "buddy_allocator.h"
#define SZ_8K (SZ_4K << 1)
#define SZ_16K (SZ_4K << 2)
#define BA_DEFAULT_BASE SZ_4K
#define BA_DEFAULT_SIZE SZ_1M
#define BA_DEFAULT_BLK_SIZE SZ_4K
@@ -150,7 +151,7 @@ int test_buddy_allocator_with_big_pages(struct unit_module *m,
}
/*
* Initialize buddy allocator, base = 0 and blk_size not pde aligned
* Initialize buddy allocator, base = 0
* Expect to fail
*/
if (nvgpu_allocator_init(g, na, vm_big_pages, "test", 0ULL, size,
@@ -160,6 +161,17 @@ int test_buddy_allocator_with_big_pages(struct unit_module *m,
"despite base=0, blk_size not pde aligned\n");
}
/*
* Initialize buddy allocator, base = 256M
* Expect to fail
*/
if (nvgpu_allocator_init(g, na, vm_big_pages, "test", SZ_256M, SZ_64K,
blk_size, max_order, flags, BUDDY_ALLOCATOR) == 0) {
free_vm_env(m, g, vm_big_pages);
unit_return_fail(m, "ba_big_pages inited "
"despite base=0, blk_size not pde aligned\n");
}
/* Initialize buddy allocator with big pages for this test */
if (nvgpu_allocator_init(g, na, vm_big_pages, "test", base, size,
blk_size, max_order, flags, BUDDY_ALLOCATOR) != 0) {
@@ -279,6 +291,7 @@ int test_buddy_allocator_with_small_pages(struct unit_module *m,
u64 max_order = 10;
u64 flags = GPU_ALLOC_GVA_SPACE;
u64 addr;
struct nvgpu_buddy_allocator *ba;
struct nvgpu_posix_fault_inj *kmem_fi =
nvgpu_kmem_get_fault_injection();
@@ -411,6 +424,22 @@ int test_buddy_allocator_with_small_pages(struct unit_module *m,
}
na->ops->fini(na);
/* Request align_order > ba->max_order */
if (nvgpu_allocator_init(g, na, vm_small_pages, "test", base, size,
blk_size, 5, flags, BUDDY_ALLOCATOR) != 0) {
free_vm_env(m, g, vm_small_pages);
unit_return_fail(m, "ba small pages init failed\n");
}
ba = na->priv;
addr = na->ops->alloc_fixed(na, ba->start, SZ_1M, SZ_4K);
if (addr != 0) {
unit_err(m, "%d: Allocated with align_order > ba->max_order\n",
__LINE__);
goto fail;
}
return UNIT_SUCCESS;
fail:
@@ -431,7 +460,6 @@ int test_nvgpu_buddy_allocator_alloc(struct unit_module *m,
u64 max_order = 0;
u64 flags = 0ULL;
u64 addr;
u64 len_orig, split_orig, alloced_orig;
struct nvgpu_buddy_allocator *ba;
struct nvgpu_posix_fault_inj *kmem_fi =
nvgpu_kmem_get_fault_injection();
@@ -553,8 +581,7 @@ int test_nvgpu_buddy_allocator_alloc(struct unit_module *m,
/*
* Test nvgpu_buddy_allocator_destroy()
*/
len_orig = ba->buddy_list_len[max_order/2];
ba->buddy_list_len[max_order/2] = 100;
ba->buddy_list_len[0] = 100;
if (!EXPECT_BUG(na->ops->fini(na))) {
unit_err(m, "%d: Excess buddies didn't trigger BUG()\n",
__LINE__);
@@ -565,29 +592,28 @@ int test_nvgpu_buddy_allocator_alloc(struct unit_module *m,
* by BUG()
*/
alloc_unlock(na);
ba->buddy_list_len[0] = 0;
ba->buddy_list_len[max_order/2] = len_orig;
split_orig = ba->buddy_list_split[max_order/3];
ba->buddy_list_split[max_order/3] = 100;
ba->buddy_list_split[0] = 100;
if (!EXPECT_BUG(na->ops->fini(na))) {
unit_err(m, "%d: Excess split nodes didn't trigger BUG()\n",
__LINE__);
goto cleanup;
}
/* Release mutex again */
/*
* Release the mutex that was left locked when fini() was interrupted
* by BUG()
*/
alloc_unlock(na);
ba->buddy_list_split[0] = 0;
ba->buddy_list_split[max_order/3] = split_orig;
alloced_orig = ba->buddy_list_alloced[max_order/4];
ba->buddy_list_alloced[max_order/4] = 100;
ba->buddy_list_alloced[0] = 100;
if (!EXPECT_BUG(na->ops->fini(na))) {
unit_err(m, "%d: Excess alloced nodes didn't trigger BUG()\n",
__LINE__);
goto cleanup;
}
ba->buddy_list_alloced[max_order/4] = alloced_orig;
ba->buddy_list_alloced[0] = 0;
result = UNIT_SUCCESS;
@@ -611,6 +637,8 @@ int test_nvgpu_buddy_allocator_carveout(struct unit_module *m,
NVGPU_CARVEOUT("test_co", 0ULL, 0ULL);
struct nvgpu_alloc_carveout test_co1 =
NVGPU_CARVEOUT("test_co1", 0ULL, 0ULL);
struct nvgpu_alloc_carveout test_co2 =
NVGPU_CARVEOUT("test_co2", 0ULL, 0ULL);
/*
* test_co base < buddy_allocator start
@@ -625,7 +653,7 @@ int test_nvgpu_buddy_allocator_carveout(struct unit_module *m,
* test_co base + test_co length > buddy allocator end
* Expect to fail
*/
test_co.base = BA_DEFAULT_BASE >> 1;
test_co.base = BA_DEFAULT_BASE;
test_co.length = BA_DEFAULT_SIZE << 1;
err = na->ops->reserve_carveout(na, &test_co);
@@ -646,18 +674,18 @@ int test_nvgpu_buddy_allocator_carveout(struct unit_module *m,
unit_return_fail(m, "carveout reserved with unaligned base\n");
}
test_co.base = BA_DEFAULT_BASE;
test_co.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co);
test_co1.base = BA_DEFAULT_BASE;
test_co1.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co1);
if (err < 0) {
unit_return_fail(m, "couldn't reserve 4K carveout\n");
}
na->ops->release_carveout(na, &test_co);
na->ops->release_carveout(na, &test_co1);
test_co.base = SZ_4K;
test_co.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co);
test_co1.base = SZ_4K;
test_co1.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co1);
if (err < 0) {
unit_return_fail(m,
"couldn't reserve 4K carveout after release\n");
@@ -667,21 +695,57 @@ int test_nvgpu_buddy_allocator_carveout(struct unit_module *m,
* Allocate 64K carveout at already allocated address
* Expect to fail
*/
test_co1.base = 0x1800;
test_co1.length = SZ_64K;
err = na->ops->reserve_carveout(na, &test_co1);
test_co.base = 0x1800;
test_co.length = SZ_64K;
err = na->ops->reserve_carveout(na, &test_co);
if (err == 0) {
unit_return_fail(m,
"64K carveout reserved at already allocated address\n");
}
test_co1.base = SZ_4K << 2;
test_co1.length = SZ_64K;
err = na->ops->reserve_carveout(na, &test_co1);
test_co2.base = SZ_16K;
test_co2.length = SZ_64K;
err = na->ops->reserve_carveout(na, &test_co2);
if (err < 0) {
unit_return_fail(m, "couldn't reserve 64K carveout\n");
}
/*
* Allocate 8K carveout at already allocated address
* Expect to fail
*/
test_co.base = 0x1800 + SZ_4K;
test_co.length = SZ_8K;
err = na->ops->reserve_carveout(na, &test_co);
if (err == 0) {
unit_return_fail(m,
"8K carveout reserved at already allocated address\n");
}
/*
* Allocate 4K carveout at already allocated address
* Expect to fail
*/
test_co.base = SZ_16K;
test_co.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co);
if (err == 0) {
unit_return_fail(m,
"8K carveout reserved at already allocated address\n");
}
/*
* Allocate 8K carveout at already allocated address
* Expect to fail
*/
test_co.base = 0x1800;
test_co.length = SZ_4K;
err = na->ops->reserve_carveout(na, &test_co);
if (err == 0) {
unit_return_fail(m,
"8K carveout reserved at already allocated address\n");
}
addr = na->ops->alloc(na, (SZ_64K >> 1));
if (addr == 0) {
unit_return_fail(m, "couldn't allocate 32K\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2020, 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"),
@@ -37,7 +37,13 @@ struct unit_module;
*
* Description: Initialize buddy allocator.
*
* Test Type: Feature
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator_init, nvgpu_buddy_allocator_init,
* nvgpu_buddy_check_argument_limits, nvgpu_buddy_set_attributes,
* balloc_allocator_align, balloc_compute_max_order, balloc_init_lists,
* balloc_max_order_in, balloc_get_order, balloc_get_order_list,
* nvgpu_allocator.ops.fini
*
* Input: None
*
@@ -74,6 +80,10 @@ int test_nvgpu_buddy_allocator_init(struct unit_module *m,
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.alloc, nvgpu_allocator.ops.reserve_carveout,
* nvgpu_allocator.ops.release_carveout,
* nvgpu_alloc_carveout_from_co_entry
*
* Input: test_nvgpu_buddy_allocator_init
*
* Steps:
@@ -100,6 +110,16 @@ int test_nvgpu_buddy_allocator_carveout(struct unit_module *m,
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.base, nvgpu_allocator.ops.length,
* nvgpu_allocator.ops.end, nvgpu_allocator.ops.inited,
* nvgpu_allocator.ops.space, nvgpu_allocator.ops.alloc,
* nvgpu_allocator.ops.alloc_pte, nvgpu_allocator.ops.free_alloc,
* nvgpu_allocator.ops.alloc_fixed, nvgpu_buddy_allocator_flag_ops,
* nvgpu_buddy_from_buddy_entry, balloc_base_shift, buddy_allocator,
* balloc_base_unshift, balloc_owner, balloc_order_to_len, alloc_lock,
* alloc_unlock, nvgpu_alloc_to_gpu, nvgpu_buddy_from_rbtree_node,
* nvgpu_fixed_alloc_from_rbtree_node
*
* Input: test_nvgpu_buddy_allocator_init
*
* Steps:
@@ -129,6 +149,8 @@ int test_nvgpu_buddy_allocator_basic_ops(struct unit_module *m,
*
* Test Type: Other (cleanup)
*
* Targets: nvgpu_allocator.ops.fini
*
* Input: test_nvgpu_buddy_allocator_init
*
* Steps:
@@ -146,7 +168,11 @@ int test_nvgpu_buddy_allocator_destroy(struct unit_module *m,
*
* Description: Test cleanup branch of memory allocations.
*
* Test Type: Feature
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator_init, nvgpu_allocator.ops.alloc,
* nvgpu_allocator.ops.alloc_fixed, nvgpu_buddy_allocator_flag_ops,
* nvgpu_allocator.ops.fini
*
* Input: None
*
@@ -178,7 +204,12 @@ int test_nvgpu_buddy_allocator_alloc(struct unit_module *m,
*
* Description: Test buddy allocator functions with big pages disabled.
*
* Test Type: Feature
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator_init, nvgpu_buddy_allocator_init,
* nvgpu_buddy_check_argument_limits, nvgpu_allocator.ops.inited
* nvgpu_buddy_set_attributes, nvgpu_allocator.ops.alloc_pte,
* nvgpu_allocator.ops.alloc_fixed, nvgpu_allocator.ops.fini
*
* Input: None
*
@@ -220,6 +251,12 @@ int test_buddy_allocator_with_small_pages(struct unit_module *m,
*
* Test Type: Feature
*
* Targets: nvgpu_allocator_init, nvgpu_buddy_allocator_init,
* nvgpu_buddy_check_argument_limits, nvgpu_buddy_set_attributes,
* nvgpu_allocator.ops.alloc_pte, nvgpu_allocator.ops.alloc_fixed
* nvgpu_allocator.ops.alloc, nvgpu_allocator.ops.free_alloc,
* nvgpu_allocator.ops.fini
*
* Input: None
*
* Steps:

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2018-2020, 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"),
@@ -24,8 +24,11 @@
#include <unit/unit.h>
#include <nvgpu/types.h>
#include <nvgpu/sizes.h>
#include <nvgpu/allocator.h>
#include "nvgpu_allocator.h"
#define OP_ALLOC 0
#define OP_FREE 1
#define OP_ALLOC_PTE 2
@@ -149,18 +152,7 @@ static struct nvgpu_allocator_ops dummy_ops = {
.fini = dummy_fini
};
/*
* Make sure the op functions are called and that's it. Verifying that the ops
* actually do what they are supposed to do is the responsibility of the unit
* tests for the actual allocator implementations.
*
* In this unit test the meaning of these ops can't really be assumed. But we
* can test that the logic for only calling present ops is tested.
*
* Also note: we don't test the fini op here; instead we test it separately as
* part of the init/destroy functionality.
*/
static int test_nvgpu_alloc_ops_present(struct unit_module *m,
int test_nvgpu_alloc_ops_present(struct unit_module *m,
struct gk20a *g, void *args)
{
u32 i;
@@ -243,13 +235,7 @@ static int test_nvgpu_alloc_ops_present(struct unit_module *m,
return UNIT_SUCCESS;
}
/*
* Test the common_init() function used by all allocator implementations. The
* test here is to simply catch that the various invalid input checks are
* exercised and that the parameters passed into the common_init() make their
* way into the allocator struct.
*/
static int test_nvgpu_alloc_common_init(struct unit_module *m,
int test_nvgpu_alloc_common_init(struct unit_module *m,
struct gk20a *g, void *args)
{
struct nvgpu_allocator a;
@@ -294,11 +280,7 @@ static int test_nvgpu_alloc_common_init(struct unit_module *m,
return UNIT_SUCCESS;
}
/*
* Test that the destroy function works. This just calls the fini() op and
* expects the allocator to have been completely zeroed.
*/
static int test_nvgpu_alloc_destroy(struct unit_module *m,
int test_nvgpu_alloc_destroy(struct unit_module *m,
struct gk20a *g, void *args)
{
struct nvgpu_allocator a;
@@ -322,10 +304,53 @@ static int test_nvgpu_alloc_destroy(struct unit_module *m,
return UNIT_SUCCESS;
}
int test_nvgpu_allocator_init(struct unit_module *m,
struct gk20a *g, void *args)
{
struct nvgpu_allocator a;
u64 base = SZ_4K;
u64 size = SZ_64K;
u64 blk_size = SZ_4K;
u64 max_order = 0;
u64 flags = 0ULL;
if (nvgpu_allocator_init(g, &a, NULL, "buddy", base, size, blk_size,
max_order, flags, BUDDY_ALLOCATOR) != 0) {
unit_return_fail(m, "failed to init buddy_allocator\n");
} else {
a.ops->fini(&a);
}
#ifdef CONFIG_NVGPU_DGPU
if (nvgpu_allocator_init(g, &a, NULL, "page", base, size, blk_size,
max_order, flags, PAGE_ALLOCATOR) != 0) {
unit_return_fail(m, "failed to init page_allocator\n");
} else {
a.ops->fini(&a);
}
#endif
if (nvgpu_allocator_init(g, &a, NULL, "bitmap", base, size, blk_size,
max_order, flags, BITMAP_ALLOCATOR) != 0) {
unit_return_fail(m, "failed to init bitmap_allocator\n");
} else {
a.ops->fini(&a);
}
/* Initialize invalid allocator */
if (nvgpu_allocator_init(g, &a, NULL, "invalid", base, size, blk_size,
max_order, flags, -1) != -EINVAL) {
unit_return_fail(m, "initialized invalid allocator\n");
}
return UNIT_SUCCESS;
}
struct unit_module_test nvgpu_allocator_tests[] = {
UNIT_TEST(common_init, test_nvgpu_alloc_common_init, NULL, 0),
UNIT_TEST(alloc_destroy, test_nvgpu_alloc_destroy, NULL, 0),
UNIT_TEST(alloc_ops, test_nvgpu_alloc_ops_present, NULL, 0),
UNIT_TEST(allocator_init, test_nvgpu_allocator_init, NULL, 0),
};
UNIT_MODULE(nvgpu_allocator, nvgpu_allocator_tests, UNIT_PRIO_NVGPU_TEST);

View File

@@ -0,0 +1,125 @@
/*
* Copyright (c) 2020, 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_ALLOCATOR_H
#define UNIT_NVGPU_ALLOCATOR_H
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-mm-allocators-nvgpu-allocator
* @{
*
* Software Unit Test Specification for mm.allocators.nvgpu_allocator
*/
/**
* Test specification for: test_nvgpu_alloc_common_init
*
* Description: Test common_init() function
*
* Test Type: Feature
*
* Targets: nvgpu_alloc_common_init
*
* Input: None
*
* Steps:
* - Initialize nvgpu allocator with default ops values.
* - Confirm that the parameters passed to the function make their way into
* allocator struct.
* - Initialize nvgpu allocator for various invalid input cases.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_alloc_common_init(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_nvgpu_alloc_destroy
*
* Description: Test allocator destroy function
*
* Test Type: Feature
*
* Targets: nvgpu_alloc_common_init, nvgpu_alloc_destroy
*
* Input: None
*
* Steps:
* - Trigger allocator destroy function which further invokes fini() op.
* - Allocator struct should be completely zeroed after this function.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_alloc_destroy(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_nvgpu_alloc_ops_present
*
* Description: Test allocator destroy function
*
* Test Type: Feature
*
* Targets: nvgpu_alloc, nvgpu_alloc_pte, nvgpu_alloc_fixed, nvgpu_free_fixed,
* nvgpu_alloc_reserve_carveout, nvgpu_alloc_release_carveout,
* nvgpu_alloc_base, nvgpu_alloc_length, nvgpu_alloc_end, nvgpu_free,
* nvgpu_alloc_initialized, nvgpu_alloc_space
*
* Input: None
*
* Steps:
* - Test the logic for calling present ops.
* - Actual functionality of the ops should be verified by the respective
* allocator unit tests.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_alloc_ops_present(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_nvgpu_allocator_init
*
* Description: Test allocator init function
*
* Test Type: Feature
*
* Targets: nvgpu_allocator_init, nvgpu_alloc_destroy
*
* Input: None
*
* Steps:
* - Initialize each allocator and check that the allocator is created
* successfully.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_allocator_init(struct unit_module *m,
struct gk20a *g, void *args);
#endif /* UNIT_NVGPU_ALLOCATOR_H */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2020, 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"),
@@ -32,6 +32,7 @@
#include <nvgpu/posix/posix-fault-injection.h>
#include <nvgpu/page_allocator.h>
#include "page_allocator.h"
#ifdef CONFIG_NVGPU_DGPU
@@ -229,12 +230,7 @@ static struct test_parameters alloc_more_than_available = {
.error_msg = "Allocated more than available memory",
};
/*
* This function is a wrapper for page_allocator alloc() function.
* test_page_alloc() - Allocates page allocator memory
*/
static int test_page_alloc(struct unit_module *m, struct gk20a *g, void *args)
int test_page_alloc(struct unit_module *m, struct gk20a *g, void *args)
{
struct test_parameters *param = (struct test_parameters *) args;
struct nvgpu_page_allocator *pa = page_allocator(na);
@@ -259,11 +255,7 @@ static int test_page_alloc(struct unit_module *m, struct gk20a *g, void *args)
}
}
/*
* This function is a wrapper for page_allocator free() function.
* test_page_free() - Frees page allocator memory
*/
static int test_page_free(struct unit_module *m, struct gk20a *g, void *args)
int test_page_free(struct unit_module *m, struct gk20a *g, void *args)
{
struct test_parameters *param = (struct test_parameters *) args;
struct nvgpu_page_allocator *pa = page_allocator(na);
@@ -275,13 +267,7 @@ static int test_page_free(struct unit_module *m, struct gk20a *g, void *args)
return UNIT_SUCCESS;
}
/*
* This function is a wrapper for page_allocator alloc_fixed() function.
* test_page_alloc_fixed() - Allocates page allocator memory starting at
* fixed address location
*/
static int test_page_alloc_fixed(struct unit_module *m, struct gk20a *g,
void *args)
int test_page_alloc_fixed(struct unit_module *m, struct gk20a *g, void *args)
{
struct test_parameters *param = (struct test_parameters *) args;
struct nvgpu_page_allocator *pa = page_allocator(na);
@@ -308,12 +294,7 @@ static int test_page_alloc_fixed(struct unit_module *m, struct gk20a *g,
}
}
/*
* This function is a wrapper for page_allocator free_fixed() function.
* test_page_free_fixed() - Frees fixed page allocator memory
*/
static int test_page_free_fixed(struct unit_module *m, struct gk20a *g,
void *args)
int test_page_free_fixed(struct unit_module *m, struct gk20a *g, void *args)
{
struct test_parameters *param = (struct test_parameters *) args;
struct nvgpu_page_allocator *pa = page_allocator(na);
@@ -325,11 +306,7 @@ static int test_page_free_fixed(struct unit_module *m, struct gk20a *g,
return UNIT_SUCCESS;
}
/*
* Tests nvgpu_page_allocator_init()
* This test considers multiple conditions to initialize page allocator
*/
static int test_page_allocator_init_slabs(struct unit_module *m,
int test_page_allocator_init_slabs(struct unit_module *m,
struct gk20a *g, void *args)
{
u64 base = SZ_64K;
@@ -383,10 +360,7 @@ static int test_page_allocator_init_slabs(struct unit_module *m,
return UNIT_SUCCESS;
}
/*
* Tests page_allocator sgt ops
*/
static int test_page_allocator_sgt_ops(struct unit_module *m,
int test_page_allocator_sgt_ops(struct unit_module *m,
struct gk20a *g, void *args)
{
u64 addr;
@@ -437,11 +411,7 @@ static int test_page_allocator_sgt_ops(struct unit_module *m,
return UNIT_SUCCESS;
}
/*
* Tests page_allocator basic ops
* Page allocator attributes are set corresponding to default init values
*/
static int test_nvgpu_page_allocator_ops(struct unit_module *m,
int test_nvgpu_page_allocator_ops(struct unit_module *m,
struct gk20a *g, void *args)
{
u64 addr;
@@ -497,23 +467,19 @@ static int test_nvgpu_page_allocator_ops(struct unit_module *m,
return UNIT_SUCCESS;
}
/*
* De-initialize page allocator
*/
static int test_nvgpu_page_allocator_destroy(struct unit_module *m,
int test_nvgpu_page_allocator_destroy(struct unit_module *m,
struct gk20a *g, void *args)
{
na->ops->fini(na);
if (na->priv != NULL) {
unit_return_fail(m, "page allocator destroy failed\n");
}
nvgpu_kfree(g, na);
return UNIT_SUCCESS;
}
/*
* Tests nvgpu_page_allocator_init()
* This test considers multiple conditions to initialize page allocator
*/
static int test_nvgpu_page_allocator_init(struct unit_module *m,
int test_nvgpu_page_allocator_init(struct unit_module *m,
struct gk20a *g, void *args)
{
u64 base = BA_DEFAULT_BASE;
@@ -602,8 +568,8 @@ struct unit_module_test page_allocator_tests[] = {
/* Below tests examine page allocation */
/*
* NOTE: The test order should not be changed. A test contructs
* required memory structure for later tests.
* NOTE: The test order should not be changed. Previous test develop
* memory allocation arrangement required for later tests.
*/
/* These tests check execution with fault injection at various locations */

View File

@@ -0,0 +1,258 @@
/*
* Copyright (c) 2020, 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_PAGE_ALLOCATOR_H
#define UNIT_PAGE_ALLOCATOR_H
struct gk20a;
struct unit_module;
/** @addtogroup SWUTS-mm-allocators-page-allocator
* @{
*
* Software Unit Test Specification for mm.allocators.page_allocator
*/
/**
* Test specification for: test_nvgpu_page_allocator_init
*
* Description: Initialize page allocator.
*
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator_init, nvgpu_page_allocator_init,
* nvgpu_allocator.ops.fini
*
* Input: None
*
* Steps:
* - Initialize page allocator with following characteristics.
* - 4K memory base address.
* - 1M length of memory.
* - 4K block size.
* - Check that page allocator initializations fails for scenarios such as
* odd value of block_size and fault injection for memory allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_page_allocator_init(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_nvgpu_page_allocator_ops
*
* Description: Test page allocator ops
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.alloc, nvgpu_allocator.ops.free_alloc,
* nvgpu_allocator.ops.reserve_carveout,
* nvgpu_allocator.ops.release_carveout, nvgpu_allocator.ops.base,
* nvgpu_allocator.ops.end, nvgpu_allocator.ops.length,
* nvgpu_allocator.ops.inited, nvgpu_allocator.ops.space
*
* Input: test_nvgpu_page_allocator_init
*
* Steps:
* - Check page_allocator attributes using allocator ops.
* - Execute allocator ops to read attibute value.
* - Confirm that value is equal to the default values set during
* initialization.
* - Allocate carveout and confirm that allocation is successful. Check that
* carveout cannot be reserved after normal page allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_page_allocator_ops(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_page_allocator_sgt_ops
*
* Description: Test page alloc sgt ops
*
* Test Type: Feature
*
* Targets: nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_next,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_phys,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_ipa,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_ipa_to_pa,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_dma,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_length,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgl_gpu_addr,
* nvgpu_page_alloc.nvgpu_sgt.nvgpu_sgt_ops.sgt_free
*
* Input: test_nvgpu_page_allocator_init
*
* Steps:
* - Check allocated page attributes using sgt ops
* - Confirm that allocation details are equal to values set during allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_allocator_sgt_ops(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_page_alloc_fixed
*
* Description: Allocate memory at fixed address
*
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator.ops.alloc_fixed
*
* Input: test_nvgpu_page_allocator_init or test_page_allocator_init_slabs,
* args (fault_at_alloc_cache, fault_at_sgl_alloc, simple_alloc_128K,
* alloc_no_scatter_gather, failing_alloc_8K)
*
* Steps:
* - Allocate chunk of memory at fixed address as per test_parameters input.
* - Check that result is equal to test_parameters expected output.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_alloc_fixed(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for: test_page_alloc
*
* Description: Allocate memory using page allocator
*
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator.ops.alloc
*
* Input: test_nvgpu_page_allocator_init or test_page_allocator_init_slabs,
* args (fault_at_alloc_cache, fault_at_nvgpu_alloc,
* first_simple_alloc_32K, fault_at_sgl_alloc, alloc_no_scatter_gather,
* alloc_contiguous, simple_alloc_512K, alloc_more_than_available,
* fault_at_page_cache, second_simple_alloc_32K, third_simple_alloc_32K,
* fourth_simple_alloc_32K, simple_alloc_8K, failing_alloc_16K)
*
* Steps:
* - Allocate chunk of memory at any address as per test_parameters input.
* - Check that result is equal to test_parameters expected output.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_alloc(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for: test_page_free
*
* Description: Free allocated memory
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.free_alloc
*
* Input: test_nvgpu_page_allocator_init or test_page_allocator_init_slabs,
* args (alloc_no_scatter_gather, first_simple_alloc_32K,
* simple_alloc_512K, fourth_simple_alloc_32K, second_simple_alloc_32K,
* first_simple_alloc_32K, third_simple_alloc_32K)
*
* Steps:
* - Free allocated memory at given address as per test_parameters input.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_free(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for: test_page_free_fixed
*
* Description: Free allocated page at given address
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.free_fixed
*
* Input: test_nvgpu_page_allocator_init, args (alloc_no_scatter_gather,
* simple_alloc_128K)
*
* Steps:
* - Free allocated memory at fixed address as per test_parameters input.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_free_fixed(struct unit_module *m, struct gk20a *g, void *args);
/**
* Test specification for: test_page_allocator_init_slabs
*
* Description: Initialize page allocator with slabs.
*
* Test Type: Feature, Error injection
*
* Targets: nvgpu_allocator_init, nvgpu_page_allocator_init,
* nvgpu_page_alloc_init_slabs, nvgpu_allocator.ops.fini
*
* Input: None
*
* Steps:
* - Initialize page allocator with following characteristics.
* - 64K memory base address.
* - 128K length of memory.
* - 64K block size.
* - Flags set to GPU_ALLOC_4K_VIDMEM_PAGES to enable slabs.
* - Check that page allocator initializations fails for scenarios such as
* odd value of block_size and fault injection for memory allocation.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_page_allocator_init_slabs(struct unit_module *m,
struct gk20a *g, void *args);
/**
* Test specification for: test_nvgpu_page_allocator_destroy
*
* Description: Destroy page allocator structure
*
* Test Type: Feature
*
* Targets: nvgpu_allocator.ops.fini
*
* Input: test_nvgpu_page_allocator_init or test_page_allocator_init_slabs
*
* Steps:
* - De-initialize page allocator structure.
*
* Output: Returns SUCCESS if the steps above were executed successfully. FAIL
* otherwise.
*/
int test_nvgpu_page_allocator_destroy(struct unit_module *m,
struct gk20a *g, void *args);
/**
* @}
*/
#endif /* UNIT_PAGE_ALLOCATOR_H */