int main(int _argc, const char *_argv[]) { ::testing::InitGoogleTest(&_argc, const_cast<char **>(_argv)); etk::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; #ifdef DEBUG if (data == "--visual-test") { TEST_PRINT("visual-test=enable"); g_visualDebug = true; } else #endif if ( data == "-h" || data == "--help") { TEST_PRINT("esvg-test - help : "); TEST_PRINT(" " << _argv[0] << " [options]"); #ifdef DEBUG TEST_PRINT(" --visual-test Enable decoration in logged file in debug mode only"); #else TEST_PRINT(" No optiions ..."); #endif return -1; } } //etk::initDefaultFolder("esvg-test"); return RUN_ALL_TESTS(); }
int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); enet::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(" " << _argv[0] << " [options]"); TEST_PRINT(" No options ..."); return -1; } } TEST_INFO("=================================="); TEST_INFO("== Test TCP server =="); TEST_INFO("=================================="); //Wait on TCP connection: enet::TcpServer interface; // Configure server interface: interface.setHostNane("127.0.0.1"); interface.setPort(12345); // Start listening ... interface.link(); // Wait a new connection .. enet::Tcp tcpConnection = std::move(interface.waitNext()); // Free Connected port interface.unlink(); int32_t iii = 0; while (tcpConnection.getConnectionStatus() == enet::Tcp::status::link) { int32_t len = tcpConnection.write("plop" + etk::to_string(iii)); TEST_INFO("write len=" << len); char data[1024]; len = tcpConnection.read(data, 1024); if (len > 0) { TEST_INFO("read len=" << len << " data='" << data << "'"); } iii++; } if (iii>=1000000) { TEST_INFO("auto disconnected"); } else if (tcpConnection.getConnectionStatus() != enet::Tcp::status::link) { TEST_INFO("server disconnected"); } else { TEST_INFO("ERROR disconnected"); } if (tcpConnection.unlink() == false) { TEST_ERROR("can not unlink to the socket..."); return -1; } return 0; }
int main(int _argc, const char *_argv[]) { ::testing::InitGoogleTest(&_argc, const_cast<char **>(_argv)); etk::init(_argc, _argv); for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; if ( data == "-h" || data == "--help") { TEST_PRINT("eproperty-test - help : "); TEST_PRINT(" " << _argv[0] << " [options]"); TEST_PRINT(" No optiions ..."); return -1; } } return RUN_ALL_TESTS(); }
void FMTest1P() { TEST_PRINT("Testing priority change"); if (NKern::NumberOfCpus()==1) return; NFastSemaphore exitSem(0); SFMTest1Info* pI = new SFMTest1Info; TEST_OOM(pI); memclr(pI, sizeof(SFMTest1Info)); TEST_PRINT1("Info@0x%08x", pI); pI->iBlockSize = 256; pI->iBlock = (TUint32*)malloc(pI->iBlockSize*sizeof(TUint32)); TEST_OOM(pI->iBlock); pI->iPriorityThreshold = 9; pI->iBlock[0] = 0; setup_block((TUint32*)pI->iBlock, pI->iBlockSize); pI->iStop = FALSE; TInt cpu; TInt threadCount = 0; TInt pri = 9; char name[16] = "FMTest1P.0"; for_each_cpu(cpu) { name[9] = (char)(threadCount + '0'); if (cpu==1) pI->iThreads[threadCount] = CreateThreadSignalOnExit("FMTest1PInterferer", &FMTest1PInterfererThread, 12, pI, 0, KSmallTimeslice, &exitSem, 1); else pI->iThreads[threadCount] = CreateThreadSignalOnExit(name, &FMTest1Thread, pri, pI, 0, KSmallTimeslice, &exitSem, cpu); pri = 10; threadCount++; } TUint32 b0 = 0xffffffffu; FOREVER { NKern::Sleep(1000); TUint32 b = pI->iBlock[0]; TEST_PRINT1("%d", b); if (b > 1048576) { pI->iStop = TRUE; break; } if (b == b0) { __crash(); } b0 = b; } while (threadCount--) NKern::FSWait(&exitSem); TEST_PRINT1("Total iterations %d", pI->iBlock[0]); free((TAny*)pI->iBlock); free(pI); }
void performanceGate() { std::vector<double> input; input.resize(8192, 0); std::vector<double> output; output.resize(8192, 0); double sampleRate = 48000.0; { double phase = 0; double baseCycle = 2.0*M_PI/sampleRate * 1280.0; for (int32_t iii=0; iii<input.size(); iii++) { input[iii] = cos(phase) * 5.0; phase += baseCycle; if (phase >= 2*M_PI) { phase -= 2*M_PI; } } } TEST_PRINT("Start Gate performance ..."); Performance perfo; audio::algo::chunkware::Gate algo; algo.setSampleRate(48000); algo.setThreshold(0); algo.setAttack(0.1); algo.setRelease(2); algo.init(); for (int32_t iii=0; iii<4096; ++iii) { perfo.tic(); algo.process(&output[0], &input[0], input.size(), 1, audio::format_double); perfo.toc(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } TEST_PRINT("Performance Gate (double): "); TEST_PRINT(" blockSize=" << input.size() << " sample"); TEST_PRINT(" min < avg < max =" << perfo.getMinProcessing().count() << "ns < " << perfo.getTotalTimeProcessing().count()/perfo.getTotalIteration() << "ns < " << perfo.getMaxProcessing().count() << "ns "); TEST_PRINT(" min < avg < max = " << (float((perfo.getMinProcessing().count()*sampleRate)/double(input.size()))/1000000000.0)*100.0 << "% < " << (float(((perfo.getTotalTimeProcessing().count()/perfo.getTotalIteration())*sampleRate)/double(input.size()))/1000000000.0)*100.0 << "% < " << (float((perfo.getMaxProcessing().count()*sampleRate)/double(input.size()))/1000000000.0)*100.0 << "%"); }
my_psend(char type, char * buf, int len) { int ret; char lbuf[600]; strncpy(lbuf,buf,len); lbuf[len] = type; TEST_PRINT("%s sends: %s\n",lbuf,""); ret=myWriteToNamedPipe(lbuf,len+1); my_peek(); return(ret); }
void my_peek() { // handle messages with may come asynchronously int ret,t,llen,l1,l2; char lbuf[600]; if(1 || !PeekNamedPipe(fe2lisp_read,lbuf,600,&llen,&l1,&l2) || llen<1) { TEST_PRINT("%s peek empty\n","",""); return; } llen -- ; t = lbuf[llen]; lbuf[llen] = '\0'; TEST_PRINT("%s peek sees message %s\n",(char*)&t, ""); if (!(t == 'x' || t == 'c' || t == 'b' || (t == 'w' && ! slave_mode))) return; TEST_PRINT("%s peek processes message %s\n",(char*)&t, ""); llen = myReadFromNamedPipe(lbuf, 600); if(t == 'x') // exit exit(0); else if(t == 'c') // remote procedure call { ret=my_plocalcall(lbuf,llen); // call local procedure my_psend('a',lbuf,ret); // result return } else if(t == 'b') bruch_bruch--; else if(t == 'w') { local_puts(lbuf); } }
my_preceive(char type, char * buf, int len) { int ret,t,llen; char lbuf[600]; TEST_PRINT("%s waits for %s\n",(char*)&type,""); next: llen = myReadFromNamedPipe(lbuf, 600); llen -- ; t = lbuf[llen]; lbuf[llen] = '\0'; if (t == type) { strncpy(buf,lbuf,llen); TEST_PRINT("%s received %s\n",&type,""); return(llen); }; TEST_PRINT("%s received %s\n",(char*)&t,""); if(t == 'x') // exit exit(0); else if(t == 'w') { local_puts(lbuf); } else if(t == 'c') // remote procedure call { TEST_PRINT("%s received RPC %s\n",lbuf,""); ret=my_plocalcall(lbuf,llen); // call local procedure TEST_PRINT("%s returns from RPC\n","",""); my_psend('a',lbuf,ret); // result return } else { sprintf(lbuf," error: unexpected message >%c< instead of >%c<\n",t,type); pmelden("%s %s\n",lbuf,""); } goto next; }
void TestFastSemaphore() { TEST_PRINT("Testing Fast Semaphores..."); TInt cpu; for_each_cpu(cpu) { DO_FS_TEST1(0,cpu); DO_FS_TEST1(1,cpu); DO_FS_TEST1(2,cpu); DO_FS_TEST1(13,cpu); } DoFsTest2(); }
void FMTest0() { TEST_PRINT("Testing non-contention case"); NFastMutex m; TEST_RESULT(!m.HeldByCurrentThread(), "Mutex held by current thread"); TEST_RESULT(!NKern::HeldFastMutex(), "Current thread holds a fast mutex"); NKern::FMWait(&m); TEST_RESULT(m.HeldByCurrentThread(), "Mutex not held by current thread"); TEST_RESULT(NKern::HeldFastMutex()==&m, "HeldFastMutex() incorrect"); NKern::FMSignal(&m); TEST_RESULT(!m.HeldByCurrentThread(), "Mutex held by current thread"); TEST_RESULT(!NKern::HeldFastMutex(), "Current thread holds a fast mutex"); }
my_master_dispatch(char * buf, int len) { // reply to slave read request. // write data to slave and wait for next read int llen,ret; char t; char lbuf[600]; if (len > -1) my_psend('d',buf,len); next: llen = myReadFromNamedPipe(lbuf, 600); llen -- ; t = lbuf[llen]; lbuf[llen] ='\0'; TEST_PRINT("%s dispatch - received: %s\n",&t,""); if (t == 'x') { exit(0); } else if(t == 'b') bruch_bruch--; else if(t == 'w') { local_puts(lbuf); my_psend('k',buf,0); } else if(t == 'c') // slave calls master { ret=my_plocalcall(lbuf,llen); // call local procedure my_psend('a',lbuf,ret); // result return goto next; } else if(t == 'r') // read data return(0); else { sprintf(lbuf,"master error: unexpected message %d: >%c<\n",llen,t); my_puts(lbuf); } goto next; }
void FMTest1() { TEST_PRINT("Testing mutual exclusion"); NFastSemaphore exitSem(0); SFMTest1Info* pI = new SFMTest1Info; TEST_OOM(pI); memclr(pI, sizeof(SFMTest1Info)); pI->iBlockSize = 256; pI->iBlock = (TUint32*)malloc(pI->iBlockSize*sizeof(TUint32)); TEST_OOM(pI->iBlock); pI->iPriorityThreshold = 10; pI->iBlock[0] = 0; setup_block((TUint32*)pI->iBlock, pI->iBlockSize); pI->iStop = FALSE; TInt cpu; TInt threads = 0; for_each_cpu(cpu) { CreateThreadSignalOnExit("FMTest1H", &FMTest1Thread, 11, pI, 0, KSmallTimeslice, &exitSem, cpu); CreateThreadSignalOnExit("FMTest1L0", &FMTest1Thread, 10, pI, 0, KSmallTimeslice, &exitSem, cpu); CreateThreadSignalOnExit("FMTest1L1", &FMTest1Thread, 10, pI, 0, KSmallTimeslice, &exitSem, cpu); threads += 3; } FOREVER { NKern::Sleep(1000); TEST_PRINT1("%d", pI->iBlock[0]); if (pI->iBlock[0] > 65536) { pI->iStop = TRUE; break; } } while (threads--) NKern::FSWait(&exitSem); TEST_PRINT1("Total iterations %d", pI->iBlock[0]); free((TAny*)pI->iBlock); free(pI); }
/*------------------------------------------------------------------------- * Function : Test_CmdStart * Definition of test register command * Input : * Output : * Return : TRUE if error, FALSE if success * ----------------------------------------------------------------------*/ BOOL Test_CmdStart(void) { BOOL RetErr = FALSE; RetErr |= STTST_RegisterCommand( "DENC_NullPt", DENC_NullPointersTest, \ "Call API functions with null pointers (bad param. test)"); #ifdef ST_OS20 RetErr |= STTST_RegisterCommand( "DENC_StackUse" , metrics_Stack_Test, ""); #endif /* ST_OS20 */ if (RetErr) { sprintf( Test_Msg, "DENC_TestCommand() \t: failed !\n"); } else { sprintf( Test_Msg, "DENC_TestCommand() \t: ok\n"); } TEST_PRINT(Test_Msg); return(!RetErr); }
int socket_api_test_echo_client_connected(socket_stack_t stack, socket_address_family_t af, socket_proto_family_t pf, bool connect, const char* server, uint16_t port) { struct socket s; socket_error_t err; const struct socket_api *api = socket_get_api(stack); client_socket = &s; mbed::Timeout to; // Create the socket TEST_CLEAR(); TEST_PRINT("\r\n%s af: %d, pf: %d, connect: %d, server: %s:%d\r\n",__func__, (int) af, (int) pf, (int) connect, server, (int) port); if (!TEST_NEQ(api, NULL)) { // Test cannot continue without API. TEST_RETURN(); } err = api->init(); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } struct socket_addr addr; // Resolve the host address err = blocking_resolve(stack, af, server, &addr); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } // Tell the host launch a server TEST_PRINT(">>> ES,%d\r\n", pf); // Allocate a data buffer for tx/rx void *data = malloc(SOCKET_SENDBUF_MAXSIZE); // Zero the socket implementation s.impl = NULL; // Create a socket err = api->create(&s, af, pf, &client_cb); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_EXIT(); } // Connect to a host if (connect) { client_event_done = false; timedout = 0; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); err = api->connect(&s, &addr, port); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_EXIT(); } // Override event for dgrams. if (pf == SOCKET_DGRAM) { client_event.event = SOCKET_EVENT_CONNECT; client_event_done = true; } // Wait for onConnect while (!timedout && !client_event_done) { __WFI(); } // Make sure that the correct event occurred if (!TEST_EQ(client_event.event, SOCKET_EVENT_CONNECT)) { TEST_EXIT(); } to.detach(); } // For several iterations for (size_t i = 0; i < SOCKET_SENDBUF_ITERATIONS; i++) { // Fill some data into a buffer const size_t nWords = SOCKET_SENDBUF_BLOCKSIZE * (1 << i) / sizeof(uint16_t); for (size_t j = 0; j < nWords; j++) { *((uint16_t*) data + j) = j; } // Send the data client_tx_done = false; client_rx_done = false; timedout = 0; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); if(connect) { err = api->send(&s, data, nWords * sizeof(uint16_t)); } else { err = api->send_to(&s, data, nWords * sizeof(uint16_t), &addr, port); } if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_PRINT("Failed to send %u bytes\r\n", nWords * sizeof(uint16_t)); } else { size_t tx_bytes = 0; do { // Wait for the onSent callback while (!timedout && !client_tx_done) { __WFI(); } if (!TEST_EQ(timedout,0)) { break; } if (!TEST_NEQ(client_tx_info.sentbytes, 0)) { break; } tx_bytes += client_tx_info.sentbytes; if (tx_bytes < nWords * sizeof(uint16_t)) { client_tx_done = false; continue; } to.detach(); TEST_EQ(tx_bytes, nWords * sizeof(uint16_t)); break; } while (1); } timedout = 0; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); memset(data, 0, nWords * sizeof(uint16_t)); // Wait for the onReadable callback size_t rx_bytes = 0; do { while (!timedout && !client_rx_done) { __WFI(); } if (!TEST_EQ(timedout,0)) { break; } size_t len = SOCKET_SENDBUF_MAXSIZE - rx_bytes; // Receive data if (connect) { err = api->recv(&s, (void*) ((uintptr_t) data + rx_bytes), &len); } else { struct socket_addr rxaddr; uint16_t rxport = 0; // addr may contain unused data in the storage element. memcpy(&rxaddr, &addr, sizeof(rxaddr)); // Receive from... err = api->recv_from(&s, (void*) ((uintptr_t) data + rx_bytes), &len, &rxaddr, &rxport); int rc = memcmp(&rxaddr.ipv6be, &addr.ipv6be, sizeof(rxaddr.ipv6be)); if(!TEST_EQ(rc, 0)) { TEST_PRINT("Spurious receive packet\r\n"); } TEST_EQ(rxport, port); } if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { break; } rx_bytes += len; if (rx_bytes < nWords * sizeof(uint16_t)) { client_rx_done = false; continue; } to.detach(); break; } while (1); if(!TEST_EQ(rx_bytes, nWords * sizeof(uint16_t))) { TEST_PRINT("Expected %u, got %u\r\n", nWords * sizeof(uint16_t), rx_bytes); } // Validate that the two buffers are the same bool match = true; size_t j; for (j = 0; match && j < nWords; j++) { match = (*((uint16_t*) data + j) == j); } if(!TEST_EQ(match, true)) { TEST_PRINT("Mismatch in %u byte packet at offset %u\r\n", nWords * sizeof(uint16_t), j * sizeof(uint16_t)); } } if (connect) { // close the socket client_event_done = false; timedout = 0; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); err = api->close(&s); TEST_EQ(err, SOCKET_ERROR_NONE); // Override event for dgrams. if (pf == SOCKET_DGRAM) { client_event.event = SOCKET_EVENT_DISCONNECT; client_event_done = true; } // wait for onClose while (!timedout && !client_event_done) { __WFI(); } if (TEST_EQ(timedout,0)) { to.detach(); } // Make sure that the correct event occurred TEST_EQ(client_event.event, SOCKET_EVENT_DISCONNECT); } // destroy the socket err = api->destroy(&s); TEST_EQ(err, SOCKET_ERROR_NONE); test_exit: TEST_PRINT(">>> KILL,ES\r\n"); free(data); TEST_RETURN(); }
int socket_api_test_connect_close(socket_stack_t stack, socket_address_family_t af, const char* server, uint16_t port) { struct socket s; int pfi; socket_error_t err; const struct socket_api * api = socket_get_api(stack); struct socket_addr addr; ConnectCloseSock = &s; TEST_CLEAR(); if (!TEST_NEQ(api, NULL)) { // Test cannot continue without API. TEST_RETURN(); } err = api->init(); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } // Create a socket for each protocol family for (pfi = SOCKET_PROTO_UNINIT+1; pfi < SOCKET_PROTO_MAX; pfi++) { socket_proto_family_t pf = static_cast<socket_proto_family_t>(pfi); // Zero the implementation s.impl = NULL; err = api->create(&s, af, pf, &connect_close_handler); // catch expected failing cases TEST_EQ(err, SOCKET_ERROR_NONE); if (!TEST_NEQ(s.impl, NULL)) { continue; } // Tell the host launch a server TEST_PRINT(">>> ES,%d\r\n", pf); // connect to a remote host err = api->str2addr(&s, &addr, server); TEST_EQ(err, SOCKET_ERROR_NONE); timedout = 0; connected = 0; mbed::Timeout to; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); err = api->connect(&s, &addr, port); TEST_EQ(err, SOCKET_ERROR_NONE); if (err!=SOCKET_ERROR_NONE) { printf("err = %d\r\n", err); } switch (pf) { case SOCKET_DGRAM: while ((!api->is_connected(&s)) && (!timedout)) { __WFI(); } break; case SOCKET_STREAM: while (!connected && !timedout) { __WFI(); } break; default: break; } to.detach(); TEST_EQ(timedout, 0); // close the connection timedout = 0; closed = 0; to.attach(onTimeout, SOCKET_TEST_TIMEOUT); err = api->close(&s); TEST_EQ(err, SOCKET_ERROR_NONE); if (err!=SOCKET_ERROR_NONE) { printf("err = %d\r\n", err); } switch (pf) { case SOCKET_DGRAM: while ((api->is_connected(&s)) && (!timedout)) { __WFI(); } break; case SOCKET_STREAM: while (!closed && !timedout) { __WFI(); } break; default: break; } to.detach(); TEST_EQ(timedout, 0); // Tell the host to kill the server TEST_PRINT(">>> KILL ES\r\n"); // Destroy the socket err = api->destroy(&s); TEST_EQ(err, SOCKET_ERROR_NONE); } TEST_RETURN(); }
int main(int argc, char **argv) { int seconds = atoi(argv[1]); if (seconds == 0) { is_profiling = 0; } size_t num_cols = argc - 2; size_t *sizes = malloc(sizeof(size_t) * num_cols); for (int i = 2; i < argc; i++) { sizes[i-2] = atoi(argv[i]); } parity avx = {"RAID-Z1 AVX", vdev_raidz_generate_parity_p_avx, vdev_raidz_reconstruct_p_avx}; parity sse4 = {"RAID-Z1 SSE4", vdev_raidz_generate_parity_p_sse4, vdev_raidz_reconstruct_p_sse4}; parity standard = {"RAID-Z1 Standard", vdev_raidz_generate_parity_p, vdev_raidz_reconstruct_p}; parity standard_pq = {"RAID-Z2 Standard", vdev_raidz_generate_parity_pq, vdev_raidz_reconstruct_pq}; parity avx_pq = {"RAID-Z2 AVX", vdev_raidz_generate_parity_pq_avx, vdev_raidz_reconstruct_pq_avx}; parity sse4_pq = {"RAID-Z2 SSE4", vdev_raidz_generate_parity_pq_sse4, vdev_raidz_reconstruct_pq_sse4}; parity standard_q = {"RAID-Z2 Standard (Q)", vdev_raidz_generate_parity_pq, vdev_raidz_reconstruct_q}; parity avx_q = {"RAID-Z2 AVX (Q)", vdev_raidz_generate_parity_pq_avx, vdev_raidz_reconstruct_q_avx}; parity sse4_q = {"RAID-Z2 SSE4 (Q)", vdev_raidz_generate_parity_pq_sse4, vdev_raidz_reconstruct_q_sse4}; parity parities_p[] = {standard, avx, sse4}; parity parities_pq[] = {standard_pq, avx_pq, sse4_pq}; parity parities_q[] = {standard_q, avx_q, sse4_q}; time_t start = time(NULL); do { raidz_map_t *map_p = make_map(num_cols, sizes, VDEV_RAIDZ_P); raidz_map_t *map_pq = make_map(num_cols, sizes, VDEV_RAIDZ_Q); raidz_map_t *map_pqr = make_map(num_cols, sizes, VDEV_RAIDZ_R); for(int i = 0; i < sizeof(parities_p) / sizeof(parity); i++) { parity p = parities_p[i]; TEST_PRINT("Testing %s\n", p.name); test_parity_p(p, map_p); TEST_PRINT("%s works!\n", p.name); } TEST_PRINT("\n"); for(int i = 0; i < sizeof(parities_pq) / sizeof(parity); i++) { parity p = parities_pq[i]; TEST_PRINT("Testing %s\n", p.name); test_parity_pq(p, map_pq); TEST_PRINT("%s works!\n", p.name); } TEST_PRINT("\n"); for(int i = 0; i < sizeof(parities_q) / sizeof(parity); i++) { parity p = parities_q[i]; TEST_PRINT("Testing %s\n", p.name); test_reconstruct_q(p, map_pq); TEST_PRINT("%s works!\n", p.name); } TEST_PRINT("\n"); TEST_PRINT("Testing RAIDZ3 AVX Generation\n"); test_parity_pqr(vdev_raidz_generate_parity_pqr_avx, map_pqr); TEST_PRINT("RAIDZ3 AVX Generation Works!\n"); TEST_PRINT("Testing RAIDZ3 SSE4 Generation\n"); test_parity_pqr(vdev_raidz_generate_parity_pqr_sse4, map_pqr); TEST_PRINT("RAIDZ3 SSE4 Generation Works!\n"); raidz_map_free(map_p); raidz_map_free(map_pq); raidz_map_free(map_pqr); } while (difftime(time(NULL), start) < seconds); free(sizes); return 0; }
/* * Function - st_alsa_print_test_params * Functionality - This function prints the test params * Input Params - test_opt * Return Value - None * Note - None */ void st_alsa_print_test_params(tc_dev_params * test_opt) { char *format = NULL; char *access = NULL; switch (test_opt->format) { case PCM_FORMAT_S8: format = "S8"; break; case PCM_FORMAT_S16_LE: format = "S16_LE"; break; case PCM_FORMAT_S16_BE: format = "S16_BE"; break; case PCM_FORMAT_U16_LE: format = "U16_LE"; break; case PCM_FORMAT_U16_BE: format = "U16_BE"; break; case PCM_FORMAT_S24_LE: format = "S24_LE"; break; case PCM_FORMAT_S24_BE: format = "S24_BE"; break; case PCM_FORMAT_U24_LE: format = "U24_LE"; break; case PCM_FORMAT_U24_BE: format = "U24_BE"; break; case PCM_FORMAT_S32_BE: format = "S32_BE"; break; case PCM_FORMAT_S32_LE: format = "S32_LE"; break; case PCM_FORMAT_U32_BE: format = "U32_BE"; break; case PCM_FORMAT_U32_LE: format = "U32_LE"; break; } switch (test_opt->access_type) { case PCM_ACCESS_MMAP_INTERLEAVED: access = "MMAP_INTERLEAVED"; break; case PCM_ACCESS_MMAP_NONINTERLEAVED: access = "MMAP_NONINTERLEAVED"; break; case PCM_ACCESS_MMAP_COMPLEX: access = "MMAP_COMPLEX"; break; case PCM_ACCESS_RW_INTERLEAVED: access = "RW_INTERLEAVED"; break; case PCM_ACCESS_RW_NONINTERLEAVED: access = "RW_NONINTERLEAVED"; break; } TEST_PRINT_TST_START(testcaseid); TEST_PRINT("******** ALSA Testcase parameters ******** "); if (play_or_record == OPTION_RECORD) { TEST_PRINT_TRC ("CAPTURE Test is going to start with following values "); } else if (play_or_record == OPTION_PLAYBACK) { TEST_PRINT_TRC ("PLAYBACK Test is going to start with following values "); } else { TEST_PRINT_TRC ("LOOPBACK Test is going to start with following values "); } TEST_PRINT_TRC("Card name |%s", test_opt->card_name); TEST_PRINT_TRC("Device Number |%d", test_opt->device); TEST_PRINT_TRC("Access Type |%s", access); TEST_PRINT_TRC("Period Size |%d", test_opt->period_size); TEST_PRINT_TRC("Sampling Rate |%d", test_opt->sampling_rate); TEST_PRINT_TRC("Channels |%d", test_opt->channel); TEST_PRINT_TRC("format |%s", format); if (test_opt->capture_to_file == TRUE || test_opt->play_from_file == TRUE) { TEST_PRINT_TRC("File name |%s", test_opt->file_name); } TEST_PRINT_TRC("Total Size |%d", test_opt->total_size); TEST_PRINT("************* End of Test params ***************** "); }
int socket_api_test_echo_server_stream(socket_stack_t stack, socket_address_family_t af, const char* local_addr, uint16_t port) { struct socket s; struct socket cs; struct socket_addr addr; socket_error_t err; const struct socket_api *api = socket_get_api(stack); server_socket = &s; client_socket = &cs; mbed::Timeout to; mbed::Ticker ticker; // Create the socket TEST_CLEAR(); if (!TEST_NEQ(api, NULL)) { // Test cannot continue without API. TEST_RETURN(); } err = api->init(); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } // Zero the socket implementation s.impl = NULL; // Create a socket err = api->create(&s, af, SOCKET_STREAM, &server_cb); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } err = api->str2addr(&s, &addr, local_addr); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } // start the TCP timer uint32_t interval_ms = api->periodic_interval(&s); TEST_NEQ(interval_ms, 0); uint32_t interval_us = interval_ms * 1000; socket_api_handler_t periodic_task = api->periodic_task(&s); if (TEST_NEQ(periodic_task, NULL)) { ticker.attach_us(periodic_task, interval_us); } err = api->bind(&s, &addr, port); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_RETURN(); } void *data = malloc(SOCKET_SENDBUF_MAXSIZE); if(!TEST_NEQ(data, NULL)) { TEST_RETURN(); } // Tell the host test to try and connect TEST_PRINT(">>> EC,%s,%d\r\n", local_addr, port); bool quit = false; // For several iterations while (!quit) { timedout = false; server_event_done = false; incoming = false; to.attach(onTimeout, SOCKET_TEST_SERVER_TIMEOUT); // Listen for incoming connections err = api->start_listen(&s, 0); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_EXIT(); } // Reset the state of client_rx_done client_rx_done = false; // Wait for a connect event while (!timedout && !incoming) { __WFI(); } if (TEST_EQ(timedout,0)) { to.detach(); } else { TEST_EXIT(); } if(!TEST_EQ(server_event.event, SOCKET_EVENT_ACCEPT)) { TEST_PRINT("Event: %d\r\n",(int)client_event.event); continue; } // Stop listening server_event_done = false; // err = api->stop_listen(&s); // TEST_EQ(err, SOCKET_ERROR_NONE); // Accept an incoming connection cs.impl = server_event.i.a.newimpl; cs.family = s.family; cs.stack = s.stack; err = api->accept(&cs, client_cb); if(!TEST_EQ(err, SOCKET_ERROR_NONE)) { continue; } to.attach(onTimeout, SOCKET_TEST_SERVER_TIMEOUT); // Client should test for successive connections being rejected // Until Client disconnects while (client_event.event != SOCKET_EVENT_ERROR && client_event.event != SOCKET_EVENT_DISCONNECT) { // Wait for a read event while (!client_event_done && !client_rx_done && !timedout) { __WFI(); } if (!TEST_EQ(client_event_done, false)) { client_event_done = false; continue; } // Reset the state of client_rx_done client_rx_done = false; // Receive some data size_t len = SOCKET_SENDBUF_MAXSIZE; err = api->recv(&cs, data, &len); if (!TEST_NEQ(err, SOCKET_ERROR_WOULD_BLOCK)) { TEST_PRINT("Rx Would Block\r\n"); continue; } if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { TEST_PRINT("err: (%d) %s\r\n", err, socket_strerror(err)); break; } // Check if the server should halt if (strncmp((const char *)data, "quit", 4) == 0) { quit = true; break; } // Send some data err = api->send(&cs, data, len); if (!TEST_EQ(err, SOCKET_ERROR_NONE)) { break; } } to.detach(); TEST_NEQ(timedout, true); // Close client socket err = api->close(&cs); TEST_EQ(err, SOCKET_ERROR_NONE); } err = api->stop_listen(&s); TEST_EQ(err, SOCKET_ERROR_NONE); test_exit: ticker.detach(); TEST_PRINT(">>> KILL,EC\r\n"); free(data); // Destroy server socket TEST_RETURN(); }
my_rpc(char * buf, int len) { TEST_PRINT("%s RPC call\n %s\n",buf,""); my_psend('c',buf,len); return(my_preceive('a',buf,len)); }
int main(void) { char buf[64]; int8_t i8; uint8_t u8; int16_t i16; uint16_t u16; #if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__) int32_t i32; uint32_t u32; #endif intmax_t imax; uintmax_t umax; TEST_PRINT(buf, PRId8, INT8_C(-128), "-128"); TEST_PRINT(buf, PRIi8, INT8_C(-128), "-128"); TEST_PRINT(buf, PRIo8, UINT8_C(255), "377"); TEST_PRINT(buf, PRIu8, UINT8_C(255), "255"); TEST_PRINT(buf, PRIx8, UINT8_C(255), "ff"); TEST_PRINT(buf, PRIX8, UINT8_C(255), "FF"); TEST_PRINT(buf, PRId16, INT16_C(-32767), "-32767"); TEST_PRINT(buf, PRIi16, INT16_C(-32767), "-32767"); TEST_PRINT(buf, PRIo16, UINT16_C(65535), "177777"); TEST_PRINT(buf, PRIu16, UINT16_C(65535), "65535"); TEST_PRINT(buf, PRIx16, UINT16_C(65535), "ffff"); TEST_PRINT(buf, PRIX16, UINT16_C(65535), "FFFF"); TEST_PRINT(buf, PRIdMAX, INTMAX_C(-32767), "-32767"); TEST_PRINT(buf, PRIuMAX, UINTMAX_C(65535), "65535"); #if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__) TEST_PRINT(buf, PRId32, INT32_C(-2147483647), "-2147483647"); TEST_PRINT(buf, PRIi32, INT32_C(-2147483647), "-2147483647"); TEST_PRINT(buf, PRIo32, UINT32_C(4294967295), "37777777777"); TEST_PRINT(buf, PRIu32, UINT32_C(4294967295), "4294967295"); TEST_PRINT(buf, PRIx32, UINT32_C(4294967295), "ffffffff"); TEST_PRINT(buf, PRIX32, UINT32_C(4294967295), "FFFFFFFF"); TEST_PRINT(buf, PRIdMAX, INTMAX_C(-2147483647), "-2147483647"); TEST_PRINT(buf, PRIuMAX, UINTMAX_C(4294967295), "4294967295"); #endif TEST_SCAN("-128", SCNd8, i8, INT8_C(-128)); TEST_SCAN("-128", SCNi8, i8, INT8_C(-128)); TEST_SCAN("377", SCNo8, u8, UINT8_C(255)); TEST_SCAN("255", SCNu8, u8, UINT8_C(255)); TEST_SCAN("Ff", SCNx8, u8, UINT8_C(255)); TEST_SCAN("-32767", SCNd16, i16, INT16_C(-32767)); TEST_SCAN("-32767", SCNi16, i16, INT16_C(-32767)); TEST_SCAN("177777", SCNo16, u16, UINT16_C(65535)); TEST_SCAN("65535", SCNu16, u16, UINT16_C(65535)); TEST_SCAN("FffF", SCNx16, u16, UINT16_C(65535)); TEST_SCAN("-32767", SCNdMAX, imax, INTMAX_C(-32767)); TEST_SCAN("65535", SCNuMAX, umax, UINTMAX_C(65535)); #if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__) TEST_SCAN("-2147483647", SCNd32, i32, INT32_C(-2147483647)); TEST_SCAN("-2147483647", SCNi32, i32, INT32_C(-2147483647)); TEST_SCAN("37777777777", SCNo32, u32, UINT32_C(4294967295)); TEST_SCAN("4294967295", SCNu32, u32, UINT32_C(4294967295)); TEST_SCAN("ffFFffFF", SCNx32, u32, UINT32_C(4294967295)); TEST_SCAN("-2147483647", SCNdMAX, imax, INTMAX_C(-2147483647)); TEST_SCAN("4294967295", SCNuMAX, umax, UINTMAX_C(4294967295)); #endif return 0; }
int main(int _argc, const char** _argv) { // the only one init for etk: etk::init(_argc, _argv); std::string inputName = ""; bool performance = false; bool perf = false; int64_t sampleRate = 48000; for (int32_t iii=0; iii<_argc ; ++iii) { std::string data = _argv[iii]; if (etk::start_with(data,"--in=")) { inputName = &data[5]; } else if (data == "--performance") { performance = true; } else if (data == "--perf") { perf = true; } else if (etk::start_with(data,"--sample-rate=")) { data = &data[14]; sampleRate = etk::string_to_int32_t(data); } else if ( data == "-h" || data == "--help") { TEST_PRINT("Help : "); TEST_PRINT(" ./xxx --fb=file.raw --mic=file.raw"); TEST_PRINT(" --in=YYY.raw inout file"); TEST_PRINT(" --performance Generate signal to force algo to maximum process time"); TEST_PRINT(" --perf Enable performence test (little slower but real performence test)"); TEST_PRINT(" --sample-rate=XXXX Signal sample rate (default 48000)"); exit(0); } } // PERFORMANCE test only .... if (performance == true) { performanceCompressor(); performanceLimiter(); performanceGate(); return 0; } if (inputName == "") { TEST_ERROR("Can not Process missing parameters..."); exit(-1); } TEST_INFO("Read input:"); std::vector<double> inputData = convert(etk::FSNodeReadAllDataType<int16_t>(inputName)); TEST_INFO(" " << inputData.size() << " samples"); // resize output : std::vector<double> output; output.resize(inputData.size(), 0); // process in chunk of 256 samples int32_t blockSize = 256; Performance perfo; /* audio::algo::chunkware::Compressor algo; algo.setThreshold(-10); algo.setRatio(-5); int32_t lastPourcent = -1; for (int32_t iii=0; iii<output.size()/blockSize; ++iii) { if (lastPourcent != 100*iii / (output.size()/blockSize)) { lastPourcent = 100*iii / (output.size()/blockSize); TEST_INFO("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize << " " << lastPourcent << "/100"); } else { TEST_VERBOSE("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize); } perfo.tic(); algo.process(audio::format_double, &output[iii*blockSize], &inputData[iii*blockSize], blockSize, 1); if (perf == true) { perfo.toc(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } */ audio::algo::chunkware::Limiter algo; algo.setSampleRate(48000); algo.setThreshold(0); algo.setAttack(0.1); algo.setRelease(2); algo.init(1); int32_t lastPourcent = -1; for (int32_t iii=0; iii<output.size()/blockSize; ++iii) { if (lastPourcent != 100*iii / (output.size()/blockSize)) { lastPourcent = 100*iii / (output.size()/blockSize); TEST_INFO("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize << " " << lastPourcent << "/100"); } else { TEST_VERBOSE("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize); } perfo.tic(); algo.process(&output[iii*blockSize], &inputData[iii*blockSize], blockSize, 1, audio::format_double); if (perf == true) { perfo.toc(); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } if (perf == true) { TEST_INFO("Performance Result: "); TEST_INFO(" blockSize=" << blockSize << " sample"); TEST_INFO(" min=" << perfo.getMinProcessing().count() << " ns"); TEST_INFO(" max=" << perfo.getMaxProcessing().count() << " ns"); TEST_INFO(" avg=" << perfo.getTotalTimeProcessing().count()/perfo.getTotalIteration() << " ns"); TEST_INFO(" min=" << (float((perfo.getMinProcessing().count()*sampleRate)/blockSize)/1000000000.0)*100.0 << " %"); TEST_INFO(" max=" << (float((perfo.getMaxProcessing().count()*sampleRate)/blockSize)/1000000000.0)*100.0 << " %"); TEST_INFO(" avg=" << (float(((perfo.getTotalTimeProcessing().count()/perfo.getTotalIteration())*sampleRate)/blockSize)/1000000000.0)*100.0 << " %"); } etk::FSNodeWriteAllDataType<int16_t>("output.raw", convert(output)); }