Skip to content
Merged
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
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ AC_ARG_ENABLE([tsan],
],
[echo "ThreadSanitizer is disabled"])

ENABLE_DYNAMIC_TABLE_SUPPORT=false
AC_ARG_ENABLE([dynamic-table-support],
AS_HELP_STRING([--enable-dynamic-table-support],[enable dynamic TR-181 table traversal support (default is no)]),
[
case "${enableval}" in
yes) ENABLE_DYNAMIC_TABLE_SUPPORT=true ;;
no) ENABLE_DYNAMIC_TABLE_SUPPORT=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-dynamic-table-support]) ;;
esac
],
[echo "dynamic table support is disabled"])
AM_CONDITIONAL([ENABLE_DYNAMIC_TABLE_SUPPORT], [test x$ENABLE_DYNAMIC_TABLE_SUPPORT = xtrue])
Comment thread
yogeswaransky marked this conversation as resolved.

if test x$ENABLE_DYNAMIC_TABLE_SUPPORT = xtrue; then
CPPFLAGS="$CPPFLAGS -DENABLE_DYNAMIC_TABLE_SUPPORT"
fi

AC_MSG_NOTICE([Dynamic table support: $ENABLE_DYNAMIC_TABLE_SUPPORT])
Comment thread
yogeswaransky marked this conversation as resolved.
Comment thread
yogeswaransky marked this conversation as resolved.

