Пример #1
0
static void _ibprof_conf_init(void)
{
	char *env;
	env = getenv("IBPROF_MODE");
	if (env)
		_ibprof_conf_mode(env);

	env = getenv("IBPROF_TEST_MASK");
	if (env)
		*(uint32_t *) enviroment[IBPROF_TEST_MASK] = sys_strtol(env, NULL, 0);

	env = getenv("IBPROF_OUTPUT_PREFIX");
	if (env)
		*(int *) enviroment[IBPROF_OUTPUT_PREFIX] = sys_strtol(env, NULL, 0);

	env = getenv("IBPROF_WARMUP_NUMBER");
	if (env)
		*(int *) enviroment[IBPROF_WARMUP_NUMBER] = sys_strtol(env, NULL, 0);

	env = getenv("IBPROF_DUMP_FILE");
	if (env)
		_ibprof_conf_dump_file(env);

	env = getenv("IBPROF_FORMAT");
	if (env)
		enviroment[IBPROF_FORMAT] = (void *) env;

	env = getenv("IBPROF_ERR_PERCENT");
	if (env)
		*(int *) enviroment[IBPROF_ERR_PERCENT] = sys_strtol(env, NULL, 0);

	env = getenv("IBPROF_ERR_SEED");
	if (env) {
		*(int *) enviroment[IBPROF_ERR_SEED] = sys_strtol(env, NULL, 0);
		srand(*(int *) enviroment[IBPROF_ERR_SEED]);
	}

	env = getenv("IBPROF_TIME_UNITS");
	if (env) {
		uint8_t val = sys_strtol(env, NULL, 0);
		if (val < IBPROF_TIME_UNITS_LAST)
			*(int *) enviroment[IBPROF_TIME_UNITS] = val;
	}
}
Пример #2
0
static int __parse_opt( const TE_NODE *node, int argc, const char *argv[] )
{
    OSH_ERROR status = OSH_ERR_NONE;
	const AOPT_OBJECT* self_opt_obj = NULL;

	/* Load supported option and create option objects */
	{
		int temp_argc = 0;

		temp_argc = argc;
		self_opt_obj = aopt_init(&temp_argc, (const char **)argv, self_opt_desc);
	}

    /* Parse specific options */
	if (!status && self_opt_obj)
    {
        if ( !status && aopt_check(self_opt_obj, 'm') )
        {
            const char* optarg = aopt_value(self_opt_obj, 'm');
            if (optarg)
            {
                errno = 0;
                long value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value > 0) )
                {
                    __max_buffer_size = (int)value;
                }
                else
                {
                    status = OSH_ERR_BAD_ARGUMENT;
                }
            }
            else
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(self_opt_obj, 'c') )
        {
            const char* optarg = aopt_value(self_opt_obj, 'c');
            if (optarg)
            {
                errno = 0;
                long value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value > 0) )
                {
                    __cycle_count = (int)value;
                }
                else
                {
                    status = OSH_ERR_BAD_ARGUMENT;
                }
            }
            else
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }
	}

    if (status)
    {
        /* Display help information */
        const char* help_str = NULL;
        char temp_buf[30];

        log_help("%s: %s\n", display_opt(node, temp_buf, sizeof(temp_buf)), node->note);
        log_help("\n");
        log_help("Options:\n");
        help_str = aopt_help(self_opt_desc);
        if (help_str)
        {
            log_help("%s\n", help_str);
            sys_free((void*)help_str);
        }
    }

    aopt_exit((AOPT_OBJECT*)self_opt_obj);

    return status;
}
Пример #3
0
static int __parse_common_opt( const AOPT_OBJECT* opt_obj )
{
    OSH_ERROR status = OSH_ERR_NONE;

    if (opt_obj) 
    {
        if ( !status && aopt_check(opt_obj, 'o') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'o');
            long value = -1;
            if (optarg) 
            {
                errno = 0;
                value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value >= LOG_NONE) ) 
                {
                    osh_config.exec_mode.out_level = (int)value;
                }
            }
            if ( value == -1 ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'd') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'd');
            long value = -1;
            if (optarg) 
            {
                errno = 0;
                value = sys_strtol(optarg, NULL, 0);
                if ( !errno && (value >= LOG_NONE) ) 
                {
                    osh_config.exec_mode.log_level = (int)value;
                }
            }
            if ( value == -1 ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'l') ) 
        {
            const char * optarg = aopt_value(opt_obj, 'l');
            char* value = NULL;
            if (optarg) 
            {
                value = sys_strdup(optarg);
                if ( value )
                {
                    if (osh_config.exec_mode.log_file_name)
                    {
                        sys_free(osh_config.exec_mode.log_file_name);
                    }
                    osh_config.exec_mode.log_file_name = value;
                }
            }
            if ( !value )
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }

        if ( !status && aopt_check(opt_obj, 'p') ) 
        {
            const char* optarg = aopt_value(opt_obj, 'p');
            unsigned long long value = 0;
            if (optarg) 
            {
                if (!sys_strcmp(optarg, "all"))
                {
                    value = INVALID_PE;
                }
                else
                {
                    value = set_pe_list(optarg);
                }
                osh_config.exec_mode.log_pe_list = value;
            }
            if ( !value ) 
            {
                status = OSH_ERR_BAD_ARGUMENT;
            }
        }
    }

    return status;
}