Files
scst/scripts/kunit/test_headers.py
Gleb Chesnokov e4a191c109 isert-scst: Stop polling before indexing a failed CQ result
Manual review found that isert_poll_cq forms &cq->wc[err] when
ib_poll_cq returns a negative errno. This pointer formation already
indexes outside the completion array, even if the following loop does
not dereference it. No saved analyzer diagnostic directly reports it.

Stop on nonpositive results before forming the end pointer and preserve
the result for the caller. Keep the loop exit next to the poll result.

Add the scst-ISER-cq KUnit suite to isert-scst.ko. Call the production
polling function with a private ib_device poll callback and task-local
stubs for the success and error completion handlers. Cover initial
-EIO and -EINVAL results, an empty queue, full and short batches, and
an error after completions. Check poll termination, completion order
and dispatch to the correct handler. Negative-result cases also exercise
kernel UBSAN bounds checking when CONFIG_UBSAN_BOUNDS is enabled.

Include iSER in the existing KUnit module inventory and build it after
iscsi-scst with the RDMA compatibility probes. Propagate the common
KUnit flags through ordinary iSER builds as well, so analyzer builds
include the suite. Extend tooling checks for module selection, dependency
order, cleanup, private headers and in-tree source export.
2026-10-21 13:20:12 +03:00

31 lines
1.3 KiB
Python

# SPDX-License-Identifier: GPL-2.0-only
"""Keep test access declarations out of ordinary SCST compilation."""
from pathlib import Path
import subprocess
import unittest
ROOT = Path(__file__).resolve().parents[2]
class HeaderTests(unittest.TestCase):
def test_normal_headers_do_not_require_kernel_or_test_types(self):
directories = ('scst/src', 'scst/src/dev_handlers', 'iscsi-scst/kernel',
'iscsi-scst/kernel/isert-scst',
'qla2x00t-32gbit/qla2x00-target')
headers = sorted(header for directory in directories
for header in (ROOT / directory).glob('*_test.h'))
self.assertTrue(headers)
source = ''.join(f'#include "{header}"\n' for header in headers)
# Kernel KUnit support alone must not expose SCST test declarations.
for options in ([], ['-DCONFIG_KUNIT=1'], ['-DCONFIG_KUNIT_MODULE=1']):
with self.subTest(options=options):
result = subprocess.run(['cc', '-E', '-P', '-x', 'c', *options, '-'],
input=source, capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout.strip(), '')
if __name__ == '__main__':
unittest.main()