Beispiel #1
0
int main(int argc, char *argv[])
{
    double now = get_current_time();
    int result = 0;
    int do_loop = 1;

    if (argc > 1) {
        if (strcmp(argv[1], "-h")==0
            || strcmp(argv[1], "--help")==0)
        {
            printf("Usage: testmany [num_sources=5] [num_dests=5] "
                   "[max_num_signals=4] [loop=1]\n");
            exit(0);
        }
        else
            num_sources = atoi(argv[1]);
    }

    if (argc > 2)
        num_dests = atoi(argv[2]);

    if (argc > 3)
        max_num_signals = atoi(argv[3]);

    if (argc > 4)
        do_loop = atoi(argv[4]);

    source_device_list = (mapper_device*)malloc(
        sizeof(mapper_device)*num_sources);

    dest_device_list = (mapper_device*)malloc(
        sizeof(mapper_device)*num_dests);

    num_signals = (int*)malloc(sizeof(int)*(num_sources + num_dests));

    signal(SIGINT, ctrlc);
	srand( time(NULL) );

	for (int i=0; i<num_sources+num_dests; i++) {

		num_signals[i] = (rand() % max_num_signals) + 1;

	}

    if (setup_sources()) {
        printf("Error initializing sources.\n");
        result = 1;
        goto done;
    }
    if (setup_destinations()) {
        printf("Error initializing destinations.\n");
        result = 1;
        goto done;
    }

    wait_local_devices(&done);
    now = get_current_time() - now;
    printf("Allocated %d devices in %f seconds.\n", num_sources + num_dests, now);

    if (do_loop)
        loop();

  done:
    cleanup_destinations();
    cleanup_sources();

    free(source_device_list);
    free(dest_device_list);
    free(num_signals);

    return result;
}
Beispiel #2
0
int main(int argc, char **argv)
{
    int i, j, result = 0;

    // process flags for -v verbose, -t terminate, -h help
    for (i = 1; i < argc; i++) {
        if (argv[i] && argv[i][0] == '-') {
            int len = strlen(argv[i]);
            for (j = 1; j < len; j++) {
                switch (argv[i][j]) {
                    case 'h':
                        printf("testcombiner.c: possible arguments "
                               "-q quiet (suppress output), "
                               "-t terminate automatically, "
                               "-h help\n");
                        return 1;
                        break;
                    case 'q':
                        verbose = 0;
                        break;
                    case 't':
                        terminate = 1;
                        break;
                    case '-':
                        if (strcmp(argv[i], "--sources")==0 && argc>i+1) {
                            i++;
                            num_sources = atoi(argv[i]);
                            if (num_sources <= 0)
                                num_sources = 1;
                            j = 1;
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }

    signal(SIGINT, ctrlc);

    if (setup_destination()) {
        eprintf("Error initializing destination.\n");
        result = 1;
        goto done;
    }

    if (setup_sources()) {
        eprintf("Done initializing %d sources.\n", num_sources);
        result = 1;
        goto done;
    }

    wait_ready(&done);

    if (autoconnect && setup_maps()) {
        eprintf("Error setting map.\n");
        result = 1;
        goto done;
    }

    loop();

    if (sent != received) {
        eprintf("Not all sent messages were received.\n");
        eprintf("Updated value %d time%s, but received %d of them.\n",
                sent, sent == 1 ? "" : "s", received);
        result = 1;
    }

  done:
    cleanup_destination();
    cleanup_source();
    printf("Test %s.\n", result ? "FAILED" : "PASSED");
    return result;
}