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

nasa / trick / 25456501308

06 May 2026 07:29PM UTC coverage: 55.935% (-0.8%) from 56.7%
25456501308

Pull #2011

github

web-flow
Merge 7ad262960 into 7054e405e
Pull Request #2011: Single-file CI and code style adoption

14612 of 26123 relevant lines covered (55.94%)

462107.16 hits per line

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

82.86
/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.") ;
×
19
        return;
×
20
    }
21

22
    for (int ii = 0; attr_list[ii].name[0] != '\0'; ii++) {
63,799✔
23

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

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

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

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

53
    if (attr == NULL) {
4,566✔
54
        emitError("write_array_var: attr_list = NULL.") ;
×
55
        return;
×
56
    }
57

58
    int array_element_count = attr->index[curr_dim].size;
4,566✔
59

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

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

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

95
// MEMBER FUNCTION
96
void Trick::MemoryManager::write_var(std::ostream& out_s, void* address, ATTRIBUTES* attr) {
62,987✔
97

98
    if (attr->num_index > 0) {
62,987✔
99
        // This is an arrayed object.
100
        write_array_var( out_s, (char*)address, attr, 0, 0) ;
3,546✔
101
    } else {
102
        // This is not an arrayed object.
103
        if ( attr->type == TRICK_STRUCTURED ) {
59,441✔
104
            // This is a composite object.
105
            write_composite_var( out_s, (char*)address, (ATTRIBUTES*)(attr->attr)) ;
1,457✔
106
        } else {
107
            // This is a primitive object.
108
            currentCheckPointAgent->assign_rvalue( out_s, address, attr, 0, 0);
57,984✔
109
        }
110
    }
111
}
62,987✔
112

113
// MEMBER FUNCTION
114
void Trick::MemoryManager::write_var(std::ostream& out_s, ALLOC_INFO* alloc_info ) {
3,170✔
115

116
    ATTRIBUTES* reference_attr;
117
    reference_attr = make_reference_attr( alloc_info);
3,170✔
118

119
    // Push the basename onto the left-side name stack.
120
    currentCheckPointAgent->push_basename( alloc_info->name);
3,170✔
121

122
    write_var(out_s, (char*)(alloc_info->start), reference_attr);
3,170✔
123

124
    // Pop the basename that we pushed above.
125
    currentCheckPointAgent->pop_elem(); // Pop basename.
3,170✔
126

127
    free_reference_attr( reference_attr);
3,170✔
128
}
3,170✔
129

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

133
    VARIABLE_MAP::iterator pos;
1✔
134
    ALLOC_INFO *alloc_info;
135

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

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

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

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

157
    if (alloc_info != NULL) {
17✔
158
        write_var( out_s, alloc_info );
17✔
159
    } else {
160
        std::stringstream message;
×
161
        message << "write_var(" << address << ") failed. No such variable is being managed.";
×
162
        emitError(message.str());
×
163
    }
×
164
    pthread_mutex_unlock(&mm_mutex);
17✔
165
}
17✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc