int test_read_null_attibute_to_hash_mrv() { //mask_return_value int ret; char *s = " {\"hid\":null,\"name\":\"Mangatewai\"}"; int i; struct _rpg_hash *r; RPG_HASH_INIT(r); i=3; READ_ATTR_TO_HASH(s,strlen(s),i,r); CU_ASSERT_NOT_EQUAL_FATAL( -1, i ); { void *data; // RPG_HASH_GET(r,"hid",data); // CU_ASSERT_EQUAL_FATAL( NULL, data ); } CU_ASSERT_EQUAL( 12, i ); i=14; READ_ATTR_TO_HASH(s,strlen(s),i,r); CU_ASSERT_NOT_EQUAL_FATAL( -1, i ); { void *data; RPG_HASH_GET(r,"name",data);RPG_CU_FNC_A_PTR_CHECK( data ); char *value = (char *)data; CU_ASSERT_STRING_EQUAL( "Mangatewai", value ); } CU_ASSERT_EQUAL( 32, i ); return SUCCESS; }
int test_read_attibute_to_hash_mrv() { //mask_return_value int ret; char *s = " {\"hid\":\"198\",\"name\":\"Mangatewai\",\"psm\":\"16 Oct 2012\",\"psc\":\"25 Jul 2012\",\"mapref\":\"\"}"; int i; struct _rpg_hash *r; RPG_HASH_INIT(r); i=3; READ_ATTR_TO_HASH(s,strlen(s),i,r); CU_ASSERT_NOT_EQUAL_FATAL( -1, i ); { void *data; RPG_HASH_GET(r,"hid",data); char *value = (char *)data; CU_ASSERT_STRING_EQUAL( "198", value ); } CU_ASSERT_EQUAL( 13, i ); i=15; READ_ATTR_TO_HASH(s,strlen(s),i,r); CU_ASSERT_NOT_EQUAL_FATAL( -1, i ); { void *data; RPG_HASH_GET(r,"name",data);RPG_CU_FNC_A_PTR_CHECK( data ); char *value = (char *)data; CU_ASSERT_STRING_EQUAL( "Mangatewai", value ); } CU_ASSERT_EQUAL( 33, i ); return SUCCESS; }
void t_field_map(void) { pool_reference list_pool = pool_create(LIST_TYPE_ID); CU_ASSERT_NOT_EQUAL_FATAL(list_pool, NULL_POOL); global_reference head = pool_alloc(&list_pool); pool_iterator itr = iterator_new(&list_pool, &head); size_t list_size = 10000; for (size_t i = 0 ; i < list_size ; ++i) { iterator_set_field(itr, 1, &i); iterator_list_insert(itr, pool_alloc(&list_pool)); itr = iterator_next(list_pool, itr); } pool_reference long_pool = pool_create(LONG_TYPE_ID); CU_ASSERT_NOT_EQUAL_FATAL(long_pool, NULL_POOL); CU_ASSERT_EQUAL(field_map(list_pool, &long_pool, 1, square), 0); uint64_t *result = pool_to_array(long_pool); int cmp_error_count = 0; for (size_t i = 0 ; i < list_size ; ++i) { cmp_error_count += i*i != result[i]; } CU_ASSERT_EQUAL(cmp_error_count, 0); iterator_destroy(&itr); pool_destroy(&long_pool); pool_destroy(&list_pool); }
void registerMemoryType_ShouldInAscendentOrder(void) { // fxture setup and test MemoryType register_error = -1; CU_ASSERT_NOT_EQUAL_FATAL(registerMemoryType(1), register_error); CU_ASSERT_NOT_EQUAL_FATAL(registerMemoryType(2), register_error); CU_ASSERT_NOT_EQUAL_FATAL(registerMemoryType(3), register_error); // verify for (unsigned i = 1; i < getRegisteredTypeNum(); ++i) CU_ASSERT(getRegisteredTypeArray()[i - 1] < getRegisteredTypeArray()[i]); }
static void test_sentence_writing(void) { unsigned int i; int rc; char buf[128]; struct nmea_t nmea; for (i = 0; i < sizeof(SENTENCES)/sizeof(SENTENCES[0]); ++i) { memset(buf, 0, sizeof(buf)); memset(&nmea, 0, sizeof(nmea)); rc = nmea_read(&nmea, SENTENCES[i]); CU_ASSERT_EQUAL(rc, 0); rc = nmea_write(buf, sizeof(buf), &nmea); if (rc == -3) { continue; /* writing not supported, which is ok */ } if (rc == -2) { printf("nmea_write: unknown sentence: '%s' (raw:'%s', type:%u)\n", SENTENCES[i], nmea.raw, nmea.type); CU_ASSERT_NOT_EQUAL_FATAL(rc, -2); } CU_ASSERT_TRUE(rc >= 0); CU_ASSERT_STRING_EQUAL(buf, SENTENCES[i]); } }
static void test_send_frame_vlan_to_vlan(void) { odp_packet_t pkt = ODP_PACKET_INVALID; odp_event_t ev; uint8_t check_buf[144]; int res; if (create_odp_packet_ip4(&pkt, test_frame_vlan, sizeof(test_frame_vlan), 0)) { CU_FAIL("Fail to create packet"); return; } memcpy(check_buf, test_frame_vlan, sizeof(test_frame_vlan)); check_buf[15] = dev_vlan->vlan; res = ofp_send_frame(dev_vlan, pkt); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt), sizeof(test_frame_vlan)); if (memcmp(odp_packet_l2_ptr(pkt, NULL), check_buf, sizeof(test_frame_vlan))) CU_FAIL("Frame data mismatch."); }
void test_modules ( void ) { processLibProcEntry* entries = NULL; RU32 entryIndex = 0; rList mods = NULL; rSequence mod = NULL; RPWCHAR path = NULL; entries = processLib_getProcessEntries( TRUE ); CU_ASSERT_PTR_NOT_EQUAL_FATAL( entries, NULL ); CU_ASSERT_NOT_EQUAL_FATAL( entries[ entryIndex ].pid, 0 ); mods = processLib_getProcessModules( entries[ entryIndex ].pid ); CU_ASSERT_PTR_NOT_EQUAL( mods, NULL ); CU_ASSERT_TRUE( rList_getSEQUENCE( mods, RP_TAGS_DLL, &mod ) ); CU_ASSERT_TRUE( rSequence_getSTRINGW( mod, RP_TAGS_FILE_PATH, &path ) ); CU_ASSERT_PTR_NOT_EQUAL( path, NULL ); CU_ASSERT_NOT_EQUAL( rpal_string_strlenw( path ), 0 ); rSequence_free( mods ); rpal_memory_free( entries ); }
void test_processInfo ( void ) { processLibProcEntry* entries = NULL; RU32 entryIndex = 0; rSequence proc = NULL; RPWCHAR path = NULL; entries = processLib_getProcessEntries( TRUE ); CU_ASSERT_PTR_NOT_EQUAL_FATAL( entries, NULL ); CU_ASSERT_NOT_EQUAL_FATAL( entries[ entryIndex ].pid, 0 ); proc = processLib_getProcessInfo( entries[ entryIndex ].pid ); CU_ASSERT_PTR_NOT_EQUAL( proc, NULL ); CU_ASSERT_TRUE( rSequence_getSTRINGW( proc, RP_TAGS_FILE_PATH, &path ) ); CU_ASSERT_PTR_NOT_EQUAL( path, NULL ); CU_ASSERT_NOT_EQUAL( rpal_string_strlenw( path ), 0 ); rSequence_free( proc ); rpal_memory_free( entries ); }
static void testSpawnAndConnect (void) { char userinfo[MAX_INFO_STRING]; player_t *player; const char *name = "name"; bool day = true; byte *buf; /* this entity string may not contain any inline models, we don't have the bsp tree loaded here */ const int size = FS_LoadFile("game/entity.txt", &buf); edict_t *e = NULL; int cnt = 0; CU_ASSERT_NOT_EQUAL_FATAL(size, -1); CU_ASSERT_FATAL(size > 0); SV_InitGameProgs(); /* otherwise we can't link the entities */ SV_ClearWorld(); player = G_PlayerGetNextHuman(0); svs.ge->SpawnEntities(name, day, (const char *)buf); CU_ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo))); CU_ASSERT_FALSE(svs.ge->RunFrame()); while ((e = G_EdictsGetNextInUse(e))) { Com_Printf("entity %i: %s\n", cnt, e->classname); cnt++; } CU_ASSERT_EQUAL(cnt, 45); SV_ShutdownGameProgs(); FS_FreeFile(buf); }
static int senderSock_init( int* const sock) { int status; int sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); CU_ASSERT_NOT_EQUAL_FATAL(sck, -1); int on = 1; struct sockaddr_in addr; (void)setsockopt(sck, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)); (void)memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(LOCAL_HOST); addr.sin_port = htons(0); // let O/S assign port status = bind(sck, (struct sockaddr*)&addr, sizeof(addr)); CU_ASSERT_EQUAL_FATAL(status, 0); status = listen(sck, 1); CU_ASSERT_EQUAL_FATAL(status, 0); *sock = sck; return 0; }
static void testSRC_IS_ACTIVE(void) { int ret; struct io_src src; int pipefd[2] = {-1, -1}; ret = pipe(pipefd); CU_ASSERT_NOT_EQUAL_FATAL(ret, -1); ret = io_src_init(&src, pipefd[0], IO_IN, my_dummy_cb); CU_ASSERT_EQUAL(ret, 0); src.active = IO_IN; /* normal use case */ CU_ASSERT(io_src_is_active(&src, IO_IN)); /* error use case */ CU_ASSERT(!io_src_is_active(&src, IO_OUT)); /* all flags must be in the same state */ CU_ASSERT(!io_src_is_active(&src, IO_DUPLEX)); CU_ASSERT(!io_src_is_active(NULL, IO_IN)); io_src_clean(&src); ut_file_fd_close(&pipefd[0]); ut_file_fd_close(&pipefd[1]); }
static void test_cond_wait(void) { void (*prevHandler)(int) = signal(SIGINT, sigHandler); CU_ASSERT_NOT_EQUAL_FATAL(prevHandler, SIG_ERR); int status = pthread_mutex_lock(&mutex); CU_ASSERT_EQUAL_FATAL(status, 0); pthread_t thread; status = pthread_create(&thread, NULL, signalCond, &thread); CU_ASSERT_EQUAL_FATAL(status, 0); while (!done) { status = pthread_cond_wait(&cond, &mutex); CU_ASSERT_EQUAL_FATAL(status, 0); // NB: pthread_cond_wait() doesn't return due to the pthread_kill(). CU_ASSERT_TRUE(done); } CU_ASSERT_TRUE(sigHandlerCalled); status = pthread_join(thread, NULL); CU_ASSERT_EQUAL_FATAL(status, 0); status = pthread_mutex_unlock(&mutex); CU_ASSERT_EQUAL_FATAL(status, 0); }
static int servlet_run( const int servSock) { /* NULL-s => not interested in receiver's address */ int sock = accept(servSock, NULL, NULL); int status; CU_ASSERT_NOT_EQUAL_FATAL(sock, -1); pthread_cleanup_push(closeSocket, &sock); Up7 up7; status = up7_init(&up7, sock); CU_ASSERT_EQUAL_FATAL(status, 0); pthread_cleanup_push(destroyUp7, &up7); // calls `up7_destroy()` status = up7_run(&up7); // might call `svc_destroy(up7->xprt)` CU_ASSERT_EQUAL(status, 0); pthread_cleanup_pop(1); // might call `svc_destroy(up7->xprt)` pthread_cleanup_pop(0); // `sock` already closed udebug("servlet_run(): Returning"); return 0; }
/* * Tests */ static void test_packet_output_gre(void) { odp_packet_t pkt = ODP_PACKET_INVALID; odp_event_t ev; int res; struct ofp_ether_header *eth; struct ofp_ip *ip; struct ofp_ip *ip_orig; struct ofp_greip *greip; if (create_odp_packet_ip4(&pkt, test_frame, sizeof(test_frame), tun_p2p)) { CU_FAIL("Fail to create packet"); return; } /* * Packet's destination is GRE tunnel's p2p address, next hop is GRE * interface. GRE+IP header is prepended. Packet's new destination is * link local. Packet is put into output queue. */ res = ofp_ip_output(pkt, NULL); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); res = ofp_send_pending_pkt(); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt), sizeof(test_frame) + 20 + 4); eth = odp_packet_l2_ptr(pkt, NULL); if (memcmp(eth->ether_dhost, tun_rem_mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); ip = odp_packet_l3_ptr(pkt, NULL); CU_ASSERT_EQUAL(ip->ip_src.s_addr, dev_ip); CU_ASSERT_EQUAL(ip->ip_dst.s_addr, tun_rem_ip); CU_ASSERT_EQUAL(ip->ip_p, OFP_IPPROTO_GRE); greip = (struct ofp_greip *)ip; CU_ASSERT_EQUAL(greip->gi_g.flags, 0); CU_ASSERT_EQUAL(greip->gi_g.ptype, odp_cpu_to_be_16(OFP_ETHERTYPE_IP)); /* inner ip */ ip = (struct ofp_ip *)(greip + 1); ip_orig = (struct ofp_ip *)(&orig_pkt_data[OFP_ETHER_HDR_LEN]); if (memcmp(ip, ip_orig, odp_be_to_cpu_16(ip_orig->ip_len))) CU_FAIL("Inner IP packet error."); }
/* Simple sanity test to ensure low-level POSIX APIs work */ void sanity(void) { char *buf; size_t len; int fd; fflush(stdout); len = asprintf(&buf, "%s/sanity", mount_dir); CU_ASSERT_NOT_EQUAL_FATAL(len, -1); CU_ASSERT_PTR_NOT_NULL(buf); unlink(buf); fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600); CU_ASSERT_NOT_EQUAL_FATAL(fd, -1); do_write_tests(fd, buf, len); do_read_tests(buf, len); do_misc_tests(buf, len); do_large_io_test(buf, len); free(buf); }
void findMemoryBlock_ShouldFindNextMemoryBlockOfType(void) { // fixture setup MemoryType type = 321; void* expected_one = makeMemoryBlock(12, type); CU_ASSERT_NOT_EQUAL_FATAL(expected_one, NULL); void* expected_two = makeMemoryBlock(12, type); CU_ASSERT_NOT_EQUAL_FATAL(expected_two, NULL); void* expected_empty = NULL; // system under control void* actual_two = findMemoryBlock(type); void* actual_one = findMemoryBlock(type); void* actual_empty = findMemoryBlock(type); // verify CU_ASSERT_EQUAL(actual_one, expected_one); CU_ASSERT_EQUAL(actual_two, expected_two); CU_ASSERT_EQUAL(actual_empty, expected_empty); }
static void test_ofp_packet_input_gre_orig_pkt_to_sp(void) { odp_packet_t pkt; int res; #ifdef SP odp_event_t ev; #endif my_test_val = TEST_LOCAL_HOOK_GRE_APP; /* Call ofp_packet_input using a GRE pkt with destination ip * that matches the local ip on ifnet, tunnel not found, * packet offered to GRE hook, returns continue. * Full packet sent to slowpath */ ifnet->ip_addr = local_ip; if (create_odp_packet_ip4(&pkt, gre_frame, sizeof(gre_frame), local_ip, tun_rem_ip + 1)) { CU_FAIL("Fail to create packet"); return; } res = ofp_packet_input(pkt, interface_queue[port], ofp_eth_vlan_processing); #ifdef SP CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); CU_ASSERT_NOT_EQUAL_FATAL(ev = odp_queue_deq(ifnet->spq_def), ODP_EVENT_INVALID); CU_ASSERT_EQUAL(odp_queue_deq(ifnet->spq_def), ODP_EVENT_INVALID); CU_ASSERT_EQUAL(odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID); if (memcmp(odp_packet_data(odp_packet_from_event(ev)), in_pkt_data, sizeof(gre_frame))) CU_FAIL("corrupt data sent to slow path"); odp_packet_free(odp_packet_from_event(ev)); ifnet->ip_addr = 0; CU_PASS("ofp_packet_input_gre_orig_pkt_to_sp"); #else CU_ASSERT_EQUAL(res, OFP_PKT_DROP); CU_ASSERT_EQUAL(odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID); #endif }
void test_memmap ( void ) { processLibProcEntry* entries = NULL; RU32 entryIndex = 0; rList regions = NULL; rSequence region = NULL; RU32 nRegions = 0; RU8 type = 0; RU8 protect = 0; RU64 ptr = 0; RU64 size = 0; entries = processLib_getProcessEntries( TRUE ); CU_ASSERT_PTR_NOT_EQUAL_FATAL( entries, NULL ); CU_ASSERT_NOT_EQUAL_FATAL( entries[ entryIndex ].pid, 0 ); regions = processLib_getProcessMemoryMap( entries[ entryIndex ].pid ); CU_ASSERT_PTR_NOT_EQUAL( regions, NULL ); while( rList_getSEQUENCE( regions, RP_TAGS_MEMORY_REGION, ®ion ) ) { CU_ASSERT_TRUE( rSequence_getRU8( region, RP_TAGS_MEMORY_TYPE, &type ) ); CU_ASSERT_TRUE( rSequence_getRU8( region, RP_TAGS_MEMORY_ACCESS, &protect ) ); CU_ASSERT_TRUE( rSequence_getPOINTER64( region, RP_TAGS_BASE_ADDRESS, &ptr ) ); CU_ASSERT_TRUE( rSequence_getRU64( region, RP_TAGS_MEMORY_SIZE, &size ) ); nRegions++; } CU_ASSERT_TRUE( 2 < nRegions ); rSequence_free( regions ); rpal_memory_free( entries ); }
static void test_packet_size_is_less_then_mtu(void) { odp_packet_t pkt_orig, pkt_sent; odp_event_t ev; int res; struct ofp_ether_header *eth; if (create_odp_packet_ip4(&pkt_orig, pkt1_frag1, sizeof(pkt1_frag1), 0)) { CU_FAIL("Fail to create packet"); return; } res = ofp_ip_output(pkt_orig, &nexthop); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); res = ofp_send_pending_pkt(); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); CU_ASSERT_EQUAL_FATAL(odp_queue_deq(dev->outq_def), ODP_EVENT_INVALID); pkt_sent = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt_sent), sizeof(pkt1_frag1)); eth = odp_packet_l2_ptr(pkt_sent, NULL); if (memcmp(eth->ether_dhost, dst_mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); if (memcmp(odp_packet_l3_ptr(pkt_sent, NULL), &orig_pkt_data[OFP_ETHER_HDR_LEN], sizeof(pkt1_frag1) - OFP_ETHER_HDR_LEN)) CU_FAIL("corrupt l3 + data forwarded"); CU_PASS("Correct packet"); odp_packet_free(pkt_sent); }
static void test_send_frame_novlan_to_vlan(void) { odp_packet_t pkt = ODP_PACKET_INVALID; odp_event_t ev; struct ofp_ether_vlan_header *eth_vlan; uint8_t *buf; int res; if (create_odp_packet_ip4(&pkt, test_frame, sizeof(test_frame), 0)) { CU_FAIL("Fail to create packet"); return; } res = ofp_send_frame(dev_vlan, pkt); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt), sizeof(test_frame) + 4); eth_vlan = odp_packet_l2_ptr(pkt, NULL); if (memcmp(eth_vlan, test_frame, 2 * OFP_ETHER_ADDR_LEN)) CU_FAIL("Frame data mismatch."); CU_ASSERT_EQUAL(eth_vlan->evl_encap_proto, odp_cpu_to_be_16(OFP_ETHERTYPE_VLAN)); CU_ASSERT_EQUAL(eth_vlan->evl_tag, odp_cpu_to_be_16(dev_vlan->vlan)); buf = (uint8_t *)eth_vlan; if (memcmp(&buf[16], &test_frame[12], sizeof(test_frame) - 2 * OFP_ETHER_ADDR_LEN)) CU_FAIL("Frame data mismatch."); }
static void testSRC_GET_FD(void) { int ret; struct io_src src; int fd; int pipefd[2] = {-1, -1}; ret = pipe(pipefd); CU_ASSERT_NOT_EQUAL_FATAL(ret, -1); /* normal use case */ ret = io_src_init(&src, pipefd[0], IO_IN, my_dummy_cb); CU_ASSERT_EQUAL(ret, 0); fd = io_src_get_fd(&src); CU_ASSERT_EQUAL(fd, pipefd[0]); /* error use case */ ret = io_src_get_fd(NULL); CU_ASSERT_EQUAL(ret, -1); io_src_clean(&src); ut_file_fd_close(&pipefd[0]); ut_file_fd_close(&pipefd[1]); }
/* Test a slot: Given a global slot ID, test the slot given. * This particular routine tests if keys are created at proper sizes. * Note that the PKCS #1 standard defines modulus bit sizes as multiples * of 8, and that it defines the number of modulus bits by rounding up * the actual number of bits used to an eightfold value. So if the prime * product of the modulus counts 1021 bits, it counts as a 1024 bit key. */ void testslot_keysizing (void) { CK_SESSION_HANDLE seshdl; CK_BYTE noappinfo; CK_ULONG minbytes, maxbytes, curbytes; CK_RV retval; /* Announce the start of this test */ if (verbosity >= 1) { printf ("Entering keysizing test\n"); } /* * Open RW session with slot */ TESTRV ("Opening session for keysizing test", P11("C_OpenSession") (slotid, CKF_SERIAL_SESSION | CKF_RW_SESSION, (void *) &noappinfo, NULL_PTR, &seshdl)); MKFATAL (); /* * Login to token as USER (possibly after setting up the PIN to use) */ if (destructive) { TESTRV ("Logging into token for setting up PIN", P11("C_Login") (seshdl, CKU_SO, (CK_UTF8CHAR_PTR) ascii_pin_so, strlen (ascii_pin_so))); TESTRV ("Setting up user PIN", P11("C_InitPIN") (seshdl, (CK_UTF8CHAR_PTR) ascii_pin_user, strlen (ascii_pin_user))); TESTRV ("Logging out after setting setting up PIN", P11("C_Logout") (seshdl)); } TESTRV ("Logging into token for keysizing test", P11("C_Login") (seshdl, CKU_USER, (CK_UTF8CHAR_PTR) ascii_pin_user, strlen (ascii_pin_user))); MKFATAL (); /* * Fetch supported key sizes for this token. Count in bytes, not * bits, to simplify later randomisation of key sizes. */ if (verbosity >= 2) { printf (" * Determine key sizes\n"); } CU_ASSERT_EQUAL (mech_rsa_pkcs.ulMinKeySize % 8, 0); CU_ASSERT_EQUAL (mech_rsa_pkcs.ulMaxKeySize % 8, 0); CU_ASSERT (mech_rsa_pkcs.ulMinKeySize <= mech_rsa_pkcs.ulMaxKeySize); CU_ASSERT (mech_rsa_pkcs.ulMinKeySize <= 512); CU_ASSERT (mech_rsa_pkcs.ulMaxKeySize >= 2048); minbytes = mech_rsa_pkcs.ulMinKeySize / 8; maxbytes = mech_rsa_pkcs.ulMaxKeySize / 8; if (verbosity >= 3) { printf (" - Key sizes supported by this token range from %lu to %lu bits\n", minbytes * 8, maxbytes * 8); } /* * Iterate over key pair lengths, checking the modulus size of each. */ if (verbosity >= 2) { printf (" * Check modulus size of each possible key pair length\n"); } curbytes = minbytes; while (curbytes <= maxbytes) { int ok = 1; CK_ULONG modbits = curbytes * 8; CK_OBJECT_HANDLE pub, priv; CK_ATTRIBUTE templ [] = { { CKA_MODULUS, NULL_PTR, 0 }, }; uint8_t *modulus; if (verbosity >= 4) { printf ("%8lu\b\b\b\b\b\b\b\b", maxbytes-curbytes); } retval = newkeypair (seshdl, modbits, &pub, &priv); TESTRV ("Creating key pair in modulus size test", retval); ok = ok && (retval == CKR_OK); if (ok) { TESTRV ("Obtaining length of modulus attribute field", P11("C_GetAttributeValue") (seshdl, pub, templ, sizeof (templ) / sizeof (*templ))); ok = ok && LASTRVOK (); } if (ok) { CU_ASSERT_NOT_EQUAL ((CK_ULONG) templ [0].ulValueLen, (CK_ULONG) -1); modulus = malloc (templ [0].ulValueLen); CU_ASSERT_PTR_NOT_NULL (modulus); templ [0].pValue = (CK_VOID_PTR) modulus; TESTRV ("Obtaining modulus attribute field", P11("C_GetAttributeValue") (seshdl, pub, templ, sizeof (templ) / sizeof (*templ))); ok = ok && LASTRVOK (); CU_ASSERT_NOT_EQUAL_FATAL ((CK_ULONG) templ [0].ulValueLen, (CK_ULONG) -1); while ((templ [0].ulValueLen > 0) && (*modulus == 0x00)) { modulus++; templ [0].ulValueLen--; } if (modulus) { free (modulus); modulus = NULL; } CU_ASSERT_EQUAL (curbytes * 8, templ [0].ulValueLen * 8); if (templ [0].ulValueLen == curbytes) { CU_PASS ("Modulus size matches expactations"); } else { CU_FAIL ("Modulus size diverted from expectations"); } } if (retval == CKR_OK) { TESTRV ("Destroying private key in modulus size test", P11("C_DestroyObject") (seshdl, priv)); TESTRV ("Destroying public key in modulus size test", P11("C_DestroyObject") (seshdl, pub)); } curbytes++; } /* * Cleanup. */ if (verbosity >= 2) { printf (" * Cleaning up token state\n"); } TESTRV ("Logging out after modulus size test", P11("C_Logout") (seshdl)); TESTRV ("Closing session after modulus size test", P11("C_CloseSession") (seshdl)); }
static void test_ofp_packet_input_gre_processed_inner_pkt_forwarded(void) { odp_packet_t pkt; odp_event_t ev; int res; struct ofp_ether_header *eth; struct ofp_ip *ip; struct ofp_ip *ip_encap; uint32_t dst_ip; uint8_t dst_mac_addr[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; my_test_val = TEST_LOCAL_HOOK_GRE; /* Call ofp_packet_input using a GRE pkt with destination ip * that matches the local ip on ifnet, tunnel found, GRE processed. * Inner packet does not match local ip, route found, * packet forwarded */ ifnet->ip_addr = local_ip; if (create_odp_packet_ip4(&pkt, gre_frame, sizeof(gre_frame), local_ip, tun_rem_ip)) { CU_FAIL("Fail to create packet"); return; } ip_encap = (struct ofp_ip *)&in_pkt_data[38]; dst_ip = local_ip + 10; test_ofp_add_route(port, vrf, vlan, ip_encap->ip_dst.s_addr, 24, 4, dst_ip); ofp_arp_ipv4_insert(dst_ip, dst_mac_addr, ifnet); res = ofp_packet_input(pkt, interface_queue[port], ofp_eth_vlan_processing); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); CU_ASSERT_NOT_EQUAL_FATAL(ev = odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID); #ifdef SP CU_ASSERT_EQUAL(odp_queue_deq(ifnet->spq_def), ODP_EVENT_INVALID); #endif CU_ASSERT_EQUAL(odp_queue_deq(ifnet->outq_def), ODP_EVENT_INVALID); pkt = odp_packet_from_event(ev); eth = odp_packet_data(pkt); ip = odp_packet_l3_ptr(pkt, NULL); if (memcmp(eth->ether_dhost, dst_mac_addr, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, ifnet->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); CU_ASSERT_EQUAL(ip->ip_src.s_addr, ip_encap->ip_src.s_addr); CU_ASSERT_EQUAL(ip->ip_dst.s_addr, ip_encap->ip_dst.s_addr); if (memcmp(ip + (ip->ip_hl << 2), ip_encap + (ip->ip_hl << 2), odp_be_to_cpu_16(ip_encap->ip_len) - (ip->ip_hl << 2))) CU_FAIL("corrupt l3 + data"); odp_packet_free(odp_packet_from_event(ev)); ifnet->ip_addr = 0; CU_PASS("ofp_packet_input_gre_processed_inner_pkt_to_sp"); }
/** * Questa funzione legge e scrive un'agenda effettuando controlli * necessari a verificare che il file sia stato formattato correttamente * e che la conversione sia corretta * * \param fagenda nome del file agenda * \param ftest nome del file in cui verranno scritte le voci covertite */ void run_testagenda (char *fagenda, char* ftest) { char record[LRECORD+2], pbu[MAXNTEST][LRECORD+1], pb[LRECORD+1]; evento_t* ev[MAXNTEST]; FILE *fsa; /* prossima posizione libera nell'array di eventi */ int i=0; int l,k; /* * Apertura del file agenda */ fsa = fopen(fagenda, "r"); CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); /* * Lettura e caricamento eventi nell'array */ while(fgets(record,LRECORD + 2,fsa) != NULL) { CU_ASSERT_EQUAL_FATAL(record[LRECORD], '\n'); record[LRECORD]='\0'; strncpy(pbu[i],record,LRECORD+1); CU_TEST_FATAL(i < MAXNTEST); ev[i]=convertiRecord(record); CU_ASSERT_NOT_EQUAL_FATAL(ev[i],NULL); i++; } fclose(fsa); printf("lette %d voci\n",i); /* * Trasformazione voci nel formato stringa */ for ( l=0; l<i; l++ ) { int ret; /* printf("confron ta la mia %s, che viene da %s,%s,%s, con la sua %s\n", pb, ev[l]->data, ev[l]->utente, ev[l]->descrizione ,pbu[l]); */ convertiEvento(ev[l],pb); /* printf("confronta la mia %s, che viene da %s con la sua %s\n", pb, ev[l]->data ,pbu[l]); */ ret=strncmp(pbu[l],pb,LRECORD+1); CU_ASSERT_EQUAL_FATAL(ret, 0); } /* * Verifica funzione di matchPattern */ for (k=0;pattern[k]!=NULL; k++) { int cont = 0; for(l=0;l<i;l++) { cont+=matchPattern(pattern[k],ev[l]); /* printf(" pattern %s : %d occurrences \n",pattern[k],cont);*/ } CU_ASSERT_EQUAL_FATAL(cont, npatternmatch[k]); } /* * Verifica funzione di matchData */ for (k=0;date[k]!=NULL; k++) { int cont = 0; for(l=0;l<i;l++) { cont+=matchData(date[k],ev[l]); } /* printf("cont: %d nmatch %d\n", cont, nmatch[k]); */ CU_ASSERT_EQUAL_FATAL(cont, nmatch[k]); } /* * Test di creazione di una nuova agenda */ fsa=fopen(ftest,"w"); CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); for ( l=0; l<i; l++ ) { convertiEvento(ev[l],pb); CU_ASSERT_NOT_EQUAL_FATAL(fputs(pb,fsa), EOF); fputs("\n",fsa); } fclose(fsa); }
static void testSRC_INIT(void) { int pipefd[2] = {-1, -1}; int fd; struct io_src src; int ret; ret = pipe(pipefd); CU_ASSERT_NOT_EQUAL_FATAL(ret, -1); fd = open("/dev/urandom", O_RDWR | O_CLOEXEC); CU_ASSERT_NOT_EQUAL_FATAL(fd, -1); /* normal use case */ /* put garbage in the struct */ ret = read(fd, &src, sizeof(src)); CU_ASSERT_EQUAL(ret, sizeof(src)); ret = io_src_init(&src, pipefd[0], IO_IN, my_dummy_cb); CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(src.fd, pipefd[0]); CU_ASSERT_EQUAL(src.type, IO_IN); CU_ASSERT_EQUAL(src.cb, my_dummy_cb); CU_ASSERT_EQUAL(src.events, 0); CU_ASSERT_EQUAL(src.active, 0); CU_ASSERT_PTR_NULL(src.node.next); CU_ASSERT_PTR_NULL(src.node.prev); /* put garbage in the struct */ ret = read(fd, &src, sizeof(src)); CU_ASSERT_EQUAL(ret, sizeof(src)); ret = io_src_init(&src, pipefd[1], IO_OUT, my_dummy_cb); CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(src.fd, pipefd[1]); CU_ASSERT_EQUAL(src.type, IO_OUT); CU_ASSERT_EQUAL(src.cb, my_dummy_cb); CU_ASSERT_EQUAL(src.events, 0); CU_ASSERT_EQUAL(src.active, 0); CU_ASSERT_PTR_NULL(src.node.next); CU_ASSERT_PTR_NULL(src.node.prev); /* put garbage in the struct */ ret = read(fd, &src, sizeof(src)); CU_ASSERT_EQUAL(ret, sizeof(src)); ret = io_src_init(&src, fd, IO_DUPLEX, my_dummy_cb); CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(src.fd, fd); CU_ASSERT_EQUAL(src.type, IO_DUPLEX); CU_ASSERT_EQUAL(src.cb, my_dummy_cb); CU_ASSERT_EQUAL(src.events, 0); CU_ASSERT_EQUAL(src.active, 0); CU_ASSERT_PTR_NULL(src.node.next); CU_ASSERT_PTR_NULL(src.node.prev); /* error use cases */ ret = io_src_init(NULL, pipefd[0], IO_IN, my_dummy_cb); CU_ASSERT_NOT_EQUAL(ret, 0); ret = io_src_init(&src, -1, IO_IN, my_dummy_cb); CU_ASSERT_NOT_EQUAL(ret, 0); ret = io_src_init(&src, pipefd[0], IO_IN, NULL); CU_ASSERT_NOT_EQUAL(ret, 0); ret = io_src_init(&src, pipefd[0], 666, my_dummy_cb); CU_ASSERT_NOT_EQUAL(ret, 0); ret = io_src_init(&src, pipefd[0], 0, my_dummy_cb); CU_ASSERT_NOT_EQUAL(ret, 0); ut_file_fd_close(&fd); fd = open("/tmp/toto", O_RDWR | O_CREAT, S_IRUSR | S_IRUSR); CU_ASSERT_NOT_EQUAL(fd, -1); ret = io_src_init(&src, fd, IO_IN, my_dummy_cb); CU_ASSERT_EQUAL(ret, -EBADF); /* cleanup */ ut_file_fd_close(&pipefd[0]); ut_file_fd_close(&pipefd[1]); ut_file_fd_close(&fd); unlink("/tmp/toto"); }
static void test_fragment_fragmented_to_two(void) { odp_packet_t pkt_orig, pkt_sent; odp_event_t ev; int res; struct ofp_ether_header *eth; struct ofp_ip *ip; struct ofp_ip *ip_orig; uint16_t pl_pos, pl_len, orig_pl_len, pktlen, start_offset; dev->if_mtu = 620; if (create_odp_packet_ip4(&pkt_orig, pkt1_frag2, sizeof(pkt1_frag2), 0)) { CU_FAIL("Fail to create packet"); return; } res = ofp_ip_output(pkt_orig, &nexthop); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); res = ofp_send_pending_pkt(); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); /* ASSERT 1st fragment */ ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt_sent = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt_sent), dev->if_mtu + OFP_ETHER_HDR_LEN); eth = odp_packet_l2_ptr(pkt_sent, NULL); if (memcmp(eth->ether_dhost, dst_mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); ip = odp_packet_l3_ptr(pkt_sent, NULL); ip_orig = (struct ofp_ip *)(&orig_pkt_data[OFP_ETHER_HDR_LEN]); orig_pl_len = odp_be_to_cpu_16(ip_orig->ip_len) - (ip_orig->ip_hl<<2); start_offset = odp_be_to_cpu_16(ip_orig->ip_off) & OFP_IP_OFFMASK; assert_ip_header(ip, ip_orig, dev->if_mtu, 1, start_offset); pl_len = dev->if_mtu - (ip->ip_hl<<2); if (memcmp((uint8_t *)ip + (ip->ip_hl<<2), (uint8_t *)ip_orig + (ip_orig->ip_hl<<2), pl_len)) CU_FAIL("corrupt l3 + data forwarded"); pl_pos = pl_len; CU_PASS("Correct packet"); odp_packet_free(pkt_sent); /* ASSERT 2nd fragment */ ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt_sent = odp_packet_from_event(ev); pl_len = orig_pl_len - pl_pos; pktlen = pl_len + OFP_ETHER_HDR_LEN + sizeof(struct ofp_ip); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt_sent), pktlen); eth = odp_packet_l2_ptr(pkt_sent, NULL); if (memcmp(eth->ether_dhost, dst_mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); ip = odp_packet_l3_ptr(pkt_sent, NULL); assert_ip_header(ip, ip_orig, pl_len + sizeof(struct ofp_ip), 0, start_offset + pl_pos/8); if (memcmp((uint8_t *)ip + (ip->ip_hl<<2), (uint8_t *)ip_orig + (ip_orig->ip_hl<<2) + pl_pos, pl_len)) CU_FAIL("corrupt l3 + data forwarded"); CU_PASS("Correct packet"); odp_packet_free(pkt_sent); /* no more fragments */ ev = odp_queue_deq(dev->outq_def); CU_ASSERT_EQUAL(ev, ODP_EVENT_INVALID); dev->if_mtu = def_mtu; }
static void test_packet_output_ipv6_to_gre(void) { odp_packet_t pkt = ODP_PACKET_INVALID; odp_event_t ev; int res; struct ofp_ether_header *eth; struct ofp_ip6_hdr *ip6, *ip6_orig; struct ofp_ip *ip; struct ofp_greip *greip; (void)tcp_frame; (void)icmp_frame; (void)arp_frame; (void)icmp6_frame; if (create_odp_packet_ip6(&pkt, ip6udp_frame, sizeof(ip6udp_frame))) { CU_FAIL("Fail to create packet"); return; } ip6 = odp_packet_l3_ptr(pkt, NULL); ofp_set_route6_params(OFP_ROUTE6_ADD, 0 /*vrf*/, 100 /*vlan*/, GRE_PORTS, ip6->ip6_dst.__u6_addr.__u6_addr8, 64 /*masklen*/, 0 /*gw*/, OFP_RTF_NET /* flags */); res = ofp_ip6_output(pkt, NULL); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); res = ofp_send_pending_pkt(); CU_ASSERT_EQUAL(res, OFP_PKT_PROCESSED); ev = odp_queue_deq(dev->outq_def); CU_ASSERT_NOT_EQUAL_FATAL(ev, ODP_EVENT_INVALID); pkt = odp_packet_from_event(ev); CU_ASSERT_EQUAL_FATAL(odp_packet_len(pkt), sizeof(ip6udp_frame) + 20 + 4); eth = odp_packet_l2_ptr(pkt, NULL); if (memcmp(eth->ether_dhost, tun_rem_mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad destination mac address."); if (memcmp(eth->ether_shost, dev->mac, OFP_ETHER_ADDR_LEN)) CU_FAIL("Bad source mac address."); ip = odp_packet_l3_ptr(pkt, NULL); CU_ASSERT_EQUAL(ip->ip_src.s_addr, dev_ip); CU_ASSERT_EQUAL(ip->ip_dst.s_addr, tun_rem_ip); CU_ASSERT_EQUAL(ip->ip_p, OFP_IPPROTO_GRE); greip = (struct ofp_greip *)ip; CU_ASSERT_EQUAL(greip->gi_g.flags, 0); CU_ASSERT_EQUAL(greip->gi_g.ptype, odp_cpu_to_be_16(OFP_ETHERTYPE_IPV6)); /* inner ip */ ip6 = (struct ofp_ip6_hdr *)(greip + 1); ip6_orig = (struct ofp_ip6_hdr *) (&orig_pkt_data[OFP_ETHER_HDR_LEN]); if (memcmp(ip6, ip6_orig, odp_be_to_cpu_16(ip6_orig->ofp_ip6_plen) + sizeof(*ip6))) CU_FAIL("Inner IP packet error."); }
static void do_misc_tests(const char *fname, size_t len) { struct stat stat_info; void *address; FILE *fp = NULL; size_t items; int rc; int fd; int new_fd; int status; rc = stat(fname, &stat_info); CU_ASSERT_EQUAL_FATAL(rc, 0); CU_ASSERT_NOT_EQUAL_FATAL(stat_info.st_size, 0); fd = open(fname, O_RDWR); printf("Opened %s, fd = %d\n", fname, fd); CU_ASSERT_NOT_EQUAL(fd, -1); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); new_fd = dup(fd); printf("Duped %d, new_fd = %d\n", fd, new_fd); CU_ASSERT_NOT_EQUAL(new_fd, -1); status = dfuse_get_bypass_status(new_fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = close(new_fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); new_fd = dup2(fd, 80); printf("dup2(%d, 80) returned %d\n", fd, new_fd); CU_ASSERT_EQUAL(new_fd, 80); status = dfuse_get_bypass_status(new_fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = close(new_fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); new_fd = fcntl(fd, F_DUPFD, 80); printf("fcntl(%d, F_DUPFD, 80) returned %d\n", fd, new_fd); CU_ASSERT(new_fd >= 80); status = dfuse_get_bypass_status(new_fd); printf("status = %d\n", status); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = close(new_fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 90); printf("fcntl(%d, F_DUPFD, 90) returned %d\n", fd, new_fd); CU_ASSERT(new_fd >= 90); status = dfuse_get_bypass_status(new_fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = close(new_fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); rc = fsync(fd); printf("fsync returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = fdatasync(fd); printf("fdatasync returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); new_fd = dup(fd); printf("Duped %d, new_fd = %d\n", fd, new_fd); CU_ASSERT_NOT_EQUAL(new_fd, -1); status = dfuse_get_bypass_status(new_fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); address = mmap(NULL, BUF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); printf("mmap returned %p\n", address); if (address == MAP_FAILED && errno == ENODEV) { printf("mmap not supported on file system\n"); goto skip_mmap; } CU_ASSERT_PTR_NOT_EQUAL_FATAL(address, MAP_FAILED); memset(address, '@', BUF_SIZE); rc = munmap(address, BUF_SIZE); printf("munmap returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_DIS_MMAP); /* dup'd descriptor should also change status */ status = dfuse_get_bypass_status(new_fd); CU_ASSERT_EQUAL(status, DFUSE_IO_DIS_MMAP); skip_mmap: rc = close(fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); rc = close(new_fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); fd = open(fname, O_RDWR); printf("Opened %s, fd = %d\n", fname, fd); CU_ASSERT_NOT_EQUAL(fd, -1); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); fp = fdopen(fd, "r"); printf("fdopen returned %p\n", fp); CU_ASSERT_PTR_NOT_EQUAL(fp, NULL); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_DIS_STREAM); if (fp != NULL) { char buf[16]; items = fread(buf, 1, 8, fp); printf("Read %zd items, expected 8\n", items); CU_ASSERT_EQUAL(items, 8); CU_ASSERT_STRING_EQUAL(buf, "@@@@@@@@"); } if (fp != NULL) { rc = fclose(fp); printf("fclose returned %d\n", rc); } else { rc = close(new_fd); printf("close returned %d\n", rc); } CU_ASSERT_EQUAL(rc, 0); fd = open(fname, O_RDWR); printf("Opened %s, fd = %d\n", fname, fd); CU_ASSERT_NOT_EQUAL(fd, -1); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_BYPASS); rc = fcntl(fd, F_SETFL, O_APPEND); printf("fcntl F_SETFL returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(fd); CU_ASSERT_EQUAL(status, DFUSE_IO_DIS_FCNTL); rc = fcntl(fd, F_GETFL); printf("fcntl F_GETFL returned %d\n", rc); CU_ASSERT(rc & O_APPEND); rc = close(fd); printf("close returned %d\n", rc); CU_ASSERT_EQUAL(rc, 0); status = dfuse_get_bypass_status(0); CU_ASSERT_EQUAL(status, DFUSE_IO_EXTERNAL); status = dfuse_get_bypass_status(1); CU_ASSERT_EQUAL(status, DFUSE_IO_EXTERNAL); status = dfuse_get_bypass_status(2); CU_ASSERT_EQUAL(status, DFUSE_IO_EXTERNAL); }
static void do_read_tests(const char *fname, size_t len) { char *buf; char buf2[len + 1]; struct iovec iov[2]; ssize_t bytes; off_t offset; int pos; int fd; int rc; buf = calloc(2, BUF_SIZE); CU_ASSERT_PTR_NOT_NULL(buf); fd = open(fname, O_RDONLY); printf("Opened %s, fd = %d\n", fname, fd); CU_ASSERT_NOT_EQUAL_FATAL(fd, -1); bytes = read(fd, buf, BUF_SIZE * 2); printf("Read %zd bytes, expected %zu\n", bytes, BUF_SIZE + (len * 4)); CU_ASSERT_EQUAL(bytes, BUF_SIZE + (len * 4)); offset = lseek(fd, 0, SEEK_CUR); printf("Seek offset is %zd, expected %zu\n", offset, BUF_SIZE + (len * 4)); CU_ASSERT_EQUAL(offset, BUF_SIZE + len * 4); pos = 0; while (pos < (len * 4)) { CU_ASSERT_NSTRING_EQUAL(fname, buf + pos, len); pos += len; } CU_ASSERT_NSTRING_EQUAL(big_string, buf + pos, BUF_SIZE); offset = lseek(fd, 0, SEEK_SET); printf("Seek offset is %zd, expected 0\n", offset); CU_ASSERT_EQUAL(offset, 0); memset(buf, 0, BUF_SIZE * 2); bytes = pread(fd, buf, len, len); printf("Read %zd bytes, expected %zu\n", bytes, len); CU_ASSERT_EQUAL(bytes, len); CU_ASSERT_STRING_EQUAL(fname, buf); offset = lseek(fd, 0, SEEK_CUR); printf("Seek offset is %zd, expected 0\n", offset); CU_ASSERT_EQUAL(offset, 0); memset(buf, 0, BUF_SIZE * 2); iov[0].iov_len = len; iov[0].iov_base = buf2; iov[1].iov_len = len; iov[1].iov_base = buf; bytes = readv(fd, iov, 2); printf("Read %zd bytes, expected %zu\n", bytes, len * 2); CU_ASSERT_EQUAL(bytes, len * 2); CU_ASSERT_STRING_EQUAL(fname, buf); CU_ASSERT_STRING_EQUAL(fname, buf2); free(buf); rc = close(fd); printf("Closed file, rc = %d\n", rc); CU_ASSERT_EQUAL(rc, 0); }