int main( int argc, char *argv[] )
{
	// Local variables
	int ch, verbose = 0, log_initialized = 0;
	int port;

	port = atoi(argv[1]);
	// Process the command line parameters
	while ((ch = getopt(argc, argv, SMSA_ARGUMENTS)) != -1) {

		switch (ch) {
		case 'h': // Help, print usage
			fprintf( stderr, USAGE );
			return( -1 );

		case 'v': // Verbose Flag
			verbose = 1;
			break;

		case 'l': // Set the log filename
			initializeLogWithFilename( optarg );
			log_initialized = 1;
			break;

		default:  // Default (unknown)
			fprintf( stderr, "Unknown command line option (%c), aborting.\n", ch );
			return( -1 );
		}
	}

	// Setup the log as needed
	if ( ! log_initialized ) {
		initializeLogWithFilehandle( CMPSC311_LOG_STDERR );
	}
	if ( verbose ) {
		enableLogLevels( LOG_INFO_LEVEL );
	}

	printf ( "port = %d", port );

	// Run the server
	smsa_server( port );

	// Return successfully
	return( 0 );
}
Example #2
0
int main( int argc, char *argv[] )
{
	// Local variables
	int ch, verbose = 0, log_initialized = 0, unit_test = 0;
	uint32_t cache_size = 1024; // Defaults to 1024 cache lines

	// Process the command line parameters
	while ((ch = getopt(argc, argv, SMSA_ARGUMENTS)) != -1) {

		switch (ch) {
		case 'h': // Help, print usage
			fprintf( stderr, USAGE );
			return( -1 );

		case 'v': // Verbose Flag
			verbose = 1;
			break;

		case 'u': // Run the unit test (instead of running the program)
			unit_test = 1;
			break;

		case 'l': // Set the log filename
			initializeLogWithFilename( optarg );
			log_initialized = 1;
			break;

		case 'c': // Set cache line size
			if ( sscanf( optarg, "%u", &cache_size ) != 1 ) {
			    logMessage( LOG_ERROR_LEVEL, "Bad  cache size [%s]", argv[optind] );
			}
			break;

		default:  // Default (unknown)
			fprintf( stderr, "Unknown command line option (%c), aborting.\n", ch );
			return( -1 );
		}
	}

	// Setup the log as needed
	if ( ! log_initialized ) {
		initializeLogWithFilehandle( CMPSC311_LOG_STDERR );
	}
	if ( verbose ) {
		enableLogLevels( LOG_INFO_LEVEL );
	}

	// If running the UNIT test
	if ( unit_test ) {

		// Increase log level, run the UNIT tests
		enableLogLevels( LOG_INFO_LEVEL );
		smsa_unit_test();
		smsa_vread_unit_test();


	} else {

		// The filename should be the next option
		if ( optind >= argc ) {
			// No filename
			fprintf( stderr, "Missing command line parameters, use -h to see usage, aborting.\n" );
			return( -1 );
		}

		// Run the simulation
		if ( simulate_SMSA(argv[optind], cache_size) == 0 ) {

			// Program completed successfully
			logMessage( LOG_INFO_LEVEL, "SMSA simulation completed successfully.\n\n" );

		} else {

			// Program completed unsuccessfully
			logMessage( LOG_INFO_LEVEL, "SMSA simulation failed.\n\n" );

		}
	}

	// Return successfully
	return( 0 );
}
Example #3
0
int main( int argc, char *argv[] ) {
	// Local variables
	int ch, verbose = 0, unit_tests = 0, log_initialized = 0, extract_file = 0;
	uint32_t cache_size = 1024; // Defaults to 1024 cache lines
	char *ex_file = NULL;

	// Process the command line parameters
	while ((ch = getopt(argc, argv, CRUD_ARGUMENTS)) != -1) {

		switch (ch) {
		case 'h': // Help, print usage
			fprintf( stderr, USAGE );
			return( -1 );

		case 'v': // Verbose Flag
			verbose = 1;
			break;

		case 'u': // Unit Tests Flag
			unit_tests = 1;
			break;

		case 'l': // Set the log filename
			initializeLogWithFilename( optarg );
			log_initialized = 1;
			break;

		case 'x': // Set the log filename
			ex_file = optarg;
			extract_file = 1;
			break;

		case 'c': // Set cache line size
			if ( sscanf( optarg, "%u", &cache_size ) != 1 ) {
			    logMessage( LOG_ERROR_LEVEL, "Bad  cache size [%s]", argv[optind] );
                return(-1);
			}
			break;

        case 'a': // Get the IP address
            if (inet_addr(optarg) == INADDR_NONE) {
			    logMessage( LOG_ERROR_LEVEL, "Bad  cache size [%s]", argv[optind] );
                return(-1);
            } 
            crud_network_address = (unsigned char *)strdup(optarg);
			break;

        case 'p': // Set the network port number
			if ( sscanf(optarg, "%hu", &crud_network_port) != 1 ) {
			    logMessage( LOG_ERROR_LEVEL, "Bad  port number [%s]", argv[optind] );
                return(-1);
			}
            break;

		default:  // Default (unknown)
			fprintf( stderr, "Unknown command line option (%c), aborting.\n", ch );
			return( -1 );
		}
	}

	// Setup the log as needed
	if ( ! log_initialized ) {
		initializeLogWithFilehandle( CMPSC311_LOG_STDERR );
	}
	if ( verbose ) {
		enableLogLevels( LOG_INFO_LEVEL );
	}

	// If we are running the unit tests, do that
	if ( unit_tests ) {

		// Enable verbose, run the tests and check the results
		enableLogLevels( LOG_INFO_LEVEL );
		if ( b64UnitTest() || crudIOUnitTest() ) {
			logMessage( LOG_ERROR_LEVEL, "CRUD unit tests failed.\n\n" );
		} else {
			logMessage( LOG_INFO_LEVEL, "CRUD unit tests completed successfully.\n\n" );
		}

	} else if (extract_file) {

		// Extracting a file from the crud file systems
		if (extract_file_from_crud(ex_file) == 0) {
			logMessage(LOG_INFO_LEVEL, "File [%s] extracted from crud successfully.\n\n", ex_file);
		} else {
			logMessage(LOG_ERROR_LEVEL, "File [%s] extraction failed, aborting.\n\n");
		}

	} else {

		// The filename should be the next option
		if ( optind >= argc ) {

			// No filename
			fprintf( stderr, "Missing command line parameters, use -h to see usage, aborting.\n" );
			return( -1 );

		}

		// Run the simulation
		if ( simulate_CRUD(argv[optind]) == 0 ) {
			logMessage( LOG_INFO_LEVEL, "CRUD simulation completed successfully.\n\n" );
		} else {
			logMessage( LOG_INFO_LEVEL, "CRUD simulation failed.\n\n" );
		}
	}

	// Return successfully
	return( 0 );
}