summaryrefslogtreecommitdiff
path: root/test/tx/module_manager/threadx_module_manager_host_test_port.h
blob: 36607d20624d4d93a63eae42a7309fe5dabc6614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***************************************************************************
 * Copyright (c) 2026 Eclipse ThreadX contributors
 * 
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 * 
 * AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5).
 * The AI-generated portions may be considered public domain (CC0-1.0)
 * and not subject to the project's licence. The human contributor has
 * reviewed and verified that the code is correct.
 * 
 * SPDX-License-Identifier: MIT and CC0-1.0
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** ThreadX Test                                                          */
/**                                                                       */
/**   Module Manager host test port shim                                  */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/* The Module Manager is not in the ThreadX library this test tree builds, and its
   control blocks come from a module port rather than a base port, so the manager
   sources under test are compiled directly against one module port's headers. Every
   module port is an embedded architecture, and their interrupt primitives are
   inline assembly for that architecture, which the host assembler cannot take.

   This header is force-included ahead of each manager source under test. It brings
   the port's headers in first, so every declaration the source needs is the port's
   own, and then replaces the three interrupt primitives with host equivalents that
   count instead of executing. Counting is not only what makes them portable: a test
   can assert that a source under test left the interrupt lock balanced, and that a
   section which has to run with interrupts disabled did so.  */

#ifndef THREADX_MODULE_MANAGER_HOST_TEST_PORT_H
#define THREADX_MODULE_MANAGER_HOST_TEST_PORT_H

#define TX_SOURCE_CODE

#include "tx_api.h"

#undef TX_INTERRUPT_SAVE_AREA
#undef TX_DISABLE
#undef TX_RESTORE

/* Nesting depth of the stand-in interrupt lock, and the deepest it has ever been.
   Defined by the test, which is the only translation unit that reads them.  */
extern unsigned int test_interrupt_disable_depth;
extern unsigned int test_interrupt_disable_max_depth;
extern unsigned int test_interrupt_restore_underflows;

#define TX_INTERRUPT_SAVE_AREA

#define TX_DISABLE                                                          \
    {                                                                       \
        test_interrupt_disable_depth++;                                     \
        if (test_interrupt_disable_depth > test_interrupt_disable_max_depth) \
        {                                                                   \
            test_interrupt_disable_max_depth = test_interrupt_disable_depth; \
        }                                                                   \
    }

#define TX_RESTORE                                                          \
    {                                                                       \
        if (test_interrupt_disable_depth == 0U)                             \
        {                                                                   \
            test_interrupt_restore_underflows++;                            \
        }                                                                   \
        else                                                                \
        {                                                                   \
            test_interrupt_disable_depth--;                                 \
        }                                                                   \
    }

#endif