void help() {
   std::cout<< "SYNOPSIS"<< std::endl;
   std::cout<< "  ec2-describe-instances [GENERAL OPTIONS] [INSTANCE [INSTANCE [...]]]"<< std::endl;
   std::cout<< "DESCRIPTION"<< std::endl;
   std::cout<< "  List and describe your instances"<< std::endl;
   std::cout<< "  The INSTANCE parameter is the instance ID(s) to describe."<< std::endl;
   std::cout<< "  If unspecified all your instances will be returned."<< std::endl;
   std::cout << cmdline_options() << std::endl;
 }
Exemplo n.º 2
0
Arquivo: satabs.cpp Projeto: olivo/BP
int main(int argc, const char **argv) 
{
  #ifndef _WIN32
  signal(SIGXCPU, &xcpu_termination_handler);
  #endif
  
  cmdline_optionst cmdline_options(argc, argv); 
  return cmdline_options.main();
}
Exemplo n.º 3
0
int Config::initialize(int argc, char* argv[])
{
    Config* c = Config::getInstance();

    std::vector< std::string > nodes;
    std::vector< std::string > hostnames;
    std::vector< std::string > box_strings;
    std::string                configfile;
    std::string                keystore_file;
    std::string                private_key_file;

    // parsing program options using boost::program_options
    namespace po = boost::program_options;

    po::options_description cmdline_options("Generic options");
    cmdline_options.add_options()
        ("help,h", "Produce this help message")
        ("config,c", po::value<std::string>(&configfile),
            "Use supplied config file instead of default one")
        ("keystore", po::value<std::string>(&keystore_file),
            "Use supplied keystore file instead of default one")
        ("privatekey", po::value<std::string>(&private_key_file),
            "Use supplied privatekey file instead of default one")
        ("create-private-key", "Create new keypair for hostnames")
    ;

    po::options_description generic_options("Allowed options");
    generic_options.add_options()
        ("node,n", po::value<std::vector< std::string >>(&nodes), 
            "Add node location to listen to (multiple arguments allowed)")
        ("box,b", po::value<std::vector <std::string> >(&box_strings), 
            "Add path of a directory to watch (multiple arguments allowed)")
        ("hostname,p", po::value<std::vector <std::string> >(&hostnames),
            "Add a name for this machine under which other nodes can reach it (multiple arguments allowed)")
    ;

    po::options_description options;
    options.add(cmdline_options).add(generic_options);


    // BUG we cannot ADD nodes/boxes through the cli,
    //     it takes either the config file or the command line...
    // parse command line arguments
    po::store(po::parse_command_line( argc, argv, options ), c->vm_);
    po::notify(c->vm_);

    // parse config file, if any
    wordexp_t expanded_config_file_path;
    if (configfile.empty()) {
        wordexp( F_CONFIG_FILE, &expanded_config_file_path, 0 );
    } else {
        wordexp( configfile.c_str(), &expanded_config_file_path, 0 );
    }
    std::ifstream ifs( expanded_config_file_path.we_wordv[0] );
    wordfree(&expanded_config_file_path);
    if ( !ifs ) {
        if (F_MSG_DEBUG) printf("config: no config file found\n");
    } else {
        po::store(po::parse_config_file(ifs, generic_options), c->vm_);
        po::notify(c->vm_);
        ifs.close();
    }

    // parse keystore file
    wordexp_t expanded_keystore_file_path;
    if (keystore_file.empty()) {
        wordexp( F_KEYSTORE_FILE, &expanded_keystore_file_path, 0 );
    } else {
        wordexp( keystore_file.c_str(), &expanded_keystore_file_path, 0 );
    }
    keystore_file = expanded_keystore_file_path.we_wordv[0];
    wordfree(&expanded_keystore_file_path);

    // parse privatekey file
    wordexp_t expanded_privatekey_file_path;
    if (private_key_file.empty()) {
        wordexp( F_PRIVATEKEY_FILE, &expanded_privatekey_file_path, 0 );
    } else {
        wordexp( private_key_file.c_str(), &expanded_privatekey_file_path, 0 );
    }
    private_key_file = expanded_privatekey_file_path.we_wordv[0];
    wordfree(&expanded_privatekey_file_path);

    int return_val;
    return_val = c->doSanityCheck( &options, &nodes, &hostnames, &box_strings );
    if ( return_val != 0 ) return return_val;
    return_val = c->synchronizeKeystore( &keystore_file, &private_key_file );
    return return_val;
}
Exemplo n.º 4
0
  void parse_options(int argc, char* argv[]) {

    std::string config_file;
    unsigned log_level;
    std::string log_file;

    po::options_description generic("Generic options");
    auto generic_add = generic.add_options();
    generic_add("help,h", "produce help message");
    generic_add("config-file,c",
                po::value<std::string>(&config_file)->default_value("flib.cfg"),
                "name of a configuration file");
    generic_add("log-level,l",
                po::value<unsigned>(&log_level)->default_value(2),
                "set the log level (all:0)");
    generic_add("log-file,L", po::value<std::string>(&log_file),
                "name of target log file");

    po::options_description config("Configuration (flib.cfg or cmd line)");
    auto config_add = config.add_options();
    config_add("flib-addr,i", po::value<pci_addr>(),
               "PCI BDF address of target FLIB in BB:DD.F format");
    config_add("identify", po::value<bool>(&_identify)->default_value(false),
               "toggle FLIB ID led");
    config_add("mc-size,t", po::value<uint32_t>(),
               "size of pattern generator microslices in units of "
               "1024 ns (31 bit wide)");
    config_add("pgen-rate,r", po::value<float>(),
               "MS fill level of pattern generator in [0,1]");
    config_add("mc-size-limit", po::value<uint32_t>(&_mc_size_limit),
               "Threshold of microslice size limiter in bytes.");

    config_add("l0_source", po::value<std::string>(),
               "Link 0 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l0_eq_id", po::value<std::string>(),
               "Equipment identifier of link 0 pgen data source (16 Bit)");
    config_add("l1_source", po::value<std::string>(),
               "Link 1 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l1_eq_id", po::value<std::string>(),
               "Equipment identifier of link 1 pgen data source (16 Bit)");
    config_add("l2_source", po::value<std::string>(),
               "Link 2 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l2_eq_id", po::value<std::string>(),
               "Equipment identifier of link 2 pgen data source (16 Bit)");
    config_add("l3_source", po::value<std::string>(),
               "Link 3 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l3_eq_id", po::value<std::string>(),
               "Equipment identifier of link 3 pgen data source (16 Bit)");
    config_add("l4_source", po::value<std::string>(),
               "Link 4 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l4_eq_id", po::value<std::string>(),
               "Equipment identifier of link 4 pgen data source (16 Bit)");
    config_add("l5_source", po::value<std::string>(),
               "Link 5 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l5_eq_id", po::value<std::string>(),
               "Equipment identifier of link 5 pgen data source (16 Bit)");
    config_add("l6_source", po::value<std::string>(),
               "Link 6 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l6_eq_id", po::value<std::string>(),
               "Equipment identifier of link 6 pgen data source (16 Bit)");
    config_add("l7_source", po::value<std::string>(),
               "Link 7 data source <disable|flim|pgen_far|pgen_near>");
    config_add("l7_eq_id", po::value<std::string>(),
               "Equipment identifier of link 7 pgen data source (16 Bit)");

    po::options_description cmdline_options("Allowed options");
    cmdline_options.add(generic).add(config);

    po::options_description config_file_options;
    config_file_options.add(config);

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
    po::notify(vm);

    std::ifstream ifs(config_file.c_str());
    if (!ifs) {
      throw ParametersException("cannot open config file: " + config_file);
    } else {
      po::store(po::parse_config_file(ifs, config_file_options), vm);
      notify(vm);
    }

    if (vm.count("help")) {
      std::cout << cmdline_options << "\n";
      exit(EXIT_SUCCESS);
    }

    logging::add_console(static_cast<severity_level>(log_level));
    if (vm.count("log-file")) {
      L_(info) << "Logging output to " << log_file;
      logging::add_file(log_file, static_cast<severity_level>(log_level));
    }

    L_(info) << "Device config:";

    if (vm.count("flib-addr")) {
      _flib_addr = vm["flib-addr"].as<pci_addr>();
      _flib_autodetect = false;
      L_(info) << " FLIB address: " << std::hex << std::setw(2)
               << std::setfill('0') << static_cast<unsigned>(_flib_addr.bus)
               << ":" << std::setw(2) << std::setfill('0')
               << static_cast<unsigned>(_flib_addr.dev) << "."
               << static_cast<unsigned>(_flib_addr.func) << std::dec;
    } else {
      _flib_autodetect = true;
      L_(info) << " FLIB address: autodetect";
    }

    if (vm.count("mc-size")) {
      _mc_size = vm["mc-size"].as<uint32_t>();
      if (_mc_size > 2147483647) { // 31 bit check
        throw ParametersException("Pgen microslice size out of range");
      } else {
        L_(info) << " Pgen microslice size: "
                 << human_readable_mc_size(_mc_size);
      }
    } else {
      L_(info) << " Pgen microslice size: " << human_readable_mc_size(_mc_size)
               << " (default)";
    }

    if (vm.count("pgen-rate")) {
      _pgen_rate = vm["pgen-rate"].as<float>();
      if (_pgen_rate < 0 || _pgen_rate > 1) { // range check
        throw ParametersException("Pgen rate out of range");
      } else {
        L_(info) << " Pgen rate: " << _pgen_rate;
      }
    }

    L_(info) << " FLIB microslice size limit: " << _mc_size_limit << " bytes";

    for (size_t i = 0; i < _num_flib_links; ++i) {
      L_(info) << "Link " << i << " config:";
      parse_data_source(vm, i);
    } // end loop over links
  }
