| 1 |
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 |
# Copyright 2021 Amazon.com, Inc. or its affiliates. All rights reserved. |
| 3 |
|
| 4 |
import errno |
| 5 |
from pyverbs.libibverbs_enums import ibv_fork_status |
| 6 |
from pyverbs.fork import fork_init, is_fork_initialized |
| 7 |
from pyverbs.pyverbs_error import PyverbsRDMAError |
| 8 |
|
| 9 |
from tests.base import PyverbsAPITestCase |
| 10 |
|
| 11 |
|
| 12 |
class ForkAPITest(PyverbsAPITestCase): |
| 13 |
""" |
| 14 |
Test the API of the fork functions. |
| 15 |
""" |
| 16 |
|
| 17 |
def test_is_fork_initialized(self): |
| 18 |
try: |
| 19 |
fork_init() |
| 20 |
expected_ret = [ibv_fork_status.IBV_FORK_ENABLED, ibv_fork_status.IBV_FORK_UNNEEDED] |
| 21 |
except PyverbsRDMAError as ex: |
| 22 |
# Depends on the order of the tests EINVAL could be returned if |
| 23 |
# fork_init() is called after an MR has already been registered. |
| 24 |
self.assertEqual(ex.error_code, errno.EINVAL) |
| 25 |
expected_ret = [ibv_fork_status.IBV_FORK_DISABLED, ibv_fork_status.IBV_FORK_UNNEEDED] |
| 26 |
|
| 27 |
ret = is_fork_initialized() |
| 28 |
if self.config['verbosity']: |
| 29 |
print(f'is_fork_initialized() = {ret}') |
| 30 |
self.assertIn(ret, expected_ret) |