summaryrefslogtreecommitdiff
path: root/test/smp/regression/threadx_smp_execution_profile_get_test.c
blob: ccfd3b2a49f79f3393fe2eaffa0780a6238c3fbb (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
 * 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 Codex (GPT-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
 **************************************************************************/

/* This test verifies that the SMP execution profile aggregate getters copy every core value.  */

#include <stdio.h>
#include "tx_api.h"
#include "tx_execution_profile.h"

extern EXECUTION_TIME             _tx_execution_thread_time_total[TX_THREAD_SMP_MAX_CORES];
extern EXECUTION_TIME             _tx_execution_isr_time_total[TX_THREAD_SMP_MAX_CORES];
extern EXECUTION_TIME             _tx_execution_idle_time_total[TX_THREAD_SMP_MAX_CORES];

ULONG                            _tx_thread_system_state[TX_THREAD_SMP_MAX_CORES];
UINT                             _tx_thread_preempt_disable;
TX_THREAD                        *_tx_thread_current_ptr[TX_THREAD_SMP_MAX_CORES];
TX_THREAD                        *_tx_thread_execute_ptr[TX_THREAD_SMP_MAX_CORES];
TX_THREAD                        *_tx_thread_created_ptr;
ULONG                            _tx_thread_created_count;


ULONG _tx_thread_smp_time_get(void)
{

    return(0);
}


static UINT verify_time_values(EXECUTION_TIME *actual, EXECUTION_TIME *expected)
{

UINT    core;


    for (core = 0; core < TX_THREAD_SMP_MAX_CORES; core++)
    {

        if (actual[core] != expected[core])
        {

            return(1);
        }
    }

    return(0);
}


int main(void)
{

EXECUTION_TIME    thread_time[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME    isr_time[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME    idle_time[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME    expected_thread_time[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME    expected_isr_time[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME    expected_idle_time[TX_THREAD_SMP_MAX_CORES];
UINT              core;
UINT              status;


    printf("Running SMP Execution Profile Get Test............................... ");

    for (core = 0; core < TX_THREAD_SMP_MAX_CORES; core++)
    {

        expected_thread_time[core] =  ((EXECUTION_TIME) 1000U) + ((EXECUTION_TIME) core);
        expected_isr_time[core] =     ((EXECUTION_TIME) 2000U) + ((EXECUTION_TIME) core);
        expected_idle_time[core] =    ((EXECUTION_TIME) 3000U) + ((EXECUTION_TIME) core);

        _tx_execution_thread_time_total[core] =  expected_thread_time[core];
        _tx_execution_isr_time_total[core] =     expected_isr_time[core];
        _tx_execution_idle_time_total[core] =    expected_idle_time[core];

        thread_time[core] =  0xFFFFFFFFFFFFFFFFULL;
        isr_time[core] =     0xFFFFFFFFFFFFFFFFULL;
        idle_time[core] =    0xFFFFFFFFFFFFFFFFULL;
    }

    status =  _tx_execution_thread_total_time_get(thread_time);
    status += _tx_execution_isr_time_get(isr_time);
    status += _tx_execution_idle_time_get(idle_time);

    if (status != TX_SUCCESS)
    {

        printf("ERROR #1\n");
        return(1);
    }

    if (verify_time_values(thread_time, expected_thread_time) != 0U)
    {

        printf("ERROR #2\n");
        return(1);
    }

    if (verify_time_values(isr_time, expected_isr_time) != 0U)
    {

        printf("ERROR #3\n");
        return(1);
    }

    if (verify_time_values(idle_time, expected_idle_time) != 0U)
    {

        printf("ERROR #4\n");
        return(1);
    }

    printf("SUCCESS!\n");
    return(0);
}