Exemplo n.º 5
0
        int runDbTests( int argc , char** argv , string default_dbpath ) {
            unsigned long long seed = time( 0 );
            int runsPerTest = 1;
            string dbpathSpec;

            po::options_description shell_options("options");
            po::options_description hidden_options("Hidden options");
            po::options_description cmdline_options("Command line options");
            po::positional_options_description positional_options;

            shell_options.add_options()
            ("help,h", "show this usage information")
            ("dbpath", po::value<string>(&dbpathSpec)->default_value(default_dbpath),
             "db data path for this test run. NOTE: the contents of this "
             "directory will be overwritten if it already exists")
            ("debug", "run tests with verbose output")
            ("list,l", "list available test suites")
            ("bigfiles", "use big datafiles instead of smallfiles which is the default")
            ("filter,f" , po::value<string>() , "string substring filter on test name" )
            ("verbose,v", "verbose")
            ("dur", "enable journaling (currently the default)")
            ("nodur", "disable journaling")
            ("seed", po::value<unsigned long long>(&seed), "random number seed")
            ("runs", po::value<int>(&runsPerTest), "number of times to run each test")
            ("perfHist", po::value<unsigned>(&perfHist), "number of back runs of perf stats to display")
            ;

            hidden_options.add_options()
            ("suites", po::value< vector<string> >(), "test suites to run")
            ("nopreallocj", "disable journal prealloc")
            ;

            positional_options.add("suites", -1);

            cmdline_options.add(shell_options).add(hidden_options);

            po::variables_map params;
            int command_line_style = (((po::command_line_style::unix_style ^
                                        po::command_line_style::allow_guessing) |
                                       po::command_line_style::allow_long_disguise) ^
                                      po::command_line_style::allow_sticky);

            try {
                po::store(po::command_line_parser(argc, argv).options(cmdline_options).
                          positional(positional_options).
                          style(command_line_style).run(), params);
                po::notify(params);
            }
            catch (po::error &e) {
                cout << "ERROR: " << e.what() << endl << endl;
                show_help_text(argv[0], shell_options);
                return EXIT_BADOPTIONS;
            }

            if (params.count("help")) {
                show_help_text(argv[0], shell_options);
                return EXIT_CLEAN;
            }

            bool nodur = false;
            if( params.count("nodur") ) {
                nodur = true;
                cmdLine.dur = false;
            }
            if( params.count("dur") || cmdLine.dur ) {
                cmdLine.dur = true;
            }

            if( params.count("nopreallocj") ) {
                cmdLine.preallocj = false;
            }

            if (params.count("debug") || params.count("verbose") ) {
                logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(1));
            }

            if (params.count("list")) {
                std::vector<std::string> suiteNames = mongo::unittest::getAllSuiteNames();
                for ( std::vector<std::string>::const_iterator i = suiteNames.begin();
                      i != suiteNames.end(); ++i ) {

                    std::cout << *i << std::endl;
                }
                return 0;
            }

            boost::filesystem::path p(dbpathSpec);

            /* remove the contents of the test directory if it exists. */
            if (boost::filesystem::exists(p)) {
                if (!boost::filesystem::is_directory(p)) {
                    cout << "ERROR: path \"" << p.string() << "\" is not a directory" << endl << endl;
                    show_help_text(argv[0], shell_options);
                    return EXIT_BADOPTIONS;
                }
                boost::filesystem::directory_iterator end_iter;
                for (boost::filesystem::directory_iterator dir_iter(p);
                        dir_iter != end_iter; ++dir_iter) {
                    boost::filesystem::remove_all(*dir_iter);
                }
            }
            else {
                boost::filesystem::create_directory(p);
            }

            string dbpathString = p.string();
            dbpath = dbpathString.c_str();

            cmdLine.prealloc = false;

            // dbtest defaults to smallfiles
            cmdLine.smallfiles = true;
            if( params.count("bigfiles") ) {
                cmdLine.dur = true;
            }

            cmdLine.oplogSize = 10 * 1024 * 1024;
            Client::initThread("testsuite");
            acquirePathLock();

            srand( (unsigned) seed );
            printGitVersion();
            printSysInfo();
            DEV log() << "_DEBUG build" << endl;
            if( sizeof(void*)==4 )
                log() << "32bit" << endl;
            log() << "random seed: " << seed << endl;

            if( time(0) % 3 == 0 && !nodur ) {
                if( !cmdLine.dur ) {
                    cmdLine.dur = true;
                    log() << "****************" << endl;
                    log() << "running with journaling enabled to test that. dbtests will do this occasionally even if --dur is not specified." << endl;
                    log() << "****************" << endl;
                }
            }

            FileAllocator::get()->start();

            vector<string> suites;
            if (params.count("suites")) {
                suites = params["suites"].as< vector<string> >();
            }

            string filter = "";
            if ( params.count( "filter" ) ) {
                filter = params["filter"].as<string>();
            }

            dur::startup();

            if( debug && cmdLine.dur ) {
                log() << "_DEBUG: automatically enabling cmdLine.durOptions=8 (DurParanoid)" << endl;
                // this was commented out.  why too slow or something? : 
                cmdLine.durOptions |= 8;
            }

            TestWatchDog twd;
            twd.go();

            // set tlogLevel to -1 to suppress MONGO_TLOG(0) output in a test program
            tlogLevel = -1;

            int ret = ::mongo::unittest::Suite::run(suites,filter,runsPerTest);

