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

nasa / trick / 42885317078

10 Nov 2026 07:26PM UTC coverage: 57.02% (+0.02%) from 57.005%
42885317078

Pull #2278

github

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

20 of 58 new or added lines in 7 files covered. (34.48%)

14 existing lines in 4 files now uncovered.

15022 of 26345 relevant lines covered (57.02%)

467325.91 hits per line

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

80.56
/trick_source/sim_services/MemoryManager/MemoryManager_write_var.cpp
1
#include <fstream>
2
#include <sstream>
3
#include <string.h>
4
#include "trick/MemoryManager.hh"
5

6
// GreenHills stuff
7
#if ( __ghs )
8
#include "ghs_stubs.h"
9
#endif
10

11

12
// MEMBER FUNCTION
13
void Trick::MemoryManager::write_composite_var( std::ostream& out_s,
3,890 ✔
14
                                                void*         address,
15
                                                ATTRIBUTES*   attr_list) {
16

17
    if (attr_list == NULL) {
3,890 ✔
18
        emitError("write_composite_var: attr_list = NULL.") ;
×
NEW
19
        checkpoint_write_success = false;
×
UNCOV
20
        return;
×
21
    }
22

23
    for (int ii = 0; attr_list[ii].name[0] != '\0'; ii++) {
66,123 ✔
24

25
        // If it's permitted to output the data type described by this ATTRIBUTE ...
26
        if (currentCheckPointAgent->output_perm_check(&attr_list[ii])) {
62,233 ✔
27
            void *elem_addr;
28
            if (attr_list[ii].mods & 2) { // This is a static member variable.
62,124 ✔
29
                elem_addr = (void*)attr_list[ii].offset;
17 ✔
30
            } else { // This is a normal member variable.
31
                elem_addr = (char*)address + (size_t)attr_list[ii].offset;
62,107 ✔
32
            }
33
            // Push the element name onto the name stack.
34
            currentCheckPointAgent->push_struct_elem( attr_list[ii].name);
62,124 ✔
35

36
            // Write the one or more assignment statements that represent the
37
            // values in this variable.
38
            write_var(out_s, elem_addr, &(attr_list[ii]));
62,124 ✔
39

40
            // Pop the element name from the name stack.
41
            currentCheckPointAgent->pop_elem();
62,124 ✔
42
        }
43
    }
44
    return;
3,890 ✔
45
}
46

47
// MEMBER FUNCTION
48
void Trick::MemoryManager::write_array_var( std::ostream& out_s,
4,572 ✔
49
                                            void*         address,
50
                                            ATTRIBUTES*   attr,
51
                                            int           curr_dim,
52
                                            int           offset) {
53

54
    if (attr == NULL) {
4,572 ✔
55
        emitError("write_array_var: attr_list = NULL.") ;
×
NEW
56
        checkpoint_write_success = false;
×
UNCOV
57
        return;
×
58
    }
59

60
    int array_element_count = attr->index[curr_dim].size;
4,572 ✔
61

62
    if (array_element_count == 0) { // This is a pointer (a.k.a: an unconstrained array).
4,572 ✔
63
        currentCheckPointAgent->assign_rvalue( out_s, address, attr, curr_dim, offset);
1,808 ✔
64
    } else { // This is a contrained array.
65

66
        // If this is an array of primitive-types and the user has not requested that we
67
        // write array in the expanded form  then write them more compactly.
68
        if ( (attr->type != TRICK_STRUCTURED ) && (expanded_arrays == false)) {
2,764 ✔
69
            currentCheckPointAgent->assign_rvalue( out_s, address, attr, 0, 0 );
2,550 ✔
70
        } else {
71

72
            // For each of the elements in the array ...
73
            for (int ii = 0; ii < array_element_count; ii++) {
3,681 ✔
74
                // Push the element index onto the name stack.
75
                currentCheckPointAgent->push_array_elem(ii);
3,467 ✔
76
                // If the current dimension is not the final dimension ...
77
                if (curr_dim < attr->num_index - 1) {
3,467 ✔
78
                    // The element itself is an array.
79
                    write_array_var( out_s, address, attr, curr_dim + 1, offset * array_element_count + ii);
1,020 ✔
80
                } else {
81
                    // The element itself is not an array.
82
                    if (attr->type == TRICK_STRUCTURED) { // The element is a composite.
2,447 ✔
83
                        char* elem_addr = (char*)address + (offset * array_element_count + ii) * attr->size ;
2,432 ✔
84
                        write_composite_var( out_s, elem_addr, (ATTRIBUTES*)attr->attr );
2,432 ✔
85
                    } else { // The element is a primitive.
86
                        int elem_offset = offset * array_element_count + ii;
15 ✔
87
                        currentCheckPointAgent->assign_rvalue( out_s, address, attr, curr_dim+1, elem_offset);
15 ✔
88
                    }
89
                }
90
                // Pop the element index back off of the name stack.
91
                currentCheckPointAgent->pop_elem();
3,467 ✔
92
            }
93
        }
94
    }
95
}
96

