sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget;/translations/zh_CN/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget;/translations/zh_TW/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget;/translations/it_IT/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget;/translations/ja_JP/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget;/translations/ko_KR/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget;/translations/sp_SP/dev-tools/kunit/api/functionredirectionmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhU/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection.rsthKubhsection)}(hhh](htitle)}(hFunction Redirection APIh]hFunction Redirection API}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hOverviewh]hOverview}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXWhen writing unit tests, it's important to be able to isolate the code being tested from other parts of the kernel. This ensures the reliability of the test (it won't be affected by external factors), reduces dependencies on specific hardware or config options (making the test easier to run), and protects the stability of the rest of the system (making it less likely for test-specific state to interfere with the rest of the system).h]hXWhen writing unit tests, it’s important to be able to isolate the code being tested from other parts of the kernel. This ensures the reliability of the test (it won’t be affected by external factors), reduces dependencies on specific hardware or config options (making the test easier to run), and protects the stability of the rest of the system (making it less likely for test-specific state to interfere with the rest of the system).}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hWhile for some code (typically generic data structures, helpers, and other "pure functions") this is trivial, for others (like device drivers, filesystems, core subsystems) the code is heavily coupled with other parts of the kernel.h]hWhile for some code (typically generic data structures, helpers, and other “pure functions”) this is trivial, for others (like device drivers, filesystems, core subsystems) the code is heavily coupled with other parts of the kernel.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hX5This coupling is often due to global state in some way: be it a global list of devices, the filesystem, or some hardware state. Tests need to either carefully manage, isolate, and restore state, or they can avoid it altogether by replacing access to and mutation of this state with a "fake" or "mock" variant.h]hX=This coupling is often due to global state in some way: be it a global list of devices, the filesystem, or some hardware state. Tests need to either carefully manage, isolate, and restore state, or they can avoid it altogether by replacing access to and mutation of this state with a “fake” or “mock” variant.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXBy refactoring access to such state, such as by introducing a layer of indirection which can use or emulate a separate set of test state. However, such refactoring comes with its own costs (and undertaking significant refactoring before being able to write tests is suboptimal).h]hXBy refactoring access to such state, such as by introducing a layer of indirection which can use or emulate a separate set of test state. However, such refactoring comes with its own costs (and undertaking significant refactoring before being able to write tests is suboptimal).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hrA simpler way to intercept and replace some of the function calls is to use function redirection via static stubs.h]hrA simpler way to intercept and replace some of the function calls is to use function redirection via static stubs.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubeh}(h]overviewah ]h"]overviewah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Static Stubsh]h Static Stubs}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj*hhhhhK%ubh)}(hStatic stubs are a way of redirecting calls to one function (the "real" function) to another function (the "replacement" function).h]hStatic stubs are a way of redirecting calls to one function (the “real” function) to another function (the “replacement” function).}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hj*hhubh)}(hIt works by adding a macro to the "real" function which checks to see if a test is running, and if a replacement function is available. If so, that function is called in place of the original.h]hIt works by adding a macro to the “real” function which checks to see if a test is running, and if a replacement function is available. If so, that function is called in place of the original.}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK*hj*hhubh)}(h-Using static stubs is pretty straightforward:h]h-Using static stubs is pretty straightforward:}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hj*hhubhenumerated_list)}(hhh](h list_item)}(hXAdd the KUNIT_STATIC_STUB_REDIRECT() macro to the start of the "real" function. This should be the first statement in the function, after any variable declarations. KUNIT_STATIC_STUB_REDIRECT() takes the name of the function, followed by all of the arguments passed to the real function. For example: .. code-block:: c void send_data_to_hardware(const char *str) { KUNIT_STATIC_STUB_REDIRECT(send_data_to_hardware, str); /* real implementation */ } h](h)}(hOAdd the KUNIT_STATIC_STUB_REDIRECT() macro to the start of the "real" function.h]hSAdd the KUNIT_STATIC_STUB_REDIRECT() macro to the start of the “real” function.}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK0hjlubh)}(hThis should be the first statement in the function, after any variable declarations. KUNIT_STATIC_STUB_REDIRECT() takes the name of the function, followed by all of the arguments passed to the real function.h]hThis should be the first statement in the function, after any variable declarations. KUNIT_STATIC_STUB_REDIRECT() takes the name of the function, followed by all of the arguments passed to the real function.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK3hjlubh)}(h For example:h]h For example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjlubh literal_block)}(hvoid send_data_to_hardware(const char *str) { KUNIT_STATIC_STUB_REDIRECT(send_data_to_hardware, str); /* real implementation */ }h]hvoid send_data_to_hardware(const char *str) { KUNIT_STATIC_STUB_REDIRECT(send_data_to_hardware, str); /* real implementation */ }}hjsbah}(h]h ]h"]h$]h&]hhforcelanguagechighlight_args}uh1jhhhK9hjlubeh}(h]h ]h"]h$]h&]uh1jjhjghhhNhNubjk)}(hX<Write one or more replacement functions. These functions should have the same function signature as the real function. In the event they need to access or modify test-specific state, they can use kunit_get_current_test() to get a struct kunit pointer. This can then be passed to the expectation/assertion macros, or used to look up KUnit resources. For example: .. code-block:: c void fake_send_data_to_hardware(const char *str) { struct kunit *test = kunit_get_current_test(); KUNIT_EXPECT_STREQ(test, str, "Hello World!"); } h](h)}(h(Write one or more replacement functions.h]h(Write one or more replacement functions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjubh)}(hX3These functions should have the same function signature as the real function. In the event they need to access or modify test-specific state, they can use kunit_get_current_test() to get a struct kunit pointer. This can then be passed to the expectation/assertion macros, or used to look up KUnit resources.h]hX3These functions should have the same function signature as the real function. In the event they need to access or modify test-specific state, they can use kunit_get_current_test() to get a struct kunit pointer. This can then be passed to the expectation/assertion macros, or used to look up KUnit resources.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubh)}(h For example:h]h For example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKIhjubj)}(hvoid fake_send_data_to_hardware(const char *str) { struct kunit *test = kunit_get_current_test(); KUNIT_EXPECT_STREQ(test, str, "Hello World!"); }h]hvoid fake_send_data_to_hardware(const char *str) { struct kunit *test = kunit_get_current_test(); KUNIT_EXPECT_STREQ(test, str, "Hello World!"); }}hjsbah}(h]h ]h"]h$]h&]hhjjjj}uh1jhhhKKhjubeh}(h]h ]h"]h$]h&]uh1jjhjghhhNhNubjk)}(hXActivate the static stub from your test. From within a test, the redirection can be enabled with kunit_activate_static_stub(), which accepts a struct kunit pointer, the real function, and the replacement function. You can call this several times with different replacement functions to swap out implementations of the function. In our example, this would be .. code-block:: c kunit_activate_static_stub(test, send_data_to_hardware, fake_send_data_to_hardware); h](h)}(h(Activate the static stub from your test.h]h(Activate the static stub from your test.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKShjubh)}(hXFrom within a test, the redirection can be enabled with kunit_activate_static_stub(), which accepts a struct kunit pointer, the real function, and the replacement function. You can call this several times with different replacement functions to swap out implementations of the function.h]hXFrom within a test, the redirection can be enabled with kunit_activate_static_stub(), which accepts a struct kunit pointer, the real function, and the replacement function. You can call this several times with different replacement functions to swap out implementations of the function.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKUhjubh)}(hIn our example, this would beh]hIn our example, this would be}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK[hjubj)}(hkunit_activate_static_stub(test, send_data_to_hardware, fake_send_data_to_hardware);h]hkunit_activate_static_stub(test, send_data_to_hardware, fake_send_data_to_hardware);}hj&sbah}(h]h ]h"]h$]h&]hhjjjj}uh1jhhhK]hjubeh}(h]h ]h"]h$]h&]uh1jjhjghhhNhNubjk)}(hXCall (perhaps indirectly) the real function. Once the redirection is activated, any call to the real function will call the replacement function instead. Such calls may be buried deep in the implementation of another function, but must occur from the test's kthread. For example: .. code-block:: c send_data_to_hardware("Hello World!"); /* Succeeds */ send_data_to_hardware("Something else"); /* Fails the test. */ h](h)}(h,Call (perhaps indirectly) the real function.h]h,Call (perhaps indirectly) the real function.}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKchj;ubh)}(hOnce the redirection is activated, any call to the real function will call the replacement function instead. Such calls may be buried deep in the implementation of another function, but must occur from the test's kthread.h]hOnce the redirection is activated, any call to the real function will call the replacement function instead. Such calls may be buried deep in the implementation of another function, but must occur from the test’s kthread.}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKehj;ubh)}(h For example:h]h For example:}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKihj;ubj)}(htsend_data_to_hardware("Hello World!"); /* Succeeds */ send_data_to_hardware("Something else"); /* Fails the test. */h]htsend_data_to_hardware("Hello World!"); /* Succeeds */ send_data_to_hardware("Something else"); /* Fails the test. */}hjisbah}(h]h ]h"]h$]h&]hhjjjj}uh1jhhhKkhj;ubeh}(h]h ]h"]h$]h&]uh1jjhjghhhNhNubjk)}(hX`(Optionally) disable the stub. When you no longer need it, disable the redirection (and hence resume the original behaviour of the 'real' function) using kunit_deactivate_static_stub(). Otherwise, it will be automatically disabled when the test exits. For example: .. code-block:: c kunit_deactivate_static_stub(test, send_data_to_hardware); h](h)}(h(Optionally) disable the stub.h]h(Optionally) disable the stub.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKphj~ubh)}(hWhen you no longer need it, disable the redirection (and hence resume the original behaviour of the 'real' function) using kunit_deactivate_static_stub(). Otherwise, it will be automatically disabled when the test exits.h]hWhen you no longer need it, disable the redirection (and hence resume the original behaviour of the ‘real’ function) using kunit_deactivate_static_stub(). Otherwise, it will be automatically disabled when the test exits.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKrhj~ubh)}(h For example:h]h For example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKwhj~ubj)}(h:kunit_deactivate_static_stub(test, send_data_to_hardware);h]h:kunit_deactivate_static_stub(test, send_data_to_hardware);}hjsbah}(h]h ]h"]h$]h&]hhjjjj}uh1jhhhKyhj~ubeh}(h]h ]h"]h$]h&]uh1jjhjghhhNhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jehj*hhhhhK0ubh)}(hqIt's also possible to use these replacement functions to test to see if a function is called at all, for example:h]hsIt’s also possible to use these replacement functions to test to see if a function is called at all, for example:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK~hj*hhubj)}(hXvoid send_data_to_hardware(const char *str) { KUNIT_STATIC_STUB_REDIRECT(send_data_to_hardware, str); /* real implementation */ } /* In test file */ int times_called = 0; void fake_send_data_to_hardware(const char *str) { times_called++; } ... /* In the test case, redirect calls for the duration of the test */ kunit_activate_static_stub(test, send_data_to_hardware, fake_send_data_to_hardware); send_data_to_hardware("hello"); KUNIT_EXPECT_EQ(test, times_called, 1); /* Can also deactivate the stub early, if wanted */ kunit_deactivate_static_stub(test, send_data_to_hardware); send_data_to_hardware("hello again"); KUNIT_EXPECT_EQ(test, times_called, 1);h]hXvoid send_data_to_hardware(const char *str) { KUNIT_STATIC_STUB_REDIRECT(send_data_to_hardware, str); /* real implementation */ } /* In test file */ int times_called = 0; void fake_send_data_to_hardware(const char *str) { times_called++; } ... /* In the test case, redirect calls for the duration of the test */ kunit_activate_static_stub(test, send_data_to_hardware, fake_send_data_to_hardware); send_data_to_hardware("hello"); KUNIT_EXPECT_EQ(test, times_called, 1); /* Can also deactivate the stub early, if wanted */ kunit_deactivate_static_stub(test, send_data_to_hardware); send_data_to_hardware("hello again"); KUNIT_EXPECT_EQ(test, times_called, 1);}hjsbah}(h]h ]h"]h$]h&]hhjjjj}uh1jhhhKhj*hhubeh}(h] static-stubsah ]h"] static stubsah$]h&]uh1hhhhhhhhK%ubh)}(hhh](h)}(h API Referenceh]h API Reference}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubhindex)}(hhh]h}(h]h ]h"]h$]h&]entries](single$KUNIT_STATIC_STUB_REDIRECT (C macro)c.KUNIT_STATIC_STUB_REDIRECThNtauh1jhjhhhNhNubhdesc)}(hhh](hdesc_signature)}(hKUNIT_STATIC_STUB_REDIRECTh]hdesc_signature_line)}(hKUNIT_STATIC_STUB_REDIRECTh]h desc_name)}(hKUNIT_STATIC_STUB_REDIRECTh]h desc_sig_name)}(hjh]hKUNIT_STATIC_STUB_REDIRECT}(hj,hhhNhNubah}(h]h ]nah"]h$]h&]uh1j*hj&ubah}(h]h ](sig-namedescnameeh"]h$]h&]hhuh1j$hj hhht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKubah}(h]h ]h"]h$]h&]hh add_permalinkuh1jsphinx_line_type declaratorhjhhhjBhKubah}(h]jah ](sig sig-objecteh"]h$]h&] is_multiline _toc_parts) _toc_namehuh1jhjBhKhjhhubh desc_content)}(hhh]h}(h]h ]h"]h$]h&]uh1jWhjhhhjBhKubeh}(h]h ](jmacroeh"]h$]h&]domainjobjtypejedesctypejenoindex noindexentrynocontentsentryuh1jhhhjhNhNubh)}(h6``KUNIT_STATIC_STUB_REDIRECT (real_fn_name, args...)``h]hliteral)}(hjqh]h2KUNIT_STATIC_STUB_REDIRECT (real_fn_name, args...)}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjoubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjhhubh block_quote)}(h/call a replacement 'static stub' if one exists h]h)}(h.call a replacement 'static stub' if one existsh]h2call a replacement ‘static stub’ if one exists}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubah}(h]h ]h"]h$]h&]uh1jhjhKhjhhubh container)}(hX**Parameters** ``real_fn_name`` The name of this function (as an identifier, not a string) ``args...`` All of the arguments passed to this function **Description** This is a function prologue which is used to allow calls to the current function to be redirected by a KUnit test. KUnit tests can call kunit_activate_static_stub() to pass a replacement function in. The replacement function will be called by KUNIT_STATIC_STUB_REDIRECT(), which will then return from the function. If the caller is not in a KUnit context, the function will continue execution as normal. .. code-block:: c int real_func(int n) { KUNIT_STATIC_STUB_REDIRECT(real_func, n); return 0; } int replacement_func(int n) { return 42; } void example_test(struct kunit *test) { kunit_activate_static_stub(test, real_func, replacement_func); KUNIT_EXPECT_EQ(test, real_func(1), 42); } **Example**h](h)}(h**Parameters**h]hstrong)}(hjh]h Parameters}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubhdefinition_list)}(hhh](hdefinition_list_item)}(hL``real_fn_name`` The name of this function (as an identifier, not a string) h](hterm)}(h``real_fn_name``h]jt)}(hjh]h real_fn_name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubh definition)}(hhh]h)}(h:The name of this function (as an identifier, not a string)h]h:The name of this function (as an identifier, not a string)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKhjubj)}(h9``args...`` All of the arguments passed to this function h](j)}(h ``args...``h]jt)}(hjh]hargs...}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshj ubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubj)}(hhh]h)}(h,All of the arguments passed to this functionh]h,All of the arguments passed to this function}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj#hKhj$ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhj#hKhjubeh}(h]h ]h"]h$]h&]uh1jhjubh)}(h**Description**h]j)}(hjIh]h Description}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjGubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubh)}(hXThis is a function prologue which is used to allow calls to the current function to be redirected by a KUnit test. KUnit tests can call kunit_activate_static_stub() to pass a replacement function in. The replacement function will be called by KUNIT_STATIC_STUB_REDIRECT(), which will then return from the function. If the caller is not in a KUnit context, the function will continue execution as normal.h]hXThis is a function prologue which is used to allow calls to the current function to be redirected by a KUnit test. KUnit tests can call kunit_activate_static_stub() to pass a replacement function in. The replacement function will be called by KUNIT_STATIC_STUB_REDIRECT(), which will then return from the function. If the caller is not in a KUnit context, the function will continue execution as normal.}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhjubj)}(hX3int real_func(int n) { KUNIT_STATIC_STUB_REDIRECT(real_func, n); return 0; } int replacement_func(int n) { return 42; } void example_test(struct kunit *test) { kunit_activate_static_stub(test, real_func, replacement_func); KUNIT_EXPECT_EQ(test, real_func(1), 42); }h]hX3int real_func(int n) { KUNIT_STATIC_STUB_REDIRECT(real_func, n); return 0; } int replacement_func(int n) { return 42; } void example_test(struct kunit *test) { kunit_activate_static_stub(test, real_func, replacement_func); KUNIT_EXPECT_EQ(test, real_func(1), 42); }}hjnsbah}(h]h ]h"]h$]h&]hhjjjj}uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhK%hjubh)}(h **Example**h]j)}(hjh]hExample}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj~ubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhK8hjubeh}(h]h ] kernelindentah"]h$]h&]uh1jhjhhhNhNubj)}(hhh]h}(h]h ]h"]h$]h&]entries](j$kunit_activate_static_stub (C macro)c.kunit_activate_static_stubhNtauh1jhjhhhNhNubj)}(hhh](j)}(hkunit_activate_static_stubh]j)}(hkunit_activate_static_stubh]j%)}(hkunit_activate_static_stubh]j+)}(hjh]hkunit_activate_static_stub}(hjhhhNhNubah}(h]h ]j6ah"]h$]h&]uh1j*hjubah}(h]h ](j=j>eh"]h$]h&]hhuh1j$hjhhht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKRubah}(h]h ]h"]h$]h&]hhjIuh1jjJjKhjhhhjhKRubah}(h]jah ](jOjPeh"]h$]h&]jTjU)jVhuh1jhjhKRhjhhubjX)}(hhh]h}(h]h ]h"]h$]h&]uh1jWhjhhhjhKRubeh}(h]h ](jmacroeh"]h$]h&]jijjjjjkjjljmjnuh1jhhhjhNhNubh)}(hE``kunit_activate_static_stub (test, real_fn_addr, replacement_addr)``h]jt)}(hjh]hAkunit_activate_static_stub (test, real_fn_addr, replacement_addr)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKThjhhubj)}(h'replace a function using static stubs. h]h)}(h&replace a function using static stubs.h]h&replace a function using static stubs.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKRhjubah}(h]h ]h"]h$]h&]uh1jhjhKRhjhhubj)}(hXy**Parameters** ``test`` A pointer to the 'struct kunit' test context for the current test. ``real_fn_addr`` The address of the function to replace. ``replacement_addr`` The address of the function to replace it with. **Description** When activated, calls to real_fn_addr from within this test (even if called indirectly) will instead call replacement_addr. The function pointed to by real_fn_addr must begin with the static stub prologue in KUNIT_STATIC_STUB_REDIRECT() for this to work. real_fn_addr and replacement_addr must have the same type. The redirection can be disabled again with kunit_deactivate_static_stub().h](h)}(h**Parameters**h]j)}(hj!h]h Parameters}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKVhjubj)}(hhh](j)}(hL``test`` A pointer to the 'struct kunit' test context for the current test. h](j)}(h``test``h]jt)}(hj@h]htest}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jshj>ubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKShj:ubj)}(hhh]h)}(hBA pointer to the 'struct kunit' test context for the current test.h]hFA pointer to the ‘struct kunit’ test context for the current test.}(hjYhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjUhKShjVubah}(h]h ]h"]h$]h&]uh1jhj:ubeh}(h]h ]h"]h$]h&]uh1jhjUhKShj7ubj)}(h9``real_fn_addr`` The address of the function to replace. h](j)}(h``real_fn_addr``h]jt)}(hjyh]h real_fn_addr}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jshjwubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKThjsubj)}(hhh]h)}(h'The address of the function to replace.h]h'The address of the function to replace.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKThjubah}(h]h ]h"]h$]h&]uh1jhjsubeh}(h]h ]h"]h$]h&]uh1jhjhKThj7ubj)}(hE``replacement_addr`` The address of the function to replace it with. h](j)}(h``replacement_addr``h]jt)}(hjh]hreplacement_addr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKUhjubj)}(hhh]h)}(h/The address of the function to replace it with.h]h/The address of the function to replace it with.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKUhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKUhj7ubeh}(h]h ]h"]h$]h&]uh1jhjubh)}(h**Description**h]j)}(hjh]h Description}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKWhjubh)}(hX9When activated, calls to real_fn_addr from within this test (even if called indirectly) will instead call replacement_addr. The function pointed to by real_fn_addr must begin with the static stub prologue in KUNIT_STATIC_STUB_REDIRECT() for this to work. real_fn_addr and replacement_addr must have the same type.h]hX9When activated, calls to real_fn_addr from within this test (even if called indirectly) will instead call replacement_addr. The function pointed to by real_fn_addr must begin with the static stub prologue in KUNIT_STATIC_STUB_REDIRECT() for this to work. real_fn_addr and replacement_addr must have the same type.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKWhjubh)}(hJThe redirection can be disabled again with kunit_deactivate_static_stub().h]hJThe redirection can be disabled again with kunit_deactivate_static_stub().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhK]hjubeh}(h]h ] kernelindentah"]h$]h&]uh1jhjhhhNhNubj)}(hhh]h}(h]h ]h"]h$]h&]entries](j)kunit_deactivate_static_stub (C function)c.kunit_deactivate_static_stubhNtauh1jhjhhhNhNubj)}(hhh](j)}(hJvoid kunit_deactivate_static_stub (struct kunit *test, void *real_fn_addr)h]j)}(hIvoid kunit_deactivate_static_stub(struct kunit *test, void *real_fn_addr)h](hdesc_sig_keyword_type)}(hvoidh]hvoid}(hjChhhNhNubah}(h]h ]ktah"]h$]h&]uh1jAhj=hhht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKfubhdesc_sig_space)}(h h]h }(hjUhhhNhNubah}(h]h ]wah"]h$]h&]uh1jShj=hhhjRhKfubj%)}(hkunit_deactivate_static_stubh]j+)}(hkunit_deactivate_static_stubh]hkunit_deactivate_static_stub}(hjhhhhNhNubah}(h]h ]j6ah"]h$]h&]uh1j*hjdubah}(h]h ](j=j>eh"]h$]h&]hhuh1j$hj=hhhjRhKfubhdesc_parameterlist)}(h((struct kunit *test, void *real_fn_addr)h](hdesc_parameter)}(hstruct kunit *testh](hdesc_sig_keyword)}(hstructh]hstruct}(hjhhhNhNubah}(h]h ]kah"]h$]h&]uh1jhjubjT)}(h h]h }(hjhhhNhNubah}(h]h ]j`ah"]h$]h&]uh1jShjubh)}(hhh]j+)}(hkunith]hkunit}(hjhhhNhNubah}(h]h ]j6ah"]h$]h&]uh1j*hjubah}(h]h ]h"]h$]h&] refdomainjreftype identifier reftargetjmodnameN classnameN c:parent_keysphinx.domains.c LookupKey)}data]j ASTIdentifier)}jjjsbc.kunit_deactivate_static_stubasbuh1hhjubjT)}(h h]h }(hjhhhNhNubah}(h]h ]j`ah"]h$]h&]uh1jShjubhdesc_sig_punctuation)}(h*h]h*}(hjhhhNhNubah}(h]h ]pah"]h$]h&]uh1jhjubj+)}(htesth]htest}(hjhhhNhNubah}(h]h ]j6ah"]h$]h&]uh1j*hjubeh}(h]h ]h"]h$]h&]noemphhhuh1jhj~ubj)}(hvoid *real_fn_addrh](jB)}(hvoidh]hvoid}(hj hhhNhNubah}(h]h ]jNah"]h$]h&]uh1jAhjubjT)}(h h]h }(hjhhhNhNubah}(h]h ]j`ah"]h$]h&]uh1jShjubj)}(hjh]h*}(hj&hhhNhNubah}(h]h ]jah"]h$]h&]uh1jhjubj+)}(h real_fn_addrh]h real_fn_addr}(hj3hhhNhNubah}(h]h ]j6ah"]h$]h&]uh1j*hjubeh}(h]h ]h"]h$]h&]noemphhhuh1jhj~ubeh}(h]h ]h"]h$]h&]hhuh1j|hj=hhhjRhKfubeh}(h]h ]h"]h$]h&]hhjIuh1jjJjKhj9hhhjRhKfubah}(h]j4ah ](jOjPeh"]h$]h&]jTjU)jVhuh1jhjRhKfhj6hhubjX)}(hhh]h)}(hdisable a function redirectionh]hdisable a function redirection}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKfhjZhhubah}(h]h ]h"]h$]h&]uh1jWhj6hhhjRhKfubeh}(h]h ](jfunctioneh"]h$]h&]jijjjjujkjujljmjnuh1jhhhjhNhNubj)}(hX**Parameters** ``struct kunit *test`` A pointer to the 'struct kunit' test context for the current test. ``void *real_fn_addr`` The address of the function to no-longer redirect **Description** Deactivates a redirection configured with kunit_activate_static_stub(). After this function returns, calls to real_fn_addr() will execute the original real_fn, not any previously-configured replacement.h](h)}(h**Parameters**h]j)}(hjh]h Parameters}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj}ubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKjhjyubj)}(hhh](j)}(hZ``struct kunit *test`` A pointer to the 'struct kunit' test context for the current test. h](j)}(h``struct kunit *test``h]jt)}(hjh]hstruct kunit *test}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKghjubj)}(hhh]h)}(hBA pointer to the 'struct kunit' test context for the current test.h]hFA pointer to the ‘struct kunit’ test context for the current test.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKghjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKghjubj)}(hI``void *real_fn_addr`` The address of the function to no-longer redirect h](j)}(h``void *real_fn_addr``h]jt)}(hjh]hvoid *real_fn_addr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jshjubah}(h]h ]h"]h$]h&]uh1jht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKhhjubj)}(hhh]h)}(h1The address of the function to no-longer redirecth]h1The address of the function to no-longer redirect}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhKhhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjhKhhjubeh}(h]h ]h"]h$]h&]uh1jhjyubh)}(h**Description**h]j)}(hjh]h Description}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKjhjyubh)}(hDeactivates a redirection configured with kunit_activate_static_stub(). After this function returns, calls to real_fn_addr() will execute the original real_fn, not any previously-configured replacement.h]hDeactivates a redirection configured with kunit_activate_static_stub(). After this function returns, calls to real_fn_addr() will execute the original real_fn, not any previously-configured replacement.}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hht/var/lib/git/docbuild/linux/Documentation/dev-tools/kunit/api/functionredirection:161: ./include/kunit/static_stub.hhKjhjyubeh}(h]h ] kernelindentah"]h$]h&]uh1jhjhhhNhNubeh}(h] api-referenceah ]h"] api referenceah$]h&]uh1hhhhhhhhKubeh}(h]function-redirection-apiah ]h"]function redirection apiah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjqerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jKjHj'j$jjjCj@u nametypes}(jKj'jjCuh}(jHhj$hjj*j@jjjjjj4j9u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.