Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/trick/ReferenceUtils.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef REFERENCE_UTILS_HH
#define REFERENCE_UTILS_HH

/*
PURPOSE: ( Provides helper functions for working with REF2. )
*/

#include "trick/reference.h"

namespace Trick
{

class ReferenceUtils
{
public:
// Returns true when ref represents an access that went through an STL container:
// stl_present == 1 (STL indexed somewhere in the path, e.g. xxx[2].yyy.www)
// OR attr->type == TRICK_STL with the reference ending in ']' (e.g. vec[0])
static bool is_stl_ref(const REF2* ref);

// Returns the effective TRICK_TYPE for value interpretation:
// TRICK_STL whose reference ends with ']' -> attr->stl_elem_type
// everything else -> attr->type
static TRICK_TYPE effective_trick_type(const REF2* ref);

// Returns the effective byte size for buffer allocation / copying:
// TRICK_STL whose reference ends with ']' -> sizeof(stl_elem_type)
// everything else -> attr->size
static size_t effective_trick_size(const REF2* ref);
};

} // namespace Trick

#endif // REFERENCE_UTILS_HH
12 changes: 12 additions & 0 deletions test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_Master.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sys.exec.out.time {s},the_object.stlc.double_vector[0] {1},the_object.stlc.double_vector[1] {1},the_object.stlc.double_vector[2] {1},the_object.stlc.float_deque[0] {1},the_object.stlc.float_deque[1] {1},the_object.stlc.float_deque[2] {1},the_object.stlc.int_array[0] {1},the_object.stlc.int_array[1] {1},the_object.stlc.int_array[2] {1},the_object.stlc.int_array[3] {1},the_object.stlc.vec_user_simple[0].b {1},the_object.stlc.vec_user_simple[0].a[0] {1},the_object.stlc.vec_user_simple[0].a[2] {1},the_object.stlc.vec_user_defined[0].a {1},the_object.stlc.vec_user_defined[0].vec[0] {1},the_object.stlc.vec_user_defined[0].vec[2] {1}
0, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.1, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.2, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.3, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.4, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.5, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.6, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.7, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.8, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
0.9, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
1, 4, 5, 6, 98.699997, 65.400002, 32.099998,10,20,30,40,8888888888,0,2,888,0,2
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_hdf5_Master.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
log_STL_DR_hdf5 byte_order is HDF5
log_STL_DR_hdf5 double s sys.exec.out.time
log_STL_DR_hdf5 double 1 the_object.stlc.double_vector[0]
log_STL_DR_hdf5 double 1 the_object.stlc.double_vector[1]
log_STL_DR_hdf5 double 1 the_object.stlc.double_vector[2]
log_STL_DR_hdf5 float 1 the_object.stlc.float_deque[0]
log_STL_DR_hdf5 float 1 the_object.stlc.float_deque[1]
log_STL_DR_hdf5 float 1 the_object.stlc.float_deque[2]
log_STL_DR_hdf5 int 1 the_object.stlc.int_array[0]
log_STL_DR_hdf5 int 1 the_object.stlc.int_array[1]
log_STL_DR_hdf5 int 1 the_object.stlc.int_array[2]
log_STL_DR_hdf5 int 1 the_object.stlc.int_array[3]
log_STL_DR_hdf5 long_long 1 the_object.stlc.vec_user_simple[0].b
log_STL_DR_hdf5 int 1 the_object.stlc.vec_user_simple[0].a[0]
log_STL_DR_hdf5 int 1 the_object.stlc.vec_user_simple[0].a[2]
log_STL_DR_hdf5 int 1 the_object.stlc.vec_user_defined[0].a
log_STL_DR_hdf5 int 1 the_object.stlc.vec_user_defined[0].vec[0]
log_STL_DR_hdf5 int 1 the_object.stlc.vec_user_defined[0].vec[2]
110 changes: 110 additions & 0 deletions test/SIM_stls/RUN_test_dr/input_dr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import trick

has_dhf5 = False
if hasattr(trick, "DRHDF5"):
has_dhf5 = True


def main():
trick.exec_set_job_onoff("the_object.stlc.addData", 1, True)
trick.exec_set_job_onoff("the_object.stlc.test", 1, False)
trick.exec_set_job_onoff("the_object.stlc.print", 1, False)

# ---------------------------------------------------------------
# ASCII data recording group for STL primitive containers
# ---------------------------------------------------------------
drg = trick.DRAscii("STL_DR")

# std::vector<double> — expected values: 4.0, 5.0, 6.0
drg.add_variable("the_object.stlc.double_vector[0]")
drg.add_variable("the_object.stlc.double_vector[1]")
drg.add_variable("the_object.stlc.double_vector[2]")

# std::deque<float> — expected values: 98.7, 65.4, 32.1
drg.add_variable("the_object.stlc.float_deque[0]")
drg.add_variable("the_object.stlc.float_deque[1]")
drg.add_variable("the_object.stlc.float_deque[2]")

# std::array<int,4> — expected values: 10, 20, 30, 40
drg.add_variable("the_object.stlc.int_array[0]")
drg.add_variable("the_object.stlc.int_array[1]")
drg.add_variable("the_object.stlc.int_array[2]")
drg.add_variable("the_object.stlc.int_array[3]")