97
// MEMBER FUNCTION
98
void Trick::MemoryManager::write_var(std::ostream& out_s, void* address, ATTRIBUTES* attr) {
65,301 ✔
99

100
    if (attr->num_index > 0) {
65,301 ✔
101
        // This is an arrayed object.
102
        write_array_var( out_s, (char*)address, attr, 0, 0) ;
3,552 ✔
103
    } else {
104
        // This is not an arrayed object.
105
        if ( attr->type == TRICK_STRUCTURED ) {
61,749 ✔
106
            // This is a composite object.
107
            write_composite_var( out_s, (char*)address, (ATTRIBUTES*)(attr->attr)) ;
1,457 ✔
108
        } else {
109
            // This is a primitive object.
110
            currentCheckPointAgent->assign_rvalue( out_s, address, attr, 0, 0);
60,292 ✔
111
        }
112
    }
113
}
65,301 ✔
114

115
// MEMBER FUNCTION
116
void Trick::MemoryManager::write_var(std::ostream& out_s, ALLOC_INFO* alloc_info ) {
3,177 ✔
117

118
    ATTRIBUTES* reference_attr;
119
    reference_attr = make_reference_attr( alloc_info);
3,177 ✔
120

121
    // Push the basename onto the left-side name stack.
122
    currentCheckPointAgent->push_basename( alloc_info->name);
3,177 ✔
123

124
    write_var(out_s, (char*)(alloc_info->start), reference_attr);
3,177 ✔
125

126
    // Pop the basename that we pushed above.
127
    currentCheckPointAgent->pop_elem(); // Pop basename.
3,177 ✔
128

129
    free_reference_attr( reference_attr);
3,177 ✔
130
}
3,177 ✔
131

132
// MEMBER FUNCTION
133
void Trick::MemoryManager::write_var( std::ostream& out_s, const char* var_name ) {
1 ✔
134

135
    VARIABLE_MAP::iterator pos;
1 ✔
136
    ALLOC_INFO *alloc_info;
137

138
    pthread_mutex_lock(&mm_mutex);
1 ✔
139
    pos = variable_map.find( var_name);
2 ✔
140

141
    if (pos != variable_map.end()) {
1 ✔
142
        alloc_info = pos->second;
1 ✔
143
        write_var( out_s, alloc_info );
1 ✔
144
    } else {
145
        std::stringstream message;
×
146
        message << "write_var(\"" << var_name << "\") failed. No such variable is being managed.";
×
147
        emitError(message.str());
×
148
    }
×
149
    pthread_mutex_unlock(&mm_mutex);
1 ✔
150
}
1 ✔
151

152
// MEMBER FUNCTION
153
void Trick::MemoryManager::write_var( std::ostream& out_s, void* address) {
17 ✔
154

155
    ALLOC_INFO *alloc_info;
156
    pthread_mutex_lock(&mm_mutex);
17 ✔
157
    alloc_info = get_alloc_info_of( address);
17 ✔
158

159
    if (alloc_info != NULL) {
17 ✔
160
        write_var( out_s, alloc_info );
17 ✔
161
    } else {
162
        std::stringstream message;
×
163
        message << "write_var(" << address << ") failed. No such variable is being managed.";
×
164
        emitError(message.str());
×
165
    }
×
166
    pthread_mutex_unlock(&mm_mutex);
17 ✔
167
}
17 ✔
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