Comment thread
yogeswaransky marked this conversation as resolved.
AC_CONFIG_FILES([Makefile
source/Makefile
source/bulkdata/Makefile
Expand Down
10 changes: 10 additions & 0 deletions source/bulkdata/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ void freeProfile(void *data)
Vector_Destroy(profile->cachedReportList, free);
profile->cachedReportList = NULL;
}
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
if(profile->dataModelTableList)
{
Vector_Destroy(profile->dataModelTableList, freeDataModelTable);
}
#endif
if(profile->jsonReportObj)
{
cJSON_Delete(profile->jsonReportObj);
Expand Down Expand Up @@ -528,11 +530,19 @@ static void* CollectAndReport(void* data)
profileParamVals = getProfileParameterValues(profile->paramList, count);
if(profileParamVals != NULL)
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
/* dataModelTableList is populated once during profile parsing
* (addParameter_marker_config / parseDataModelTableParams) before
* the report thread is started. It is never modified after
* initialization, so no mutex is needed here — immutable-after-
* publish pattern. Thread safety is guaranteed by the lifecycle:
* parse -> start thread -> (reads only) -> join thread -> free. */
if (profile->dataModelTableList != NULL && Vector_Size(profile->dataModelTableList) > 0)
{
encodeParamResultInJSON(valArray, profile->paramList, profileParamVals, profile->dataModelTableList);
}
else
#endif
{
encodeParamResultInJSON(valArray, profile->paramList, profileParamVals, NULL);
}
Expand Down
2 changes: 2 additions & 0 deletions source/bulkdata/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ typedef struct _Profile
Vector *gMarkerList;
Vector *topMarkerList;
Vector *cachedReportList;
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
Vector *dataModelTableList; // List of DataModelTable
#endif
Comment thread
yogeswaransky marked this conversation as resolved.
Comment thread
yogeswaransky marked this conversation as resolved.
cJSON *jsonReportObj;
pthread_t reportThread;
pthread_mutex_t triggerCondMutex;
Expand Down
7 changes: 7 additions & 0 deletions source/reportgen/reportgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ cJSON* findOrCreateArrayItem(cJSON *array, int targetIndex)
return newItem;
}

#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
//Function to get the basePath like Device.WiFi.AccessPoint.
int getBasePath(const char *input, char *basePath, size_t maxLength)
Comment thread
yogeswaransky marked this conversation as resolved.
{
Expand Down Expand Up @@ -387,6 +388,7 @@ DataModelTable *findTableByReference(Vector *dataModelTableList, const char *ful
}
return table;
}
#endif

bool isDataModelTable(const char *paramName)
{
Expand All @@ -397,6 +399,9 @@ bool isDataModelTable(const char *paramName)

T2ERROR encodeParamResultInJSON(cJSON *valArray, Vector *paramNameList, Vector *paramValueList, Vector *dataModelTableList)
{
#ifndef ENABLE_DYNAMIC_TABLE_SUPPORT
(void)dataModelTableList;
#endif
if(valArray == NULL || paramNameList == NULL || paramValueList == NULL)
{
T2Error("Invalid or NULL arguments\n");
Expand Down Expand Up @@ -523,6 +528,7 @@ T2ERROR encodeParamResultInJSON(cJSON *valArray, Vector *paramNameList, Vector *
}
else
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
if (((dataModelTableList != NULL) && (Vector_Size(dataModelTableList) > 0)))
{
int valIndex = 0;
Expand Down Expand Up @@ -786,6 +792,7 @@ T2ERROR encodeParamResultInJSON(cJSON *valArray, Vector *paramNameList, Vector *
}
}
else
#endif
{
cJSON *valList = NULL;
cJSON *valItem = NULL;
Expand Down
45 changes: 45 additions & 0 deletions source/t2parser/t2parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ void time_param_Reporting_Adjustments_valid_set(Profile *profile, cJSON *jprofil
}
}

#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
static int buildFullPath(char* fullPath, const char* basePath, const char* reference)
{
T2Debug("%s ++in\n", __FUNCTION__);
Expand Down Expand Up @@ -916,7 +917,20 @@ static T2ERROR parseDataModelTableParams(Profile* profile, cJSON* tableItem, con

// Initialize root table
currentTable->reference = strdup(jpReference->valuestring);
if (!currentTable->reference)
{
T2Error("Failed to allocate memory for DataModelTable reference\n");
free(currentTable);
return T2ERROR_FAILURE;
}
currentTable->index = jpIndex ? strdup(jpIndex->valuestring) : NULL;
if (jpIndex && !currentTable->index)
{
T2Error("Failed to allocate memory for DataModelTable index\n");
free(currentTable->reference);
free(currentTable);
return T2ERROR_FAILURE;
}
Vector_Create(&currentTable->paramList);

if (!profile->dataModelTableList)
Expand Down Expand Up @@ -992,6 +1006,13 @@ static T2ERROR parseDataModelTableParams(Profile* profile, cJSON* tableItem, con
continue;
}
param->name = strdup(fullPath);
if (!param->name)
{
T2Error("Failed to allocate memory for DataModelParam name\n");
free(param->reference);
free(param);
continue;
}
param->reportEmpty = false;

// Add to table's parameter list
Expand All @@ -1003,6 +1024,7 @@ static T2ERROR parseDataModelTableParams(Profile* profile, cJSON* tableItem, con
T2Debug("%s ++out\n", __FUNCTION__);
return T2ERROR_SUCCESS;
}
#endif

T2ERROR addParameter_marker_config(Profile* profile, cJSON *jprofileParameter, int ThisProfileParameter_count)
{
Expand Down Expand Up @@ -1036,10 +1058,12 @@ T2ERROR addParameter_marker_config(Profile* profile, cJSON *jprofileParameter, i
{
Vector_Create(&profile->cachedReportList);
}
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
if (!profile->dataModelTableList)
{
Vector_Create(&profile->dataModelTableList);
}
#endif

profile->grepSeekProfile = createGrepSeekProfile(0);

Expand Down Expand Up @@ -1164,6 +1188,7 @@ T2ERROR addParameter_marker_config(Profile* profile, cJSON *jprofileParameter, i
}
else if (!(strcmp(paramtype, "dataModelTable")))
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
T2Debug("Processing dataModelTable configuration\n");
char basePath[256] = "";
char index[64] = "";
Expand Down Expand Up @@ -1281,6 +1306,10 @@ T2ERROR addParameter_marker_config(Profile* profile, cJSON *jprofileParameter, i
{
T2Error("Missing reference in dataModelTable configuration\n");
}
#else
T2Debug("Dynamic table support disabled, ignoring dataModelTable parameter\n");
continue;
#endif
}
else if(!(strcmp(paramtype, "event")))
{
Expand Down Expand Up @@ -2482,6 +2511,22 @@ T2ERROR addParameterMsgpack_marker_config(Profile* profile, msgpack_object* valu
}
}
}
else if(0 == msgpack_strcmp(Parameter_type_str, "dataModelTable"))
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
T2Debug("MsgPack dataModelTable parsing is enabled only in JSON flow currently\n");
T2Error("%s dataModelTable in MsgPack profile is not supported in current implementation\n", __FUNCTION__);
#else
T2Debug("Dynamic table support disabled, ignoring dataModelTable parameter\n");
#endif
free(paramtype);
free(use);
if(regex != NULL)
{
free(regex);
}
continue;
}
else
{
T2Error("%s Unknown parameter type %s \n", __FUNCTION__, paramtype);
Expand Down
2 changes: 1 addition & 1 deletion source/test/bulkdata/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ reportprofiles_gtest_bin_LDFLAGS += -Wl,--wrap=isRbusEnabled -Wl,--wrap=sendRepo
# DataModelTable (PR-161) & Memory Safety (PR-363) Test Suite
profile_dynamictable_gtest_bin_CFLAGS = -DGTEST_ENABLE

profile_dynamictable_gtest_bin_CPPFLAGS = $(profile_gtest_bin_CPPFLAGS)
profile_dynamictable_gtest_bin_CPPFLAGS = $(profile_gtest_bin_CPPFLAGS) -DENABLE_DYNAMIC_TABLE_SUPPORT

profile_dynamictable_gtest_bin_SOURCES = profile_dynamictable_Test.cpp ../mocks/rdklogMock.cpp ../mocks/rbusMock.cpp ../mocks/profileStub.c ../../utils/vector.c ../../utils/t2log_wrapper.c ../../utils/t2common.c ../../utils/t2collection.c

Expand Down
14 changes: 14 additions & 0 deletions source/test/bulkdata/profile_dynamictable_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ProfileDynamicTableTestFixture : public ::testing::Test {
*/
TEST_F(ProfileDynamicTableTestFixture, NullDataModelTableList_NoCrash)
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
// Create a profile without data model tables
Profile* testProfile = (Profile*)calloc(1, sizeof(Profile));
ASSERT_NE(testProfile, nullptr);
Expand Down Expand Up @@ -138,6 +139,9 @@ TEST_F(ProfileDynamicTableTestFixture, NullDataModelTableList_NoCrash)
Vector_Destroy(testProfile->gMarkerList, NULL);
Vector_Destroy(testProfile->staticParamList, NULL);
free(testProfile);
#else
GTEST_SKIP() << "Dynamic table support is disabled in this build";
#endif
}

/**
Expand All @@ -150,6 +154,7 @@ TEST_F(ProfileDynamicTableTestFixture, NullDataModelTableList_NoCrash)
*/
TEST_F(ProfileDynamicTableTestFixture, EmptyDataModelTableList_SkipsEncoding)
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
Profile* testProfile = (Profile*)calloc(1, sizeof(Profile));
ASSERT_NE(testProfile, nullptr);

Expand Down Expand Up @@ -183,6 +188,9 @@ TEST_F(ProfileDynamicTableTestFixture, EmptyDataModelTableList_SkipsEncoding)
Vector_Destroy(testProfile->gMarkerList, NULL);
Vector_Destroy(testProfile->staticParamList, NULL);
free(testProfile);
#else
GTEST_SKIP() << "Dynamic table support is disabled in this build";
#endif
}

/**
Expand All @@ -194,6 +202,7 @@ TEST_F(ProfileDynamicTableTestFixture, EmptyDataModelTableList_SkipsEncoding)
*/
TEST_F(ProfileDynamicTableTestFixture, ValidDataModelTableList_ProceedsToEncoding)
{
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
Profile* testProfile = (Profile*)calloc(1, sizeof(Profile));
ASSERT_NE(testProfile, nullptr);

Expand Down Expand Up @@ -232,6 +241,9 @@ TEST_F(ProfileDynamicTableTestFixture, ValidDataModelTableList_ProceedsToEncodin
Vector_Destroy(testProfile->dataModelTableList, NULL);

free(testProfile);
#else
GTEST_SKIP() << "Dynamic table support is disabled in this build";
#endif
}

/**
Expand Down Expand Up @@ -278,7 +290,9 @@ TEST_F(ProfileDynamicTableTestFixture, FreeProfile_ValidProfile_CleansUp)
Vector_Create(&testProfile->eMarkerList);
Vector_Create(&testProfile->gMarkerList);
Vector_Create(&testProfile->staticParamList);
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
Vector_Create(&testProfile->dataModelTableList);
#endif

// freeProfile() should clean up everything
freeProfile(testProfile);
Expand Down
2 changes: 2 additions & 0 deletions source/test/mocks/profileStub.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ void freeProfile(void *data)
{
Vector_Destroy(profile->topMarkerList, NULL);
}
#ifdef ENABLE_DYNAMIC_TABLE_SUPPORT
if(profile->dataModelTableList)
{
Vector_Destroy(profile->dataModelTableList, NULL);
}
Comment thread
yogeswaransky marked this conversation as resolved.
#endif
if(profile->triggerConditionList)
{
Vector_Destroy(profile->triggerConditionList, NULL);
Expand Down
2 changes: 1 addition & 1 deletion source/test/reportgen/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ reportgen_gtest_bin_SOURCES = gtest_main.cpp reportgenTest.cpp reportgenMock.cpp
reportgen_gtest_bin_LDFLAGS = -lgtest -lgcov -L/src/googletest/googlemock/lib -L/usr/src/googletest/googlemock/lib/.libs -lgmock -lcjson -lcurl -lmsgpackc

# DataModelTable (PR-161) & Memory Safety (PR-363) Test Suite
reportgen_dynamictable_gtest_bin_CPPFLAGS = $(reportgen_gtest_bin_CPPFLAGS) -I${top_srcdir}/source/bulkdata
reportgen_dynamictable_gtest_bin_CPPFLAGS = $(reportgen_gtest_bin_CPPFLAGS) -I${top_srcdir}/source/bulkdata -DENABLE_DYNAMIC_TABLE_SUPPORT

reportgen_dynamictable_gtest_bin_SOURCES = gtest_main.cpp reportgen_dynamictable_Test.cpp reportgenMock.cpp ../mocks/rdklogMock.cpp ../../utils/t2log_wrapper.c ../../reportgen/reportgen.c ../../utils/vector.c ../../utils/t2common.c

Expand Down
Loading
Loading