• 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

57.75
/trick_source/sim_services/MemoryManager/MemoryManager_restore.cpp
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <sstream>
5
#include <fstream>
6

7
#include "trick/MemoryManager.hh"
8
#include "trick/ClassicCheckPointAgent.hh"
9

10
int Trick::MemoryManager::set_restore_stls_default (bool on_off) {
×
11
    restore_stls_default = on_off;
×
12
    return 0;
×
13
}
14

15
int Trick::MemoryManager::read_checkpoint( std::istream *is, bool do_restore_stl) {
24✔
16

17
    ALLOC_INFO_MAP::iterator pos;
24✔
18
    ALLOC_INFO* alloc_info;
19

20
    if (debug_level) {
24✔
21
        std::cout << std::endl << "- Reading checkpoint." << std::endl;
1✔
22
        std::cout.flush();
1✔
23
    }
24

25
    if (currentCheckPointAgent->restore( is) !=0 ) {
24✔
26
       emitError("Checkpoint restore failed.") ;
×
27
    }
28

29

30
    // Search for stls and restore them
31
    if(do_restore_stl) {
24✔
32
        for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) {
1,262✔
33
            restore_stls(pos->second) ;
1,239✔
34
        }
35
    }
36

37
    // Go through all of the allocations that have been created looking
38
    // for those whose names start with the temporary-variable prefix and:
39
    pthread_mutex_lock(&mm_mutex);
24✔
40
    for ( pos=alloc_info_map.begin() ; pos!=alloc_info_map.end() ; pos++ ) {
448✔
41

42
        alloc_info = pos->second;
424✔
43

44

45
        if ( alloc_info->stcl == TRICK_LOCAL) {
424✔
46

47
            // If the temporary-variable prefix occurs at the beginning of the name ...
48
            if ( (alloc_info->name !=NULL) &&
141✔
49
                 ((strstr( alloc_info->name, local_anon_var_prefix)) == alloc_info->name )) {
83✔
50

51
                std::string name = alloc_info->name;
50✔
52

53
                // 1) Unregister the associated variable.
54
                variable_map.erase( name);
50✔
55

56
                // 2) free the name
57
                free( alloc_info->name);
50✔
58
                alloc_info->name = NULL;
50✔
59

60
            }
50✔
61
        }
62
    }
63
    pthread_mutex_unlock(&mm_mutex);
24✔
64
    return(0);
24✔
65
}
66

67
int Trick::MemoryManager::read_checkpoint( const char* filename, bool restore_stls ) {
11✔
68

69
    // Create a stream from the named file.
70
    std::ifstream infile(filename , std::ios::in);
11✔
71
    if (infile.is_open()) {
11✔
72
        return ( read_checkpoint( &infile, restore_stls )) ;
11✔
73
    } else {
74
        std::stringstream message;
×
75
        message << "Couldn't open \"" << filename << "\"." ;
×
76
        emitError(message.str());
×
77
    }
×
78
    return 1;
×
79
}
11✔
80

81
int Trick::MemoryManager::read_checkpoint_from_string(const char* s, bool restore_stls ) {
13✔
82

83
    // Create a stream from the string argument.
84
    std::stringstream ss;
13✔
85

86
    if ( s!= NULL) {
13✔
87
        ss << s;
13✔
88
        if ( ss.str().find(';') == std::string::npos ) {
13✔
89
            /* Unlike python, the old Trick input parser requires a semicolon
90
             * after each input file assignment command. Append one if missing.
91
             */
92
            ss << ";" ;
×
93
        }
94
        return ( read_checkpoint( &ss, restore_stls));
13✔
95
    } else {
96
        emitError("Checkpoint string is NULL.") ;
×
97
    }
98
    return 1;
×
99
}
13✔
100

101
int Trick::MemoryManager::init_from_checkpoint(const char* filename, bool restore_stls ) {
11✔
102

103
    if (debug_level) {
11✔
104
        std::cout << std::endl << "Initializing from checkpoint" << std::endl;
×
105
        std::cout << std::endl << "- Resetting managed memory." << std::endl;
×
106
        std::cout.flush();
×
107
    }
108

109
    reset_memory();
11✔
110

111
    if (debug_level) {
11✔
112
        std::cout << std::endl << "- Reading checkpoint." << std::endl;
×
113
        std::cout.flush();
×
114
    }
115

116
    read_checkpoint( filename, restore_stls);
11✔
117

118
    if (debug_level) {
11✔
119
        std::cout << std::endl << "Initialization from checkpoint finished." << std::endl;
×
120
        std::cout.flush();
×
121
    }
122

123
    return 0 ;
11✔
124
}
125

126
int Trick::MemoryManager::init_from_checkpoint( std::istream *is, bool restore_stls) {
×
127

128
    if (debug_level) {
×
129
        std::cout << std::endl << "Initializing from checkpoint" << std::endl;
×
130
        std::cout << std::endl << "- Resetting managed memory." << std::endl;
×
131
        std::cout.flush();
×
132
    }
133

134
    reset_memory();
×
135

136
    read_checkpoint( is, restore_stls );
×
137

138
    if (debug_level) {
×
139
        std::cout << std::endl << "Initialization from checkpoint finished." << std::endl;
×
140
        std::cout.flush();
×
141
    }
142

143
    return 0 ;
×
144
}
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