# STL-element struct member: vec_user_simple is std::vector<UserClass>
# vec_user_simple[i].a[j] = i+j, vec_user_simple[i].b = 8888888888
drg.add_variable("the_object.stlc.vec_user_simple[0].b")
drg.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg.add_variable("the_object.stlc.vec_user_simple[0].a[2]")

# STL-element struct member: vec_user_defined is std::vector<SimpleWrapper>
# vec_user_defined[i].a = 888, vec_user_defined[i].vec[j] = i+j
drg.add_variable("the_object.stlc.vec_user_defined[0].a")

# Nested STL: outer vector element's inner vector element
# vec_user_defined[0].vec = {0, 1, 2, ..., 9}
drg.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")

drg.set_cycle(0.1)
drg.freq = trick.DR_Always
trick.add_data_record_group(drg, trick.DR_Buffer)

# ---------------------------------------------------------------
# Binary data recording group — same variables
# ---------------------------------------------------------------
drg_bin = trick.DRBinary("STL_DR_bin")
drg_bin.add_variable("the_object.stlc.double_vector[0]")
drg_bin.add_variable("the_object.stlc.double_vector[1]")
drg_bin.add_variable("the_object.stlc.double_vector[2]")
drg_bin.add_variable("the_object.stlc.float_deque[0]")
drg_bin.add_variable("the_object.stlc.float_deque[1]")
drg_bin.add_variable("the_object.stlc.float_deque[2]")
drg_bin.add_variable("the_object.stlc.int_array[0]")
drg_bin.add_variable("the_object.stlc.int_array[1]")
drg_bin.add_variable("the_object.stlc.int_array[2]")
drg_bin.add_variable("the_object.stlc.int_array[3]")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].b")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg_bin.add_variable("the_object.stlc.vec_user_simple[0].a[2]")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].a")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg_bin.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")
drg_bin.set_cycle(0.1)
drg_bin.freq = trick.DR_Always
trick.add_data_record_group(drg_bin, trick.DR_Buffer)

# ---------------------------------------------------------------
# HDF5 data recording group — same variables (only when HDF5 is available)
# ---------------------------------------------------------------
if not has_dhf5:
trick.exec_set_freeze_frame(0.10)
trick.stop(1.0)
return
drg_hdf5 = trick.DRHDF5("STL_DR_hdf5")
drg_hdf5.add_variable("the_object.stlc.double_vector[0]")
drg_hdf5.add_variable("the_object.stlc.double_vector[1]")
drg_hdf5.add_variable("the_object.stlc.double_vector[2]")
drg_hdf5.add_variable("the_object.stlc.float_deque[0]")
drg_hdf5.add_variable("the_object.stlc.float_deque[1]")
drg_hdf5.add_variable("the_object.stlc.float_deque[2]")
drg_hdf5.add_variable("the_object.stlc.int_array[0]")
drg_hdf5.add_variable("the_object.stlc.int_array[1]")
drg_hdf5.add_variable("the_object.stlc.int_array[2]")
drg_hdf5.add_variable("the_object.stlc.int_array[3]")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].b")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].a[0]")
drg_hdf5.add_variable("the_object.stlc.vec_user_simple[0].a[2]")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].a")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].vec[0]")
drg_hdf5.add_variable("the_object.stlc.vec_user_defined[0].vec[2]")
drg_hdf5.set_cycle(0.1)
drg_hdf5.freq = trick.DR_Always
trick.add_data_record_group(drg_hdf5, trick.DR_Buffer)

trick.exec_set_freeze_frame(0.10)
trick.stop(1.0)


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions test/SIM_stls/models/STLCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ int STLCheckpoint::addData() {
float_deque.push_back(65.4) ;
float_deque.push_back(32.1) ;

int_array[0] = 10;
int_array[1] = 20;
int_array[2] = 30;
int_array[3] = 40;

string_deque.push_back("Welcome") ;
string_deque.push_back("to") ;
string_deque.push_back("PhoneMart") ;
Expand Down
14 changes: 8 additions & 6 deletions test/SIM_stls/models/STLCheckpoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#ifndef STLCHECKPOINT_HH
#define STLCHECKPOINT_HH

#include <map>
#include <vector>
#include <list>
#include <array>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <string>
#include <utility>

#include <vector>

class SimpleWrapper {
public:
Expand Down Expand Up @@ -61,6 +61,8 @@ class STLCheckpoint {
std::multimap< int , std::string > string_data_multimap ;
std::multimap< std::string , std::string > string_multimap ;

std::array<int, 4> int_array;

std::vector< double > double_vector ;
std::vector< std::string > string_vector ;

Expand Down
6 changes: 6 additions & 0 deletions test_sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ SIM_stls:
returns: 0
RUN_test/unit_test.py:
returns: 0
RUN_test_dr/input_dr.py:
returns: 0
compare:
- test/SIM_stls/RUN_test_dr/log_STL_DR.csv vs. test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_Master.csv
- test/SIM_stls/RUN_test_dr/log_STL_DR_bin.trk vs. test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_bin_Master.trk
analyze: "test ! -f test/SIM_stls/RUN_test_dr/log_STL_DR_hdf5.header || diff test/SIM_stls/RUN_test_dr/log_STL_DR_hdf5.header test/SIM_stls/RUN_test_dr/Ref_Logs/log_STL_DR_hdf5_Master.header"

SIM_test_dr:
path: test/SIM_test_dr
Expand Down
Loading