static bool testClientsManagerExecurePurchase(){ Email email = NULL; emailCreate("baba@ganosh", &email); Email mail = NULL; emailCreate("baba@gash", &mail); ClientsManager manager = clientsManagerCreate(); clientsManagerAdd( manager, email, 1, 1, 200); ASSERT_TEST( clientsManagerExecutePurchase( NULL, email, 330) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerExecutePurchase( manager, NULL, 330) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerExecutePurchase( manager, mail, 330) == CLIENT_MANAGER_NOT_EXISTS); ASSERT_TEST( clientsManagerExecutePurchase( manager, email, 330) == CLIENT_MANAGER_SUCCESS); emailDestroy(mail); emailDestroy(email); clientsManagerDestroy(manager); return true; }
static void test_decoding_of_type2_message() { char const * data = "TlRMTVNTUAACAAAAAAAAADgAAADzgpjiavm/AUnPdy4AAAAAAAAAAIYAhgA4AAAABQLODgAAAA8CABAAQgBJAFIARABMAEEATgBEAAEACgBZAFUAQwBDAEEABAAYAGIAaQByAGQAbABhAG4AZAAuAGkAbgB0AAMAJAB5AHUAYwBjAGEALgBiAGkAcgBkAGwAYQBuAGQALgBpAG4AdAAFABgAYgBpAHIAZABsAGEAbgBkAC4AaQBuAHQAAAAAAA=="; pal::type2_message t2(pal::as_bytes_from_base64_string(data)); ASSERT_TEST( t2.challenge() == (uint64_t)0x2e77cf4901bff96a ); ASSERT_TEST( t2.ssp_flags() == (uint32_t)0xe29882f3 ); }
/* Release PCIe device */ static int pcie_release (llio_t *self, llio_endpoint_t *endpoint) { (void) endpoint; if (!llio_get_endpoint_open (self)) { /* Nothing to close */ return 0; } llio_err_e lerr = LLIO_SUCCESS; int err = 0; llio_dev_pcie_t *dev_pcie = llio_get_dev_handler (self); ASSERT_TEST(dev_pcie != NULL, "Could not get PCIe handler", err_dev_pcie_handler, -1); /* Deattach specific device handler to generic one */ lerr = llio_dev_pcie_destroy (&dev_pcie); ASSERT_TEST (lerr==LLIO_SUCCESS, "Could not close device appropriately", err_dealloc, -1); llio_set_dev_handler (self, NULL); llio_set_endpoint_open (self, false); DBE_DEBUG (DBG_LL_IO | DBG_LVL_INFO, "[ll_io_pcie] Closed PCIe device located at %s\n", llio_get_endpoint_name (self)); return err; err_dealloc: err_dev_pcie_handler: return err; }
int test_insertion3(){ Lock_list<int> list; Node<int>* node; int x = 1; list.insertFirst(x); node = list.lockFirst(); //1 ASSERT_TEST(**node == 1); list.unlockCurrent(node); x = 3; list.insertBeforeCurrent(x, node); node = list.lockPrev(node); //3,1 ASSERT_TEST(**node == 3); list.unlockCurrent(node); node = list.lockNext(node); ASSERT_TEST(**node == 1); list.unlockCurrent(node); x = 5; list.insertAfterCurrent(x, node); node = list.lockNext(node); //3,1,5 ASSERT_TEST(**node == 5); list.unlockCurrent(node); return 1; }
static ssize_t _thsafe_zmq_client_recv_write (smio_t *self) { ssize_t ret_size = -1; /* Returns NULL if confirmation was not OK or in case of error. * Returns the original message if the confirmation was OK */ zmsg_t *recv_msg = _thsafe_zmq_client_recv_confirmation (self); ASSERT_TEST(recv_msg != NULL, "Could not receive confirmation code", err_null_recv_msg); /* If we are here, confirmation code was OK. Check for second frame */ zframe_t *reply_frame = zmsg_pop (recv_msg); zframe_destroy (&reply_frame); /* Don't do anything with the reply code */ zframe_t *return_frame = zmsg_pop (recv_msg); ASSERT_TEST(return_frame != NULL, "Could not receive retrurn code", err_null_ret_code_frame); if (zframe_size (return_frame) != THSAFE_RETURN_SIZE) { DBE_DEBUG (DBG_MSG | DBG_LVL_ERR, "[smio_thsafe_client:zmq] Return frame size is wrong\n"); goto err_wrong_size_ret_frame; } ret_size = *(THSAFE_RETURN_TYPE *) zframe_data (return_frame); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received code: %zd\n", ret_size); err_wrong_size_ret_frame: zframe_destroy (&return_frame); err_null_ret_code_frame: err_null_recv_msg: return ret_size; }
static void _devio_destroy_smio (devio_t *self, uint32_t smio_id) { assert (self); /* Stringify ID */ char *key_c = halutils_stringify_key (smio_id); ASSERT_ALLOC (key_c, err_key_alloc); /* Lookup SMIO reference in hash table */ void *pipe = zhash_lookup (self->sm_io_h, key_c); ASSERT_TEST (pipe != NULL, "Could not find SMIO registered with this ID", err_hash_lookup); /* Send message to SMIO informing it to destroy itself */ /* This cannot fail at this point... but it can */ zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC (send_msg, err_msg_alloc); /* An empty message means to selfdestruct */ zmsg_pushstr (send_msg, ""); int zerr = zmsg_send (&send_msg, pipe); ASSERT_TEST (zerr == 0, "Could not send self-destruct message to SMIO instance", err_send_msg); /* Finally, remove the pipe from hash */ zhash_delete (self->sm_io_h, key_c); err_send_msg: zmsg_destroy (&send_msg); err_msg_alloc: err_hash_lookup: free (key_c); err_key_alloc: return; }
static bool testCacheExtractElementByKey() { char * andykaufman = "andykaufman"; char * agonist = "agonist"; char * nightwish = "nightwish"; Cache cache = cacheCreate(256, freeString, copyString, compareStrings, getFirstLetter); ASSERT_TEST(cache != NULL); ASSERT_TEST(cachePush(cache, nightwish) == CACHE_SUCCESS); ASSERT_TEST(cachePush(cache, nightwish) == CACHE_ITEM_ALREADY_EXISTS); ASSERT_TEST(cacheIsIn(cache, nightwish)); ASSERT_TEST(cachePush(cache, andykaufman) == CACHE_SUCCESS); ASSERT_TEST(cachePush(cache, andykaufman) == CACHE_ITEM_ALREADY_EXISTS); ASSERT_TEST(cacheIsIn(cache, andykaufman)); ASSERT_TEST(cachePush(cache, agonist) == CACHE_SUCCESS); ASSERT_TEST(cachePush(cache, agonist) == CACHE_ITEM_ALREADY_EXISTS); ASSERT_TEST(cacheIsIn(cache, agonist)); const int SIZE = 3; char * elements[SIZE]; int i = 0; CACHE_FOREACH(set, cache) { SET_FOREACH(char *, str, set) { elements[i++] = str; } }
bool block_program_test() { const char* name1 = "/root/hw1_tests/prog1"; const char* name2 = "/root/hw1_tests/prog2"; const char* name3 = ""; int len = strlen(name1); ASSERT_TEST(block_program(NULL, 5) == -1); ASSERT_TEST(errno == EINVAL); ASSERT_TEST(block_program(name3, 0) == -1); ASSERT_TEST(errno == EINVAL); ASSERT_TEST(block_program(name1, 0) == -1); ASSERT_TEST(errno == EINVAL); ASSERT_TEST(block_program(name2, len) == 0); ASSERT_TEST(block_program(name1, len) == 0); ASSERT_TEST(block_program(name2, len) == 1); ASSERT_TEST(block_program(name1, len) == 1); char *argva[] = {"/root/hw1_tests/prog1", 0}; char *argvb[] = {"/root/hw1_tests/prog2", 0}; //fails execv(name1, argva); execv(name2, argvb); unblock_program (name1, len); unblock_program (name2, len); return true; }
static ssize_t _thsafe_zmq_client_read_generic (smio_t *self, loff_t offs, uint8_t *data, uint32_t size) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling _thsafe_read_generic\n"); switch (size) { case THSAFE_READ_16_DSIZE: opcode = THSAFE_READ_16; break; case THSAFE_READ_32_DSIZE: opcode = THSAFE_READ_32; break; case THSAFE_READ_64_DSIZE: opcode = THSAFE_READ_64; break; default: opcode = THSAFE_READ_32; } /* Message is: * frame 0: READ<size> opcode * frame 1: offset */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add READ opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code * frame 2: data */ ret_size = _thsafe_zmq_client_recv_read (self, data, size); err_send_msg: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
static void test_creating_nt_response() { std::vector<uint8_t> pwdhash = pal::create_password_hash("secret"); std::vector<uint8_t> expected = pal::as_bytes_from_hex_string("878D8014606CDA29677A44EFA1353FC7"); ASSERT_TEST(pwdhash.size() == 16); ASSERT_TEST(pwdhash.size() == expected.size()); ASSERT_TEST(std::equal(pwdhash.begin(), pwdhash.end(), expected.begin())); }
static void test_creating_md4_digest() { std::vector<uint8_t> input = pal::as_bytes_from_hex_string("8899AABBCCDDEEFF0011223344556677"); std::vector<uint8_t> output = pal::md4(input); std::vector<uint8_t> expected = pal::as_bytes_from_hex_string("5C0EC35E7A167E8D218C3CE168888723"); ASSERT_TEST(expected.size() == output.size()); ASSERT_TEST(std::equal(expected.begin(), expected.end(), output.begin())); }
static void test_encoding_with_rc4() { std::vector<uint8_t> text = pal::as_bytes_from_hex_string("8899AABBCCDDEEFF0011223344556677"); std::vector<uint8_t> key = pal::as_bytes_from_hex_string("00112233445566778899AABBCCDDEEFF"); std::vector<uint8_t> cipher = pal::rc4(key,text); std::vector<uint8_t> expected = pal::as_bytes_from_hex_string("0DC206EC5EFA8F7AF8489B08D1101BE3"); ASSERT_TEST(expected.size() == cipher.size()); ASSERT_TEST(std::equal(expected.begin(), expected.end(), cipher.begin())); }
static void test_converting_string_to_unicode() { std::vector<uint8_t> ustr = pal::as_unicode("Hello"); uint8_t expected[] = {'H',0,'e',0,'l',0,'l',0,'o',0}; ASSERT_TEST( std::equal(ustr.begin(), ustr.end(), expected) ); ASSERT_TEST( ustr.size() == 10 ); ustr = pal::as_unicode(""); ASSERT_TEST( ustr.size() == 0 ); }
static void test_calculating_lm_response() { uint64_t challenge = 0xCAFEBABEDEADBEEF; std::vector<uint8_t> lmr = pal::calculate_lm_response("secret", challenge); ASSERT_TEST( lmr.size() == 24 ); std::vector<uint8_t> expected = pal::as_bytes_from_hex_string("86730DE4EE77DB37308780F2801F7097CE876C4F37A90E18"); ASSERT_TEST( lmr.size() == expected.size() ); ASSERT_TEST( std::equal(expected.begin(), expected.end(), lmr.begin()) ); }
static void test_creating_encrypted_session_key() { std::vector<uint8_t> ph = pal::create_password_hash("secret"); std::vector<uint8_t> sk = pal::as_bytes_from_hex_string("00112233445566778899AABBCCDDEEFF"); std::vector<uint8_t> esk = pal::create_encrypted_session_key(ph,sk); std::vector<uint8_t> expected = pal::as_bytes_from_hex_string("F108FD16C6A48F619EDC61EC9EEC32F9"); ASSERT_TEST(esk.size() == expected.size()); ASSERT_TEST(std::equal(esk.begin(), esk.end(), expected.begin())); }
static bool testCacheFreeElement(void) { Cache cache = cacheCreate(255, freeString, copyString, compareStrings, getFirstLetter); char outOfRange[2] = { (char)255, '\0' }; char *notInCache = "Rock"; char *doubled = "Louna"; char * elements[] = { "Ramones", "Lumen", "Louna", "Arch Enemy" "Linkin park", }; const int ELEMENTS_SIZE = sizeof(elements) / sizeof(*elements); for (int i = 0; i < ELEMENTS_SIZE; ++i) { ASSERT_TEST(cachePush(cache, elements[i]) == CACHE_SUCCESS); } ASSERT_TEST(cachePush(cache, outOfRange) == CACHE_OUT_OF_RANGE); ASSERT_TEST(cachePush(cache, doubled) == CACHE_ITEM_ALREADY_EXISTS); ASSERT_TEST(cacheFreeElement(cache, outOfRange) == CACHE_ITEM_DOES_NOT_EXIST); ASSERT_TEST(cacheFreeElement(cache, notInCache) == CACHE_ITEM_DOES_NOT_EXIST); for (int i = ELEMENTS_SIZE-1; i >= 0; --i) { ASSERT_TEST(cacheFreeElement(cache, elements[i]) == CACHE_SUCCESS); } ASSERT_TEST(cacheFreeElement(cache, doubled) == CACHE_ITEM_DOES_NOT_EXIST); ASSERT_TEST(cacheFreeElement(NULL, doubled) == CACHE_NULL_ARGUMENT); ASSERT_TEST(cacheFreeElement(NULL, NULL) == CACHE_NULL_ARGUMENT); cacheDestroy(cache); return true; }
/** * List of tests, one for each function is usually a good thumb rule. */ static bool testListCreate() { ASSERT_TEST(listCreate(NULL,NULL) == NULL); ASSERT_TEST(listCreate(NULL,NULL) == NULL); ASSERT_TEST(listCreate(personCopyHelper,NULL) == NULL); ASSERT_TEST(listCreate(NULL,personDestroyHelper) == NULL); List list = listCreate(personCopyHelper, personDestroyHelper); ASSERT_TEST(list != NULL); listDestroy(list); return true; }
static void test_converting_between_hex_string_and_bytes() { std::vector<uint8_t> buf = pal::as_bytes_from_hex_string("CAFE0142"); ASSERT_TEST(buf.size() == 4); ASSERT_TEST(buf[0] == 0xCA && buf[1] == 0xFE && buf[2] == 0x01 && buf[3] == 0x42); std::string str = pal::as_hex_string(buf); ASSERT_TEST(str == "CAFE0142"); buf = pal::as_bytes_from_hex_string(""); ASSERT_TEST(buf.size() == 0); str = pal::as_hex_string(buf); ASSERT_TEST(str == ""); }
int test_doremove(){ Lock_list<int> list; Node<int>* node; for (int i = 0; i < 10; i++){ list.insertLast(i); } // 0, ... , 9 node = list.lockFirst(); list.unlockCurrent(node); node = list.lockNext(node); list.unlockCurrent(node); node = list.lockNext(node); // should point to 2 ASSERT_TEST(**node == 2); // 0,1,3...,9 node=list.doRemove(node); ASSERT_TEST(**node == 1); node = list.lockNext(node); ASSERT_TEST(**node == 3); list.unlockCurrent(node); node = list.lockLast(); ASSERT_TEST(**node == 9); node = list.lockPrev(node); ASSERT_TEST(**node == 8); list.unlockNext(node); list.unlockCurrent(node); // 0,1,3,..,7,9 node=list.doRemove(node); ASSERT_TEST(**node == 7); node = list.lockNext(node); ASSERT_TEST(**node == 9); list.unlockCurrent(node); node = list.lockFirst(); ASSERT_TEST(**node == 0); node = list.doRemove(node); ASSERT_TEST(node==NULL); node = list.lockFirst(); ASSERT_TEST(**node == 1); list.unlockCurrent(node); return 1; }
static ssize_t _thsafe_zmq_client_recv_read (smio_t *self, uint8_t *data, uint32_t size) { ssize_t ret_size = -1; /* Returns NULL if confirmation was not OK or in case of error. * Returns the original message if the confirmation was OK */ zmsg_t *recv_msg = _thsafe_zmq_client_recv_confirmation (self); ASSERT_TEST(recv_msg != NULL, "Could not receive confirmation code", err_null_recv_msg); /* If we are here, confirmation code was OK. Check for second frame */ zframe_t *reply_frame = zmsg_pop (recv_msg); zframe_destroy (&reply_frame); /* Don't do anything with the reply code */ zframe_t *return_frame = zmsg_pop (recv_msg); ASSERT_TEST(return_frame != NULL, "Could not receive retrurn code", err_null_ret_code_frame); if (zframe_size (return_frame) != THSAFE_RETURN_SIZE) { DBE_DEBUG (DBG_MSG | DBG_LVL_ERR, "[smio_thsafe_client:zmq] Return frame size is wrong\n"); goto err_wrong_size_ret_frame; } zframe_t *data_frame = zmsg_pop (recv_msg); ASSERT_TEST(data_frame != NULL, "Could not receive data", err_recv_data); /* Check if the frame has the number of bytes requested. * For now, we consider a success only when the number of * bytes requested is the same as the actually read*/ if ((ssize_t) zframe_size (data_frame) != *(THSAFE_RETURN_TYPE *) zframe_data (return_frame)) { DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Data frame size is wrong\n"); goto err_recv_data; } uint8_t* raw_data = (uint8_t *) zframe_data (data_frame); memcpy (data, raw_data, size); ret_size = size; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received data successfully\n"); zframe_destroy (&data_frame); err_recv_data: err_wrong_size_ret_frame: zframe_destroy (&return_frame); err_null_ret_code_frame: zmsg_destroy (&recv_msg); err_null_recv_msg: return ret_size; }
/**************** Helper Functions ***************/ static devio_err_e _devio_do_smio_op (devio_t *self, void *msg) { zmq_server_args_t *server_args = (zmq_server_args_t *) msg; /* Message is: * frame 0: opcode * frame 1: payload */ /* Extract the first frame and determine the opcode */ zframe_t *opcode = zmsg_pop (*server_args->msg); devio_err_e err = (opcode == NULL) ? DEVIO_ERR_BAD_MSG : DEVIO_SUCCESS; ASSERT_TEST(opcode != NULL, "Could not receive opcode", err_null_opcode); if (zframe_size (opcode) != THSAFE_OPCODE_SIZE) { DBE_DEBUG (DBG_DEV_IO | DBG_LVL_ERR, "[dev_io_core:poll_all_sm] Invalid opcode size received\n"); err = DEVIO_ERR_BAD_MSG; goto err_wrong_opcode_size; } uint32_t opcode_data = *(uint32_t *) zframe_data (opcode); if (opcode_data > THSAFE_OPCODE_END-1) { DBE_DEBUG (DBG_DEV_IO | DBG_LVL_ERR, "[dev_io_core:poll_all_sm] Invalid opcode received\n"); err = DEVIO_ERR_BAD_MSG; goto err_invalid_opcode; } /* Do the actual work... */ disp_table_call (self->disp_table_thsafe_ops, opcode_data, self, server_args); err_invalid_opcode: err_wrong_opcode_size: zframe_destroy (&opcode); err_null_opcode: return err; }
/* Creates a new instance of the SMCH PCA9547 */ smch_pca9547_t * smch_pca9547_new (smio_t *parent, uint64_t base, uint32_t addr, int verbose) { (void) verbose; assert (parent); smch_pca9547_t *self = (smch_pca9547_t *) zmalloc (sizeof *self); ASSERT_ALLOC(self, err_self_alloc); self->i2c = smpr_new (SMCH_PCA9547_NAME, parent, SMPR_I2C, verbose); ASSERT_ALLOC(self->i2c, err_i2c_alloc); /* Initalize the I2C protocol */ int smpr_err = smpr_open (self->i2c, base, NULL /* Default parameters are fine */); ASSERT_TEST(smpr_err == 0, "Could not initialize SMPR protocol", err_smpr_init); self->addr = addr; DBE_DEBUG (DBG_SM_CH | DBG_LVL_INFO, "[sm_ch:pca9547] Created instance of SMCH\n"); return self; err_smpr_init: smpr_destroy (&self->i2c); err_i2c_alloc: free (self); err_self_alloc: return NULL; }
static halutils_err_e _disp_table_insert (disp_table_t *self, uint32_t key, disp_table_func_fp func_fp) { if (func_fp == NULL) { return HALUTILS_ERR_NULL_POINTER; } DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_TRACE, "[halutils:disp_table] Registering function (%p) opcode (%u) into dispatch table\n", func_fp, key); func_fp_wrapper_t *func_fp_wrapper = zmalloc (sizeof *func_fp_wrapper); ASSERT_ALLOC (func_fp_wrapper, err_func_wrapper_alloc); /* Initialize func_p_wrapper struct */ func_fp_wrapper->func_fp = func_fp; char *key_c = halutils_stringify_key (key); ASSERT_ALLOC (key_c, err_key_c_alloc); int zerr = zhash_insert (self->table_h, key_c, func_fp_wrapper); ASSERT_TEST(zerr == 0, "Could not insert item into dispatch table", err_insert_hash); /* Setup free function */ zhash_freefn (self->table_h, key_c, _disp_table_free_item); free (key_c); return HALUTILS_SUCCESS; err_insert_hash: free (key_c); err_key_c_alloc: free (func_fp_wrapper); err_func_wrapper_alloc: return HALUTILS_ERR_ALLOC; }
int test_insertion2(){ Lock_list<int> list; Node<int>* node; for (int i = 0; i < 10; i++){ list.insertFirst(i); } list.iterFirst(&node); for (int i = 9; i >=0; i--){ ASSERT_TEST(**node== i); list.iterNext(&node); } ASSERT_TEST(node==NULL); return 1; }
/* TODO: Avoid exporting the functions before we have initialized * our server with the default values */ smio_err_e trigger_iface_config_defaults (char *broker_endp, char *service, const char *log_file_name) { (void) log_file_name; DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io:trigger_iface_defaults] Configuring SMIO " "TRIGGER_IFACE with default values ...\n"); bpm_client_err_e client_err = BPM_CLIENT_SUCCESS; smio_err_e err = SMIO_SUCCESS; bpm_client_t *config_client = bpm_client_new_log_mode (broker_endp, 0, log_file_name, SMIO_TRIGGER_IFACE_LIBBPMCLIENT_LOG_MODE); ASSERT_ALLOC(config_client, err_alloc_client); uint32_t chan; for (chan = 0; chan < SMIO_TRIGGER_IFACE_MAX_CHAN; ++chan) { client_err = bpm_set_trigger_dir (config_client, service, chan, TRIGGER_IFACE_DFLT_DIR); client_err |= bpm_set_trigger_dir_pol (config_client, service, chan, TRIGGER_IFACE_DFLT_DIR_POL); client_err |= bpm_set_trigger_rcv_count_rst (config_client, service, chan, TRIGGER_IFACE_DFLT_RCV_RST); client_err |= bpm_set_trigger_transm_count_rst (config_client, service, chan, TRIGGER_IFACE_DFLT_TRANSM_RST); client_err |= bpm_set_trigger_rcv_len (config_client, service, chan, TRIGGER_IFACE_DFLT_RCV_LEN); client_err |= bpm_set_trigger_transm_len (config_client, service, chan, TRIGGER_IFACE_DFLT_TRANSM_LEN); } ASSERT_TEST(client_err == BPM_CLIENT_SUCCESS, "Could set trigger defaults", err_param_set, SMIO_ERR_CONFIG_DFLT); err_param_set: bpm_client_destroy (&config_client); err_alloc_client: DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io:trigger_iface_defaults] Exiting Config thread %s\n", service); return err; }
/* Creates a new instance of the SMCH RFFE */ smch_rffe_t * smch_rffe_new (smio_t *parent, int verbose) { (void) verbose; assert (parent); smch_rffe_t *self = (smch_rffe_t *) zmalloc (sizeof *self); ASSERT_ALLOC(self, err_self_alloc); self->bsmp = smpr_new (SMCH_RFFE_NAME, parent, SMPR_BSMP, verbose); ASSERT_ALLOC(self->bsmp, err_bsmp_alloc); /* Initalize the BSMP protocol */ int smpr_err = smpr_open (self->bsmp, 0, NULL /* Default parameters are fine */); ASSERT_TEST(smpr_err == 0, "Could not initialize SMPR protocol", err_smpr_init); DBE_DEBUG (DBG_SM_CH | DBG_LVL_INFO, "[sm_ch:rffe] Created instance of SMCH\n"); return self; err_smpr_init: smpr_destroy (&self->bsmp); err_bsmp_alloc: free (self); err_self_alloc: return NULL; }
/**** Write data block from device function pointer, size in bytes ****/ ssize_t thsafe_zmq_client_write_block (smio_t *self, loff_t offs, size_t size, const uint32_t *data) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode = THSAFE_WRITE_BLOCK; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling thsafe_write_block\n"); /* Message is: * frame 0: WRITE_BLOCK opcode * frame 1: offset * frame 2: data to be written * */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add WRITE opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); zerr = zmsg_addmem (send_msg, data, size); ASSERT_TEST(zerr == 0, "Could not add data in message", err_add_data); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code */ ret_size = _thsafe_zmq_client_recv_write (self); err_send_msg: err_add_data: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
/**** Read data block from device function pointer, size in bytes ****/ ssize_t thsafe_zmq_client_read_block (smio_t *self, loff_t offs, size_t size, uint32_t *data) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode = THSAFE_READ_BLOCK; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling thsafe_read_block\n"); /* Message is: * frame 0: READ_BLOCK opcode * frame 1: offset * frame 2: number of bytes to be read */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add READ opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); zerr = zmsg_addmem (send_msg, &size, sizeof (size)); ASSERT_TEST(zerr == 0, "Could not add size in message", err_add_size); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code * frame 2: data */ ret_size = _thsafe_zmq_client_recv_read (self, (uint8_t *) data, size); err_send_msg: err_add_size: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
static bool testClientsManagerAddClient(){ Email email = NULL; emailCreate("baba@ganosh", &email); ClientsManager manager = clientsManagerCreate(); ASSERT_TEST( clientsManagerAdd( NULL, email, 1, 1, 200) == CLIENT_MANAGER_NULL_PARAMETERS); ASSERT_TEST( clientsManagerAdd( manager, NULL, 1, 1, 200) == CLIENT_MANAGER_NULL_PARAMETERS); ASSERT_TEST( clientsManagerAdd( manager, email, -2, 1, 200) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerAdd( manager, email, 1, 0, 200) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerAdd( manager, email, 1, 1, -9) == CLIENT_MANAGER_INVALID_PARAMETERS); ASSERT_TEST( clientsManagerAdd( manager, email, 1, 1, 200) == CLIENT_MANAGER_SUCCESS); ASSERT_TEST( clientsManagerAdd( manager, email, 1, 1, 200) == CLIENT_MANAGER_ALREADY_EXISTS); emailDestroy(email); clientsManagerDestroy(manager); return true; }
static bpm_client_err_e _bpm_data_acquire (bpm_client_t *self, char *service, acq_req_t *acq_req) { assert (self); assert (service); assert (acq_req); bpm_client_err_e err = BPM_CLIENT_SUCCESS; ACQ_OPCODE_TYPE operation = ACQ_OPCODE_DATA_ACQUIRE; /* Message is: * frame 0: operation code * frame 1: number of samples * frame 2: channel */ zmsg_t *request = zmsg_new (); zmsg_addmem (request, &operation, sizeof (operation)); zmsg_addmem (request, &acq_req->num_samples, sizeof (acq_req->num_samples)); zmsg_addmem (request, &acq_req->chan, sizeof (acq_req->chan)); mdp_client_send (self->mdp_client, service, &request); /* Receive report */ zmsg_t *report = mdp_client_recv (self->mdp_client, NULL, NULL); ASSERT_TEST(report != NULL, "Report received is NULL", err_null_report); assert (zmsg_size (report) == 1); /* Message is: * frame 0: error code */ zframe_t *err_code = zmsg_pop(report); ASSERT_TEST(err_code != NULL, "Could not receive error code", err_null_code); if ( *(ACQ_REPLY_TYPE *) zframe_data(err_code) != ACQ_OK) { DBE_DEBUG (DBG_LIB_CLIENT | DBG_LVL_TRACE, "[libclient] bpm_data_acquire: " "Data acquire was not required correctly\n"); err = BPM_CLIENT_ERR_AGAIN; goto err_data_acquire; } DBE_DEBUG (DBG_LIB_CLIENT | DBG_LVL_TRACE, "[libclient] bpm_data_acquire: " "Data acquire was successfully required\n"); err_data_acquire: zframe_destroy (&err_code); err_null_code: zmsg_destroy (&report); err_null_report: return err; }