void test_error_logs_if_logging_level_is_WARNING() { expect_string( mock_fprintf, output, "ERROR message.\n" ); set_logging_level( "warning" ); error( "ERROR message." ); }
void test_LOGGING_LEVEL_overrides_logging_level() { setenv( "LOGGING_LEVEL", "DEBUG", 1 ); set_logging_level( "critical" ); init_log( "tetris", get_trema_tmp(), LOGGING_TYPE_FILE ); assert_int_equal( LOG_DEBUG, get_logging_level() ); }
void test_warn_logs_if_logging_level_is_NOTICE() { expect_string( mock_fprintf, output, "WARN message.\n" ); set_logging_level( "notice" ); warn( "WARN message." ); }
void test_warn_logs_if_logging_level_is_WARNING() { expect_string( mock_fprintf, output, "WARN message.\n" ); set_logging_level( "warning" ); warn( "WARN message." ); }
/** * Initializes the Logger. This creates a log file to which messages * are written. * * @param ident name of the log file, used as an identifier. * @param log_directory the directory in which log file is created. * @param type log output type. * @return true on success; false otherwise. */ bool init_log( const char *ident, const char *directory, logging_type type ) { assert( ident != NULL ); assert( directory != NULL ); pthread_mutex_lock( &mutex ); // set_logging_level() may be called before init_log(). // level = -1 indicates that logging level is not set yet. if ( level < 0 || level > LOG_DEBUG ) { level = LOG_INFO; } char *level_string = getenv( "LOGGING_LEVEL" ); if ( level_string != NULL ) { set_logging_level( level_string ); } set_ident_string( ident ); set_log_directory( directory ); output = type; if ( output & LOGGING_TYPE_FILE ) { fd = open_log_file( false ); } if ( output & LOGGING_TYPE_SYSLOG ) { open_log_syslog(); } initialized = true; pthread_mutex_unlock( &mutex ); return true; }
void test_info_logs_if_logging_level_is_DEBUG() { expect_string( mock_fprintf, output, "INFO message.\n" ); set_logging_level( "debug" ); info( "INFO message." ); }
void test_DEBUG_logs_if_logging_level_is_DEBUG() { expect_string( mock_fprintf, output, "DEBUG message.\n" ); set_logging_level( "debug" ); debug( "DEBUG message." ); }
void test_critical_logs_if_logging_level_is_ERROR() { expect_string( mock_fprintf, output, "CRITICAL message.\n" ); set_logging_level( "error" ); critical( "CRITICAL message." ); }
void test_notice_logs_if_logging_level_is_INFO() { expect_string( mock_fprintf, output, "NOTICE message.\n" ); set_logging_level( "info" ); notice( "NOTICE message." ); }
int main(int argc, char* argv[]) { print_title("BBN APS2 Enumerate Utility"); set_logging_level(logDEBUG1); //First get the number of devices we can see unsigned numDevices = 0; get_numDevices(&numDevices); cout << concol::CYAN << numDevices << " APS device" << (numDevices > 1 ? "s": "") << " found" << concol::RESET << endl; cout << endl; //If we don't see anything bail if (numDevices < 1) return 0; //Get IP strings and firmware versions const char ** serialBuffer = new const char*[numDevices]; get_device_IPs(serialBuffer); for (unsigned ct=0; ct < numDevices; ct++) { APS2_STATUS status; status = connect_APS(serialBuffer[ct]); if (status != APS2_OK) { cout << concol::RED << "Failed to connect to " << serialBuffer[ct] << concol::RESET << endl; continue; } char version_string[64]; get_firmware_version(serialBuffer[ct], nullptr, nullptr, nullptr, version_string); double uptime{0}; get_uptime(serialBuffer[ct], &uptime); std::chrono::duration<float> uptime_seconds(uptime); auto uptime_days = std::chrono::duration_cast<std::chrono::duration<int, std::ratio<24*3600>>>(uptime_seconds); std::ostringstream uptime_pretty; if (uptime_days.count()) { uptime_pretty << uptime_days.count() << " day" << (uptime_days.count() > 1 ? "s " : " "); } uptime_seconds -= uptime_days; auto uptime_hours = std::chrono::duration_cast<std::chrono::hours>(uptime_seconds); uptime_pretty << std::setfill('0') << std::setw(2) << uptime_hours.count() << ":"; uptime_seconds -= uptime_hours; auto uptime_minutes = std::chrono::duration_cast<std::chrono::minutes>(uptime_seconds); uptime_pretty << std::setfill('0') << std::setw(2) << uptime_minutes.count() << ":"; uptime_seconds -= uptime_minutes; uptime_pretty << std::fixed << std::setprecision(3) << uptime_seconds.count(); cout << concol::CYAN << "Device " << ct << " at IPv4 address " << serialBuffer[ct] << " running firmware version " << version_string << " has been up " << uptime_pretty.str() << concol::RESET << endl; disconnect_APS(serialBuffer[ct]); } cout << endl; return 0; }
void test_DEBUG_donothing_if_logging_level_is_INFO() { set_logging_level( "info" ); debug( "This message must not be logged." ); }
void test_notice_donothing_if_logging_level_is_WARNING() { set_logging_level( "warning" ); notice( "This message must not be logged." ); }
void test_info_donothing_if_logging_level_is_NOTICE() { set_logging_level( "notice" ); info( "This message must not be logged." ); }
void test_error_donothing_if_logging_level_is_CRITICAL() { set_logging_level( "critical" ); error( "This message must not be logged." ); }
void test_warn_donothing_if_logging_level_is_ERROR() { set_logging_level( "error" ); warn( "This message must not be logged." ); }
void test_set_logging_level_fail_with_invalid_value() { expect_string( mock_die, output, "Invalid logging level: INVALID_LEVEL" ); expect_assert_failure( set_logging_level( "INVALID_LEVEL" ) ); }
void test_set_logging_level_die_if_no_init() { expect_assert_failure( set_logging_level( "DEBUG" ) ); }
static void parse_argv( int *argc, char ***argv ) { assert( argc != NULL ); assert( argv != NULL ); int argc_tmp = *argc; char *new_argv[ *argc ]; run_as_daemon = false; controller.ip = 0x7f000001; controller.port = 6633; for ( int i = 0; i < *argc; ++i ) { new_argv[ i ] = ( *argv )[ i ]; } for ( ;; ) { opterr = 0; int c = getopt_long( *argc, *argv, short_options, long_options, NULL ); if ( c == -1 ) { break; } switch ( c ) { case 'i': if ( optarg != NULL ) { string_to_datapath_id( optarg, &datapath_id ); } break; case 'c': if ( optarg != NULL ) { struct in_addr addr; inet_aton( optarg, &addr ); controller.ip = ntohl( addr.s_addr ); } break; case 'p': if ( optarg != NULL && atoi( optarg ) <= UINT16_MAX ) { controller.port = ( uint16_t ) atoi( optarg ); } break; case 'd': run_as_daemon = true; break; case 'l': set_logging_level( optarg ); break; case 'h': usage(); exit( EXIT_SUCCESS ); break; default: continue; } if ( optarg == NULL || strchr( new_argv[ optind - 1 ], '=' ) != NULL ) { argc_tmp -= 1; new_argv[ optind - 1 ] = NULL; } else { argc_tmp -= 2; new_argv[ optind - 1 ] = NULL; new_argv[ optind - 2 ] = NULL; } } for ( int i = 0, j = 0; i < *argc; ++i ) { if ( new_argv[ i ] != NULL ) { ( *argv )[ j ] = new_argv[ i ]; j++; } } if ( argc_tmp < *argc ) { ( *argv )[ argc_tmp ] = NULL; } *argc = argc_tmp; reset_getopt(); }
void test_set_logging_level_succeed() { set_logging_level( "critical" ); assert_int_equal( LOG_CRITICAL, get_logging_level() ); }
int main(int argc, char** argv) { int err; set_logging_level(logDEBUG1); if (argc < 2 || cmdOptionExists(argv, argv + argc, "-h")) { test::printHelp(); return 0; } int device_id = atoi(argv[1]); string bitFile = getCmdOption(argv, argv + argc, "-b"); if (bitFile.length() == 0) { bitFile = "../../bitfiles/mqco_aps_latest"; } cout << "Programming device " << device_id << " using: " << string(bitFile) << endl; //Initialize the APSRack from the DLL init(); if (cmdOptionExists(argv, argv + argc, "-0")) { char s[] = "stdout"; set_log(s); } //Connect to device connect_by_ID(device_id); err = initAPS(device_id, const_cast<char*>(bitFile.c_str()), true); if (err != APS_OK) { cout << "Error initializing APS Rack: " << err << endl; exit(-1); } // vector<float> waveform(0); // // for(int ct=0; ct<1000;ct++){ // waveform.push_back(float(ct)/1000); // } // stop(0); // set_waveform_float(0, 0, &waveform.front(), waveform.size()); // set_run_mode(0, 0, 0); // run(0); // usleep(1000); // stop(0); // select test to run if (cmdOptionExists(argv, argv + argc, "-wf")) { test::programSquareWaves(); } if (cmdOptionExists(argv, argv + argc, "-stream")) { test::streaming(); } if (cmdOptionExists(argv, argv + argc, "-t")) { test::doToggleTest(); } if (cmdOptionExists(argv, argv + argc, "-w")) { test::doStoreLoadTest(); } if (cmdOptionExists(argv, argv + argc, "-bf")) { test::doBulkStateFileTest(); } if (cmdOptionExists(argv, argv + argc, "-sf")) { test::doStateFilesTest(); } if (cmdOptionExists(argv, argv + argc, "-trig")) { test::getSetTriggerInterval(); } if (cmdOptionExists(argv, argv + argc, "-seq")) { test::loadSequenceFile(); } if (cmdOptionExists(argv, argv + argc, "-offset")) { test::offsetScale(); } disconnect_by_ID(device_id); cout << "Made it through!" << endl; return 0; }
int main(int argc, char* argv[]) { print_title("BBN APS2 Sequence Player"); argc-=(argc>0); argv+=(argc>0); // skip program name argv[0] if present option::Stats stats(usage, argc, argv); option::Option *options = new option::Option[stats.options_max]; option::Option *buffer = new option::Option[stats.buffer_max]; option::Parser parse(usage, argc, argv, options, buffer); if (parse.error()) return -1; if (options[HELP] || argc == 0) { option::printUsage(std::cout, usage); return 0; } for (option::Option* opt = options[UNKNOWN]; opt; opt = opt->next()) std::cout << "Unknown option: " << opt->name << "\n"; for (int i = 0; i < parse.nonOptionsCount(); ++i) std::cout << "Non-option #" << i << ": " << parse.nonOption(i) << "\n"; //Logging level TLogLevel logLevel = logINFO; if (options[LOG_LEVEL]) { logLevel = TLogLevel(atoi(options[LOG_LEVEL].arg)); } //Trigger source -- default of internal APS2_TRIGGER_SOURCE triggerSource = INTERNAL; if (options[TRIG_MODE]) { triggerSource = APS2_TRIGGER_SOURCE(atoi(options[TRIG_MODE].arg)); } set_logging_level(logLevel); set_log("stdout"); //Trigger interval -- default of 10ms double trigInterval = 10e-3; if (options[TRIG_INTERVAL]) { trigInterval = atof(options[TRIG_INTERVAL].arg); } string seqFile; if (options[SEQ_FILE]){ seqFile = string(options[SEQ_FILE].arg); } else { std::cerr << "A sequence file is required."; return -1; } string deviceSerial = get_device_id(); if (deviceSerial.empty()){ cout << concol::RED << "No APS2 devices connected! Exiting..." << concol::RESET << endl; return 0; } connect_APS(deviceSerial.c_str()); double uptime; get_uptime(deviceSerial.c_str(), &uptime); cout << concol::CYAN << "Uptime for device " << deviceSerial << " is " << uptime << " seconds" << concol::RESET << endl; // force initialize device init_APS(deviceSerial.c_str(), 1); //load the sequence file load_sequence_file(deviceSerial.c_str(), seqFile.c_str()); //Set the trigger mode set_trigger_source(deviceSerial.c_str(), triggerSource); //Trigger interval set_trigger_interval(deviceSerial.c_str(), trigInterval); //Set to sequence mode set_run_mode(deviceSerial.c_str(), RUN_SEQUENCE); run(deviceSerial.c_str()); //For software trigger, trigger on key stroke if (triggerSource == 2) { cout << concol::YELLOW << "Press t-Return to trigger or q-Return to exit" << concol::RESET << endl; while(true) { char keyStroke = cin.get(); if (keyStroke == 't') { trigger(deviceSerial.c_str()); } else if (keyStroke == 'q') { break; } } } else { cout << concol::YELLOW << "Press any key to stop" << concol::RESET; cin.get(); } stop(deviceSerial.c_str()); disconnect_APS(deviceSerial.c_str()); delete[] options; delete[] buffer; return 0; }
int main (int argc, char* argv []) { int rv = -1; bool debug = true; try { ContalignParams p; set_logging_level (Logger::ERROR); if (!p.parseCmdline (argc, argv)) { if (!p.help_mode ()) { errlog << "Error processing parameters "; p.cmdline ()->reportErrors (errlog.o_); errlog << std::endl; rv = 2; } else rv = 0; debug = false; } else if (!p.process ()) { errlog << "Parameters processing failed" << std::endl; rv = 2; debug = false; } else { debug = p.debug (); if (p.debug () >= 5) set_logging_level (Logger::TRACE); else if (p.debug () >= 4) set_logging_level (Logger::DEBUG); else if (p.verbose ()) set_logging_level (Logger::INFO); else set_logging_level (Logger::WARNING); dbglog << "Program parameters:\n"; p.parameters_->log (dbglog); dbglog << std::endl; rv = process (p); } } catch (Rerror& err) { errlog << "\nError: " << err << std::endl; rv = 1; } catch (std::exception& e) { if (debug) { wait_key (rv, true); throw; } errlog << "\nSystem exception: " << e.what () << " Run in Debug mode to see trace" << std::endl; } catch (...) { if (debug) { wait_key (rv, true); throw; } errlog << "\nUnhandled exception caught, run in Debug mode to see trace" << std::endl; } if (debug) wait_key (rv, false); return rv; }
RunOnInit() { boost::nowide::nowide_filesystem(); set_logging_level(1); }
void _parse_options( struct switch_arguments *args, int argc, char **argv ) { static struct option long_options[] = { { "logging_level", required_argument, 0, 'l' }, { "daemonize", no_argument, 0, 'd' }, { "datapath_id", required_argument, 0, 'i' }, { "max_flow_entries", required_argument, 0, 'm' }, { "server_ip", required_argument, 0, 'c' }, { "server_port", required_argument, 0, 'p' }, { "switch_ports", optional_argument, 0, 'e' }, { "administer", optional_argument, 0, 'a' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; static const char *short_options = "l:di:c:p:e:h"; set_default_opts( args, long_options ); int c, index = 0; optind = 0; while ( 1 ) { c = getopt_long( argc, argv, short_options, args->options, &index ); if ( c == -1 ) { break; } switch ( c ) { case 'h': print_usage( args, 0 ); break; case 'a': args->administer = true; break; case 'l': if ( optarg ) { args->log_level = optarg; set_logging_level( args->log_level ); } break; case 'd': args->run_as_daemon = true; break; case 'i': if ( optarg ) { string_to_datapath_id( optarg, &args->datapath_id ); } break; case 'm': if ( optarg ) { args->max_flow_entries = ( uint16_t ) atoi( optarg ); } break; case 'c': if ( optarg ) { char *save_ptr = NULL; uint32_t temp_addr = 0; char *p = strtok_r( optarg, ".", &save_ptr ); while ( p ) { temp_addr = ( temp_addr << 8 ) | ( uint32_t ) atoi( p ); p = strtok_r( NULL, ".", &save_ptr ); } if ( temp_addr ) { args->server_ip = temp_addr; } } break; case 'p': if ( optarg ) { args->server_port = ( uint16_t ) atoi( optarg ); } break; case 'e': if ( optarg ) { args->datapath_ports = optarg; } break; default: break; } } }
void test_set_logging_level_fail_with_invalid_value() { expect_assert_failure( set_logging_level( "INVALID_LEVEL" ) ); }
void test_set_logging_level_is_called_before_init_log() { set_logging_level( "critical" ); init_log( "tetris", get_trema_tmp(), LOGGING_TYPE_FILE ); assert_int_equal( LOG_CRIT, get_logging_level() ); }