From ce5c751130bcdcca7e7c35b2618d6a7bf2483faf Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Wed, 23 Oct 2024 17:11:45 -0500 Subject: [PATCH 1/3] Added new function calls to data_record_utilities for getting the total number of data recording groups and the data recording group pointer by its id number per customer request. --- include/trick/DataRecordDispatcher.hh | 8 +++- include/trick/data_record_proto.h | 2 + test/SIM_test_dr/RUN_test/unit_test.py | 43 ++++++++++++++++--- test/SIM_test_dr/models/dr/include/DR.hh | 3 ++ .../DataRecord/DataRecordDispatcher.cpp | 23 ++++++++++ .../DataRecord/data_record_utilities.cpp | 14 ++++++ 6 files changed, 86 insertions(+), 7 deletions(-) diff --git a/include/trick/DataRecordDispatcher.hh b/include/trick/DataRecordDispatcher.hh index f1509da2b..78d05859d 100644 --- a/include/trick/DataRecordDispatcher.hh +++ b/include/trick/DataRecordDispatcher.hh @@ -75,9 +75,15 @@ namespace Trick { /** @brief Removes all data recording groups. */ void remove_all_groups() ; - /** @brief Gets a data recording group. */ + /** @brief Gets a data recording group by its name. */ Trick::DataRecordGroup * get_group(std::string group_name) ; + /** @brief Gets a data recording group by its id number */ + Trick::DataRecordGroup * get_group(int idx) ; + + /** @brief Gets the size of all added data recroding groups */ + int get_groups_size() ; + /** @brief Signal the write thread to execute. */ virtual int signal_thread() ; diff --git a/include/trick/data_record_proto.h b/include/trick/data_record_proto.h index d5b18e354..2e5a427ee 100644 --- a/include/trick/data_record_proto.h +++ b/include/trick/data_record_proto.h @@ -23,6 +23,8 @@ int set_max_size_record_group (const char * in_name, uint64_t bytes ) ; int add_data_record_group( Trick::DataRecordGroup * in_group, Trick::DR_Buffering buffering = Trick::DR_Not_Specified ) ; int remove_data_record_group( Trick::DataRecordGroup * in_group ) ; Trick::DataRecordGroup * get_data_record_group( std::string in_name ) ; +Trick::DataRecordGroup * get_data_record_group_by_idx( int idx ) ; +int get_num_data_record_groups() ; } #endif diff --git a/test/SIM_test_dr/RUN_test/unit_test.py b/test/SIM_test_dr/RUN_test/unit_test.py index eaeac8218..62806fb45 100644 --- a/test/SIM_test_dr/RUN_test/unit_test.py +++ b/test/SIM_test_dr/RUN_test/unit_test.py @@ -1,10 +1,41 @@ -exec(open("Modified_data/dr_typesASCII.dr").read()) -exec(open("Modified_data/dr_typesBINARY.dr").read()) -exec(open("Modified_data/dr_bitfASCII.dr").read()) -exec(open("Modified_data/dr_bitfBINARY.dr").read()) +from trick.unit_test import * -trick_utest.unit_tests.enable() ; -trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_dr.xml" ) ; +# The first item of each pair is the .dr file name and the second item of each pair is the drg name +dr_file_name_drg_name_tuple = (('Modified_data/dr_typesASCII.dr', 'DR_typesASCII'), + ('Modified_data/dr_typesBINARY.dr', 'DR_typesBINARY'), + ('Modified_data/dr_bitfASCII.dr', 'DR_bitfieldsASCII'), + ('Modified_data/dr_bitfBINARY.dr', 'DR_bitfieldsBINARY')) + +num_files = len(dr_file_name_drg_name_tuple) +for i in range(num_files): + exec(open(dr_file_name_drg_name_tuple[i][0]).read()) + +trick_utest.unit_tests.enable() +trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_dr.xml" ) + +trick_utest.unit_tests.set_test_name( "DRTest" ) + +###################################################################################################################### + +test_suite = "drg api" + +# Get the number of data recording groups created +num_drgs = trick.get_num_data_record_groups() + +# Check the result of trick.get_num_data_record_groups() +TRICK_EXPECT_EQ( num_drgs , 4 , test_suite , "num of dr groups" ) + +# Test trick.get_data_record_group() for getting the drg pointer by its name +# Check the name of the obtained drg instead of the drg pointer +for i in range(num_drgs): + drx.drt.drg = trick.get_data_record_group(dr_file_name_drg_name_tuple[i][1]) + TRICK_EXPECT_EQ( drx.drt.drg.get_group_name(), dr_file_name_drg_name_tuple[i][1], test_suite , "get drg by name" ) + +# Test trick.get_data_record_group( #include +#include "trick/DataRecordGroup.hh" #ifndef DR_HH @@ -101,6 +102,8 @@ class DRTypes { MIX_BITS mixB; + Trick::DataRecordGroup * drg; + DRTypes(); ~DRTypes(); diff --git a/trick_source/sim_services/DataRecord/DataRecordDispatcher.cpp b/trick_source/sim_services/DataRecord/DataRecordDispatcher.cpp index ac75689c0..9669ba705 100644 --- a/trick_source/sim_services/DataRecord/DataRecordDispatcher.cpp +++ b/trick_source/sim_services/DataRecord/DataRecordDispatcher.cpp @@ -180,6 +180,10 @@ void Trick::DataRecordDispatcher::remove_all_groups() { } } +/** + @details + -# Gets the data recording group by its name + */ Trick::DataRecordGroup * Trick::DataRecordDispatcher::get_group(std::string in_name) { std::vector ::iterator it ; for ( it = groups.begin() ; it != groups.end() ; ++it ) { @@ -189,6 +193,25 @@ Trick::DataRecordGroup * Trick::DataRecordDispatcher::get_group(std::string in_n return NULL ; } +/** + @details + -# Gets the data recording group by its id number + */ +Trick::DataRecordGroup * Trick::DataRecordDispatcher::get_group(int in_idx) { + if (!groups.empty() && in_idx > -1 && in_idx < groups.size()) { + return groups[in_idx]; + } + return NULL ; +} + +/** + @details + -# Gets the size of all added data recroding groups + */ +int Trick::DataRecordDispatcher::get_groups_size() { + return groups.size(); +} + /** @details -# If the writer thread condition variable is unlocked diff --git a/trick_source/sim_services/DataRecord/data_record_utilities.cpp b/trick_source/sim_services/DataRecord/data_record_utilities.cpp index 479ac758d..a9b5bbaa9 100644 --- a/trick_source/sim_services/DataRecord/data_record_utilities.cpp +++ b/trick_source/sim_services/DataRecord/data_record_utilities.cpp @@ -79,6 +79,20 @@ extern "C" Trick::DataRecordGroup * get_data_record_group( std::string in_name ) return NULL ; } +extern "C" Trick::DataRecordGroup * get_data_record_group_by_idx( int in_idx ) { + if ( the_drd != NULL ) { + return the_drd->get_group(in_idx) ; + } + return NULL ; +} + +extern "C" int get_num_data_record_groups() { + if ( the_drd != NULL ) { + return the_drd->get_groups_size() ; + } + return NULL ; +} + extern "C" int set_max_size_record_group (const char * in_name, uint64_t bytes ) { if ( the_drd != NULL ) { return the_drd->set_group_max_file_size(in_name, bytes ) ; From cf7ded219a48bbb97143cf2f571d1a75568b6719 Mon Sep 17 00:00:00 2001 From: Hong Chen Date: Wed, 23 Oct 2024 22:20:55 -0500 Subject: [PATCH 2/3] Deleted unnecessary variable. --- test/SIM_test_dr/RUN_test/unit_test.py | 8 +++----- test/SIM_test_dr/models/dr/include/DR.hh | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/test/SIM_test_dr/RUN_test/unit_test.py b/test/SIM_test_dr/RUN_test/unit_test.py index 62806fb45..046f09802 100644 --- a/test/SIM_test_dr/RUN_test/unit_test.py +++ b/test/SIM_test_dr/RUN_test/unit_test.py @@ -28,14 +28,12 @@ # Test trick.get_data_record_group() for getting the drg pointer by its name # Check the name of the obtained drg instead of the drg pointer for i in range(num_drgs): - drx.drt.drg = trick.get_data_record_group(dr_file_name_drg_name_tuple[i][1]) - TRICK_EXPECT_EQ( drx.drt.drg.get_group_name(), dr_file_name_drg_name_tuple[i][1], test_suite , "get drg by name" ) + TRICK_EXPECT_EQ( trick.get_data_record_group(dr_file_name_drg_name_tuple[i][1]).get_group_name(), dr_file_name_drg_name_tuple[i][1], test_suite , "get drg by name" ) -# Test trick.get_data_record_group( Date: Thu, 24 Oct 2024 08:58:22 -0500 Subject: [PATCH 3/3] Added a couple of more unit tests and fixed the return number to 0 instead of NULL for getting total number of drgs. --- test/SIM_test_dr/RUN_test/unit_test.py | 46 +++++++++++++------ test/SIM_test_dr/models/dr/include/DR.hh | 1 - .../DataRecord/data_record_utilities.cpp | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/test/SIM_test_dr/RUN_test/unit_test.py b/test/SIM_test_dr/RUN_test/unit_test.py index 046f09802..2d3cf3a52 100644 --- a/test/SIM_test_dr/RUN_test/unit_test.py +++ b/test/SIM_test_dr/RUN_test/unit_test.py @@ -1,5 +1,20 @@ from trick.unit_test import * +trick_utest.unit_tests.enable() +trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_dr.xml" ) + +trick_utest.unit_tests.set_test_name( "DRTest" ) + +###################################################################################################################### + +test_suite = "drg api" + +# Get the number of data recording groups before any drg is created +num_drgs = trick.get_num_data_record_groups() + +# Check the result of trick.get_num_data_record_groups() +TRICK_EXPECT_EQ( num_drgs , 0 , test_suite , "0 drgs before any created" ) + # The first item of each pair is the .dr file name and the second item of each pair is the drg name dr_file_name_drg_name_tuple = (('Modified_data/dr_typesASCII.dr', 'DR_typesASCII'), ('Modified_data/dr_typesBINARY.dr', 'DR_typesBINARY'), @@ -10,30 +25,35 @@ for i in range(num_files): exec(open(dr_file_name_drg_name_tuple[i][0]).read()) -trick_utest.unit_tests.enable() -trick_utest.unit_tests.set_file_name( os.getenv("TRICK_HOME") + "/trick_test/SIM_test_dr.xml" ) - -trick_utest.unit_tests.set_test_name( "DRTest" ) - -###################################################################################################################### - -test_suite = "drg api" - # Get the number of data recording groups created num_drgs = trick.get_num_data_record_groups() # Check the result of trick.get_num_data_record_groups() -TRICK_EXPECT_EQ( num_drgs , 4 , test_suite , "num of dr groups" ) +TRICK_EXPECT_EQ( num_drgs , 4 , test_suite , "num of dr groups = 4" ) # Test trick.get_data_record_group() for getting the drg pointer by its name # Check the name of the obtained drg instead of the drg pointer for i in range(num_drgs): - TRICK_EXPECT_EQ( trick.get_data_record_group(dr_file_name_drg_name_tuple[i][1]).get_group_name(), dr_file_name_drg_name_tuple[i][1], test_suite , "get drg by name" ) + TRICK_EXPECT_EQ( trick.get_data_record_group(dr_file_name_drg_name_tuple[i][1]).get_group_name(), dr_file_name_drg_name_tuple[i][1], test_suite , "get drg by name " + dr_file_name_drg_name_tuple[i][1] ) # Test trick.get_data_record_group_by_idx( #include -#include "trick/DataRecordGroup.hh" #ifndef DR_HH diff --git a/trick_source/sim_services/DataRecord/data_record_utilities.cpp b/trick_source/sim_services/DataRecord/data_record_utilities.cpp index a9b5bbaa9..1077861e9 100644 --- a/trick_source/sim_services/DataRecord/data_record_utilities.cpp +++ b/trick_source/sim_services/DataRecord/data_record_utilities.cpp @@ -90,7 +90,7 @@ extern "C" int get_num_data_record_groups() { if ( the_drd != NULL ) { return the_drd->get_groups_size() ; } - return NULL ; + return 0 ; } extern "C" int set_max_size_record_group (const char * in_name, uint64_t bytes ) {