#if !defined(_WIN32) && !defined(__sunos__)
            flock( lockFile, LOCK_UN );
#endif

            cc().shutdown();
            dbexit( (ExitCode)ret ); // so everything shuts down cleanly
            return ret;
        }
Exemplo n.º 6
0
        int Suite::run( int argc , char** argv , string default_dbpath ) {
            unsigned long long seed = time( 0 );
            string dbpathSpec;

            po::options_description shell_options("options");
            po::options_description hidden_options("Hidden options");
            po::options_description cmdline_options("Command line options");
            po::positional_options_description positional_options;

            shell_options.add_options()
                ("help,h", "show this usage information")
                ("dbpath", po::value<string>(&dbpathSpec)->default_value(default_dbpath),
                 "db data path for this test run. NOTE: the contents of this "
                 "directory will be overwritten if it already exists")
                ("debug", "run tests with verbose output")
                ("list,l", "list available test suites")
                ("verbose,v", "verbose")
                ("seed", po::value<unsigned long long>(&seed), "random number seed")
                ;

            hidden_options.add_options()
                ("suites", po::value< vector<string> >(), "test suites to run")
                ;

            positional_options.add("suites", -1);

            cmdline_options.add(shell_options).add(hidden_options);

            po::variables_map params;
            int command_line_style = (((po::command_line_style::unix_style ^
                                        po::command_line_style::allow_guessing) |
                                       po::command_line_style::allow_long_disguise) ^
                                      po::command_line_style::allow_sticky);

            try {
                po::store(po::command_line_parser(argc, argv).options(cmdline_options).
                          positional(positional_options).
                          style(command_line_style).run(), params);
                po::notify(params);
            } catch (po::error &e) {
                cout << "ERROR: " << e.what() << endl << endl;
                show_help_text(argv[0], shell_options);
                return EXIT_BADOPTIONS;
            }

            if (params.count("help")) {
                show_help_text(argv[0], shell_options);
                return EXIT_CLEAN;
            }

            if (params.count("debug") || params.count("verbose") ) {
                logLevel = 1;
            }

            if (params.count("list")) {
                for ( map<string,Suite*>::iterator i = _suites->begin() ; i != _suites->end(); i++ )
                    cout << i->first << endl;
                return 0;
            }

            boost::filesystem::path p(dbpathSpec);

            /* remove the contents of the test directory if it exists. */
            if (boost::filesystem::exists(p)) {
                if (!boost::filesystem::is_directory(p)) {
                    cout << "ERROR: path \"" << p.string() << "\" is not a directory" << endl << endl;
                    show_help_text(argv[0], shell_options);
                    return EXIT_BADOPTIONS;
                }
                boost::filesystem::directory_iterator end_iter;
                for (boost::filesystem::directory_iterator dir_iter(p);
                     dir_iter != end_iter; ++dir_iter) {
                    boost::filesystem::remove_all(*dir_iter);
                }
            } else {
                boost::filesystem::create_directory(p);
            }

            string dbpathString = p.native_directory_string();
            dbpath = dbpathString.c_str();
            
            cmdLine.prealloc = false;
            cmdLine.smallfiles = true;
            cmdLine.oplogSize = 10 * 1024 * 1024;
            Client::initThread("testsuite");
            acquirePathLock();

            srand( (unsigned) seed );
            printGitVersion();
            printSysInfo();
            out() << "random seed: " << seed << endl;

            theFileAllocator().start();

            vector<string> suites;
            if (params.count("suites")) {
                suites = params["suites"].as< vector<string> >();
            }
            int ret = run(suites);

#if !defined(_WIN32) && !defined(__sunos__)
            flock( lockFile, LOCK_UN );
#endif
            
            cc().shutdown();
            dbexit( (ExitCode)ret ); // so everything shuts down cleanly
            return ret;
        }
