示例#1
0
int
string_test()
{
    grpc_error_t ret;
    char *buffer = NULL;
    char teststring[TEST_STR_LENGTH];
    int i;
    int success = 1;
    int handleInitialized = 0;

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/string_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }
    handleInitialized = 1;

    for (i = 0; i < TEST_STR_LENGTH -1; i++) {
        *(teststring + i) = (i % 10) + '0';
    }
    *(teststring + i) = '\0';

    ret = grpc_call(&handles, teststring, &buffer);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }

    if (strcmp(teststring, buffer) != 0) {
        if (verbose) {
            printf("%s != %s\n", teststring, buffer);
        }
        success = 0;
    }

finalize:
    if (handleInitialized != 0) {
        ret = grpc_function_handle_destruct(&handles);
        if (ret != GRPC_NO_ERROR) {
            fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
                grpc_error_string(ret));
            success = 0;
        }
        handleInitialized = 0;
    }

    /* buffer was allocated in grpc_call() by malloc() */
    free(buffer);

    return success;
}
示例#2
0
int
long_test()
{
    grpc_error_t ret;
    long a[N], b[N];
    int success = 1;
    int i;
    int handleInitialized = 0;

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/long_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, 
            "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }
    handleInitialized = 1;

    for (i = 0; i < N; i++) {
        a[i] = i;
        b[i] = 0;
    }
    ret = grpc_call(&handles, (long)N, a, b);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, 
            "grpc_call() error. (%s)\n", grpc_error_string(ret));
        success = 0;
        goto finalize;
    }

    for (i = 0; i < N; i++) {
        if (a[i] != b[i]) {
            success = 0;
            if (verbose) {
                printf("long_test: a[%d](%ld) != b[%d](%ld)\n",
                    i, a[i], i, b[i]);
            }
        }
    }

finalize:
    if (handleInitialized != 0) {
        ret = grpc_function_handle_destruct(&handles);
        if (ret != GRPC_NO_ERROR) {
            fprintf(stderr, 
                "grpc_function_handle_destruct() error. (%s)\n",
                grpc_error_string(ret));
            success = 0;
        }
        handleInitialized = 0;
    }

    return success;
}
示例#3
0
int
callback_multi_test()
{
    grpc_error_t ret;
    double a[N][N], b[N][N];
    int i, j;
    int rVal = 1;

    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            a[i][j] = i * N + j;
            b[i][j] = 0.0;
        }
    }

    ret = grpc_function_handle_default(&handles,
        MODULE_NAME "/callback_multi_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
        goto end;
    }

    ret = grpc_call(&handles, N, a, b,
        callback_return_func, callback_return_func);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    ret = grpc_function_handle_destruct(&handles);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    if (rVal != 0) {
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) {
                if (a[i][j] != b[i][j]) {
                    rVal = 0;
                    goto end;
                }
            }
        }
    }

end:
    return rVal;
}
示例#4
0
int
callback_string_test()
{
    grpc_error_t ret;
    char *strings[] = {"caller0","caller1","caller2","caller3","caller4"};
    char string[64]= "";
    int i;
    int rVal = 1;

    for (i = 0; i < 5; i++) {
        strcat(string, strings[i]);
    }

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/callbackstr");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
        goto end;
    }

    ret = grpc_call(&handles, strings, callbackstring_func);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    ret = grpc_function_handle_destruct(&handles);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    if (verbose) {
        printf("\ncallbacked = '%s'", callbacked);
    }

    if (verbose) {
        printf("\nfrontend   = '%s'\n", string);
    }

    if (rVal != 0) {
        if (strcmp(callbacked, string) != 0) {
            rVal = 0;
        }
    }

