Patch add new test case of new suite 41 to test saNtfNotificationReadNext
after the cold sync of cached alarm
---
 src/ntf/Makefile.am                               |   3 +-
 src/ntf/apitest/tet_coldsync.c                    | 211 ++++++++++++++++++++++
 src/ntf/apitest/tet_ntf.h                         |   2 +
 src/ntf/apitest/tet_ntf_common.c                  |  97 +++++++++-
 src/ntf/apitest/tet_ntf_common.h                  |   2 +
 src/ntf/apitest/tet_ntf_main.c                    |   3 +
 src/ntf/apitest/tet_scOutage_reinitializeHandle.c |  77 +-------
 7 files changed, 316 insertions(+), 79 deletions(-)
 create mode 100644 src/ntf/apitest/tet_coldsync.c

diff --git a/src/ntf/Makefile.am b/src/ntf/Makefile.am
index 3512154..28e3c84 100644
--- a/src/ntf/Makefile.am
+++ b/src/ntf/Makefile.am
@@ -271,7 +271,8 @@ bin_ntftest_SOURCES = \
        src/ntf/apitest/test_ntfFilterVerification.c \
        src/ntf/apitest/tet_longDnObject_notification.c \
        src/ntf/apitest/tet_scOutage_reinitializeHandle.c \
-       src/ntf/apitest/tet_ntf_clm.c
+       src/ntf/apitest/tet_ntf_clm.c \
+       src/ntf/apitest/tet_coldsync.c
 
 bin_ntftest_LDADD = \
        lib/libapitest.la
