File indexing completed on 2025-05-11 08:24:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #include <rtems/test.h>
0038
0039 #include <rtems/score/heapimpl.h>
0040 #include <rtems/score/wkspace.h>
0041 #include <rtems/malloc.h>
0042
0043 typedef struct {
0044 Heap_Information_block heap_info;
0045 Heap_Information_block workspace_info;
0046 } T_resource_heap_context;
0047
0048 static T_resource_heap_context T_resource_heap_instance;
0049
0050 static void
0051 T_get_heap_info(Heap_Control *heap, Heap_Information_block *info)
0052 {
0053 _Heap_Get_information(heap, info);
0054 memset(&info->Stats, 0, sizeof(info->Stats));
0055 }
0056
0057 static void
0058 T_heap_run_initialize(void)
0059 {
0060 T_resource_heap_context *ctx;
0061
0062 ctx = &T_resource_heap_instance;
0063 T_get_heap_info(&_Workspace_Area, &ctx->workspace_info);
0064
0065 if (!rtems_configuration_get_unified_work_area()) {
0066 T_get_heap_info(RTEMS_Malloc_Heap, &ctx->heap_info);
0067 }
0068 }
0069
0070 static void
0071 T_heap_case_end(void)
0072 {
0073 T_resource_heap_context *ctx;
0074 Heap_Information_block info;
0075 bool ok;
0076
0077 ctx = &T_resource_heap_instance;
0078
0079 T_get_heap_info(&_Workspace_Area, &info);
0080 ok = memcmp(&info, &ctx->workspace_info, sizeof(info)) == 0;
0081
0082 if (!ok) {
0083 const char *where;
0084
0085 if (rtems_configuration_get_unified_work_area()) {
0086 where = "workspace or heap";
0087 } else {
0088 where = "workspace";
0089 }
0090
0091 T_check(&T_special, ok, "memory leak in %s", where);
0092 memcpy(&ctx->workspace_info, &info, sizeof(info));
0093 }
0094
0095 if (!rtems_configuration_get_unified_work_area()) {
0096 T_get_heap_info(RTEMS_Malloc_Heap, &info);
0097 ok = memcmp(&info, &ctx->heap_info, sizeof(info)) == 0;
0098
0099 if (!ok) {
0100 T_check(&T_special, ok, "memory leak in heap");
0101 memcpy(&ctx->heap_info, &info, sizeof(info));
0102 }
0103 }
0104 }
0105
0106 void
0107 T_check_heap(T_event event, const char *name)
0108 {
0109 (void)name;
0110
0111 switch (event) {
0112 case T_EVENT_RUN_INITIALIZE_EARLY:
0113 T_heap_run_initialize();
0114 break;
0115 case T_EVENT_CASE_END:
0116 T_heap_case_end();
0117 break;
0118 default:
0119 break;
0120 };
0121 }