MCPcopy Create free account
hub / github.com/corosync/corosync / test_basics

Function test_basics

test/testsam.c:70–182  ·  view source on GitHub ↗

* First test will just register SAM, with policy restart. First instance will * sleep one second, send hc and sleep another 3 seconds. This should force restart. * Second instance will sleep one second, send hc, stop hc and sleep 3 seconds. * Then start hc again and sleep 3 seconds. This should force restart again. * Last instance just calls initialize again. This should end with error. * The

Source from the content-addressed store, hash-verified

68 * (none should succeed).
69 */
70static int test_basics (void)
71{
72 cs_error_t error;
73 unsigned int instance_id;
74 int i;
75
76 printf ("%s: initialize\n", __FUNCTION__);
77 error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
78 if (error != CS_OK) {
79 fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
80 return 1;
81 }
82 printf ("%s: register\n", __FUNCTION__);
83 error = sam_register (&instance_id);
84 if (error != CS_OK) {
85 fprintf (stderr, "Can't register. Error %d\n", error);
86 return 1;
87 }
88
89 if (instance_id == 1 || instance_id == 2) {
90 printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
91 error = sam_start ();
92 if (error != CS_OK) {
93 fprintf (stderr, "Can't start hc. Error %d\n", error);
94 return 1;
95 }
96
97 for (i = 0; i < 10; i++) {
98 printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
99 sleep (1);
100
101 printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id);
102 error = sam_hc_send ();
103 if (error != CS_OK) {
104 fprintf (stderr, "Can't send hc. Error %d\n", error);
105 return 1;
106 }
107 }
108
109 if (instance_id == 2) {
110 printf ("%s iid %d: stop\n", __FUNCTION__, instance_id);
111 error = sam_stop ();
112
113 if (error != CS_OK) {
114 fprintf (stderr, "Can't stop hc. Error %d\n", error);
115 return 1;
116 }
117 }
118
119 printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
120 sleep (3);
121
122 if (instance_id == 1) {
123 printf ("%s iid %d: Failed. Wasn't killed.\n", __FUNCTION__, instance_id);
124
125 return 1;
126 }
127

Callers

nothing calls this directly

Calls 7

sam_initializeFunction · 0.85
sam_registerFunction · 0.85
sam_startFunction · 0.85
sam_hc_sendFunction · 0.85
sam_stopFunction · 0.85
sam_finalizeFunction · 0.85
sam_hc_callback_registerFunction · 0.85

Tested by

no test coverage detected