diff options
Diffstat (limited to 'connect/test')
-rw-r--r-- | connect/test/ncbi_conntest.c | 64 | ||||
-rw-r--r-- | connect/test/test_assert_impl.h | 9 | ||||
-rw-r--r-- | connect/test/test_ncbi_core.c | 62 | ||||
-rw-r--r-- | connect/test/test_ncbi_disp.c | 107 | ||||
-rw-r--r-- | connect/test/test_ncbi_dsock.c | 41 | ||||
-rw-r--r-- | connect/test/test_ncbi_ftp_connector.c | 76 | ||||
-rw-r--r-- | connect/test/test_ncbi_heapmgr.c | 201 | ||||
-rw-r--r-- | connect/test/test_ncbi_socket.c | 94 |
8 files changed, 262 insertions, 392 deletions
diff --git a/connect/test/ncbi_conntest.c b/connect/test/ncbi_conntest.c index 37559801..9e943fa9 100644 --- a/connect/test/ncbi_conntest.c +++ b/connect/test/ncbi_conntest.c @@ -1,4 +1,4 @@ -/* $Id: ncbi_conntest.c,v 6.10 2005/08/03 20:15:25 lavr Exp $ +/* $Id: ncbi_conntest.c,v 6.11 2007/04/17 11:25:54 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -61,31 +61,30 @@ static void s_SingleBouncePrint FILE* data_file) { static const char write_str[] = "This is a s_*BouncePrint test string.\n"; - EIO_Status status; size_t n_written, n_read; char buf[8192]; + EIO_Status status; TEST_LOG(eIO_Success, "[s_SingleBouncePrint] Starting..."); /* WRITE */ status = CONN_Write(conn, write_str, strlen(write_str), &n_written, eIO_WritePersist); - if (status != eIO_Success || n_written != strlen(write_str)) { + if (status != eIO_Success || n_written != strlen(write_str)) TEST_LOG(status, "[s_SingleBouncePrint] Write failed!"); - } assert(n_written == strlen(write_str)); assert(status == eIO_Success); - /* READ the "bounced" data from the connection */ status = CONN_Read(conn, buf, sizeof(buf) - 1, &n_read, eIO_ReadPersist); TEST_LOG(status, "[s_SingleBouncePrint] after READ"); - /* Printout to LOG file, if any */ + /* Printout to data file, if any */ if (data_file && n_read) { fprintf(data_file, "\ns_SingleBouncePrint(BEGIN PRINT)\n"); assert(fwrite(buf, n_read, 1, data_file) == 1); fprintf(data_file, "\ns_SingleBouncePrint(END PRINT)\n"); + fflush(data_file); } /* Check-up */ @@ -102,16 +101,20 @@ static void s_MultiBouncePrint int i; TEST_LOG(eIO_Success, "[s_MultiBouncePrint] Starting..."); - if ( data_file ) + if ( data_file ) { fprintf(data_file, "\ns_MultiBouncePrint(BEGIN)\n"); + fflush(data_file); + } for (i = 0; i < 5; i++) { s_SingleBouncePrint(conn, data_file); } TEST_LOG(eIO_Success, "[s_MultiBouncePrint] ...finished"); - if ( data_file ) + if ( data_file ) { fprintf(data_file, "\ns_MultiBouncePrint(END)\n"); + fflush(data_file); + } } @@ -272,19 +275,23 @@ static void s_SingleBounceCheck return; fprintf(data_file, "\ns_SingleBounceCheck(BEGIN EXTRA DATA)\n"); + fflush(data_file); for (;;) { size_t n_read; status = CONN_Read(conn, buf, sizeof(buf), &n_read, eIO_ReadPersist); TEST_LOG(status, "s_SingleBounceCheck(The extra data READ...)"); - if ( n_read ) + if ( n_read ) { assert(fwrite(buf, n_read, 1, data_file) == 1); + fflush(data_file); + } if (status == eIO_Closed || status == eIO_Timeout) break; /* okay */ - assert(status == eIO_Success || status == eIO_Timeout); + assert(status == eIO_Success); } fprintf(data_file, "\ns_SingleBounceCheck(END EXTRA DATA)\n\n"); + fflush(data_file); } @@ -347,40 +354,3 @@ extern void CONN_TestConnector TEST_LOG(status, "Test completed successfully"); } - - -/* - * -------------------------------------------------------------------------- - * $Log: ncbi_conntest.c,v $ - * Revision 6.10 2005/08/03 20:15:25 lavr - * Better asserts - * - * Revision 6.9 2004/02/23 15:23:42 lavr - * New (last) parameter "how" added in CONN_Write() API call - * - * Revision 6.8 2003/02/10 15:57:35 lavr - * Announce successful test completion - * - * Revision 6.7 2002/08/07 16:38:08 lavr - * EIO_ReadMethod enums changed accordingly; log moved to end - * - * Revision 6.6 2002/03/22 19:46:02 lavr - * Test_assert.h made last among the include files - * - * Revision 6.5 2002/01/16 21:23:14 vakatov - * Utilize header "test_assert.h" to switch on ASSERTs in the Release mode too - * - * Revision 6.4 2001/03/02 20:03:34 lavr - * Typos fixed - * - * Revision 6.3 2000/12/29 18:25:06 lavr - * CONN Reconnect replaced with ReInit. - * - * Revision 6.2 2000/04/21 19:53:11 vakatov - * Minor cosmetic changes - * - * Revision 6.1 2000/04/07 20:03:01 vakatov - * Initial revision - * - * ========================================================================== - */ diff --git a/connect/test/test_assert_impl.h b/connect/test/test_assert_impl.h index 28a8e2fb..8524c45e 100644 --- a/connect/test/test_assert_impl.h +++ b/connect/test/test_assert_impl.h @@ -1,7 +1,7 @@ #ifndef TEST_ASSERT_IMPL__H #define TEST_ASSERT_IMPL__H -/* $Id: test_assert_impl.h,v 1.1 2006/03/07 18:22:09 lavr Exp $ +/* $Id: test_assert_impl.h,v 1.2 2007/01/30 21:13:40 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -139,11 +139,18 @@ static int (*_SDPM)(void) = _SuppressDiagPopupMessages; # undef _ASSERT #endif #define _ASSERT assert +#ifdef _DEBUG_ARG +# undef _DEBUG_ARG +#endif +#define _DEBUG_ARG(arg) arg /* * -------------------------------------------------------------------------- * $Log: test_assert_impl.h,v $ + * Revision 1.2 2007/01/30 21:13:40 kazimird + * Synchronized with the C++ Toolkit. + * * Revision 1.1 2006/03/07 18:22:09 lavr * Initial revision * diff --git a/connect/test/test_ncbi_core.c b/connect/test/test_ncbi_core.c index 80858a0d..36bdd195 100644 --- a/connect/test/test_ncbi_core.c +++ b/connect/test/test_ncbi_core.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_core.c,v 6.12 2006/07/26 14:47:32 lavr Exp $ +/* $Id: test_ncbi_core.c,v 6.13 2007/06/25 16:55:29 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -117,6 +117,12 @@ static int/*bool*/ TEST_CORE_LockHandler(void* user_data, EMT_Lock how) case eMT_Unlock: str = "eMT_Unlock"; break; + case eMT_TryLock: + str = "eMT_TryLock"; + break; + case eMT_TryLockRead: + str = "eMT_TryLockRead"; + break; } assert(str); printf("TEST_CORE_LockHandler(%s)\n", str); @@ -164,10 +170,21 @@ static void TEST_CORE_Lock(void) TEST_CORE_LockHandler, TEST_CORE_LockCleanup); assert(x_lock); + /* NB: Write after read is not usually an allowed lock nesting */ verify(MT_LOCK_Do(x_lock, eMT_LockRead)); verify(MT_LOCK_Do(x_lock, eMT_Lock)); verify(MT_LOCK_Do(x_lock, eMT_Unlock)); verify(MT_LOCK_Do(x_lock, eMT_Unlock)); + /* Read after write is usually okay */ + verify(MT_LOCK_Do(x_lock, eMT_Lock)); + verify(MT_LOCK_Do(x_lock, eMT_LockRead)); + verify(MT_LOCK_Do(x_lock, eMT_Unlock)); + verify(MT_LOCK_Do(x_lock, eMT_Unlock)); + /* Try-locking sequence */ + verify(MT_LOCK_Do(x_lock, eMT_TryLock)); + verify(MT_LOCK_Do(x_lock, eMT_TryLockRead)); + verify(MT_LOCK_Do(x_lock, eMT_Unlock)); + verify(MT_LOCK_Do(x_lock, eMT_Unlock)); verify(MT_LOCK_Delete(x_lock) == 0); } @@ -391,46 +408,3 @@ int main(void) TEST_UTIL(); return 0; } - - -/* - * --------------------------------------------------------------------------- - * $Log: test_ncbi_core.c,v $ - * Revision 6.12 2006/07/26 14:47:32 lavr - * +TEST_UTIL_MatchesMask, +TEST_CORE_GetVMPageSize - * - * Revision 6.11 2006/06/15 03:02:32 lavr - * GetUsername test moved here - * - * Revision 6.10 2005/04/20 18:23:11 lavr - * +"../ncbi_assert.h" - * - * Revision 6.9 2002/08/14 03:35:26 lavr - * Fix ELOG_Level test; add eIO_Interrupt to EIO_Status test - * - * Revision 6.8 2002/03/22 19:46:57 lavr - * Test_assert.h made last among the include files - * - * Revision 6.7 2002/01/16 21:23:15 vakatov - * Utilize header "test_assert.h" to switch on ASSERTs in the Release mode too - * - * Revision 6.6 2001/08/09 16:25:28 lavr - * Remove last (unneeded) parameter from LOG_Reset() and its test - * - * Revision 6.5 2001/05/17 17:59:03 vakatov - * TEST_UTIL_Log:: Set "errno" to zero before testing LOG_WRITE_ERRNO() - * - * Revision 6.4 2000/06/23 19:35:51 vakatov - * Test the logging of binary data - * - * Revision 6.3 2000/06/01 18:35:12 vakatov - * Dont log with level "eLOG_Fatal" (it exits/coredumps now) - * - * Revision 6.2 2000/04/07 20:00:51 vakatov - * + <errno.h> - * - * Revision 6.1 2000/02/23 22:37:37 vakatov - * Initial revision - * - * =========================================================================== - */ diff --git a/connect/test/test_ncbi_disp.c b/connect/test/test_ncbi_disp.c index 378dbcfa..674f7f23 100644 --- a/connect/test/test_ncbi_disp.c +++ b/connect/test/test_ncbi_disp.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_disp.c,v 6.23 2006/04/05 15:07:09 lavr Exp $ +/* $Id: test_ncbi_disp.c,v 6.31 2007/04/20 01:55:30 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -30,10 +30,12 @@ * */ +#include "../ncbi_ansi_ext.h" +#include "../ncbi_lbsmd.h" #include "../ncbi_priv.h" /* CORE logging facilities */ #include "../ncbi_servicep.h" +#include <connect/ncbi_heapmgr.h> #include <stdlib.h> -#include <string.h> /* This header must go last */ #include "test_assert.h" @@ -52,6 +54,27 @@ int main(int argc, const char* argv[]) CORE_SetLOGFormatFlags(fLOG_None | fLOG_Level | fLOG_OmitNoteLevel | fLOG_DateTime); CORE_SetLOGFILE(stderr, 0/*false*/); + if (argc > 2) { + if (strcasecmp(argv[2],"heap") == 0 || strcasecmp(argv[2],"all") == 0){ + HEAP_Options(eOff, eDefault); + CORE_LOG(eLOG_Note, "Using slow heap access (w/checks)"); + } + if (strcasecmp(argv[2],"lbsm") == 0 || strcasecmp(argv[2],"all") == 0){ +#ifdef NCBI_OS_MSWIN + if (strcasecmp(argv[2],"lbsm") == 0) { + CORE_LOG(eLOG_Warning, + "Option \"lbsm\" has no useful effect on MS-Windows"); + } +#else + LBSMD_FastHeapAccess(eOn); + CORE_LOG(eLOG_Note, "Using live (faster) LBSM heap access"); +#endif /*NCBI_OS_MSWIN*/ + } + if (strcasecmp(argv[2],"lbsm") != 0 && + strcasecmp(argv[2],"heap") != 0 && + strcasecmp(argv[2],"all") != 0) + CORE_LOGF(eLOG_Fatal, ("Unknown option `%s'", argv[2])); + } CORE_LOGF(eLOG_Note, ("Looking for service `%s'", service)); net_info = ConnNetInfo_Create(service); @@ -68,7 +91,7 @@ int main(int argc, const char* argv[]) SERV_MapperName(iter))); while ((info = SERV_GetNextInfoEx(iter, &hinfo)) != 0) { char* info_str = SERV_WriteInfo(info); - CORE_LOGF(eLOG_Note, ("Service `%s' = %s", + CORE_LOGF(eLOG_Note, ("Server #%d `%s' = %s", ++n_found, SERV_CurrentName(iter), info_str)); if (hinfo) { double array[2]; @@ -97,7 +120,6 @@ int main(int argc, const char* argv[]) free(hinfo); } free(info_str); - n_found++; } CORE_LOG(eLOG_Trace, "Resetting service mapper"); SERV_Reset(iter); @@ -135,80 +157,3 @@ int main(int argc, const char* argv[]) CORE_SetLOG(0); return 0; } - - -/* - * -------------------------------------------------------------------------- - * $Log: test_ncbi_disp.c,v $ - * Revision 6.23 2006/04/05 15:07:09 lavr - * Print mapper name first - * - * Revision 6.22 2006/03/05 17:43:01 lavr - * Log service mapper name; extract affinities (if any) - * - * Revision 6.21 2006/01/11 16:35:59 lavr - * Open service iterator for everything (but FIREWALL) - * - * Revision 6.20 2005/12/23 18:20:33 lavr - * Use new SERV_OpenP() for iterator opening (and thus allow service wildcards) - * - * Revision 6.19 2005/12/14 21:45:39 lavr - * Adjust to use new SERV_OpenP() prototype - * - * Revision 6.18 2005/07/11 18:49:15 lavr - * Hashed preference generation algorithm retired (proven to fail often) - * - * Revision 6.17 2005/07/11 18:26:05 lavr - * Allow wildcard in local name searches - * - * Revision 6.16 2004/06/21 18:02:45 lavr - * Test on service "bounce" by default ("io_bounce" is retired now) - * - * Revision 6.15 2003/05/14 03:58:43 lavr - * Match changes in respective APIs of the tests - * - * Revision 6.14 2002/10/29 22:15:52 lavr - * Host info output slightly modified - * - * Revision 6.13 2002/10/29 00:35:47 lavr - * Added tests for host info API - * - * Revision 6.12 2002/04/15 19:21:44 lavr - * +#include "../test/test_assert.h" - * - * Revision 6.11 2002/03/22 19:48:57 lavr - * Removed <stdio.h>: included from ncbi_util.h or ncbi_priv.h - * - * Revision 6.10 2002/02/20 20:56:49 lavr - * Added missing calls to free(server_info) - * - * Revision 6.9 2001/11/29 22:20:52 lavr - * Flow control trace messages added - * - * Revision 6.8 2001/09/24 20:35:34 lavr - * +Test for SERV_Reset() - * - * Revision 6.7 2001/07/18 17:44:18 lavr - * Added parameter to switch to local test - * - * Revision 6.6 2001/03/20 22:14:08 lavr - * Second test added to list service by server type (yet #if 0'ed out) - * - * Revision 6.5 2001/03/09 04:58:26 lavr - * Typo (made of pretty styling by vakatov) corrected in comparison - * - * Revision 6.4 2001/03/08 17:56:25 lavr - * Redesigned to show that SERV_Open can return SERV_ITER, that - * in turn returns 0 even if used for the very first time. - * - * Revision 6.3 2001/03/05 23:21:11 lavr - * SERV_WriteInfo take only one argument now - * - * Revision 6.2 2001/03/02 20:01:38 lavr - * SERV_Close() shown; "../ncbi_priv.h" explained - * - * Revision 6.1 2001/03/01 00:33:59 lavr - * Initial revision - * - * ========================================================================== - */ diff --git a/connect/test/test_ncbi_dsock.c b/connect/test/test_ncbi_dsock.c index a549cc9c..72601918 100644 --- a/connect/test/test_ncbi_dsock.c +++ b/connect/test/test_ncbi_dsock.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_dsock.c,v 6.18 2006/01/27 17:12:10 lavr Exp $ +/* $Id: test_ncbi_dsock.c,v 6.19 2006/11/27 21:33:44 lavr Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -48,8 +48,8 @@ /* This has been found experimentally on IRIX64 6.5 04101931 IP25 */ # define MAX_DGRAM_SIZE (60*1024) #elif defined(NCBI_OS_LINUX) -/* Larger sizes do not seem to work everywhere */ -# define MAX_DGRAM_SIZE 65000 + /* Larger sizes do not seem to work everywhere */ +# define MAX_DGRAM_SIZE 59550 #else /* This is the maximal datagram size defined by the UDP standard */ # define MAX_DGRAM_SIZE 65535 @@ -137,7 +137,7 @@ static int s_Server(int x_port) "%lu bytes", addr, peerport, (unsigned long) msglen)); - if (!(buf = (char*) malloc(msglen ? msglen : 1))) { + if (!(buf = (char*) malloc(msglen < 10 ? 10 : msglen))) { CORE_LOG_ERRNO(eLOG_Error, errno,"[Server] Cannot alloc msg buf"); break; } @@ -157,6 +157,7 @@ static int s_Server(int x_port) len += n; } assert(SOCK_Read(server, 0, 1, &n, eIO_ReadPlain) == eIO_Closed); + assert(memcmp(buf + msglen - 10, "\0\0\0\0\0\0\0\0\0", 10) == 0); CORE_LOG(eLOG_Note, "[Server] Bouncing the message to sender"); @@ -169,6 +170,7 @@ static int s_Server(int x_port) break; } + msglen -= 10; for (len = 0; len < msglen; len += n) { n = (size_t)(((double)rand()/(double)RAND_MAX)*(msglen-len) + 0.5); if ((status = SOCK_Write(server, buf + len, n, &n, eIO_WritePlain)) @@ -182,7 +184,7 @@ static int s_Server(int x_port) free(buf); - if ((status = DSOCK_SendMsg(server, addr, peerport, "--Reply--", 9)) + if ((status = DSOCK_SendMsg(server, addr, peerport, "--Reply--", 10)) != eIO_Success) { CORE_LOGF(eLOG_Error, ("[Server] Error sending to DSOCK: %s", IO_StatusStr(status))); @@ -224,21 +226,21 @@ static int s_Client(int x_port, unsigned int max_try) return 1; } - msglen = (size_t)(((double)rand()/(double)RAND_MAX)*(s_MTU - 10)); - if (msglen < sizeof(time_t)) - msglen = sizeof(time_t); + msglen = (size_t)(((double)rand()/(double)RAND_MAX) * s_MTU); + if (msglen < sizeof(time_t) + 10) + msglen = sizeof(time_t) + 10; CORE_LOGF(eLOG_Note, ("[Client] Generating a message %lu bytes long", (unsigned long) msglen)); - if (!(buf = (char*) malloc(2*msglen + 9))) { + if (!(buf = (char*) malloc(2 * msglen))) { CORE_LOG_ERRNO(eLOG_Error, errno, "[Client] Cannot alloc msg buf"); return 1; } - - for (n = sizeof(unsigned long); n < msglen; n++) + for (n = sizeof(unsigned long); n < msglen - 10; n++) buf[n] = rand() % 0xFF; + memcpy(buf + msglen - 10, "\0\0\0\0\0\0\0\0\0", 10); id = (unsigned long) time(0); @@ -268,20 +270,20 @@ static int s_Client(int x_port, unsigned int max_try) } again: - if ((status = DSOCK_RecvMsg(client, &buf[msglen], msglen+9,0, &n, 0,0)) + if ((status = DSOCK_RecvMsg(client, buf + msglen, msglen, 0, &n, 0, 0)) != eIO_Success) { CORE_LOGF(eLOG_Error, ("[Client] Error reading from DSOCK: %s", IO_StatusStr(status))); continue; } - if (n != msglen + 9) { + if (n != msglen) { CORE_LOGF(eLOG_Error, ("[Client] Received message of wrong size: " "%lu", (unsigned long) n)); return 1; } - memcpy(&tmp, &buf[msglen], sizeof(tmp)); + memcpy(&tmp, buf + msglen, sizeof(tmp)); if (SOCK_NetToHostLong(tmp) != id) { m++; CORE_LOGF(m < max_try ? eLOG_Warning : eLOG_Error, @@ -300,20 +302,20 @@ static int s_Client(int x_port, unsigned int max_try) if (m > max_try) return 1; - for (n = sizeof(unsigned long); n < msglen; n++) { + for (n = sizeof(unsigned long); n < msglen - 10; n++) { if (buf[n] != buf[msglen + n]) break; } - if (n < msglen) { + if (n < msglen - 10) { CORE_LOGF(eLOG_Error, ("[Client] Bounced message corrupted, off=%lu", (unsigned long) n)); return 1; } - if (strncmp(&buf[msglen*2], "--Reply--", 9) != 0) { + if (strcmp(buf + msglen*2 - 10, "--Reply--") != 0) { CORE_LOGF(eLOG_Error, ("[Client] No signature in the message: %.9s", - &buf[msglen*2])); + buf + msglen*2 - 10)); return 1; } @@ -381,6 +383,9 @@ int main(int argc, const char* argv[]) /* * -------------------------------------------------------------------------- * $Log: test_ncbi_dsock.c,v $ + * Revision 6.19 2006/11/27 21:33:44 lavr + * Lower MAX_DGRAM_SIZE for Linux (i686 seems to fail on former default 65000) + * * Revision 6.18 2006/01/27 17:12:10 lavr * Replace obsolete call names with current ones * diff --git a/connect/test/test_ncbi_ftp_connector.c b/connect/test/test_ncbi_ftp_connector.c index fa38c912..08bbb9de 100644 --- a/connect/test/test_ncbi_ftp_connector.c +++ b/connect/test/test_ncbi_ftp_connector.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_ftp_connector.c,v 1.11 2005/07/22 16:09:15 lavr Exp $ +/* $Id: test_ncbi_ftp_connector.c,v 1.13 2007/06/27 14:25:40 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -40,17 +40,17 @@ #include "test_assert.h" -#define TEST_HOST "ftp.ncbi.nlm.nih.gov" -#define TEST_PORT 0 -#define TEST_USER "ftp" -#define TEST_PASS "none" -#define TEST_PATH ((char*) 0) +#define TEST_HOST "ftp.ncbi.nlm.nih.gov" +#define TEST_PORT 0 +#define TEST_USER "ftp" +#define TEST_PASS "none" +#define TEST_PATH ((char*) 0) int main(int argc, char* argv[]) { - static const char k_chdir[] = "CWD /toolbox/ncbi_tools\n"; - static const char k_file[] = "RETR CURRENT/ncbi.tar.gz"; + static const char kChdir[] = "CWD /toolbox/ncbi_tools\n"; + static const char kFile[] = "RETR CURRENT/ncbi.tar.gz"; const char* env = getenv("CONN_DEBUG_PRINTOUT"); int/*bool*/ aborting = 0, first; TFCDC_Flags flags = 0; @@ -72,13 +72,13 @@ int main(int argc, char* argv[]) data_file = fopen("test_ncbi_ftp_connector.out", "wb"); assert(data_file); - timeout.sec = 3; + timeout.sec = 5; timeout.usec = 0; if (env) { - if ( strcasecmp(env, "1") == 0 || - strcasecmp(env, "TRUE") == 0 || - strcasecmp(env, "SOME") == 0) + if ( strcasecmp(env, "1") == 0 || + strcasecmp(env, "TRUE") == 0 || + strcasecmp(env, "SOME") == 0) flags |= eFCDC_LogControl; else if (strcasecmp(env, "DATA") == 0) flags |= eFCDC_LogData; @@ -156,15 +156,15 @@ int main(int argc, char* argv[]) printf("<EOF>\n"); } - if (CONN_Write(conn, k_chdir, sizeof(k_chdir) - 1, &n, eIO_WritePlain) + if (CONN_Write(conn, kChdir, sizeof(kChdir) - 1, &n, eIO_WritePlain) != eIO_Success) { CORE_LOGF(eLOG_Fatal, ("Cannot execute %.*s", - (int)sizeof(k_chdir) - 2, k_chdir)); + (int) sizeof(kChdir) - 2, kChdir)); } - if (CONN_Write(conn, k_file, sizeof(k_file) - 1, &n, eIO_WritePersist) + if (CONN_Write(conn, kFile, sizeof(kFile) - 1, &n, eIO_WritePersist) != eIO_Success) { - CORE_LOGF(eLOG_Fatal, ("Cannot write %s", k_file)); + CORE_LOGF(eLOG_Fatal, ("Cannot write %s", kFile)); } size = 0; @@ -183,10 +183,10 @@ int main(int argc, char* argv[]) if (!aborting || (rand() & 1) == 0) { if (CONN_Write(conn, "NLST blah*", 10, &n, eIO_WritePlain) != eIO_Success) { - CORE_LOG(eLOG_Fatal, "Cannot write gobbled NLST command"); + CORE_LOG(eLOG_Fatal, "Cannot write garbled NLST command"); } - CORE_LOG(eLOG_Note, "Gobbled NLST command output (should be empty):"); + CORE_LOG(eLOG_Note, "Garbled NLST command output (should be empty):"); first = 1/*true*/; do { status = CONN_Read(conn, buf, sizeof(buf), &n, eIO_ReadPlain); @@ -217,43 +217,3 @@ int main(int argc, char* argv[]) CORE_SetLOG(0); return 0; } - - -/* - * -------------------------------------------------------------------------- - * $Log: test_ncbi_ftp_connector.c,v $ - * Revision 1.11 2005/07/22 16:09:15 lavr - * Implement data xfer timeout - * - * Revision 1.10 2005/07/21 17:38:58 lavr - * Proper URL printout when connecting - * - * Revision 1.9 2005/07/11 18:24:41 lavr - * Spell ADDEND - * - * Revision 1.8 2005/05/20 12:56:35 lavr - * Added test for multiple commands and '[\r]\n'-terminated input - * - * Revision 1.7 2005/05/20 12:11:29 lavr - * Test ABOR with command and connection closure (both should now work) - * - * Revision 1.6 2005/05/20 11:41:47 lavr - * Separate control and data FTP connection debugging setting - * - * Revision 1.5 2005/05/11 20:00:25 lavr - * Empty NLST result list bug fixed - * - * Revision 1.4 2005/05/02 16:13:05 lavr - * Use global random seed; show NLST use example; add more logging - * - * Revision 1.3 2004/12/27 15:32:10 lavr - * Randomly test ABORTs (if there is an argument for main()) - * - * Revision 1.2 2004/12/06 22:02:51 ucko - * +<stdlib.h> for getenv() - * - * Revision 1.1 2004/12/06 17:49:00 lavr - * Initial revision - * - * ========================================================================== - */ diff --git a/connect/test/test_ncbi_heapmgr.c b/connect/test/test_ncbi_heapmgr.c index 5ce930a2..ffba52f9 100644 --- a/connect/test/test_ncbi_heapmgr.c +++ b/connect/test/test_ncbi_heapmgr.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_heapmgr.c,v 6.15 2006/03/05 17:42:10 lavr Exp $ +/* $Id: test_ncbi_heapmgr.c,v 6.18 2006/11/21 14:47:58 lavr Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -33,6 +33,7 @@ #include "../ncbi_priv.h" #include <connect/ncbi_heapmgr.h> #include <stdlib.h> +#include <string.h> #include <time.h> #if 0 # define eLOG_Warning eLOG_Fatal @@ -43,6 +44,9 @@ #include "test_assert.h" +#define HEAP_ADDR(b, h) ((unsigned int)((char*) b - (char*) HEAP_Base(h)) >> 4) + + #ifdef __cplusplus extern "C" { #endif @@ -50,7 +54,7 @@ extern "C" { /*ARGSUSED*/ static void* s_Expand(void* base, TNCBI_Size size, void* arg) { - if (base && size) + if (base && size) return realloc(base, size); if (size) return malloc(size); @@ -64,102 +68,174 @@ static void* s_Expand(void* base, TNCBI_Size size, void* arg) #endif -int main(void) +static void s_Walk(HEAP heap, const char* which) +{ + unsigned int i = 0; + SHEAP_Block* blk = 0; + TNCBI_Size total = 0; + CORE_LOGF(eLOG_Note, + ("Walking %s%sheap", + which && *which ? which : "", &" "[!which || !*which])); + while ((blk = HEAP_Walk(heap, blk)) != 0) { + const char* flag = (int) blk->flag < 0 ? ", last" : ""; + TNCBI_Size size = blk->size; + if ((short) blk->flag) { + TNCBI_Size data_size = size - sizeof(*blk); + CORE_LOGF(eLOG_Note, + ("Used%s @%u, size %u, data size %u", + flag, HEAP_ADDR(blk, heap), size, data_size)); + assert(data_size); + } else { + unsigned int* ptr = (unsigned int*) blk; + CORE_LOGF(eLOG_Note, + ("Free%s @%u, size %u, <-%u, %u->", + flag, HEAP_ADDR(blk, heap), size, ptr[2], ptr[3])); + } + total += size; + i++; + } + CORE_LOGF(eLOG_Note, + ("%d block%s total; total size %u", i, &"s"[i == 1], total)); +} + + +int main(int argc, const char* argv[]) { SHEAP_Block* blk; int r, j, i, n; HEAP heap; char* c; + /* CORE_SetLOGFormatFlags(fLOG_None | fLOG_Level | fLOG_OmitNoteLevel); */ CORE_SetLOGFILE(stderr, 0/*false*/); - for (j = 1; j <= 3; j++) { + if (argc > 1) + g_NCBI_ConnectRandomSeed = atoi(argv[1]); + else g_NCBI_ConnectRandomSeed = (int) time(0) ^ NCBI_CONNECT_SRAND_ADDEND; - srand(g_NCBI_ConnectRandomSeed); + CORE_LOGF(eLOG_Note, ("Using seed %d", g_NCBI_ConnectRandomSeed)); + HEAP_Options(eOff/*slow*/, eOn/*newalk*/); + srand(g_NCBI_ConnectRandomSeed); + for (j = 1; j <= 3; j++) { CORE_LOGF(eLOG_Note, ("Creating heap %d", j)); if (!(heap = HEAP_Create(0, 0, 4096, s_Expand, 0))) CORE_LOG(eLOG_Error, "Cannot create heap"); for (n = 0; n < 1000 && (rand() & 0xFFFF) != 0x1234; n++) { r = rand() & 7; - if (r == 1 || r == 3) { + if (r == 1 || r == 3) { + int/*bool*/ fast = rand() & 1; i = rand() & 0xFF; if (i) { - CORE_LOGF(eLOG_Note, ("Allocating %d data byte(s)", i)); - if (!(blk = HEAP_Alloc(heap, i))) + CORE_LOGF(eLOG_Note, + ("Allocating%s data size %d", + fast ? " fast" : "", i)); + blk = fast ? HEAP_AllocFast(heap, i) : HEAP_Alloc(heap, i); + if (blk) { + CORE_LOGF(eLOG_Note, + ("Done @%u, size %u", + HEAP_ADDR(blk, heap), blk->size)); + } else CORE_LOG(eLOG_Error, "Allocation failed"); - else - CORE_LOG(eLOG_Note, "Done"); c = (char*) blk + sizeof(*blk); while (i--) *c++ = rand(); + s_Walk(heap, 0); + } else { + assert(!(fast + ? HEAP_AllocFast(heap, i) + : HEAP_Alloc(heap, i))); } - } else if (r == 2 || r == 4) { + } else if (r == 2 || r == 4) { blk = 0; - i = 0; do { - blk = HEAP_Walk(heap, blk); - if (!blk) + if (!(blk = HEAP_Walk(heap, blk))) break; - i++; - } while (rand() & 0x7); - if (blk && (short) blk->flag) { - unsigned data_size = blk->size - sizeof(*blk); + } while (rand() & 7); + if (blk && (short) blk->flag) { + unsigned size = blk->size; + unsigned data_size = size - sizeof(*blk); CORE_LOGF(eLOG_Note, - ("Deleting block #%d, data size %u", i, - data_size)); + ("Freeing @%u, size %u, data size %u", + HEAP_ADDR(blk, heap), size, data_size)); assert(data_size); HEAP_Free(heap, blk); CORE_LOG(eLOG_Note, "Done"); + s_Walk(heap, 0); } } else if (r == 5) { + const SHEAP_Block* prev = 0; + unsigned ok = 0; blk = 0; - i = 0; - CORE_LOG(eLOG_Note, "Walking the heap"); - while ((blk = HEAP_Walk(heap, blk)) != 0) { - unsigned data_size = blk->size - sizeof(*blk); - CORE_LOGF(eLOG_Note, - ("Block #%d (%s), data size %u", ++i, - (short) blk->flag ? "used" : "free", - data_size)); - assert(data_size); + for (;;) { + if (!(blk = HEAP_Walk(heap, blk))) + break; + if ((short) blk->flag && (rand() & 7)) { + char buf[32]; + unsigned size = blk->size; + int/*bool*/ fast = rand() & 1; + unsigned data_size = size - sizeof(*blk); + if (!fast || !prev) + *buf = '\0'; + else + sprintf(buf, ", prev @%u", HEAP_ADDR(prev, heap)); + CORE_LOGF(eLOG_Note, + ("Freeing%s%s @%u%s in walk," + " size %u, data size %u", + fast ? " fast" : "", ok ? " more" : "", + HEAP_ADDR(blk,heap), buf, size, data_size)); + assert(data_size); + if (fast) + HEAP_FreeFast(heap, blk, prev); + else + HEAP_Free(heap, blk); + CORE_LOG(eLOG_Note, "Done"); + s_Walk(heap, 0); + ok = 1; + if (prev && !((short) prev->flag)) + continue; + } + prev = blk; } - CORE_LOGF(eLOG_Note, - ("Total of %d block%s", i, i == 1 ? "" : "s")); - } else if (r == 6 || r == 7) { + if (!ok) + s_Walk(heap, "the"); + else + CORE_LOG(eLOG_Note, "Done with freeing while walking"); + } else if (r == 6 || r == 7) { HEAP newheap; - if (r == 6) - newheap = HEAP_Attach(HEAP_Base(heap), 0); - else + if (r == 6) { + int/*bool*/ fast = rand() & 1; + if (fast) { + CORE_LOG(eLOG_Note, "Attaching heap fast"); + newheap = HEAP_AttachFast(HEAP_Base(heap), + HEAP_Size(heap), 0); + } else { + CORE_LOG(eLOG_Note, "Attaching heap"); + newheap = HEAP_Attach(HEAP_Base(heap), 0); + } + } else { + CORE_LOG(eLOG_Note, "Copying heap"); newheap = HEAP_Copy(heap, 0, 0); + } if (!newheap) { - CORE_LOGF(eLOG_Error, ("%s failed", - r == 6 ? "Attach" : "Copy")); - } - i = 0; - blk = 0; - CORE_LOGF(eLOG_Note, ("Walking %s heap", - r == 6 ? "attached" : "copied")); - while ((blk = HEAP_Walk(newheap, blk)) != 0) { - unsigned data_size = blk->size - sizeof(*blk); - CORE_LOGF(eLOG_Note, - ("Block #%d (%s), data size %u", ++i, - (short) blk->flag ? "used" : "free", - data_size)); - assert(data_size); - } - CORE_LOGF(eLOG_Note, - ("Total of %d block%s", i, i == 1 ? "" : "s")); + CORE_LOGF(eLOG_Error, + ("%s failed", r == 6 ? "Attach" : "Copy")); + } else + s_Walk(newheap, r == 6 ? "attached" : "copied"); HEAP_Detach(newheap); } else { TNCBI_Size size = HEAP_Size(heap); - HEAP newheap = HEAP_Trim(heap); - CORE_LOGF(eLOG_Note, ("Heap %strimmed: %u -> %u", - newheap ? "" : "NOT ", - (unsigned) size, - (unsigned) HEAP_Size(newheap))); - if (newheap) + HEAP newheap; + + CORE_LOG(eLOG_Note, "Trimming heap"); + newheap = HEAP_Trim(heap); + CORE_LOGF(eLOG_Note, + ("Heap %strimmed: %u -> %u", newheap ? "" : "NOT ", + size, HEAP_Size(newheap))); + if (newheap) { heap = newheap; + s_Walk(heap, "trimmed"); + } } } HEAP_Destroy(heap); @@ -174,6 +250,15 @@ int main(void) /* * -------------------------------------------------------------------------- * $Log: test_ncbi_heapmgr.c,v $ + * Revision 6.18 2006/11/21 14:47:58 lavr + * Implement correct fast freeing and fast allocation checks + * + * Revision 6.17 2006/11/20 17:25:00 lavr + * Test extended to use HEAP_FreeFast() and HEAP_AttachFast() + * + * Revision 6.16 2006/11/20 16:42:31 lavr + * Test extended to be more thorough + * * Revision 6.15 2006/03/05 17:42:10 lavr * Adjust for revised API * diff --git a/connect/test/test_ncbi_socket.c b/connect/test/test_ncbi_socket.c index d891f511..fbb0dc28 100644 --- a/connect/test/test_ncbi_socket.c +++ b/connect/test/test_ncbi_socket.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_socket.c,v 6.23 2006/03/31 19:58:22 lavr Exp $ +/* $Id: test_ncbi_socket.c,v 6.25 2007/07/06 16:55:28 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -683,6 +683,7 @@ static void TEST__server(unsigned short port) */ static char TEST_LockUserData[] = "TEST_LockUserData"; + #if defined(__cplusplus) extern "C" { static int/*bool*/ TEST_LockHandler(void* user_data, EMT_Lock how); @@ -704,6 +705,12 @@ static int/*bool*/ TEST_LockHandler(void* user_data, EMT_Lock how) case eMT_Unlock: what_str = "eMT_Unlock"; break; + case eMT_TryLock: + what_str = "eMT_TryLock"; + break; + case eMT_TryLockRead: + what_str = "eMT_TryLockRead"; + break; } fprintf(log_fp, "TEST_LockHandler(\"%s\", %s)\n", user_data ? (char*)user_data : "<NULL>", what_str); @@ -718,8 +725,6 @@ static void TEST_LockCleanup(void* user_data) } -static int/*bool*/ TEST_gethostbyaddr(unsigned int host); - static const char* s_ntoa(unsigned int host) { static char buf[256]; @@ -730,6 +735,7 @@ static const char* s_ntoa(unsigned int host) return buf; } + static int/*bool*/ TEST_gethostbyname(const char* name) { char buf[256]; @@ -935,85 +941,3 @@ extern int main(int argc, char** argv) CORE_SetLOCK(0); return 1; } - - -/* - * --------------------------------------------------------------------------- - * $Log: test_ncbi_socket.c,v $ - * Revision 6.23 2006/03/31 19:58:22 lavr - * Added more data logging - * - * Revision 6.22 2006/01/27 17:12:15 lavr - * Replace obsolete call names with current ones - * - * Revision 6.21 2003/05/21 17:46:51 lavr - * Fix MSVC-related problems with SOCK_Shutdown() - * - * Revision 6.20 2003/05/14 03:58:43 lavr - * Match changes in respective APIs of the tests - * - * Revision 6.19 2002/12/04 16:58:13 lavr - * No changes - * - * Revision 6.18 2002/11/01 20:17:39 lavr - * Change hostname buffers to hold up to 256 chars - * - * Revision 6.17 2002/10/11 19:58:23 lavr - * Remove asserts() (replace with tests) for SOCK_gethostbyaddr({0|0xFFFFFFFF}) - * - * Revision 6.16 2002/08/12 15:10:43 lavr - * Use persistent SOCK_Write() - * - * Revision 6.15 2002/08/07 16:38:08 lavr - * EIO_ReadMethod enums changed accordingly; log moved to end - * - * Revision 6.14 2002/03/22 19:47:48 lavr - * Test_assert.h made last among the include files - * - * Revision 6.13 2002/02/11 20:36:45 lavr - * Use "ncbi_config.h" - * - * Revision 6.12 2002/01/16 21:23:15 vakatov - * Utilize header "test_assert.h" to switch on ASSERTs in the Release mode too - * - * Revision 6.11 2001/07/11 00:44:33 vakatov - * Added TEST_gethostby***() -- tests for SOCK_gethostby{addr,name}() - * - * Revision 6.10 2001/05/21 15:11:13 ivanov - * Added test for automatic read on write data from the socket - * (stall protection). - * - * Revision 6.9 2001/01/26 23:55:10 vakatov - * [NCBI_OS_MAC] Do not do server write shutdown for MAC client - * - * Revision 6.8 2000/11/15 18:51:44 vakatov - * Add tests for SOCK_Shutdown() and SOCK_Status(). - * Use SOCK_Status() instead of SOCK_Eof(). - * - * Revision 6.7 2000/06/23 19:39:22 vakatov - * Test the logging of socket I/O (incl. binary data) - * - * Revision 6.6 2000/03/24 23:12:13 vakatov - * Starting the development quasi-branch to implement CONN API. - * All development is performed in the NCBI C++ tree only, while - * the NCBI C tree still contains "frozen" (see the last revision) code. - * - * Revision 6.5 2000/02/24 23:09:42 vakatov - * Use C++ Toolkit specific wrapper "test_ncbi_socket_.c" for - * "test_ncbi_socket.c" - * - * Revision 6.4 2000/02/23 22:34:37 vakatov - * Can work both "standalone" and as a part of NCBI C++ or C toolkits - * - * Revision 6.3 1999/11/26 19:05:21 vakatov - * Initialize "log_fp" in "main()"... - * - * Revision 6.2 1999/10/19 16:16:03 vakatov - * Try the NCBI C and C++ headers only if NCBI_OS_{UNIX, MSWIN, MAC} is - * not #define'd - * - * Revision 6.1 1999/10/18 15:40:21 vakatov - * Initial revision - * - * =========================================================================== - */ |