static void test6_signal (int sig) { cs_error_t error; printf ("%s\n", __FUNCTION__); test6_sig_delivered++; if ((error = sam_data_store (&test6_sig_delivered, sizeof (test6_sig_delivered))) != CS_OK) { fprintf (stderr, "Can't store data! Error : %d\n", error); } }
static void test6_signal (int sig) { cs_error_t error; qb_enter(); test6_sig_delivered++; if ((error = sam_data_store (&test6_sig_delivered, sizeof (test6_sig_delivered))) != CS_OK) { qb_log (LOG_ERR, "Can't store data! Error : %d", error); } }
static int test5_hc_cb (void) { printf ("%s %d\n", __FUNCTION__, ++test5_hc_cb_count); sam_data_store (&test5_hc_cb_count, sizeof (test5_hc_cb_count)); if (test5_hc_cb_count > 10) return 1; return 0; }
static int test5_hc_cb (void) { cs_error_t res; qb_log (LOG_INFO, "%d", ++test5_hc_cb_count); res = sam_data_store (&test5_hc_cb_count, sizeof (test5_hc_cb_count)); if (res != CS_OK) return 1; if (test5_hc_cb_count > 10) return 1; return 0; }
static cs_error_t sam_parent_data_store ( int parent_fd_in, int parent_fd_out) { char *user_data; ssize_t size; cs_error_t err; err = CS_OK; user_data = NULL; if (sam_safe_read (parent_fd_in, &size, sizeof (size)) != sizeof (size)) { err = CS_ERR_LIBRARY; goto error_reply; } if (size > 0) { user_data = malloc (size); if (user_data == NULL) { err = CS_ERR_NO_MEMORY; goto error_reply; } if (sam_safe_read (parent_fd_in, user_data, size) != size) { err = CS_ERR_LIBRARY; goto free_error_reply; } } err = sam_data_store (user_data, size); if (err != CS_OK) { goto free_error_reply; } free (user_data); return (sam_parent_reply_send (CS_OK, parent_fd_in, parent_fd_out)); free_error_reply: free (user_data); error_reply: return (sam_parent_reply_send (err, parent_fd_in, parent_fd_out)); }
/* * Test sam_data_store, sam_data_restore and sam_data_getsize */ static int test4 (void) { size_t size; cs_error_t err; int i; unsigned int instance_id; char saved_data[128]; char saved_data2[128]; qb_log (LOG_INFO, "sam_data_getsize 1"); err = sam_data_getsize (&size); if (err != CS_ERR_BAD_HANDLE) { qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err); return 1; } qb_log (LOG_INFO, "sam_data_getsize 2"); err = sam_data_getsize (NULL); if (err != CS_ERR_INVALID_PARAM) { qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err); return 1; } qb_log (LOG_INFO, "sam_data_store 1"); err = sam_data_store (NULL, 0); if (err != CS_ERR_BAD_HANDLE) { qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err); return 1; } qb_log (LOG_INFO, "sam_data_restore 1"); err = sam_data_restore (saved_data, sizeof (saved_data)); if (err != CS_ERR_BAD_HANDLE) { qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err); return 1; } qb_log (LOG_INFO, "sam_initialize"); err = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART); if (err != CS_OK) { qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err); return 1; } qb_log (LOG_INFO, "sam_data_getsize 3"); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err); return 1; } if (size != 0) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } qb_log (LOG_INFO, "sam_data_restore 2"); err = sam_data_restore (NULL, sizeof (saved_data)); if (err != CS_ERR_INVALID_PARAM) { qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err); return 1; } /* * Store some real data */ for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i + 5); } qb_log (LOG_INFO, "sam_data_store 2"); err = sam_data_store (saved_data, sizeof (saved_data)); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } qb_log (LOG_INFO, " sam_data_getsize 4"); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (size != sizeof (saved_data)) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } qb_log (LOG_INFO, " sam_data_restore 3"); err = sam_data_restore (saved_data2, sizeof (saved_data2) - 1); if (err != CS_ERR_INVALID_PARAM) { qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err); return 1; } qb_log (LOG_INFO, " sam_data_restore 4"); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) { qb_log (LOG_ERR, "Retored data are not same"); return 1; } memset (saved_data2, 0, sizeof (saved_data2)); qb_log (LOG_INFO, " sam_data_store 3"); err = sam_data_store (NULL, 1); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } qb_log (LOG_INFO, " sam_data_getsize 5"); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (size != 0) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } qb_log (LOG_INFO, " sam_data_store 4"); err = sam_data_store (saved_data, sizeof (saved_data)); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } qb_log (LOG_INFO, " register"); err = sam_register (&instance_id); if (err != CS_OK) { qb_log (LOG_ERR, "Can't register. Error %d", err); return 1; } if (instance_id == 1) { qb_log (LOG_INFO, "iid %d: sam_start", instance_id); err = sam_start (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", err); return 1; } qb_log (LOG_INFO, "iid %d: sam_data_getsize 6", instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (size != sizeof (saved_data2)) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } qb_log (LOG_INFO, "iid %d: sam_data_restore 5", instance_id); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) { qb_log (LOG_ERR, "Retored data are not same"); return 1; } for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i - 5); } qb_log (LOG_INFO, "iid %d: sam_data_store 5", instance_id); err = sam_data_store (saved_data, sizeof (saved_data) - 7); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } exit (1); } if (instance_id == 2) { qb_log (LOG_INFO, "iid %d: sam_start", instance_id); err = sam_start (); if (err != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", err); return 1; } qb_log (LOG_INFO, "iid %d: sam_data_getsize 7", instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (size != sizeof (saved_data2) - 7) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } qb_log (LOG_INFO, "iid %d: sam_data_restore 6", instance_id); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i - 5); } if (memcmp (saved_data, saved_data2, sizeof (saved_data2) - 7) != 0) { qb_log (LOG_ERR, "Retored data are not same"); return 1; } qb_log (LOG_INFO, "iid %d: sam_data_store 6", instance_id); err = sam_data_store (NULL, 0); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } exit (1); } if (instance_id == 3) { qb_log (LOG_INFO, "iid %d: sam_data_getsize 8", instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err); return 1; } if (size != 0) { qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size); return 1; } } return (0); }
/* * Test sam_data_store, sam_data_restore and sam_data_getsize */ static int sam_test4 (void) { size_t size; cs_error_t err; int i; unsigned int instance_id; char saved_data[128]; char saved_data2[128]; setlinebuf(stdout); printf ("%s: sam_data_getsize 1\n", __FUNCTION__); err = sam_data_getsize (&size); if (err != CS_ERR_BAD_HANDLE) { fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err); return 1; } printf ("%s: sam_data_getsize 2\n", __FUNCTION__); err = sam_data_getsize (NULL); if (err != CS_ERR_INVALID_PARAM) { fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err); return 1; } printf ("%s: sam_data_store 1\n", __FUNCTION__); err = sam_data_store (NULL, 0); if (err != CS_ERR_BAD_HANDLE) { fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err); return 1; } printf ("%s: sam_data_restore 1\n", __FUNCTION__); err = sam_data_restore (saved_data, sizeof (saved_data)); if (err != CS_ERR_BAD_HANDLE) { fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err); return 1; } printf ("%s: sam_initialize\n", __FUNCTION__); err = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART); if (err != CS_OK) { fprintf (stderr, "Can't initialize SAM API. Error %d\n", err); return 1; } printf ("%s: sam_data_getsize 3\n", __FUNCTION__); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err); return 1; } if (size != 0) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } printf ("%s: sam_data_restore 2\n", __FUNCTION__); err = sam_data_restore (NULL, sizeof (saved_data)); if (err != CS_ERR_INVALID_PARAM) { fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err); return 1; } /* * Store some real data */ for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i + 5); } printf ("%s: sam_data_store 2\n", __FUNCTION__); err = sam_data_store (saved_data, sizeof (saved_data)); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } printf ("%s: sam_data_getsize 4\n", __FUNCTION__); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (size != sizeof (saved_data)) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } printf ("%s: sam_data_restore 3\n", __FUNCTION__); err = sam_data_restore (saved_data2, sizeof (saved_data2) - 1); if (err != CS_ERR_INVALID_PARAM) { fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err); return 1; } printf ("%s: sam_data_restore 4\n", __FUNCTION__); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) { fprintf (stderr, "Retored data are not same\n"); return 1; } memset (saved_data2, 0, sizeof (saved_data2)); printf ("%s: sam_data_store 3\n", __FUNCTION__); err = sam_data_store (NULL, 1); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } printf ("%s: sam_data_getsize 5\n", __FUNCTION__); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (size != 0) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } printf ("%s: sam_data_store 4\n", __FUNCTION__); err = sam_data_store (saved_data, sizeof (saved_data)); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } printf ("%s: register\n", __FUNCTION__); err = sam_register (&instance_id); if (err != CS_OK) { fprintf (stderr, "Can't register. Error %d\n", err); return 1; } if (instance_id == 1) { printf ("%s iid %d: sam_start\n", __FUNCTION__, instance_id); err = sam_start (); if (err != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", err); return 1; } printf ("%s iid %d: sam_data_getsize 6\n", __FUNCTION__, instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (size != sizeof (saved_data2)) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } printf ("%s iid %d: sam_data_restore 5\n", __FUNCTION__, instance_id); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) { fprintf (stderr, "Retored data are not same\n"); return 1; } for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i - 5); } printf ("%s iid %d: sam_data_store 5\n", __FUNCTION__, instance_id); err = sam_data_store (saved_data, sizeof (saved_data) - 7); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } exit (1); } if (instance_id == 2) { printf ("%s iid %d: sam_start\n", __FUNCTION__, instance_id); err = sam_start (); if (err != CS_OK) { fprintf (stderr, "Can't start hc. Error %d\n", err); return 1; } printf ("%s iid %d: sam_data_getsize 7\n", __FUNCTION__, instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (size != sizeof (saved_data2) - 7) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } printf ("%s iid %d: sam_data_restore 6\n", __FUNCTION__, instance_id); err = sam_data_restore (saved_data2, sizeof (saved_data2)); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } for (i = 0; i < sizeof (saved_data); i++) { saved_data[i] = (char)(i - 5); } if (memcmp (saved_data, saved_data2, sizeof (saved_data2) - 7) != 0) { fprintf (stderr, "Retored data are not same\n"); return 1; } printf ("%s iid %d: sam_data_store 6\n", __FUNCTION__, instance_id); err = sam_data_store (NULL, 0); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } exit (1); } if (instance_id == 3) { printf ("%s iid %d: sam_data_getsize 8\n", __FUNCTION__, instance_id); err = sam_data_getsize (&size); if (err != CS_OK) { fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err); return 1; } if (size != 0) { fprintf (stderr, "Test should return size of 0. Returned %zx\n", size); return 1; } } return (0); }