• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 43336118544

13 Nov 2026 12:19AM UTC coverage: 57.196% (+0.2%) from 57.005%
43336118544

Pull #2278

github

web-flow
Merge fa86b4180 into ed6bbea72
Pull Request #2278: feat: Add TMM/MM calls for determining whether any errors while writing a checkpoint

101 of 155 new or added lines in 9 files covered. (65.16%)

15 existing lines in 5 files now uncovered.

15122 of 26439 relevant lines covered (57.2%)

966474.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.7
/trick_source/sim_services/MemoryManager/MemoryManager_alloc_depends.cpp
1
#include "trick/MemoryManager.hh"
2
#include "trick/attributes.h"
3

4
// MEMBER FUNCTION
5
void Trick::MemoryManager::get_alloc_deps_in_allocation(ALLOC_INFO* alloc_info ) {
206 ✔
6

7
    ATTRIBUTES* reference_attr;
8

9
    bool found = false;
206 ✔
10
    int n_depends = dependencies.size();
206 ✔
11

12
    if (debug_level > 1) {
206 ✔
13
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
×
14
    }
15

16
    if (alloc_info == NULL) {
206 ✔
17
        std::cerr << "ERROR: Trick::MemoryManager::get_alloc_deps_in_allocation called with alloc_info == NULL." << std::endl;
×
NEW
18
        checkpoint_write_success = false;
×
19
        std::cout.flush();
×
20
        return;
×
21
    }
22

23
    if (debug_level > 1) {
206 ✔
24
        debug_write_alloc_info(alloc_info);
×
25
    }
26

27
    if (debug_level) {
206 ✔
28
        std::cout << __FUNCTION__ << ": Allocation @" << (void*)alloc_info->start ;
×
29
        if (alloc_info->name != NULL) {
×
30
            std::cout << " is named \"" << alloc_info->name << "\"." << std::endl;
×
31
        } else {
32
            std::cout << " is anonymous." << std::endl;
×
33
        }
34
    }
35

36
    std::cout.flush();
206 ✔
37

38
    for (int ii = 0 ; ii < n_depends ; ii ++) {
416 ✔
39
        if (alloc_info == dependencies[ii]) {
214 ✔
40
            found = true;
4 ✔
41
            if (debug_level) {
4 ✔
42
                std::cout << __FUNCTION__ << ": Dependencies of allocation @"<< (void*)alloc_info->start <<" are already known." << std::endl;
×
43
            }
44
            return;
4 ✔
45
        }
46
    }
47

48
    if (!found) {
202 ✔
49

50
        if (debug_level) {
202 ✔
51
            std::cout << __FUNCTION__ <<  ": Begin scan of allocation @" << (void*)alloc_info->start << " for dependencies." << std::endl;
×
52
        }
53

54
        // The allocation is dependent upon itself.
55
        dependencies.push_back(alloc_info);
202 ✔
56

57
        reference_attr = make_reference_attr( alloc_info);
202 ✔
58

59
        // Get the dependencies of the allocation
60
        if (alloc_info->type == TRICK_STRUCTURED) {
202 ✔
61
            if (reference_attr->num_index > 0) {
82 ✔
62
                get_alloc_deps_in_arrayed_class( (char*)(alloc_info->start), reference_attr, 0, 0) ;
20 ✔
63
            } else {
64
                get_alloc_deps_in_class( (char*)(alloc_info->start), alloc_info->attr) ;
62 ✔
65
            }
66
        } else {
67
            get_alloc_deps_in_intrinsic( alloc_info->start, reference_attr, 0, 0 );
120 ✔
68
        }
69

70
        if (debug_level) {
202 ✔
71
            std::cout <<  __FUNCTION__ << ": End scan of allocation @" << (void*)alloc_info->start << "." << std::endl;
×
72
        }
73

74
        free_reference_attr( reference_attr);
202 ✔
75
    }
76

77
}
78

79
// MEMBER FUNCTION
80
void Trick::MemoryManager::get_alloc_deps_in_allocation( const char* var_name ) {
116 ✔
81

82
    VARIABLE_MAP::iterator pos;
116 ✔
83
    ALLOC_INFO *alloc_info;
84

85
    if (debug_level > 1) {
116 ✔
86
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
×
87
    }
88

89
    pos = variable_map.find( var_name);
232 ✔
90

91
    if (pos != variable_map.end()) {
116 ✔
92
        alloc_info = pos->second;
114 ✔
93
        get_alloc_deps_in_allocation( alloc_info );
114 ✔
94
    } else {
95
        std::cerr << "ERROR: get_alloc_deps_in_allocation(\""<< var_name
96
                  <<"\") failed because the given name is'nt known by the MemoryManager."
2 ✔
97
                  << std::endl;
2 ✔
98
        std::cerr.flush();
2 ✔
99
        checkpoint_write_success = false;
2 ✔
100
    }
101
}
116 ✔
102

103