Exemplo n.º 7
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");

  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );

  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << generic << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The default image (with path) must be specified."
	      << std::endl;
    
    return 1;
  }
  
  // Initialize the window
  if( !initialize() )
  {
    return 1;
  }
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name ))
    {
      return 1;
    }
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_RenderClear( g_renderer );

	// Render texture to screen
	SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );

	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Exemplo n.º 8
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The modulation components
      unsigned char r = 255, g = 255, b = 255;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;

	  // On keypress, change rgb values
	  else if( event.type == SDL_KEYDOWN )
	  {
	    switch( event.key.keysym.sym )
	    {
	      // Increase red
	      case SDLK_q:
		r += 32;
		break;

	      // Increase green
	      case SDLK_w:
		g += 32;
		break;

	      // Increase blue
	      case SDLK_e:
		b += 32;
		break;
		
	      // Decrease red
	      case SDLK_a:
		r -= 32;
		break;

	      // Decrease green
	      case SDLK_s:
		g -= 32;
		break;

	      // Decrease blue
	      case SDLK_d:
		b -= 32;
		break;
	    }
	  }
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Modulate the render texture
	g_modulated_texture.setColor( r, g, b );
	g_modulated_texture.render( 0, 0 );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Exemplo n.º 9
0
        int runDbTests( int argc , char** argv , string default_dbpath ) {
            unsigned long long seed = time( 0 );
            int runsPerTest = 1;
            string dbpathSpec;

            po::options_description shell_options("options");
            po::options_description hidden_options("Hidden options");
            po::options_description cmdline_options("Command line options");
            po::positional_options_description positional_options;

            shell_options.add_options()
            ("help,h", "show this usage information")
            ("dbpath", po::value<string>(&dbpathSpec)->default_value(default_dbpath),
             "db data path for this test run. NOTE: the contents of this "
             "directory will be overwritten if it already exists")
            ("debug", "run tests with verbose output")
            ("list,l", "list available test suites")
            ("filter,f" , po::value<string>() , "string substring filter on test name" )
            ("verbose,v", "be more verbose (include multiple times for more verbosity e.g. -vvvvv)")
            ("dur", "enable journaling (currently the default)")
            ("nodur", "disable journaling")
            ("seed", po::value<unsigned long long>(&seed), "random number seed")
            ("runs", po::value<int>(&runsPerTest), "number of times to run each test")
            ("perfHist", po::value<unsigned>(&perfHist), "number of back runs of perf stats to display")
            ;

            hidden_options.add_options()
            ("suites", po::value< vector<string> >(), "test suites to run")
            ;

            positional_options.add("suites", -1);

            /* support for -vv -vvvv etc. */
            for (string s = "vv"; s.length() <= 10; s.append("v")) {
                hidden_options.add_options()(s.c_str(), "verbose");
            }

            cmdline_options.add(shell_options).add(hidden_options);

            po::variables_map params;
            int command_line_style = (((po::command_line_style::unix_style ^
                                        po::command_line_style::allow_guessing) |
                                       po::command_line_style::allow_long_disguise) ^
                                      po::command_line_style::allow_sticky);

            try {
                po::store(po::command_line_parser(argc, argv).options(cmdline_options).
                          positional(positional_options).
                          style(command_line_style).run(), params);
                po::notify(params);
            }
            catch (po::error &e) {
                cout << "ERROR: " << e.what() << endl << endl;
                show_help_text(argv[0], shell_options);
                return EXIT_BADOPTIONS;
            }

            if (params.count("help")) {
                show_help_text(argv[0], shell_options);
                return EXIT_CLEAN;
            }

            if (params.count("debug") || params.count("verbose") ) {
                logLevel = 1;
            }

            for (string s = "vv"; s.length() <= 10; s.append("v")) {
                if (params.count(s)) {
                    logLevel = s.length();
                }
            }

            if (params.count("list")) {
                std::vector<std::string> suiteNames = mongo::unittest::getAllSuiteNames();
                for ( std::vector<std::string>::const_iterator i = suiteNames.begin();
                      i != suiteNames.end(); ++i ) {

                    std::cout << *i << std::endl;
                }
                return 0;
            }

            boost::filesystem::path p(dbpathSpec);

            /* remove the contents of the test directory if it exists. */
            if (boost::filesystem::exists(p)) {
                if (!boost::filesystem::is_directory(p)) {
                    cout << "ERROR: path \"" << p.string() << "\" is not a directory" << endl << endl;
                    show_help_text(argv[0], shell_options);
                    return EXIT_BADOPTIONS;
                }
                boost::filesystem::directory_iterator end_iter;
                for (boost::filesystem::directory_iterator dir_iter(p);
                        dir_iter != end_iter; ++dir_iter) {
                    boost::filesystem::remove_all(*dir_iter);
                }
            }
            else {
                boost::filesystem::create_directory(p);
            }

            string dbpathString = p.native_directory_string();
            dbpath = dbpathString.c_str();

            Client::initThread("testsuite");
            acquirePathLock();

            srand( (unsigned) seed );
            printGitVersion();
            printSysInfo();
            DEV log() << "_DEBUG build" << endl;
            if( sizeof(void*)==4 )
                log() << "32bit" << endl;
            log() << "random seed: " << seed << endl;

            vector<string> suites;
            if (params.count("suites")) {
                suites = params["suites"].as< vector<string> >();
            }

            string filter = "";
            if ( params.count( "filter" ) ) {
                filter = params["filter"].as<string>();
            }

            mongo::setTxnCompleteHooks(&mongo::_txnCompleteHooks);
            storage::startup();

            TestWatchDog twd;
            twd.go();

            // set tlogLevel to -1 to suppress tlog() output in a test program
            tlogLevel = -1;

            int ret = ::mongo::unittest::Suite::run(suites,filter,runsPerTest);

#if !defined(_WIN32) && !defined(__sunos__)
            flock( lockFile, LOCK_UN );
#endif

            cc().shutdown();
            dbexit( (ExitCode)ret ); // so everything shuts down cleanly
            return ret;
        }
Exemplo n.º 10
0
int main( int argc, char** argv )
{
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("image,i",
     boost::program_options::value<std::string>(),
     "Set the optional image to render (with path)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << generic << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  
  // Initialize the window
  if( !initialize() )
  {
    return 1;
  }
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name ))
    {
      return 1;
    }
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Render the user supplied image (texture) to the screen
	if( image_name.size() > 0 )
	{
	  // Clear the screen
	  SDL_RenderClear( g_renderer );
	
	  SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );
	}
	else
	{
	  SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );

	  // Clear the screen
	  SDL_RenderClear( g_renderer );
	}

	// Render red filled quad
	SDL_Rect fill_rect = { screen_width_height[0]/4,
			       screen_width_height[1]/4,
			       screen_width_height[0]/2,
			       screen_width_height[1]/2 };
	
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0x00, 0x00, 0xFF );
	SDL_RenderFillRect( g_renderer, &fill_rect );
	
	// Render green outlined quad
	SDL_Rect outline_rect = { screen_width_height[0]/6,
				  screen_width_height[1]/6,
				  screen_width_height[0]*2/3,
				  screen_width_height[1]*2/3 };
	
	SDL_SetRenderDrawColor( g_renderer, 0x00, 0xFF, 0x00, 0xFF );
	SDL_RenderDrawRect( g_renderer, &outline_rect );
	
	// Draw a blue horizontal line
	SDL_SetRenderDrawColor( g_renderer, 0x00, 0x00, 0xFF, 0xFF );
	SDL_RenderDrawLine( g_renderer, 
			    0, 
			    screen_width_height[1]/2,
			    screen_width_height[0],
			    screen_width_height[1]/2 );
	
	// Draw a vertial line of yellow dots
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0x00, 0xFF );
	
	for( int i = 0; i < screen_width_height[1]; i += 4 )
	  SDL_RenderDrawPoint( g_renderer, screen_width_height[0]/2, i );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Exemplo n.º 11
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The current animation frame
      int frame = 0;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Render the current frame
	SDL_Rect* current_clip = &g_sprite_clips[frame/4];
	
	g_sprite_sheet_texture.render( (screen_width_height[0] -
					current_clip->w)/2,
				       (screen_width_height[1] - 
					current_clip->h)/2,
				       current_clip );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );

	// Increment the frame
	++frame;

	// Reset animation
	if( frame/4 >= g_frames )
	  frame = 0;
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Exemplo n.º 12
0
Arquivo: satabs.cpp Projeto: olivo/BP
int wmain(int argc, const wchar_t **argv_wide)
{
  const char **argv=narrow_argv(argc, argv_wide);
  cmdline_optionst cmdline_options(argc, argv); 
  return cmdline_options.main();
}
Exemplo n.º 13
0
  void parse_options(int argc, char* argv[]) {

    std::string config_file;
    unsigned log_level;
    std::string log_file;

    po::options_description generic("Generic options");
    auto generic_add = generic.add_options();
    generic_add("help,h", "produce help message");
    generic_add(
        "config-file,c",
        po::value<std::string>(&config_file)->default_value("flib_server.cfg"),
        "name of a configuration file");

    po::options_description config(
        "Configuration (flib_server.cfg or cmd line)");
    auto config_add = config.add_options();
    config_add("flib-addr,i", po::value<pci_addr>(),
               "PCI BDF address of target FLIB in BB:DD.F format");
    config_add(
        "shm,o",
        po::value<std::string>(&_shm)->default_value("flib_shared_memory"),
        "name of the shared memory to be used");
    config_add("data-buffer-size-exp",
               po::value<size_t>(&_data_buffer_size_exp)->default_value(27),
               "exp. size of the data buffer in bytes");
    config_add("desc-buffer-size-exp",
               po::value<size_t>(&_desc_buffer_size_exp)->default_value(19),
               "exp. size of the descriptor buffer (number of entries)");
    config_add("log-level,l", po::value<unsigned>(&log_level)->default_value(2),
               "set the log level (all:0)");
    config_add("log-file,L", po::value<std::string>(&log_file),
               "name of target log file");
    config_add("etcd-authority",
               po::value<std::string>(&_etcd.authority)
                   ->default_value("127.0.0.1:2379"),
               "where to find the etcd server");
    config_add("etcd-path", po::value<std::string>(&_etcd.path),
               "base path for this instance, leave empty to not use etcd");
    config_add("exec,e", po::value<std::string>(&_exec)->value_name("<string>"),
               "name of an executable to run after startup");

    po::options_description cmdline_options("Allowed options");
    cmdline_options.add(generic).add(config);

    po::options_description config_file_options;
    config_file_options.add(config);

    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
    po::notify(vm);

    std::ifstream ifs(config_file.c_str());
    if (!ifs) {
      if (config_file != "flib_server.cfg") {
        throw ParametersException("Cannot open config file: " + config_file);
      }
    } else {
      std::cout << "Using config file: " << config_file << "\n";
      po::store(po::parse_config_file(ifs, config_file_options), vm);
      notify(vm);
    }

    if (vm.count("help")) {
      std::cout << cmdline_options << "\n";
      exit(EXIT_SUCCESS);
    }

    logging::add_console(static_cast<severity_level>(log_level));
    if (vm.count("log-file")) {
      L_(info) << "Logging output to " << log_file;
      logging::add_file(log_file, static_cast<severity_level>(log_level));
    }

    if (vm.count("flib-addr")) {
      _flib_addr = vm["flib-addr"].as<pci_addr>();
      _flib_autodetect = false;
      L_(debug) << "FLIB address: " << std::hex << std::setw(2)
                << std::setfill('0') << static_cast<unsigned>(_flib_addr.bus)
                << ":" << std::setw(2) << std::setfill('0')
                << static_cast<unsigned>(_flib_addr.dev) << "."
                << static_cast<unsigned>(_flib_addr.func);
    } else {
      _flib_autodetect = true;
      L_(debug) << "FLIB address: autodetect";
    }

    if (vm.count("etcd-path")) {
      _etcd.use_etcd = true;
    }

    L_(info) << "Shared memory file: " << _shm;
    L_(info) << print_buffer_info();
  }
