1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/* $Id: test_ncbi_disp.c,v 6.38 2010/06/04 14:59:37 kazimird Exp $
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
* Author: Anton Lavrentiev
*
* File Description:
* Standard test for named service resolution facility
*
*/
#include "../ncbi_ansi_ext.h"
#include "../ncbi_lbsmd.h"
#include "../ncbi_priv.h" /* CORE logging facilities */
#include <stdlib.h>
#include <time.h>
/* This header must go last */
#include "test_assert.h"
/* One can define env.var. 'service'_CONN_HOST to reroute dispatching
* information to particular dispatching host (instead of default).
*/
int main(int argc, const char* argv[])
{
static const char kParameter[] = "test_parameter";
const char* service = argc > 1 ? argv[1] : "bounce";
SConnNetInfo* net_info;
const SSERV_Info* info;
const char* value;
int n_found = 0;
SERV_ITER iter;
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]));
}
value = LBSMD_GetHostParameter(SERV_LOCALHOST, kParameter);
CORE_LOGF(eLOG_Note, ("Querying host parameter `%s': %s%s%s", kParameter,
"`" + !value,
value ? value : "Not found",
"'" + !value));
if (value)
free((void*) value);
CORE_LOGF(eLOG_Note, ("Looking for service `%s'", service));
net_info = ConnNetInfo_Create(service);
CORE_LOG(eLOG_Trace, "Opening service mapper");
iter = SERV_OpenP(service, (fSERV_All & ~fSERV_Firewall) |
(strpbrk(service, "?*") ? fSERV_Promiscuous : 0),
SERV_LOCALHOST, 0/*port*/, 0.0/*preference*/,
net_info, 0/*skip*/, 0/*n_skip*/,
0/*external*/, 0/*arg*/, 0/*val*/);
ConnNetInfo_Destroy(net_info);
if (iter) {
HOST_INFO hinfo;
CORE_LOGF(eLOG_Trace,("%s service mapper has been successfully opened",
SERV_MapperName(iter)));
while ((info = SERV_GetNextInfoEx(iter, &hinfo)) != 0) {
char* info_str = SERV_WriteInfo(info);
CORE_LOGF(eLOG_Note, ("Server #%d `%s' = %s", ++n_found,
SERV_CurrentName(iter), info_str));
if (hinfo) {
static const char kTimeFormat[] = "%m/%d/%y %H:%M:%S";
time_t t;
char buf[80];
double array[5];
SHINFO_Params params;
const char* e = HINFO_Environment(hinfo);
const char* a = HINFO_AffinityArgument(hinfo);
const char* v = HINFO_AffinityArgvalue(hinfo);
CORE_LOG(eLOG_Note, " Host info available:");
CORE_LOGF(eLOG_Note, (" Number of CPUs: %d",
HINFO_CpuCount(hinfo)));
CORE_LOGF(eLOG_Note, (" Number of CPU units: %d @ %.0fMHz",
HINFO_CpuUnits(hinfo),
HINFO_CpuClock(hinfo)));
CORE_LOGF(eLOG_Note, (" Number of tasks: %d",
HINFO_TaskCount(hinfo)));
if (HINFO_MachineParams(hinfo, ¶ms)) {
CORE_LOGF(eLOG_Note, (" Arch: %d",
params.arch));
CORE_LOGF(eLOG_Note, (" OSType: %d",
params.ostype));
t = (time_t) params.bootup;
strftime(buf, sizeof(buf), kTimeFormat, localtime(&t));
CORE_LOGF(eLOG_Note, (" Kernel: %hu.%hu.%hu @ %s",
params.kernel.major,
params.kernel.minor,
params.kernel.patch, buf));
CORE_LOGF(eLOG_Note, (" Bits: %hu",
params.bits));
CORE_LOGF(eLOG_Note, (" Page size: %lu",
(unsigned long) params.pgsize));
t = (time_t) params.start;
strftime(buf, sizeof(buf), kTimeFormat, localtime(&t));
CORE_LOGF(eLOG_Note, (" LBSMD: %hu.%hu.%hu @ %s",
params.daemon.major,
params.daemon.minor,
params.daemon.patch, buf));
} else
CORE_LOG (eLOG_Note, " Machine params: unavailable");
if (HINFO_Memusage(hinfo, array)) {
CORE_LOGF(eLOG_Note, (" Total RAM: %.2fMB", array[0]));
CORE_LOGF(eLOG_Note, (" Cache RAM: %.2fMB", array[1]));
CORE_LOGF(eLOG_Note, (" Free RAM: %.2fMB", array[2]));
CORE_LOGF(eLOG_Note, (" Total Swap: %.2fMB", array[3]));
CORE_LOGF(eLOG_Note, (" Free Swap: %.2fMB", array[4]));
} else
CORE_LOG (eLOG_Note, " Memory usage: unavailable");
if (HINFO_LoadAverage(hinfo, array)) {
CORE_LOGF(eLOG_Note, (" Load averages: %f, %f (BLAST)",
array[0], array[1]));
} else
CORE_LOG (eLOG_Note, " Load averages: unavailable");
if (a) {
assert(*a);
CORE_LOGF(eLOG_Note, (" Affinity argument: %s", a));
}
if (a && v)
CORE_LOGF(eLOG_Note, (" Affinity value: %s%s%s",
*v ? "" : "\"", v, *v ? "" : "\""));
CORE_LOGF(eLOG_Note, (" Host environment: %s%s%s",
e? "\"": "", e? e: "NULL", e? "\"": ""));
free(hinfo);
}
free(info_str);
}
CORE_LOG(eLOG_Trace, "Resetting service mapper");
SERV_Reset(iter);
CORE_LOG(eLOG_Trace, "Service mapper has been reset");
if (n_found && !(info = SERV_GetNextInfo(iter)))
CORE_LOG(eLOG_Fatal, "Service not found after reset");
CORE_LOG(eLOG_Trace, "Closing service mapper");
SERV_Close(iter);
}
if (n_found != 0)
CORE_LOGF(eLOG_Note, ("%d server(s) found", n_found));
else
CORE_LOG(eLOG_Fatal, "Requested service not found");
#if 0
{{
SConnNetInfo* net_info;
net_info = ConnNetInfo_Create(service);
iter = SERV_Open(service, fSERV_Http, SERV_LOCALHOST, net_info);
ConnNetInfo_Destroy(net_info);
}}
if (iter != 0) {
while ((info = SERV_GetNextInfo(iter)) != 0) {
char* info_str = SERV_WriteInfo(info);
CORE_LOGF(eLOG_Note, ("Service `%s' = %s", service, info_str));
free(info_str);
n_found++;
}
SERV_Close(iter);
}
#endif
CORE_LOG(eLOG_Note, "TEST completed successfully");
CORE_SetLOG(0);
return 0;
}
|