104
// MEMBER FUNCTION
105
void Trick::MemoryManager::get_alloc_deps_in_class( char* address, ATTRIBUTES* attr) {
108 ✔
106
    int ii;
107

108
    if (debug_level > 1) {
108 ✔
109
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
×
110
    }
111

112
    if (attr == NULL) {
108 ✔
113
        std::cerr << "ERROR: Trick::MemoryManager::get_alloc_deps_in_class called with attr = NULL." << std::endl;
×
NEW
114
        checkpoint_write_success = false;
×
UNCOV
115
        return;
×
116
    }
117

118
    for (ii = 0; attr[ii].name[0] != '\0'; ii++) {
432 ✔
119
        if (currentCheckPointAgent->output_perm_check(&attr[ii])) {
324 ✔
120
            char *elem_addr;
121
            if (attr[ii].mods & 2) {
316 ✔
122
                elem_addr = (char *) attr[ii].offset;
×
123
            } else {
124
                elem_addr = address + attr[ii].offset;
316 ✔
125
            }
126

127
            if (attr[ii].type == TRICK_STRUCTURED) {
316 ✔
128
                if (attr[ii].num_index != 0) {
70 ✔
129
                    get_alloc_deps_in_arrayed_class( elem_addr, &attr[ii], 0, 0);
70 ✔
130
                } else {
131
                    get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)(attr[ii].attr));
×
132
                }
133
            } else {
134
                get_alloc_deps_in_intrinsic( elem_addr, &(attr[ii]), 0, 0);
246 ✔
135
            }
136
        }
137
    }
138
}
139

140
// MEMBER FUNCTION
141
void Trick::MemoryManager::get_alloc_deps_in_arrayed_class(
100 ✔
142
                                                char*       address,
143
                                                ATTRIBUTES* attr,
144
                                                int         curr_dim,
145
                                                int         offset) {
146
    int ii;
147

148
    if (debug_level > 1) {
100 ✔
149
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
×
150
    }
151

152
    if (attr == NULL) {
100 ✔
153
        std::cerr << "Trick::MemoryManager::get_alloc_deps_in_arrayed_class: ERROR: attr = NULL." << std::endl;
×
NEW
154
        checkpoint_write_success = false;
×
UNCOV
155
        return;
×
156
    }
157

158
    if (attr->index[curr_dim].size == 0) {
100 ✔
159

160
        void* pointer = *(void**)((char*)address + offset * sizeof(void*));
80 ✔
161

162
        if (pointer != NULL) {
80 ✔
163
            ALLOC_INFO *alloc_info;
164
            alloc_info = get_alloc_info_of( pointer);
36 ✔
165
            if (alloc_info != NULL) {
36 ✔
166

167
                if (debug_level) {
36 ✔
168
                    std::cout << __FUNCTION__ << ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl;
×
169
                }
170
                get_alloc_deps_in_allocation(alloc_info);
36 ✔
171
            } else {
172
                if (debug_level) {
×
173
                    std::cout << __FUNCTION__ << ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl;
×
174
                    std::cout.flush();
×
175
                }
176
            }
177
        } else {
178
            if (debug_level) {
44 ✔
179
                std::cout << __FUNCTION__ << ": Allocation reference is NULL." << std::endl;
×
180
                std::cout.flush();
×
181
            }
182
        }
183

184
    } else {
185
        int curr_dim_size;
186
        curr_dim_size = attr->index[curr_dim].size;
20 ✔
187
        for (ii = 0; ii < curr_dim_size; ii++) {
76 ✔
188
            if (curr_dim < attr->num_index - 1) {
56 ✔
189
                get_alloc_deps_in_arrayed_class( address, attr, curr_dim + 1, offset * curr_dim_size + ii);
10 ✔
190
            } else {
191
                char* elem_addr;
192
                elem_addr = address + (offset * curr_dim + ii) * attr->size ;
46 ✔
193
                get_alloc_deps_in_class( elem_addr, (ATTRIBUTES*)attr->attr );
46 ✔
194
            }
195
        }
196
    }
197
}
198

199

200
// MEMBER FUNCTION
201
void Trick::MemoryManager::get_alloc_deps_in_intrinsic( void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
3,104 ✔
202

203
    if (debug_level > 1) {
3,104 ✔
204
          std::cout << "DEBUG: Entered function:" <<  __FUNCTION__ << std::endl;
×
205
    }
206

207
    // If the variable that we are pointing to is an arrayed
208
    if (curr_dim < attr->num_index) {
3,104 ✔
209

210
        // If it is an unconstrained array (a pointer)
211
        if (attr->index[curr_dim].size == 0) {
712 ✔
212

213
            void* pointer = *(void**)((char*)address + offset * sizeof(void*));
148 ✔
214

215
            if (pointer != NULL) {
148 ✔
216
                ALLOC_INFO *alloc_info;
217
                alloc_info = get_alloc_info_of( pointer);
60 ✔
218
                if (alloc_info != NULL) {
60 ✔
219
                    if (debug_level) {
56 ✔
220
                        std::cout << __FUNCTION__ <<  ": @" << (void*)address << "." << attr->name << "[" << offset << "] points to @" << (void*)pointer << std::endl;
×
221
                    }
222
                    get_alloc_deps_in_allocation(alloc_info);
56 ✔
223
                } else {
224
                    if (debug_level) {
4 ✔
225
                        std::cout << __FUNCTION__ <<  ": Pointer ("<< (void*)pointer <<") refers to memory that the MemoryManager doesn't know about." << std::endl;
×
226
                        std::cout.flush();
×
227
                    }
228
                }
229
            } else {
230
                if (debug_level) {
88 ✔
231
                    std::cout << __FUNCTION__ <<  ": Allocation reference is NULL." << std::endl;
×
232
                    std::cout.flush();
×
233
                }
234
            }
235

236
        } else { // otherwise its a constrained array.
237
            int ii;
238
            for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) {
3,302 ✔
239
                get_alloc_deps_in_intrinsic( address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
2,738 ✔
240
            }
241
        }
242
    }
243
}
3,104 ✔
244

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc