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

nasa / trick / 28043519565

23 Jun 2026 05:13PM UTC coverage: 56.232% (+0.1%) from 56.126%
28043519565

Pull #2154

github

web-flow
Merge 87d8bac31 into 4a137dd0c
Pull Request #2154: Add data recording support for STL (vector, deque, and array) of supported data types.

120 of 145 new or added lines in 5 files covered. (82.76%)

2 existing lines in 1 file now uncovered.

14722 of 26181 relevant lines covered (56.23%)

481357.37 hits per line

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

92.54
/trick_source/sim_services/DataRecord/DRBinary.cpp
1
/*
2
PURPOSE:
3
    (Data record to disk in binary format.)
4
PROGRAMMERS:
5
     (((Robert W. Bailey) (LinCom Corp) (3/96) (SES upgrades)
6
     ((Alex Lin) (NASA) (April 2009) (--) (c++ port)))
7
*/
8

9
#include "trick/DRBinary.hh"
10

11
#include "trick/ReferenceUtils.hh"
12
#include "trick/bitfield_proto.h"
13
#include "trick/command_line_protos.h"
14
#include "trick/memorymanager_c_intf.h"
15

16
#include <fcntl.h>
17
#include <iostream>
18
#include <stdlib.h>
19
#include <string.h>
20
#include <sys/stat.h>
21
#include <unistd.h>
22

23
/*
24
   Other classes inherit from DRBinary. In these cases, we don't want to register the memory as DRBinary,
25
   so register_group will be set to false.
26
*/
27
Trick::DRBinary::DRBinary( std::string in_name, bool register_group, Trick::DR_Type dr_type ) : Trick::DataRecordGroup(in_name, dr_type) {
586✔
28
    if ( register_group ) {
586✔
29
        register_group_with_mm(this, "Trick::DRBinary") ;
17✔
30
    }
31
}
586✔
32

33
int Trick::DRBinary::format_specific_header( std::fstream & out_stream ) {
23✔
34
    out_stream << " byte_order is " << byte_order << std::endl ;
23✔
35
    return(0) ;
23✔
36
}
37

38
/**
39
@details
40
-# Set the file extension to ".trk"
41
-# Allocate enough memory to hold #record_size of records in memory
42
-# Open the log file
43
   -# Return an error if the open failed
44
-# Write out the magic Trick-07-[LB] keyword, L for little endian, B for big.
45
-# Write out the number of variables recorded
46
-# For each variable to be recorded
47
   -# Write out the name
48
   -# Write out the units
49
   -# Write out the type
50
   -# Write out the size
51
-# Declare the recording group to the memory manager so that the group can be checkpointed
52
   and restored
53
*/
54
int Trick::DRBinary::format_specific_init() {
23✔
55

56
    unsigned int jj ;
57
    int write_value ;
58
    /* number of bytes written to data record */
59
    int bytes = 0 ;
23✔
60

61
    union {
62
        long l;
63
        char c[sizeof(long)];
64
    } byte_order_union;
65

66
    file_name.append(".trk");
23✔
67

68
    /* Calculate a "worst case" for space used for 1 record. */
69
    writer_buff = (char *)calloc(1 , record_size * rec_buffer.size()) ;
23✔
70

71
    /* This loop touches all of the memory locations in the allocation forcing the
72
       system to actually do the allocation */
73
    for ( jj= 0 ; jj < record_size * rec_buffer.size() ; jj += 1024 ) {
49✔
74
        writer_buff[jj] = 1 ;
26✔
75
    }
76
    writer_buff[record_size * rec_buffer.size() - 1] = 1 ;
23✔
77

78
    /* start header information in trk file */
79
    if ((fd = creat(file_name.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) == -1) {
23✔
80
        record = false ;
×
81
        return (-1) ;
×
82
    }
83

84

85
    /* Check to see if data is being recorded in little endian
86
     * byte order, and add little endian line if so.
87
     */
88
    byte_order_union.l = 1 ;
23✔
89
    if (byte_order_union.c[sizeof(long)-1] != 1) {
23✔
90
        bytes += write( fd , "Trick-10-L", (size_t)10 ) ;
23✔
91
        
92
    } else {
93
        bytes += write( fd , "Trick-10-B", (size_t)10 ) ;
×
94
    }
95
    write_value = rec_buffer.size() ;
23✔
96
    bytes += write( fd , &write_value , sizeof(int) ) ;
23✔
97

98
    for (jj = 0; jj < rec_buffer.size(); jj++) {
464✔
99
        /* name */
100
        write_value = strlen(rec_buffer[jj]->ref->reference) ;
441✔
101
        bytes += write( fd , &write_value , sizeof(int)) ;
441✔
102
        bytes += write( fd , rec_buffer[jj]->ref->reference , write_value ) ;
441✔
103

104
        /* units */
105
        if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) {
441✔
106
            write_value = strlen("--") ;
4✔
107
            bytes += write( fd , &write_value , sizeof(int)) ;
4✔
108
            bytes += write( fd , "--" , write_value ) ;
4✔
109
        } else {
110
            write_value = strlen(rec_buffer[jj]->ref->attr->units) ;
437✔
111
            bytes += write( fd , &write_value , sizeof(int)) ;
437✔
112
            bytes += write( fd , rec_buffer[jj]->ref->attr->units , write_value ) ;
437✔
113
        }
114

115
        write_value  = (int)Trick::ReferenceUtils::effective_trick_type(rec_buffer[jj]->ref);
441✔
116
        bytes += write( fd , &write_value , sizeof(int)) ;
441✔
117

118
        write_value  = (int)Trick::ReferenceUtils::effective_trick_size(rec_buffer[jj]->ref);
441✔
119
        bytes       += write(fd, &write_value, sizeof(int));
441✔
120
    }
121
    total_bytes_written += bytes;
23✔
122
    return(0) ;
23✔
123
}
124

125
/**
126
@details
127
-# While there is data in memory that has not been written to disk
128
   -# Write out each of the other parameter values to the temporary #writer_buff
129
   -# Write #writer_buff to the output file
130
-# return the number of bytes written
131
*/
132
int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {
4,704,175✔
133

134
        unsigned long bf;
135
        int sbf;
136
    unsigned int ii ;
137
    unsigned int len = 0 ;
4,704,175✔
138
    char *address = 0 ;
4,704,175✔
139

140
    /* Write out all parameters */
141
    for (ii = 0; ii < rec_buffer.size() ; ii++) {
39,233,796✔
142
        int item_size        = (int)Trick::ReferenceUtils::effective_trick_size(rec_buffer[ii]->ref);
34,529,621✔
143
        TRICK_TYPE item_type = Trick::ReferenceUtils::effective_trick_type(rec_buffer[ii]->ref);
34,529,621✔
144
        address              = rec_buffer[ii]->buffer + (writer_offset * item_size);
34,529,621✔
145

146
        switch (item_type)
34,529,621✔
147
        {
148
        case TRICK_CHARACTER:
34,529,313✔
149
        case TRICK_UNSIGNED_CHARACTER:
150
        case TRICK_SHORT:
151
        case TRICK_UNSIGNED_SHORT:
152
        case TRICK_BOOLEAN:
153
        case TRICK_ENUMERATED:
154
        case TRICK_INTEGER:
155
        case TRICK_UNSIGNED_INTEGER:
156
        case TRICK_FLOAT:
157
        case TRICK_LONG:
158
        case TRICK_UNSIGNED_LONG:
159
        case TRICK_LONG_LONG:
160
        case TRICK_UNSIGNED_LONG_LONG:
161
        case TRICK_STRUCTURED:
162
        case TRICK_DOUBLE:
163
            memcpy(writer_buff + len, address, (size_t)item_size);
34,529,313✔
164
            break;
34,529,313✔
165

166
        case TRICK_BITFIELD:
154✔
167
            sbf = GET_BITFIELD(address, rec_buffer[ii]->ref->attr->size, rec_buffer[ii]->ref->attr->index[0].start,
154✔
168
                               rec_buffer[ii]->ref->attr->index[0].size);
169
            memcpy(writer_buff + len, &sbf, (size_t)item_size);
154✔
170
            break;
154✔
171

172
        case TRICK_UNSIGNED_BITFIELD:
154✔
173
            bf = GET_UNSIGNED_BITFIELD(address, rec_buffer[ii]->ref->attr->size,
154✔
174
                                       rec_buffer[ii]->ref->attr->index[0].start,
175
                                       rec_buffer[ii]->ref->attr->index[0].size);
176
            memcpy(writer_buff + len, &bf, (size_t)item_size);
154✔
177
            break;
154✔
178

NEW
179
        default:
×
NEW
180
            break;
×
181
        }
182
        len += item_size;
34,529,621✔
183
    }
184

185
    return write( fd , writer_buff , len) ;
9,408,350✔
186
}
187

188
/**
189
@details
190
-# Close the output file stream
191
*/
192
int Trick::DRBinary::format_specific_shutdown() {
20✔
193

194
    if ( inited ) {
20✔
195
        close(fd) ;
20✔
196
    }
197
    return(0) ;
20✔
198
}
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