end:
    return rVal;
}
示例#5
0
int
callback_test()
{
    grpc_error_t ret;
    double initial = 100.0, lsum = 0.0;
    int times = 1;
    int rVal = 1;

    sum = 0.0;

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/callback_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
        goto end;
    }

    ret = grpc_call(&handles, initial, times, callback_func);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    ret = grpc_function_handle_destruct(&handles);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
            grpc_error_string(ret));
        rVal = 0;
    }

    if (rVal != 0) {
        int i;
        double d = 0.0;

        for (i = 0; i < times; i++) {
            d += initial;
            lsum += d;
        }
        if (sum != lsum) {
            if (verbose) {
                printf("sum = %f(should be %f)\n", sum, lsum);
            }
            rVal = 0;
        }
    }

end:
    return rVal;
}
示例#6
0
/*
 * Copy from inout-file to out-file and from in-file to inout-file.
 */
int
main(int argc, char *argv[])
{
    grpc_error_t ret;

    if (argc < 5) {
        fprintf(stderr, "Usage: %s config in-file inout-file out-file\n",
            argv[0]);
        exit(2);
    }

    ret = grpc_initialize(argv[1]);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr,
            "grpc_initialize() error. (%s)\n", grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/filename_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_call(&handles, argv[2], argv[3], argv[4]);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_function_handle_destruct(&handles);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_finalize();
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_finalize() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }
 
    return 0;
}
示例#7
0
int
dcomplex_test()
{
    grpc_error_t ret;
    dcomplex scalarIn, scalarOut;
    dcomplex a[N], b[N];
    int success = 1;
    int i;
    int handleInitialized = 0;

    scalarIn.r = 1.0;
    scalarIn.i = 2.0;
    scalarOut.r = 0.0;
    scalarOut.i = 0.0;

    for (i = 0; i < N; i++) {
        a[i].r = i;
        a[i].i = i + 0.1; 
        b[i].r = 0;
        b[i].i = 0; 
    }

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/dcomplex_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }
    handleInitialized = 1;

    ret = grpc_call(&handles, N, scalarIn, a, &scalarOut, b);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }

    if ((scalarOut.r != scalarIn.r) || (scalarOut.i != scalarIn.i)) {
	success = 0;
	if (verbose) {
	    printf("dcomplex_test: scalarIn(%f, %f) != scalarOut(%f, %f)\n",
		scalarIn.r, scalarIn.i, scalarOut.r, scalarOut.i);
	}
    }

    for (i = 0; i < N; i++) {
        if (!compare_double(a[i].r, b[i].r) ||
            !compare_double(a[i].i, b[i].i)) {
            success = 0;
            if (verbose) {
                printf("dcomplex_test: a[%d](%f, %f) != b[%d](%f, %f)\n", 
	            i, a[i].r, a[i].i, i, b[i].r, b[i].i);
            }
        }
    }

