int main( int /*argc*/, char** /*argv*/ ) { MessageTest *r = new MessageTest(); r->start(); delete( r ); return 0; }
int main( int /*argc*/, char** /*argv*/ ) { #ifdef HAVE_GNUTLS MessageTest *r = new MessageTest(); r->start(); delete( r ); #endif // HAVE_GNUTLS return 0; }
//******************************************************* //******************************************************* int main( int argc, char* argv[] ) { //测试注册用户 /* RegTest *r = new RegTest(); r->start(); delete( r ); */ //测试消息,包括聊天室,文件传输,语音消息,图片等,具体参考消息命令 MessageTest * r = new MessageTest(); r->start(); delete( r ); return 0; }
void runTest() { suite_MessageTest.testValues(); }
int main(int argc, char *argv[]) { int num = 127; vector< marked_istream_ptr > is(num, marked_istream_ptr()); vector< marked_ostream_ptr > os(num, marked_ostream_ptr()); vector< float > mbps(omp_get_max_threads(), 0); int cycles = 1000; int burstMean = 32, burstStd; int waitMicroMean = 0, waitMicroStd; int bufferSize = 8192, numBuffers = 256; if (argc >= 2) { cycles = atoi(argv[1]); } if (argc >= 3) { burstMean = atoi(argv[2]); } burstStd = burstMean * 2; if (argc >= 4) { waitMicroMean = atoi(argv[3]); } waitMicroStd = waitMicroMean * 2; if (argc >= 5) { bufferSize = atoi(argv[4]); } if (argc >= 6) { numBuffers = atoi(argv[5]); } LOG("cycles: " << cycles << ", avgMessageBytes: " << burstMean << ", avgMessageDelay: " << waitMicroMean << " us, bufferSize: " << bufferSize << ", numBuffers: " << numBuffers); int activeWriters, readers, writers; for (readers = 1 ; readers < omp_get_max_threads(); readers++) { LOG("Running with " << readers << " readers, " << omp_get_max_threads()-readers << " writers"); boost::system_time start = boost::get_system_time(); BufferFifo bfifo(bufferSize, numBuffers); int inMessages = 0, outMessages = 0; #pragma omp parallel for for(int i = 0; i < num ; i++) { is[i].reset( new marked_istream(bfifo) ); os[i].reset( new marked_ostream(bfifo) ); } // test many outputs, one input #pragma omp parallel { int threadId = omp_get_thread_num(); int numThreads = omp_get_num_threads(); long myBytes = 0; int myMessages = 0; boost::random::mt19937 rng; rng.seed( threadId * threadId * threadId * threadId ); boost::random::normal_distribution<> burst_bytes(burstMean, burstStd), wait_us(waitMicroMean, waitMicroStd); #pragma omp single { writers = numThreads-readers; activeWriters = writers; } boost::system_time myStart = boost::get_system_time(); //std::cout << "Starting thread " << threadId << std::endl; if (threadId < readers) { MessageTest msg; // scan through all os until no more writers int lastpass = 1; while(lastpass) { if (bfifo.isEOF()) lastpass--; for(int i = 0; i < num ; i++) { if ((i % readers) != threadId) continue; int messages = 0, totalBytes = 0; assert(is[i]->good()); while (is[i]->isReady()) { msg.read(*is[i]); totalBytes += msg.getBytes(); myBytes += msg.getBytes(); assert(msg.validate()); messages++; assert(is[i]->good()); } myMessages += messages; } } for(int i = 0; i < num ; i++) { if ((i % readers) != threadId) continue; is[i].reset(); } #pragma omp atomic inMessages += myMessages; //LOG("Input Thread Finished: " << myMessages << " messages"); } // reader else { // writer MessageTest msg; for(int j = 0; j < cycles ; j++) { for(int i = 0; i < num; i++) { if ((i % writers) + readers != threadId) continue; assert(os[i]->good()); int blockBytes; while ((blockBytes = burst_bytes(rng)) <= 0); msg.setMessage(i, blockBytes); assert(msg.validate()); msg.write(*os[i]); os[i]->setMark(); assert(os[i]->good()); myMessages++; myBytes += blockBytes; long waittime; while ((waittime = (waitMicroMean > 0 ? wait_us(rng) : 0)) < 0); boost::this_thread::sleep( boost::posix_time::microseconds( waittime ) ); } } // Finish up. for(int i = 0; i < num; i++) { if ((i % writers) + readers != threadId) continue; os[i]->flush(); os[i].reset(); } #pragma omp atomic outMessages += myMessages; //LOG("Output Thread Finished: " << myMessages); #pragma omp critical { // only the last one should setEOF if (--activeWriters == 0 && bfifo.getActiveWriterCount() == 0) { bfifo.setEOF(); } } } // writer boost::system_time myEnd = boost::get_system_time(); mbps[ threadId ] = (myBytes / 1000000.0) / ((myEnd - myStart).total_microseconds() / 1000000.0); } // parallel boost::system_time end = boost::get_system_time(); std::stringstream ss; for(int i = 0; i < (int) mbps.size(); i++) ss << ", " << mbps[i]; std::string str = ss.str(); LOG("Wrote " << outMessages << " Read " << inMessages << ". " << (end - start).total_milliseconds() << "ms " << str); LOG(bfifo.getState()); assert(outMessages == inMessages); } // number of readers return 0; }