Exemplo n.º 14
0
int main(int argc, char **argv)

{

  OPTION  opt;
  int     err = 0;


  /*
    -- init options and cmdline parsing
  */

  init_PidMemory ();


  if (! cmdline_options (argc,argv, &opt) ) return (-1);

  setVerboseLevel (opt.printdecode);
  setHexPrintMode (opt.printhex);



  indent (0);
  if (! opt.binary_out) {
     if (! opt.hide_copyright) {
        out_nl (1, "%s -- %s ", DVBSNOOP_PROG_VERSION, DVBSNOOP_URL);
     }

     if (! opt.inpPidFile) {
	if (opt.pid != DUMMY_PID) {
		out_nl (9, "   PID   : %d (0x%04x)",opt.pid,opt.pid);
	}
	if ((opt.packet_mode == SECT) && (opt.filterLen > 0)) {		// filter are only for sections

		int i;
		out (9, "   Filter: 0x");
		for (i=0; i < opt.filterLen; i++) {
			out (9,"%02x ",opt.filter[i]);
		}
		out_NL (9);
		out (9, "   Mask  : 0x");
		for (i=0; i < opt.filterLen; i++) {
			out (9,"%02x ",opt.mask[i]);
		}
		out_NL (9);
		out_nl (9, "   Max. Filtersize: %d",DMX_FILTER_SIZE);

	}
	out_nl (9, "   DEMUX : %s",opt.devDemux);
	out_nl (9, "   DVR   : %s",opt.devDvr);
	out_nl (9, "   FRONTEND: %s",opt.devFE);
     }
  }



  initOSSigHandler ();
  init_receive_time ();


	  switch (opt.packet_mode) {
		case SECT:
			err = doReadSECT (&opt);
			break;

		case PS:
		case PES:
			err = doReadPES (&opt);
			break;

		case TS:
			err = doReadTS (&opt);
			break;

		case PIDSCAN:
			err = ts_pidscan (&opt);
			break;

		case PIDBANDWIDTH:
			err = ts_pidbandwidth (&opt);
			break;

		case SCAN_FE_SIGNAL:
			err = do_SignalStrength (&opt);
			break;

		case SCAN_FE_INFO:
			err = do_FE_Info (&opt);
			break;

		default:
			fprintf (stderr,"unknown snoop type (this should never happen).\n");
			break;

	  }




 if ( isSigAbort() ) {
	 out_nl (1,"... aborted (Signal: %d)",isSigAbort());
 }
 restoreOSSigHandler();
 return err;

}
Exemplo n.º 15
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");

  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );

  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << generic << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name ))
      return 1;
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Set the viewport to the top left corner
	SDL_Rect top_left_viewport;
	top_left_viewport.x = 0;
	top_left_viewport.y = 0;
	top_left_viewport.w = screen_width_height[0]/2;
	top_left_viewport.h = screen_width_height[1]/2;

	SDL_RenderSetViewport( g_renderer, &top_left_viewport );
	
	// Render texture to the screen
	SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );
	
	// Set the viewport to the top right corner
	SDL_Rect top_right_viewport;
	top_right_viewport.x = screen_width_height[0]/2;
	top_right_viewport.y = 0;
	top_right_viewport.w = screen_width_height[0]/2;
	top_right_viewport.h = screen_width_height[1]/2;
	
	SDL_RenderSetViewport( g_renderer, &top_right_viewport );

	// Render texture to screen
	SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );
	
	// Set the viewport to the bottom
	SDL_Rect bottom_viewport;
	bottom_viewport.x = 0;
	bottom_viewport.y = screen_width_height[0]/2;
	bottom_viewport.w = screen_width_height[0];
	bottom_viewport.h = screen_width_height[1]/2;

	SDL_RenderSetViewport( g_renderer, &bottom_viewport );

	// Render texture to screen
	SDL_RenderCopy( g_renderer, g_texture, NULL, NULL );

	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Exemplo n.º 16
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("sprite_sheet",
     boost::program_options::value<std::string>(),
     "the sprite sheet (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("sprite_sheet", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string sprite_sheet_name;

  if( vm.count( "sprite_sheet" ) )
    sprite_sheet_name = vm["sprite_sheet"].as<std::string>();
  else
  {
    std::cerr << "The sprite sheet (with path) must be specified."
	      << std::endl;

    return 1;
  }
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( sprite_sheet_name ) )
      return 1;
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Render the top left sprite
	g_sprite_sheet_texture.render( 0, 0, &g_sprite_clips[0] );

	// Render the top right sprite
	g_sprite_sheet_texture.render( screen_width_height[0] -
				       g_sprite_clips[1].w,
				       0,
				       &g_sprite_clips[1] );

	// Render the bottom left sprite
	g_sprite_sheet_texture.render( 0,
				       screen_width_height[1] - 
				       g_sprite_clips[2].h,
				       &g_sprite_clips[2] );

	// Render the bottom right sprite
	g_sprite_sheet_texture.render( screen_width_height[0] - 
				       g_sprite_clips[3].w,
				       screen_width_height[1] -
				       g_sprite_clips[3].h,
				       &g_sprite_clips[3] );	
	
	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}