blob: 9e88861fb6d629e1241fea2f7aa1ad32ff6a219e (
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* 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.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** Thread-Metric Component */
/** */
/** Memory Allocation Test */
/** */
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* tm_memory_allocation_test PORTABLE C */
/* 6.1.7 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This file defines the Message exchange processing test. */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 10-15-2021 William E. Lamie Initial Version 6.1.7 */
/* */
/**************************************************************************/
#include "tm_api.h"
/* Define the counters used in the demo application... */
unsigned long tm_memory_allocation_counter;
/* Define the test thread prototypes. */
void tm_memory_allocation_thread_0_entry(void);
/* Define the reporting thread prototype. */
void tm_memory_allocation_thread_report(void);
/* Define the initialization prototype. */
void tm_memory_allocation_initialize(void);
/* Define main entry point. */
void tm_main()
{
/* Initialize the test. */
tm_initialize(tm_memory_allocation_initialize);
}
/* Define the memory allocation processing test initialization. */
void tm_memory_allocation_initialize(void)
{
/* Create thread 0 at priority 10. */
tm_thread_create(0, 10, tm_memory_allocation_thread_0_entry);
/* Resume thread 0. */
tm_thread_resume(0);
/* Create a memory pool. */
tm_memory_pool_create(0);
/* Create the reporting thread. It will preempt the other
threads and print out the test results. */
tm_thread_create(5, 2, tm_memory_allocation_thread_report);
tm_thread_resume(5);
}
/* Define the memory allocation processing thread. */
void tm_memory_allocation_thread_0_entry(void)
{
int status;
unsigned char *memory_ptr;
while(1)
{
/* Allocate memory from pool. */
tm_memory_pool_allocate(0, &memory_ptr);
/* Release the memory back to the pool. */
status = tm_memory_pool_deallocate(0, memory_ptr);
/* Check for invalid memory allocation/deallocation. */
if (status != TM_SUCCESS)
break;
/* Increment the number of memory allocations sent and received. */
tm_memory_allocation_counter++;
}
}
/* Define the memory allocation test reporting thread. */
void tm_memory_allocation_thread_report(void)
{
unsigned long last_counter;
unsigned long relative_time;
/* Initialize the last counter. */
last_counter = 0;
/* Initialize the relative time. */
relative_time = 0;
while(1)
{
/* Sleep to allow the test to run. */
tm_thread_sleep(TM_TEST_DURATION);
/* Increment the relative time. */
relative_time = relative_time + TM_TEST_DURATION;
/* Print results to the stdio window. */
printf("**** Thread-Metric Memory Allocation Test **** Relative Time: %lu\n", relative_time);
/* See if there are any errors. */
if (tm_memory_allocation_counter == last_counter)
{
printf("ERROR: Invalid counter value(s). Error allocating/deallocating memory!\n");
}
/* Show the time period total. */
printf("Time Period Total: %lu\n\n", tm_memory_allocation_counter - last_counter);
/* Save the last counter. */
last_counter = tm_memory_allocation_counter;
}
}
|