finalize:
    if (handleInitialized != 0) {
        ret = grpc_function_handle_destruct(&handles);
        if (ret != GRPC_NO_ERROR) {
            fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
                grpc_error_string(ret));
            success = 0;
        }
        handleInitialized = 0;
    }

    return success;
}
示例#8
0
int
string_array_test()
{
    static const char *in[] = {
        "This is a test for array of string.\n",
        "Hello, World",
        "Sun Mon Tue Wed Thu Fri Sat",
        "ls -- list directory contents",
        "All tests were successful.",
    };

    static const char *answer[] = {
        "Were all tests successful?",
        "Sun Mon Tue Wed Thu Fri Sat",
        "Good morning",
    };

    char *out[3] = {NULL, NULL, NULL};
    grpc_error_t ret;
    int success = 1;
    int handleInitialized = 0;

    ret = grpc_function_handle_default(&handles,
        MODULE_NAME "/string_array_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }
    handleInitialized = 1;

    ret = grpc_call(&handles, in, out);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }

    if (strcmp(out[0], answer[0]) != 0) {
        if (verbose) {
            printf("%s != %s\n", out[0], answer[0]);
        }
        success = 0;
    }

    if (strcmp(out[1], answer[1]) != 0) {
        if (verbose) {
            printf("%s != %s\n", out[1], answer[1]);
        }
        success = 0;
    }

    if (strcmp(out[2], answer[2]) != 0) {
        if (verbose) {
            printf("%s != %s\n", out[2], answer[2]);
        }
        success = 0;
    }

finalize:
    /* out was allocated in grpc_call() by malloc() */
    free(out[0]);
    free(out[1]);
    free(out[2]);

    if (handleInitialized != 0) {
        ret = grpc_function_handle_destruct(&handles);
        if (ret != GRPC_NO_ERROR) {
            fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
                grpc_error_string(ret));
            success = 0;
        }
        handleInitialized = 0;
    }

    return 1;
}
示例#9
0
int
double_test()
{
    grpc_error_t ret;
    double scalarIn, scalarOut;
    double a[N], b[N];
    int success = 1;
    int i;
    int handleInitialized = 0;

    ret = grpc_function_handle_default(&handles, MODULE_NAME "/double_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }
    handleInitialized = 1;

    scalarIn = 1.0;
    scalarOut = 0.0;

    for (i = 0; i < N; i++) {
        a[i] = i;
        b[i] = 0;
    }

    ret = grpc_call(&handles, N, scalarIn, a, &scalarOut, b);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        success = 0;
        goto finalize;
    }

    if (scalarOut != scalarIn) {
	success = 0;
	if (verbose) {
	    printf("double_test: scalarIn(%f) != scalarOut(%f)\n",
		scalarIn, scalarOut);
	}
    }

    for (i = 0; i < N; i++) {
        if (!compare_double(a[i],b[i])) {
            success = 0;
            if (verbose) {
                printf("double_test: a[%d](%f) != b[%d](%f)\n",
                    i, a[i], i, b[i]);
            }
        }
    }

finalize:
    if (handleInitialized != 0) {
        ret = grpc_function_handle_destruct(&handles);
        if (ret != GRPC_NO_ERROR) {
            fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
                grpc_error_string(ret));
            success = 0;
        }
        handleInitialized = 0;
    }

    return success;
}
示例#10
0
/*
 * Copy from inout-file to out-file and from in-file to inout-file.
 */
int
main(int argc, char *argv[])
{
    grpc_error_t ret;
    int result;
    char *conf, *array_size_str, *end;
    int array_size;
    char **in_file_array, **inout_file_array, **out_file_array;
    char *in_file, *inout_file, *out_file;

    if (argc < 6) {
        fprintf(stderr, "Usage: %s config count in-file inout-file out-file\n",
            argv[0]);
        exit(2);
    }

    conf = argv[1];
    array_size_str = argv[2];
    in_file = argv[3];
    inout_file = argv[4];
    out_file = argv[5];

    ret = grpc_initialize(conf);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr,
            "grpc_initialize() error. (%s)\n", grpc_error_string(ret));
        exit(2);
    }

    array_size = strtol(array_size_str, &end, 0);
    if (*end != '\0') {
        fprintf(stderr, "Argument \"%s\" is not digit.\n", array_size_str);
        exit(1);
    } else if (array_size < 1){
        fprintf(stderr, "array_size %d < 1 (min)\n", array_size);
        exit(1);
    }

    result = create_file_names(array_size, in_file, inout_file, out_file,
        &in_file_array, &inout_file_array, &out_file_array);
    if (result == 0) {
        fprintf(stderr, "creating filenames failed\n");
        exit(1);
    }

    result = check_files(array_size, in_file_array, inout_file_array);
    if (result == 0) {
        fprintf(stderr, "files are not prepared. no test performed.\n");
        exit(1);
    }

    ret = grpc_function_handle_default(
        &handles, MODULE_NAME "/filename_array_test");
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_default() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_call(&handles,
        array_size, in_file_array, inout_file_array, out_file_array);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_call() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_function_handle_destruct(&handles);
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    ret = grpc_finalize();
    if (ret != GRPC_NO_ERROR) {
        fprintf(stderr, "grpc_finalize() error. (%s)\n",
            grpc_error_string(ret));
        exit(2);
    }

    result = destroy_file_names(array_size, &in_file_array, &inout_file_array, &out_file_array);
    if (result == 0) {
        fprintf(stderr, "destroying filenames failed\n");
        exit(1);
    }
 
    return 0;
}