Example #1
0
static int
check_constraints( Modification *mod, int *newlevel )
{
	int		i;

	if ( mod->sm_nvalues != NULL ) {
		ber_bvarray_free( mod->sm_nvalues );
		mod->sm_nvalues = NULL;
	}

	for ( i = 0; !BER_BVISNULL( &mod->sm_values[ i ] ); i++ ) {
		int		l;
		struct berval	bv;

		if ( str2loglevel( mod->sm_values[ i ].bv_val, &l ) ) {
			return LDAP_CONSTRAINT_VIOLATION;
		}

		if ( loglevel2bv( l, &bv ) ) {
			return LDAP_CONSTRAINT_VIOLATION;
		}
		
		assert( bv.bv_len == mod->sm_values[ i ].bv_len );
		
		AC_MEMCPY( mod->sm_values[ i ].bv_val,
				bv.bv_val, bv.bv_len );

		*newlevel |= l;
	}

	return LDAP_SUCCESS;
}	
Example #2
0
static int handle_args(int argc, char *argv[], struct app_params *p)
{
    int c, idx;
    bool ok;
    bladerf_log_level log_level;

    /* Print help */
    if (argc == 1) {
        return 1;
    }

    while ((c = getopt_long(argc, argv, OPTSTR, long_options, &idx)) >= 0) {
        switch (c) {
            case 'v':
                log_level = str2loglevel(optarg, &ok);
                if (!ok) {
                    fprintf(stderr, "Invalid log level: %s\n", optarg);
                    return -1;
                } else {
                    bladerf_log_set_verbosity(log_level);
                }
                break;

            case 'h':
                return 1;

            case 'd':
                if (p->device_str != NULL) {
                    fprintf(stderr, "Device already specified: %s\n",
                            p->device_str);
                    return -1;
                } else {
                    p->device_str = strdup(optarg);
                    if (p->device_str == NULL) {
                        perror("strdup");
                        return -1;
                    }
                }
                break;

            case 's':
                p->samplerate = str2uint_suffix(optarg,
                                                BLADERF_SAMPLERATE_MIN,
                                                BLADERF_SAMPLERATE_REC_MAX,
                                                freq_suffixes,
                                                ARRAY_SIZE(freq_suffixes),
                                                &ok);
                if (!ok) {
                    fprintf(stderr, "Invalid sample rate: %s\n", optarg);
                    return -1;
                }
                break;

            case 'B':
                p->buf_size = str2uint_suffix(optarg,
                                              1024,
                                              UINT_MAX,
                                              len_suffixes,
                                              ARRAY_SIZE(len_suffixes),
                                              &ok);

                if (!ok || (p->buf_size % 1024) != 0) {
                    fprintf(stderr, "Invalid buffer length: %s\n", optarg);
                    return -1;
                }

                break;

            case 't':
                p->test_name = strdup(optarg);
                if (p->test_name == NULL) {
                    perror("strdup");
                    return -1;
                }
                break;

            case 'S':
                p->prng_seed = str2uint64(optarg, 1, UINT64_MAX, &ok);
                if (!ok) {
                    fprintf(stderr, "Invalid seed value: %s\n", optarg);
                    return -1;
                }
                break;

            default:
                return -1;
        }
    }

    return 0;
}
Example #3
0
int handle_cmdline(int argc, char *argv[], struct test_params *p)
{
    int c;
    int idx;
    bool ok;
    bladerf_log_level level;

    test_init_params(p);

    while ((c = getopt_long(argc, argv, OPTSTR, long_options, &idx)) >= 0) {
        switch (c) {

            case 1:
                level = str2loglevel(optarg, &ok);
                if (!ok) {
                    log_error("Invalid log level provided: %s\n", optarg);
                    return -1;
                } else {
                    log_set_verbosity(level);
                }
                break;

            case 2:
                level = str2loglevel(optarg, &ok);
                if (!ok) {
                    log_error("Invalid log level provided: %s\n", optarg);
                    return -1;
                } else {
                    bladerf_log_set_verbosity(level);
                }
                break;

            case 'h':
                return 1;

            case 'd':
                if (p->device_str != NULL) {
                    log_error("Device was already specified.\n");
                    return -1;
                }

                p->device_str = strdup(optarg);
                if (p->device_str == NULL) {
                    perror("strdup");
                    return -1;
                }
                break;

            case 's':
                p->samplerate = str2uint_suffix(optarg,
                                                BLADERF_SAMPLERATE_MIN,
                                                BLADERF_SAMPLERATE_REC_MAX,
                                                freq_suffixes,
                                                num_freq_suffixes,
                                                &ok);
                if (!ok) {
                    log_error("Invalid sample rate: %s\n", optarg);
                    return -1;
                }
                break;

            case 'f':
                p->frequency = str2uint_suffix(optarg,
                                               BLADERF_FREQUENCY_MIN,
                                               BLADERF_FREQUENCY_MAX,
                                               freq_suffixes,
                                               num_freq_suffixes,
                                               &ok);
                if (!ok) {
                    log_error("Invalid frequency: %s\n", optarg);
                    return -1;
                }
                break;

            case 'l':
                if (str2loopback(optarg, &p->loopback) != 0) {
                    log_error("Invalid loopback mode: %s\n", optarg);
                    return -1;
                }
                break;

            case 'i':
                if (p->in_file) {
                    log_error("Input file already provided.\n");
                    return -1;
                }

                p->in_file = fopen(optarg, "rb");
                if (p->in_file == NULL) {
                    log_error("Failed to open input file - %s\n",
                            strerror(errno));
                    return -1;
                }
                break;

            case 'o':
                if (p->out_file) {
                    log_error("Output file already provided.\n");
                    return -1;
                }

                p->out_file = fopen(optarg, "wb");
                if (p->out_file == NULL) {
                    log_error("Failed to open output file - %s\n",
                            strerror(errno));
                    return -1;
                }
                break;

            case 'r':
                p->tx_repetitions = str2uint_suffix(optarg, 1, UINT_MAX,
                                                    count_suffixes,
                                                    num_count_suffixes,
                                                    &ok);
                if (!ok) {
                    log_error("Invalid TX repetition value: %s\n", optarg);
                    return -1;
                }

                break;

            case 'c':
                p->rx_count = str2uint_suffix(optarg, 1, UINT_MAX,
                                              count_suffixes,
                                              num_count_suffixes,
                                              &ok);
                if (!ok) {
                    log_error("Invalid RX count: %s\n", optarg);
                    return -1;
                }

                break;

            case 'b':
                p->block_size = str2uint_suffix(optarg, 1, UINT_MAX,
                                                size_suffixes,
                                                num_size_suffixes,
                                                &ok);

                if (!ok) {
                    log_error("Invalid block size: %s\n", optarg);
                    return -1;
                }
                break;

            case 'X':
                p->num_xfers = str2uint(optarg, 1, UINT_MAX, &ok);
                if (!ok) {
                    log_error("Invalid stream transfer count: %s\n", optarg);
                    return -1;
                }
                break;

            case 'B':
                p->stream_buffer_size = str2uint(optarg, 1, UINT_MAX, &ok);
                if (!ok) {
                    log_error("Invalid stream buffer size: %s\n", optarg);
                    return -1;
                }
                break;

            case 'C':
                p->stream_buffer_count = str2uint(optarg, 1, UINT_MAX, &ok);
                if (!ok) {
                    log_error("Invalid stream buffer count: %s\n", optarg);
                    return -1;
                }
                break;

            case 'T':
                p->timeout_ms = str2uint(optarg, 0, UINT_MAX, &ok);
                if (!ok) {
                    log_error("Invalid stream timeout: %s\n", optarg);
                    return -1;
                }
                break;
        }
    }

    if (p->in_file == NULL && p->out_file == NULL) {
        log_error("An input or output file is required.\n");
        return -1;
    }

    if (p->frequency == 0) {
        p->frequency = DEFAULT_FREQUENCY;
    }

    if (p->samplerate == 0) {
        p->samplerate = DEFAULT_SAMPLERATE;
    }

    if (p->tx_repetitions == 0) {
        p->tx_repetitions = DEFAULT_TX_REPETITIONS;
    }

    if (p->rx_count == 0) {
        p->rx_count = DEFAULT_RX_COUNT;
    }

    if (p->block_size == 0) {
        p->block_size = DEFAULT_BLOCK_SIZE;
    }

    return 0;
}
Example #4
0
/* Parse a single option. */
static int opts_parse_opt(const char *cmd,
                          int key, char *arg, struct opts *opts)
{
    struct event event;
    struct event *event_node;

    memset(&event, 0, sizeof(event));

    switch (key) {
        case 'T':
            _req_opt('T')->cnt++;
            opts->htime = arg ? atoi(arg) : -1;
            break;
        case 'P':
            _req_opt('T')->cnt++;
            opts->ptime = arg ? atoi(arg) : -1;
            break;
        case 'c':
            _req_opt('c')->cnt++;
            strncpy(opts->ftrace_clock, arg, NAME_MAX);
            break;
        case 's':
            _req_opt('s')->cnt++;
            opts->ftrace_buffsz = arg ? atoi(arg) : -1;
            break;
        case 'v':
            _req_opt('v')->cnt++;
            if (arg[0] >= '0' && arg[0] <= '9')
                *opts->loglevel = arg ? atoi(arg) : 0;
            else {
                int ok;
                *opts->loglevel = str2loglevel(arg, &ok);
                if (!ok)
                    LOGW("loglevel [%s] invalid. Falling back to default\n",
                         arg);
            }
            break;
        case 'z':
            _req_opt('z')->cnt++;
            opts->daemon = 1;
            break;
        case 'm':
            _req_opt('m')->cnt++;
            strncpy(opts->debugfs_path, arg, PATH_MAX);
            break;
        case 'w':
            _req_opt('w')->cnt++;
            strncpy(opts->workdir, arg, PATH_MAX);
            break;
        case 'o':
            _req_opt('o')->cnt++;
            strncpy(opts->outfname, arg, PATH_MAX);
            break;
        case 'p':
            _req_opt('p')->cnt++;
            opts->pid = arg ? atoi(arg) : 0;
            break;
        case 't':
            _req_opt('t')->cnt++;
            opts->threads = 1;
            break;
        case 'e':
            _req_opt('e')->cnt++;
            strncpy(event.name, arg, PATH_MAX);
            event.id = uq_eid++;
            assert_np(mlist_add_last(etrace.event_list, &event));
            break;
        case 'f':
            _req_opt('f')->cnt++;
            assert_np(event_node = mdata_curr(etrace.event_list));
            if (event_node->filter
                && strnlen(event_node->filter, FILTER_MAX) > 0) {

                LOGE("Filer [%s] is overwritten by [%s] for event [%s] (#%d)",
                     event_node->filter, arg, event_node->name,
                     mlist_len(etrace.event_list));

                LOGE("Check order for options -e and -f\n");
                return E_OPT_USAGE;
            }
            event_node->filter = strndup(arg, FILTER_MAX);
            break;
        case 'i':
            _req_opt('i')->cnt++;
            opts->rid = arg ? atoi(arg) : 0;
            break;
        case 'u':
            _req_opt('u')->cnt++;
            opts_help(stdout, HELP_USAGE | HELP_EXIT);
            break;
        case 'h':
            _req_opt('h')->cnt++;
            opts_help(stdout, HELP_LONG | HELP_EXIT);
            break;
        case 'D':
            _req_opt('D')->cnt++;
            doc_print();
            etrace_exit(0);
            break;
        case '?':
            /* getopt_long already printed an error message. */
            opts_help(stderr, HELP_TRY | HELP_EXIT_ERR);
            break;
        case ':':
            /* getopt_long already printed an error message. */
            fprintf(stderr, "%s: option `-%c' requires an argument\n",
                    cmd, optopt);
            opts_help(stderr, HELP_TRY | HELP_EXIT_ERR);
            break;
        case 'V':
            _req_opt('V')->cnt++;
            opts_help(stdout, HELP_VERSION | HELP_EXIT);
            break;
        default:
            fprintf(stderr, "etrace: unrecognized option '-%c'\n", (char)key);
            opts_help(stderr, HELP_TRY | HELP_EXIT_ERR);
            break;
    }
    return OPT_OK;
}
Example #5
0
int get_params(int argc, char *argv[], struct app_params *p)
{
    int c, idx;
    bool ok;
    bladerf_log_level level;

    memset(p, 0, sizeof(p[0]));
    p->randval_seed = 1;

    while((c = getopt_long(argc, argv, OPTARG, long_options, &idx)) != -1) {
        switch (c) {
            case 'd':
                if (p->device_str) {
                    fprintf(stderr, "Device already specified!\n");
                    return -1;
                } else {
                    p->device_str = strdup(optarg);
                    if (p->device_str == NULL) {
                        perror("strdup");
                        return -1;
                    }
                }
                break;

            case 't':
                if (p->test_name) {
                    fprintf(stderr, "Test already specified!\n");
                    return -1;
                } else {
                    p->test_name = strdup(optarg);
                    if (p->test_name == NULL) {
                        perror("strdup");
                        return -1;
                    }
                }
                break;

            case 's':
                p->randval_seed = str2uint64(optarg, 1, UINT64_MAX, &ok);
                if (!ok) {
                    fprintf(stderr, "Invalid seed value: %s\n", optarg);
                    return -1;
                }
                break;

            case 'h':
                usage(argv[0]);
                return 1;

            case 1:
                p->use_xb200 = true;
                break;

            case 'L':
                list_tests();
                return 1;

            case 'v':
                level = str2loglevel(optarg, &ok);
                if (ok) {
                    bladerf_log_set_verbosity(level);
                } else {
                    fprintf(stderr, "Invalid log level: %s\n", optarg);
                    return -1;
                }
                break;

            default:
                return -1;
        }
    }

    return 0;
}