mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 01:33:06 +00:00
tests: idr: add test cases for idr.
So far idr support was available for only radix-tree based idrs. Thus radix-tree tests were implicity covering idr test as well. Now as we are supporting non radix-tree based idrs as well, so add explicit test cases for idr testing. The test are applicable for both new (i.e radix-tree based) and old implementation of idrs. Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
This commit is contained in:
parent
4d7c709621
commit
4f2c8f0735
71
tests/linux_kernel/helpers/test_idr.py
Normal file
71
tests/linux_kernel/helpers/test_idr.py
Normal file
@ -0,0 +1,71 @@
|
||||
# Copyright (c) 2023, Oracle and/or its affiliates.
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
from drgn import NULL, Object
|
||||
from drgn.helpers.linux.idr import idr_find, idr_for_each
|
||||
from tests.linux_kernel import LinuxKernelTestCase, skip_unless_have_test_kmod
|
||||
|
||||
|
||||
@skip_unless_have_test_kmod
|
||||
class TestIDR(LinuxKernelTestCase):
|
||||
def test_idr_find_empty(self):
|
||||
root = self.prog["drgn_test_idr_empty"].address_of_()
|
||||
self.assertIdentical(idr_find(root, 0), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 100), NULL(self.prog, "void *"))
|
||||
|
||||
def test_idr_for_each_empty(self):
|
||||
root = self.prog["drgn_test_idr_empty"].address_of_()
|
||||
self.assertIdentical(list(idr_for_each(root)), [])
|
||||
|
||||
def test_idr_find_one(self):
|
||||
root = self.prog["drgn_test_idr_one"].address_of_()
|
||||
self.assertIdentical(idr_find(root, 0), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 65), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 66), Object(self.prog, "void *", 0xDEADB00))
|
||||
self.assertIdentical(idr_find(root, 67), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 100), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 256 + 66), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 2**24 + 66), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 2**56 + 66), NULL(self.prog, "void *"))
|
||||
|
||||
def test_idr_for_each_one(self):
|
||||
root = self.prog["drgn_test_idr_one"].address_of_()
|
||||
self.assertIdentical(
|
||||
list(idr_for_each(root)),
|
||||
[(66, Object(self.prog, "void *", 0xDEADB00))],
|
||||
)
|
||||
|
||||
def test_idr_lookup_one_at_zero(self):
|
||||
root = self.prog["drgn_test_idr_one_at_zero"].address_of_()
|
||||
self.assertIdentical(idr_find(root, 0), Object(self.prog, "void *", 0x1234))
|
||||
self.assertIdentical(idr_find(root, 1), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 100), NULL(self.prog, "void *"))
|
||||
|
||||
def test_idr_for_each_one_at_zero(self):
|
||||
root = self.prog["drgn_test_idr_one_at_zero"].address_of_()
|
||||
self.assertIdentical(
|
||||
list(idr_for_each(root)), [(0, Object(self.prog, "void *", 0x1234))]
|
||||
)
|
||||
|
||||
def test_idr_find_sparse(self):
|
||||
root = self.prog["drgn_test_idr_sparse"].address_of_()
|
||||
self.assertIdentical(idr_find(root, 0), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 1), Object(self.prog, "void *", 0x1234))
|
||||
self.assertIdentical(idr_find(root, 2), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 0x40), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 0x70), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 0x7F), NULL(self.prog, "void *"))
|
||||
self.assertIdentical(idr_find(root, 0x80), Object(self.prog, "void *", 0x5678))
|
||||
self.assertIdentical(idr_find(root, 0xEE), Object(self.prog, "void *", 0x9ABC))
|
||||
self.assertIdentical(idr_find(root, 0xEF), NULL(self.prog, "void *"))
|
||||
|
||||
def test_idr_for_each_sparse(self):
|
||||
root = self.prog["drgn_test_idr_sparse"].address_of_()
|
||||
self.assertIdentical(
|
||||
list(idr_for_each(root)),
|
||||
[
|
||||
(1, Object(self.prog, "void *", 0x1234)),
|
||||
(0x80, Object(self.prog, "void *", 0x5678)),
|
||||
(0xEE, Object(self.prog, "void *", 0x9ABC)),
|
||||
],
|
||||
)
|
@ -739,6 +739,68 @@ static void drgn_test_xarray_exit(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
// idr
|
||||
|
||||
DEFINE_IDR(drgn_test_idr_empty);
|
||||
DEFINE_IDR(drgn_test_idr_one);
|
||||
DEFINE_IDR(drgn_test_idr_one_at_zero);
|
||||
DEFINE_IDR(drgn_test_idr_sparse);
|
||||
DEFINE_IDR(drgn_test_idr_dense);
|
||||
static unsigned long drgn_test_idr_ptrs[5] = {
|
||||
0x12121212,
|
||||
0x34343434,
|
||||
0x5656565656565656,
|
||||
0x1234567812345678,
|
||||
0x1234567890abcdef,
|
||||
};
|
||||
|
||||
static int drgn_test_idr_init(void)
|
||||
{
|
||||
int ret, i;
|
||||
|
||||
ret = idr_alloc(&drgn_test_idr_one, (void *)0xdeadb00, 66, 67,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = idr_alloc(&drgn_test_idr_one_at_zero, (void *)0x1234, 0, 1,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = idr_alloc(&drgn_test_idr_sparse, (void *)0x1234, 1, 2,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = idr_alloc(&drgn_test_idr_sparse, (void *)0x5678, 0x80, 0x81,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = idr_alloc(&drgn_test_idr_sparse, (void *)0x9abc, 0xee, 0xef,
|
||||
GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
for (i = 10; i < 15; i++) {
|
||||
ret = idr_alloc(&drgn_test_idr_dense, (void *)drgn_test_idr_ptrs[i - 10],
|
||||
i, i + 1, GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void drgn_test_idr_exit(void)
|
||||
{
|
||||
idr_destroy(&drgn_test_idr_one);
|
||||
idr_destroy(&drgn_test_idr_one_at_zero);
|
||||
idr_destroy(&drgn_test_idr_sparse);
|
||||
idr_destroy(&drgn_test_idr_dense);
|
||||
}
|
||||
|
||||
// Dummy function symbol.
|
||||
int drgn_test_function(int x)
|
||||
{
|
||||
@ -753,6 +815,7 @@ static void drgn_test_exit(void)
|
||||
drgn_test_stack_trace_exit();
|
||||
drgn_test_radix_tree_exit();
|
||||
drgn_test_xarray_exit();
|
||||
drgn_test_idr_exit();
|
||||
}
|
||||
|
||||
static int __init drgn_test_init(void)
|
||||
@ -778,6 +841,9 @@ static int __init drgn_test_init(void)
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = drgn_test_xarray_init();
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = drgn_test_idr_init();
|
||||
out:
|
||||
if (ret)
|
||||
drgn_test_exit();
|
||||
|
Loading…
Reference in New Issue
Block a user