Adding 05 new test case into a new testsuite 22 --- .../test_saImmOiRtObjectCreate_2.c | 9 +- .../implementer/test_saImmOiRtObjectDelete.c | 4 +- .../test_saImmOiRtObjectUpdate_2.c | 4 +- src/log/Makefile.am | 7 +- src/log/apitest/log_server.cc | 47 +++ src/log/apitest/log_server.h | 35 +++ .../apitest/tet_saLogStreamConfigFacilityId.c | 279 ++++++++++++++++++ src/log/tests/lgs_dest_test.cc | 3 + 8 files changed, 381 insertions(+), 7 deletions(-) create mode 100644 src/log/apitest/log_server.cc create mode 100644 src/log/apitest/log_server.h create mode 100644 src/log/apitest/tet_saLogStreamConfigFacilityId.c
diff --git a/src/imm/apitest/implementer/test_saImmOiRtObjectCreate_2.c b/src/imm/apitest/implementer/test_saImmOiRtObjectCreate_2.c index df260a9d5..709332954 100644 --- a/src/imm/apitest/implementer/test_saImmOiRtObjectCreate_2.c +++ b/src/imm/apitest/implementer/test_saImmOiRtObjectCreate_2.c @@ -59,9 +59,11 @@ static SaImmAttrValuesT_2 v10 = {"saLogStreamSeverityFilter", SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static SaImmAttrValuesT_2 v11 = {"saLogStreamCreationTimestamp", SA_IMM_ATTR_SATIMET, 1, (void **)lint1Values}; +static SaImmAttrValuesT_2 v12 = {"saLogStreamFacilityId", + SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static const SaImmAttrValuesT_2 *attrValues[] = { - &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, NULL}; + &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, &v12, NULL}; static const SaImmClassNameT className = "SaLogStream"; void saImmOiRtObjectCreate_2_01(void) @@ -188,8 +190,9 @@ void saImmOiRtObjectCreate_2_07(void) // const SaNameT *nameValues27[] = {&rdnObj27}; const SaImmAttrValuesT_2 v27 = {"safLgStr", SA_IMM_ATTR_SASTRINGT, 1, (void **)nameValues27}; - const SaImmAttrValuesT_2 *attrValues27[] = { - &v1, &v27, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, NULL}; + const SaImmAttrValuesT_2 *attrValues27[] = {&v1, &v27, &v3, &v4, &v5, + &v6, &v7, &v8, &v9, &v10, + &v11, &v12, NULL}; SaNameT tmpName; diff --git a/src/imm/apitest/implementer/test_saImmOiRtObjectDelete.c b/src/imm/apitest/implementer/test_saImmOiRtObjectDelete.c index 986ec88aa..341d5144a 100644 --- a/src/imm/apitest/implementer/test_saImmOiRtObjectDelete.c +++ b/src/imm/apitest/implementer/test_saImmOiRtObjectDelete.c @@ -59,9 +59,11 @@ static SaImmAttrValuesT_2 v10 = {"saLogStreamSeverityFilter", SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static SaImmAttrValuesT_2 v11 = {"saLogStreamCreationTimestamp", SA_IMM_ATTR_SATIMET, 1, (void **)lint1Values}; +static SaImmAttrValuesT_2 v12 = {"saLogStreamFacilityId", + SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static const SaImmAttrValuesT_2 *attrValues[] = { - &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, NULL}; + &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, &v12, NULL}; static const SaImmClassNameT className = "SaLogStream"; void saImmOiRtObjectDelete_01(void) diff --git a/src/imm/apitest/implementer/test_saImmOiRtObjectUpdate_2.c b/src/imm/apitest/implementer/test_saImmOiRtObjectUpdate_2.c index 1a551fd9f..2f2b941dc 100644 --- a/src/imm/apitest/implementer/test_saImmOiRtObjectUpdate_2.c +++ b/src/imm/apitest/implementer/test_saImmOiRtObjectUpdate_2.c @@ -55,9 +55,11 @@ static SaImmAttrValuesT_2 v10 = {"saLogStreamSeverityFilter", SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static SaImmAttrValuesT_2 v11 = {"saLogStreamCreationTimestamp", SA_IMM_ATTR_SATIMET, 1, (void **)lint1Values}; +static SaImmAttrValuesT_2 v12 = {"saLogStreamFacilityId", + SA_IMM_ATTR_SAUINT32T, 1, (void **)int1Values}; static const SaImmAttrValuesT_2 *attrValues[] = { - &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, NULL}; + &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, &v12, NULL}; static const SaImmClassNameT className = "SaLogStream"; diff --git a/src/log/Makefile.am b/src/log/Makefile.am index a2a98baec..2dad3cfb1 100644 --- a/src/log/Makefile.am +++ b/src/log/Makefile.am @@ -190,7 +190,8 @@ bin_PROGRAMS += bin/logtest bin/saflogtest bin/logtestfr noinst_HEADERS += \ src/log/apitest/logtest.h \ src/log/apitest/logutil.h \ - src/log/apitest/imm_tstutil.h + src/log/apitest/imm_tstutil.h \ + src/log/apitest/log_server.h bin_logtest_CFLAGS = $(AM_CFLAGS) -Wformat=1 @@ -227,7 +228,9 @@ bin_logtest_SOURCES = \ src/log/apitest/tet_Log_clm.c \ src/log/apitest/tet_cfg_destination.c \ src/log/apitest/tet_multiple_thread.c \ - src/log/apitest/tet_saLogWriteLogAsync_cache.c + src/log/apitest/tet_saLogWriteLogAsync_cache.c \ + src/log/apitest/tet_saLogStreamConfigFacilityId.c \ + src/log/apitest/log_server.cc bin_logtest_LDADD = \ lib/libapitest.la \ diff --git a/src/log/apitest/log_server.cc b/src/log/apitest/log_server.cc new file mode 100644 index 000000000..81bb3d651 --- /dev/null +++ b/src/log/apitest/log_server.cc @@ -0,0 +1,47 @@ +/* -*- OpenSAF -*- + * + * Copyright Ericsson AB 2020 - All Rights Reserved. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + * Author(s): Ericsson AB + * + */ + +#include "log/apitest/log_server.h" +#include "base/unix_server_socket.h" + +static base::UnixServerSocket *server; + +void StartUnixServer() { + server = new base::UnixServerSocket("/tmp/test.sock", + base::UnixSocket::kNonblocking, 0777); + server->fd(); +} + +bool FindExpectedPRI(char *PRI_Field, char *msg) { + char *buf = new char[1024]; + bool isFound = false; + do { + memset(buf, 0, 1024); + size_t len = server->Recv(buf, 1024); + buf[len] = '\0'; + if (!strncmp(buf, PRI_Field, strlen(PRI_Field))) { + isFound = true; + } + } while (!strstr(buf, msg)); + delete[] buf; + return isFound; +} + +void StopUnixServer() { + server->~UnixServerSocket(); + delete server; +} diff --git a/src/log/apitest/log_server.h b/src/log/apitest/log_server.h new file mode 100644 index 000000000..752d42007 --- /dev/null +++ b/src/log/apitest/log_server.h @@ -0,0 +1,35 @@ +/* -*- OpenSAF -*- + * + * Copyright Ericsson AB 2020 - All Rights Reserved. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + * Author(s): Ericsson AB + * + */ + +#ifndef LOG_APITEST_LOG_SERVER_H_ +#define LOG_APITEST_LOG_SERVER_H_ + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void StartUnixServer(); +bool FindExpectedPRI(char *data, char *msg); +void StopUnixServer(); + +#ifdef __cplusplus +} // closing brace for extern "C" +#endif + +#endif // LOG_APITEST_LOG_SERVER_H_ diff --git a/src/log/apitest/tet_saLogStreamConfigFacilityId.c b/src/log/apitest/tet_saLogStreamConfigFacilityId.c new file mode 100644 index 000000000..f8d44c202 --- /dev/null +++ b/src/log/apitest/tet_saLogStreamConfigFacilityId.c @@ -0,0 +1,279 @@ +/* -*- OpenSAF -*- + * + * Copyright Ericsson AB 2020 - All Rights Reserved. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + * Author(s): Ericsson AB + * + */ + +#include "log/apitest/log_server.h" +#include "log/apitest/logtest.h" + +typedef enum { ACTIVE_NODE = 0, STANDBY_NODE = 1, PAYLOAD = 2 } role; + +//> +// 02 test cases about configuring `saLogStreamFacilityId`: +// 1) try to set a valid value, expect getting OK. +// 2) try to set an invalid value, expect getting NOK. +//< + +// TC#1: Set a valid value to `saLogStreamFacilityId` +void config_saLogStreamFacilityId_1() +{ + const char *command = + "immcfg -a saLogStreamFacilityId=4 " SA_LOG_STREAM_SYSTEM; + rc_validate(systemCall(command), EXIT_SUCCESS); + + /* Restore the value back to the default value */ + command = "immcfg -a saLogStreamFacilityId= " SA_LOG_STREAM_SYSTEM; + (void)systemCall(command); +} + +// TC#2: Set an invalid value to `saLogStreamFacilityId` +void config_saLogStreamFacilityId_2() +{ + const char *command = + "immcfg -a saLogStreamFacilityId=24 " SA_LOG_STREAM_SYSTEM + " 2> /dev/null"; + rc_validate(systemCall(command), EXIT_FAILURE); +} + +static void switch_over() +{ + const char *command = + "amf-adm si-swap safSi=SC-2N,safApp=OpenSAF 2>/dev/null"; + (void)systemCall(command); +} + +static uint8_t get_role() +{ + char node[256]; + sprintf(node, "SC-%d", get_active_sc()); + if (strncmp("PL", hostname(), 2) == 0) { + return PAYLOAD; + } else { + if (strcmp(node, hostname()) == 0) + return ACTIVE_NODE; + return STANDBY_NODE; + } +} + +static void setup(uint32_t facilityId) +{ + const char dest[] = "test;UNIX_SOCKET;/tmp/test.sock"; + char command[1000]; + + StartUnixServer(); + + memset(command, 0, sizeof(command)); + sprintf( + command, + "immcfg -a logRecordDestinationConfiguration=\"%s\" %s 2>/dev/null", + dest, SA_LOG_CONFIGURATION_OBJECT); + (void)systemCall(command); + + sprintf(command, "immcfg -a saLogRecordDestination=test %s 2>/dev/null", + SA_LOG_STREAM_SYSTEM); + (void)systemCall(command); + + memset(command, 0, sizeof(command)); + if (facilityId < 24) { + sprintf(command, + "immcfg -a saLogStreamFacilityId=%d %s 2>/dev/null", + facilityId, SA_LOG_STREAM_SYSTEM); + } else { + sprintf(command, + "immcfg -a saLogStreamFacilityId= %s 2>/dev/null", + SA_LOG_STREAM_SYSTEM); + } + (void)systemCall(command); +} + +static void restore_default_value() +{ + char command[1000]; + + /* Restore the value back to the default value */ + memset(command, 0, sizeof(command)); + sprintf(command, "immcfg -a saLogStreamFacilityId= %s 2>/dev/null", + SA_LOG_STREAM_SYSTEM); + (void)systemCall(command); + + memset(command, 0, sizeof(command)); + sprintf(command, "immcfg -a saLogRecordDestination= %s 2>/dev/null", + SA_LOG_STREAM_SYSTEM); + (void)systemCall(command); + + memset(command, 0, sizeof(command)); + sprintf(command, + "immcfg -a logRecordDestinationConfiguration= %s 2>/dev/null", + SA_LOG_CONFIGURATION_OBJECT); + (void)systemCall(command); +} + +//> +// TC#3: Verify if PRI = 38 (saLogStreamFacilityId * 8 + severity) in package +// RFC5424 format.The test must run on active node. +// +// Change `saLogStreamFacilityId = 4` and send the log record with severity = 6 +//< +void streaming_log_record_then_verify_PRI_1() +{ + if (get_role() != ACTIVE_NODE) { + test_validate(true, true); + return; + } + + setup(4); + + strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__); + genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); + genLogRecord.logHeader.genericHdr.logSeverity = SA_LOG_SEV_INFO; + + rc = logInitialize(); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logStreamOpen(&systemStreamName); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logWriteAsync(&genLogRecord); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + test_validate(FindExpectedPRI("<38>", (char *)__FUNCTION__), true); + +done: + restore_default_value(); + logStreamClose(); + logFinalize(); + StopUnixServer(); +} + +//> +// TC#4: Verify if PRI = 134 (saLogStreamFacilityId (16)* 8 + severity) in +// package RFC5424 format.The test must run on active node. +// +// Delete attribute `saLogStreamFacilityId` and send the log record with +// severity = 6(information message) +//< +void streaming_log_record_then_verify_PRI_2() +{ + if (get_role() != ACTIVE_NODE) { + test_validate(true, true); + return; + } + + setup(127); + + strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__); + genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); + genLogRecord.logHeader.genericHdr.logSeverity = SA_LOG_SEV_INFO; + + rc = logInitialize(); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logStreamOpen(&systemStreamName); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logWriteAsync(&genLogRecord); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + test_validate(FindExpectedPRI("<134>", (char *)__FUNCTION__), true); + +done: + restore_default_value(); + logStreamClose(); + logFinalize(); + StopUnixServer(); +} + +//> +// TC#5: This test case verify if the PRI=38 after trigger switch-over and +// streaming log record ('PRI'field in package RFC5425 ).The test must run +// on standby node. +//< +void streaming_log_record_then_verify_PRI_3() +{ + if (get_role() != STANDBY_NODE) { + test_validate(true, true); + return; + } + + setup(4); + + switch_over(); + + strcpy((char *)genLogRecord.logBuffer->logBuf, __FUNCTION__); + genLogRecord.logBuffer->logBufSize = strlen(__FUNCTION__); + genLogRecord.logHeader.genericHdr.logSeverity = SA_LOG_SEV_INFO; + + rc = logInitialize(); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logStreamOpen(&systemStreamName); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + rc = logWriteAsync(&genLogRecord); + if (rc != SA_AIS_OK) { + test_validate(rc, SA_AIS_OK); + goto done; + } + + test_validate(FindExpectedPRI("<38>", (char *)__FUNCTION__), true); + +done: + restore_default_value(); + logStreamClose(); + logFinalize(); + StopUnixServer(); +} + +__attribute__((constructor)) static void saLibraryLifeCycle_constructor(void) +{ + test_suite_add(22, "Test log stream config facility id"); + test_case_add(22, config_saLogStreamFacilityId_1, + "Set a valid value to saLogStreamFacilityId"); + test_case_add(22, config_saLogStreamFacilityId_2, + "Set a invalid value to saLogStreamFacilityId"); + test_case_add(22, streaming_log_record_then_verify_PRI_1, + "Streaming with configure saLogStreamFacilityId=4 and " + "verify PRI field"); + test_case_add( + 22, streaming_log_record_then_verify_PRI_2, + "Delelte attribute saLogStreamFacilityId and verify PRI field"); + test_case_add(22, streaming_log_record_then_verify_PRI_3, + "Trigger switch-over then verify PRI field in package " + "RFC5424 format"); +} diff --git a/src/log/tests/lgs_dest_test.cc b/src/log/tests/lgs_dest_test.cc index 3f1b90e57..6ef27ac0d 100644 --- a/src/log/tests/lgs_dest_test.cc +++ b/src/log/tests/lgs_dest_test.cc @@ -147,6 +147,7 @@ static const char rec[] = "hello world"; static const char hostname[] = "sc-1"; static const char networkname[] = "networkA"; static const uint16_t sev = 3; +static const uint32_t facilityId = 4; static const char appname[] = "lgs_dest_test"; static const char dn[] = "safLgStrCfg=test"; static const char msgid[] = "testC"; @@ -162,6 +163,7 @@ void initData(RecordData* data) { data->recordId = 1; data->sev = 3; data->time = base::ReadRealtimeClock(); + data->facilityId = facilityId; } // No destination name & no destination configuration exist @@ -258,6 +260,7 @@ TEST(WriteToDestination, HaveDestNameAndDestCfg) { info.severity = data.sev; info.time = data.time; info.origin = origin.c_str(); + info.facilityId = data.facilityId; WriteToDestination(data, {"test"}); -- 2.17.1 _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel