Exemplo n.º 1
0
/* ARGSUSED */
Void smain(Int argc, Char * argv[])
{
    BUFRES_Args        args;
    BUFRES_Handle      bufres[10];
    BUFRES_Params      config;
    IRES_Status        status;
    Int                scratchId;
    Void              *base;
    Bool               passed = FALSE;

    config.iresConfig.size = sizeof(BUFRES_Params);
    config.iresConfig.allocFxn = DSKT2_allocPersistent;
    config.iresConfig.freeFxn = DSKT2_freePersistent;

    config.base = (Void *)&BUFMEM_base;
    config.length = (UInt32)&BUFMEM_end - (UInt32)&BUFMEM_base + 1;

    status = BUFRES_init(&config);

    if (status != IRES_OK) {
        /* Test failed */
        goto done;
    }
    else {
        /* Allocate a bunch of resources */
        args.iresArgs.size = sizeof(BUFRES_Args);
        args.iresArgs.mode = IRES_SCRATCH;
        args.align = 8;
        args.length = 0x18;

        scratchId = 1;
        if ((bufres[0] = BUFRES_get((IALG_Handle)NULL, &args, scratchId, 
                &status)) == NULL) {
            goto done;
        }
        else {
            base = bufres[0]->base;
            status = BUFRES_free((IALG_Handle)NULL, bufres[0], &args, 
                    scratchId);
            bufres[0] = NULL;
            if (status != IRES_OK) {
                goto done;
            }
        }

        args.iresArgs.mode = IRES_PERSISTENT;
        bufres[0] =  BUFRES_get((IALG_Handle) NULL, &args, scratchId, &status);

        if (bufres[0] == NULL) {
            printf("BUFRES_get() failed [0x%x]\n", status);
            goto done;
        }
        else {
            /* Should get the same base address as before */
            if (base != bufres[0]->base) {
                printf("BUFRES_get() returned wrong base address [0x%x] "
                        "should have been [0x%x]\n",
                        bufres[0]->base, base);
                goto done;
            }
        }

        /* Should not be allowed to allocate another persistent buffer */
        args.iresArgs.mode = IRES_PERSISTENT;
        if ((bufres[1] = BUFRES_get((IALG_Handle)NULL, &args, scratchId, 
                &status)) != NULL) {
            goto done;
        }

        /* Should not be allowed to allocate another scratch buffer */
        args.iresArgs.mode = IRES_SCRATCH;
        bufres[1] = BUFRES_get((IALG_Handle)NULL, &args, scratchId, &status);
        if (bufres[1] != NULL) {
            printf("BUFRES_get() failed to fail for scratch resource [0x%x]\n",
                    status);
            goto done;
        }

        status = BUFRES_free((IALG_Handle)NULL, bufres[0], &args, scratchId);
        bufres[0] = NULL;
        if (status != IRES_OK) {
            printf("BUFRES_free() failed [0x%x]\n", status);
            goto done;
        }
        args.iresArgs.mode = IRES_SCRATCH;
        bufres[0] = BUFRES_get((IALG_Handle)NULL, &args, scratchId, &status);
        if (bufres[0] == NULL) {
            printf("BUFRES_get() failed for scratch resource [0x%x]\n",
                    status);
            goto done;
        }

        /* Should not be allowed to allocate scratch buffer in another group */
        args.iresArgs.mode = IRES_SCRATCH;
        bufres[1] = BUFRES_get((IALG_Handle)NULL, &args, scratchId + 1,
                &status);
        if (bufres[1] != NULL) {
            printf("BUFRES_get() failed to fail for allocating scratch "
                    "resource from another group [0x%x]\n", status);
            goto done;
        }

        /* Allowed to allocate another scratch buffer in same group */
        bufres[1] = BUFRES_get((IALG_Handle)NULL, &args, scratchId, &status);
        if (bufres[1] == NULL) {
            printf("BUFRES_get() failed for second scratch resource [0x%x]\n",
                    status);
            goto done;
        }
        if (bufres[1]->base != bufres[0]->base) {
            printf("BUFRES_get() failed: bufres[1]->base [0x%x] different "
                    "from bufres[0]->base [0x%x]\n", bufres[1]->base,
                    bufres[0]->base);
            goto done;
        }
        BUFRES_free((IALG_Handle)NULL, bufres[0], &args, scratchId);
        BUFRES_free((IALG_Handle)NULL, bufres[1], &args, scratchId);
        bufres[0] = bufres[1] = NULL;

        passed = TRUE;
    }

done:
    if (passed) {
        printf("TEST PASSED\n");
    }
    else {
        printf("TEST FAILED\n");
    }
}
/* ARGSUSED */
Void smain(Int argc, Char * argv[])
{
    BUFRES_Args        args;
    BUFRES_Handle      bufres[10];
    IRES_Status        status;
    Int                scratchId;
    Void              *base;
    Bool               passed = FALSE;
    IRES_ResourceDescriptor resDesc;
    IRES_ProtocolRevision rev= {1,0,0};


    resDesc.resourceName = "BUFRES_PROTOCOLNAME";
    resDesc.revision = &rev;
    resDesc.protocolArgs = (IRES_ProtocolArgs *)&args;
    /* Allocate a bunch of resources */
    resDesc.protocolArgs->size = sizeof(BUFRES_Args);
    resDesc.protocolArgs->mode = IRES_SCRATCH;

    args.align = 8;
    args.length = 0x18;

    scratchId = 1;
    if ((bufres[0] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId,
                                &status)) == NULL) {
        goto done;
    }
    else {
        base = bufres[0]->base;
        status = BUFRES_free((IALG_Handle)NULL, bufres[0], &resDesc,
                             scratchId);
        bufres[0] = NULL;
        if (status != IRES_OK) {
            goto done;
        }
    }

    resDesc.protocolArgs->mode = IRES_PERSISTENT;
    if ((bufres[0] = BUFRES_get((IALG_Handle) NULL, &resDesc, scratchId,
                                &status)) == NULL) {
        goto done;
    }
    else {
        /* Should get the same base address as before */
        if (base != bufres[0]->base) {
            goto done;
        }
    }

    /* Should not be allowed to allocate another persistent buffer */
    resDesc.protocolArgs->mode = IRES_PERSISTENT;
    if ((bufres[1] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId,
                                &status)) != NULL) {
        goto done;
    }

    /* Should not be allowed to allocate another scratch buffer */
    resDesc.protocolArgs->mode = IRES_PERSISTENT;
    bufres[1] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId, &status);
    if (bufres[1] != NULL) {
        goto done;
    }

    status = BUFRES_free((IALG_Handle)NULL, bufres[0], &resDesc, scratchId);
    bufres[0] = NULL;
    if (status != IRES_OK) {
        goto done;
    }
    resDesc.protocolArgs->mode = IRES_SCRATCH;
    bufres[0] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId, &status);
    if (bufres[0] == NULL) {
        goto done;
    }

    /* Should not be allowed to allocate scratch buffer in another group */
    resDesc.protocolArgs->mode = IRES_SCRATCH;
    bufres[1] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId + 1, &status);
    if (bufres[1] != NULL) {
        goto done;
    }

    /* Allowed to allocate another scratch buffer in same group */
    bufres[1] = BUFRES_get((IALG_Handle)NULL, &resDesc, scratchId, &status);
    if (bufres[1] == NULL) {
        goto done;
    }
    if (bufres[1]->base != bufres[0]->base) {
        goto done;
    }
    BUFRES_free((IALG_Handle)NULL, bufres[0], &resDesc, scratchId);
    BUFRES_free((IALG_Handle)NULL, bufres[1], &resDesc, scratchId);
    bufres[0] = bufres[1] = NULL;

    passed = TRUE;

done:
    if (passed) {
        System_printf("TEST PASSED\n");
    }
    else {
        System_printf("TEST FAILED\n");
    }
}