diff --git a/src/ntf/apitest/tet_coldsync.c b/src/ntf/apitest/tet_coldsync.c
new file mode 100644
index 0000000..32ac067
--- /dev/null
+++ b/src/ntf/apitest/tet_coldsync.c
@@ -0,0 +1,211 @@
+/*      -*- OpenSAF  -*-
+ *
+ * (C) Copyright 2018 The OpenSAF Foundation
+ *
+ * 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 <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <wait.h>
+#include "osaf/apitest/utest.h"
+#include "osaf/apitest/util.h"
+#include "tet_ntf.h"
+#include "tet_ntf_common.h"
+
+extern int verbose;
+
+void free_notif_2(SaNtfSubscriptionIdT subscriptionId,
+               const SaNtfNotificationsT *notification)
+{
+       SaNtfNotificationHandleT notificationHandle = 0;
+       switch (notification->notificationType) {
+       case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
+               notificationHandle =
+                   notification->notification.objectCreateDeleteNotification
+                       .notificationHandle;
+               break;
+
+       case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
+               notificationHandle =
+                   notification->notification.attributeChangeNotification
+                       .notificationHandle;
+               break;
+
+       case SA_NTF_TYPE_STATE_CHANGE:
+               notificationHandle =
+                   notification->notification.stateChangeNotification
+                       .notificationHandle;
+               break;
+
+       case SA_NTF_TYPE_ALARM:
+               notificationHandle = notification->notification
+                                        .alarmNotification.notificationHandle;
+               break;
+
+       case SA_NTF_TYPE_SECURITY_ALARM:
+               notificationHandle =
+                   notification->notification.securityAlarmNotification
+                       .notificationHandle;
+               break;
+
+       default:
+               assert(0);
+               break;
+       }
+       if (notificationHandle != 0) {
+               safassert(saNtfNotificationFree(notificationHandle), SA_AIS_OK);
+       }
+}
+
+/**
+ * Reboot the standby, switch over and
+ * reader is successful to read (alarm)notifications
+ */
+void test_coldsync_saNtfNotificationReadNext_01(void)
+{
+       saNotificationAllocationParamsT myNotificationAllocationParams;
+       saNotificationFilterAllocationParamsT
+                       myNotificationFilterAllocationParams;
+       saNotificationParamsT myNotificationParams;
+
+       SaNtfSearchCriteriaT searchCriteria;
+       SaNtfAlarmNotificationFilterT myAlarmFilter;
+       SaNtfNotificationTypeFilterHandlesT myNotificationFilterHandles = {
+                       0, 0, 0, 0, 0};
+       SaNtfReadHandleT readHandle;
+       SaNtfHandleT ntfHandle;
+       SaNtfNotificationsT returnedNotification;
+       SaNtfAlarmNotificationT myNotification;
+       searchCriteria.searchMode = SA_NTF_SEARCH_ONLY_FILTER;
+       SaAisErrorT errorCode;
+       SaUint32T readCounter = 0;
+
+       fillInDefaultValues(&myNotificationAllocationParams,
+                                       &myNotificationFilterAllocationParams,
+                                       &myNotificationParams);
+
+       safassert(ntftest_saNtfInitialize(&ntfHandle,
+               &ntfCallbacks, &ntfVersion), SA_AIS_OK);
+
+       safassert(ntftest_saNtfAlarmNotificationFilterAllocate(
+               ntfHandle, /* handle to Notification Service instance */
+               &myAlarmFilter, /* put filter here */
+               /* number of event types */
+               myNotificationFilterAllocationParams.numEventTypes,
+               /* number of notification objects */
+               myNotificationFilterAllocationParams.numNotificationObjects,
+               /* number of notifying objects */
+               myNotificationFilterAllocationParams.numNotifyingObjects,
+               /* number of notification class ids */
+               myNotificationFilterAllocationParams.numNotificationClassIds,
+               /* number of probable causes */
+               myNotificationFilterAllocationParams.numProbableCauses,
+               /* number of perceived severities */
+               myNotificationFilterAllocationParams.numPerceivedSeverities,
+               /* number of trend indications */
+               myNotificationFilterAllocationParams.numTrends),
+               SA_AIS_OK);
+
+       myNotificationFilterHandles.alarmFilterHandle =
+               myAlarmFilter.notificationFilterHandle;
+       myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING;
+       myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED;
+
+       /* Send one alarm notification */
+       safassert(ntftest_saNtfAlarmNotificationAllocate(
+               ntfHandle, /* handle to Notification Service instance */
+               &myNotification,
+               /* number of correlated notifications */
+               myNotificationAllocationParams.numCorrelatedNotifications,
+               /* length of additional text */
+               myNotificationAllocationParams.lengthAdditionalText,
+               /* number of additional info items*/
+               myNotificationAllocationParams.numAdditionalInfo,
+               /* number of specific problems */
+               myNotificationAllocationParams.numSpecificProblems,
+               /* number of monitored attributes */
+               myNotificationAllocationParams.numMonitoredAttributes,
+               /* number of proposed repair actions */
+               myNotificationAllocationParams.numProposedRepairActions,
+               /* use default allocation size */
+               myNotificationAllocationParams.variableDataSize),
+               SA_AIS_OK);
+
+       myNotificationParams.eventType = myNotificationParams.alarmEventType;
+
+       fill_header_part(&myNotification.notificationHeader,
+                        (saNotificationParamsT *)&myNotificationParams,
+                        myNotificationAllocationParams.lengthAdditionalText);
+
+       /* determine perceived severity */
+       *(myNotification.perceivedSeverity) =
+                       myNotificationParams.perceivedSeverity;
+
+       /* set probable cause*/
+       *(myNotification.probableCause) = myNotificationParams.probableCause;
+
+       safassert(ntftest_saNtfNotificationSend(
+                       myNotification.notificationHandle),SA_AIS_OK);
+
+       // reboot standby, switchover
+       wait_controllers(3);
+       wait_controllers(4);
+
+       /* Read initialize here to get the notification above */
+       safassert(ntftest_saNtfNotificationReadInitialize(searchCriteria,
+               &myNotificationFilterHandles, &readHandle),
+               SA_AIS_OK);
+
+       /* read as many matching notifications as exist for the time period
+        between the last received one and now */
+       for (; (errorCode = ntftest_saNtfNotificationReadNext(
+                               readHandle, SA_NTF_SEARCH_YOUNGER,
+                               &returnedNotification)) == SA_AIS_OK;) {
+               safassert(errorCode, SA_AIS_OK);
+               readCounter++;
+
+               if (verbose) {
+                       newNotification(69, &returnedNotification);
+               } else {
+                       free_notif_2(0, &returnedNotification);
+               }
+       }
+       if (verbose) {
+               (void)printf("\n errorcode to break loop: %d\n",
+                       (int)errorCode);
+       }
+       if (readCounter == 0) {
+               errorCode = SA_AIS_ERR_FAILED_OPERATION;
+       }
+
+       // No more...
+       safassert(ntftest_saNtfNotificationReadFinalize(readHandle), SA_AIS_OK);
+       safassert(ntftest_saNtfNotificationFilterFree(
+               myAlarmFilter.notificationFilterHandle), SA_AIS_OK);
+       free(myNotificationParams.additionalText);
+       
safassert(ntftest_saNtfNotificationFree(myNotification.notificationHandle),
+                       SA_AIS_OK);
+       safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);
+       test_validate(errorCode, SA_AIS_ERR_NOT_EXIST);
+}
+
+void add_coldsync_test(void)
+{
+       install_sigusr2();
+
+       test_suite_add(41, "Cold sync - Reader");
+       test_case_add(41, test_coldsync_saNtfNotificationReadNext_01,
+           "saNtfNotificationReadNext after rebooting standby SC and switch 
over");
+}
diff --git a/src/ntf/apitest/tet_ntf.h b/src/ntf/apitest/tet_ntf.h
index 87ce758..fef6673 100644
--- a/src/ntf/apitest/tet_ntf.h
+++ b/src/ntf/apitest/tet_ntf.h
@@ -46,6 +46,8 @@ extern SaSelectionObjectT selectionObject;
 int verbose;
 int gl_tag_mode;
 int gl_prompt_mode;
+bool gl_suspending;
+
 #define DEFAULT_ADDITIONAL_TEXT "this is additional text info"
 
 typedef struct {
diff --git a/src/ntf/apitest/tet_ntf_common.c b/src/ntf/apitest/tet_ntf_common.c
index f69cf1d..c966520 100644
--- a/src/ntf/apitest/tet_ntf_common.c
+++ b/src/ntf/apitest/tet_ntf_common.c
@@ -21,24 +21,117 @@
 #include <poll.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <pthread.h>
 #include "sa_error.h"
 #include "tet_ntf.h"
 #include "tet_ntf_common.h"
 
 #define CALLBACK_USED 1
-
+#define TST_TAG_ND "\nTAG_ND\n" /* Tag for take SC nodes down */
+#define TST_TAG_NU "\nTAG_NU\n" /* Tag for start SC nodes */
+#define TST_TAG_STB_ND "\nTAG_STB_ND\n" /* Tag for take standby SC down */
+#define TST_TAG_SWITCHOVER "\nTAG_SWITCHOVER\n" /* Tag for switch over */
 SaNtfIdentifierT last_not_id = SA_NTF_IDENTIFIER_UNUSED;
 extern int verbose;
 extern int gl_tag_mode;
 extern int gl_prompt_mode;
+extern bool gl_suspending;
 
 void assertvalue_impl(__const char *__assertion, __const char *__file,
-                     unsigned int __line, __const char *__function)
+                         unsigned int __line, __const char *__function)
 {
        fprintf(stderr, "assert failed in %s at %u, %s(): %s\n", __file, __line,
                __function, __assertion);
 }
 
+static void sigusr2_handler(int sig)
+{
+       if (gl_suspending)
+               gl_suspending = false;
+}
+
+void install_sigusr2() {
+       signal(SIGUSR2, sigusr2_handler);
+}
+
+/*
+ * Loop of reading key press, stop if 'n+Enter'. Sleep 1 between reading key
+ */
+static void *nonblk_io_getchar()
+{
+       while (gl_suspending) {
+               int c = getchar();
+               if (c == 'n')
+                       gl_suspending = false;
+               else
+                       sleep(1);
+       }
+       return NULL;
+}
+
+/*
+ * Wait for controllers (SCs):
+ * - Both SCs UP(wished_scs_state=1)
+ * - Both SCs DOWN(wished_scs_state=2)
+ * - Standby SC DOWN(wished_scs_state=3)
+ * - SC switch over(wished_scs_state=4)
+ * Press 'n' or send USR2 to ntftest to continue the test
+ */
+void wait_controllers(int wished_scs_state)
+{
+       int i = 0;
+       pthread_t thread_id;
+       gl_suspending = true;
+       /* print slogan */
+       if (wished_scs_state == 1) {
+               fprintf_p(stdout, "\nNext: manually START both SCs"
+                       "(in UML env. ./opensaf nodestart <1|2>)");
+               if (gl_tag_mode == 1) {
+                       fprintf_t(stdout, TST_TAG_NU);
+               }
+       } else if (wished_scs_state == 2) {
+               fprintf_p(stdout, "\nNext: manually STOP both SCs"
+                       "(in UML env. ./opensaf nodestop <1|2>)");
+               if (gl_tag_mode == 1) {
+                       fprintf_t(stdout, TST_TAG_ND);
+               }
+       } else if (wished_scs_state == 3) {
+               fprintf_p(stdout, "\nNext: manually STOP standby SC"
+                       "(in UML env. ./opensaf nodestop <1|2>)");
+               if (gl_tag_mode == 1) {
+                       fprintf_t(stdout, TST_TAG_STB_ND);
+               }
+       } else if (wished_scs_state == 4) {
+               fprintf_p(stdout, "\nNext: manually switch over"
+                       "(amf-adm si-swap safSi=SC-2N,safApp=OpenSAF)");
+               if (gl_tag_mode == 4) {
+                       fprintf_t(stdout, TST_TAG_SWITCHOVER);
+               }
+       } else {
+               fprintf_p(stderr, "wrong value wished_scs_state:%d\n",
+                       wished_scs_state);
+               exit(EXIT_FAILURE);
+       }
+
+       /* start non-blocking io thread */
+       if (pthread_create(&thread_id, NULL, nonblk_io_getchar, NULL) != 0) {
+               fprintf_p(stderr, "%d, %s; pthread_create FAILED: %s\n",
+                       __LINE__, __FUNCTION__, strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+       fprintf_p(stdout, "\nThen press 'n' and 'Enter'"
+               " (or 'pkill -USR2 ntftest') to continue. Waiting ...\n");
+       while (gl_suspending) {
+               i++;
+               i = i % 20;
+               i > 0 ? fprintf_p(stdout, ".") : fprintf_p(stdout, "\n");
+               fflush(stdout);
+               sleep(1);
+       }
+}
+
 extern SaNtfIdentifierT get_ntf_id(const SaNtfNotificationsT *notif)
 {
        switch (notif->notificationType) {
diff --git a/src/ntf/apitest/tet_ntf_common.h b/src/ntf/apitest/tet_ntf_common.h
index c655496..6ed9f85 100644
--- a/src/ntf/apitest/tet_ntf_common.h
+++ b/src/ntf/apitest/tet_ntf_common.h
@@ -358,6 +358,8 @@ SaAisErrorT 
ntftest_saNtfAttributeChangeNotificationFilterAllocate(
 void fprintf_v(FILE *, const char *format, ...);
 void fprintf_t(FILE *, const char *format, ...);
 void fprintf_p(FILE *, const char *format, ...);
+void wait_controllers(int wished_scs_state);
+void install_sigusr2();
 
 extern void assertvalue_impl(__const char *__assertion, __const char *__file,
                              unsigned int __line, __const char *__function);
diff --git a/src/ntf/apitest/tet_ntf_main.c b/src/ntf/apitest/tet_ntf_main.c
index f9c7af2..4ac239d 100644
--- a/src/ntf/apitest/tet_ntf_main.c
+++ b/src/ntf/apitest/tet_ntf_main.c
@@ -32,6 +32,7 @@ SaNtfHandleT ntfHandle = 0;
 SaNtfCallbacksT ntfCallbacks = {NULL, NULL};
 SaSelectionObjectT selectionObject;
 extern void add_scOutage_reinitializeHandle_test(void);
+extern void add_coldsync_test(void);
 extern int verbose;
 extern int gl_tag_mode;
 extern int gl_prompt_mode;
@@ -133,6 +134,7 @@ int main(int argc, char **argv)
                                exit(0);
                        case 'l':
                                add_scOutage_reinitializeHandle_test();
+                               add_coldsync_test();
                                test_list();
                                exit(0);
                        case 'v':
@@ -157,6 +159,7 @@ int main(int argc, char **argv)
                                        suite = atoi(argv[optind - 1]);
                                        extendedTest = 1;
                                        add_scOutage_reinitializeHandle_test();
+                                       add_coldsync_test();
                                } else
                                        err_exit();
                                if (optind < argc && argv[optind] != NULL)
diff --git a/src/ntf/apitest/tet_scOutage_reinitializeHandle.c 
b/src/ntf/apitest/tet_scOutage_reinitializeHandle.c
index 4af22ef..378d921 100644
--- a/src/ntf/apitest/tet_scOutage_reinitializeHandle.c
+++ b/src/ntf/apitest/tet_scOutage_reinitializeHandle.c
@@ -21,15 +21,11 @@
 #include "osaf/apitest/util.h"
 #include <unistd.h>
 #include <sys/stat.h>
-#include <signal.h>
 #include <poll.h>
-#include <pthread.h>
 #include "tet_ntf.h"
 #include "tet_ntf_common.h"
 #define NTF_REST_MAX_IDS 30
 #define DEFAULT_UNEXT_NAME_STRING "This is unextended SaNameT string (<256)"
-#define TST_TAG_ND "\nTAG_ND\n" /* Tag for take SC nodes down */
-#define TST_TAG_NU "\nTAG_NU\n" /* Tag for start SC nodes */
 
 struct not_idsT {
        int length;
@@ -104,14 +100,6 @@ static SaAisErrorT global_error_id = SA_AIS_OK;
 
 extern int gl_tag_mode;
 
-bool gl_suspending = true;
-
-static void sigusr2_handler(int sig)
-{
-       if (gl_suspending)
-               gl_suspending = false;
-}
-
 /**
  * Store all recieved notificationIds
  */
@@ -302,69 +290,6 @@ static void 
saNtfNotificationCallbackT(SaNtfSubscriptionIdT subscriptionId,
                saferror(saNtfNotificationFree(notificationHandle), SA_AIS_OK);
 }
 
-/*
- * Loop of reading key press, stop if 'n+Enter'. Sleep 1 between reading key
- */
-static void *nonblk_io_getchar()
-{
-       while (gl_suspending) {
-               int c = getchar();
-               if (c == 'n')
-                       gl_suspending = false;
-               else
-                       sleep(1);
-       }
-       return NULL;
-}
-
-/*
- * Wait for both controllers UP(wished_scs_state=1) or DOWN(wished_scs_state=2)
- * Once bring up/down controllers, tester press 'n' or send USR2 to ntftest to
- * continue the test
- */
-void wait_controllers(int wished_scs_state)
-{
-       int i = 0;
-       pthread_t thread_id;
-       gl_suspending = true;
-       /* print slogan */
-       if (wished_scs_state == 1) {
-               fprintf_p(
-                   stdout,
-                   "\nNext: manually START both SCs(in UML env. ./opensaf 
nodestart <1|2>)");
-               if (gl_tag_mode == 1) {
-                       fprintf_t(stdout, TST_TAG_NU);
-               }
-       } else if (wished_scs_state == 2) {
-               fprintf_p(
-                   stdout,
-                   "\nNext: manually STOP both SCs(in UML env. ./opensaf 
nodestop <1|2>)");
-               if (gl_tag_mode == 1) {
-                       fprintf_t(stdout, TST_TAG_ND);
-               }
-       } else {
-               fprintf_p(stderr, "wrong value wished_scs_state:%d\n",
-                         wished_scs_state);
-               exit(EXIT_FAILURE);
-       }
-
-       /* start non-blocking io thread */
-       if (pthread_create(&thread_id, NULL, nonblk_io_getchar, NULL) != 0) {
-               fprintf_p(stderr, "%d, %s; pthread_create FAILED: %s\n",
-                         __LINE__, __FUNCTION__, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-       fprintf_p(
-           stdout,
-           "\nThen press 'n' and 'Enter' (or 'pkill -USR2 ntftest') to 
continue. Waiting ...\n");
-       while (gl_suspending) {
-               i++;
-               i = i % 20;
-               i > 0 ? fprintf_p(stdout, ".") : fprintf_p(stdout, "\n");
-               fflush(stdout);
-               sleep(1);
-       }
-}
 
 static SaNtfCallbacksT ntfCbTest = {saNtfNotificationCallbackT, NULL};
 
@@ -1243,7 +1168,7 @@ void test_sc_outage_reader_3()
 
 void add_scOutage_reinitializeHandle_test(void)
 {
-       signal(SIGUSR2, sigusr2_handler);
+  install_sigusr2();
 
        test_suite_add(37, "SC outage: Test for producer");
        test_case_add(37, test_sc_outage_producer_1, "Test saNtfInitialize");
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to