Exemplo n.º 1
0
long long
test(char** tname)
    {
    int i;
    pSmRegion r;
    int iter;
    int j,k;
    void* alloc[1024];

	smInitialize();

	*tname = "smmalloc-03 malloc/free 1MB, free order = LIFO, size=1K";
	iter = 300;
	r = smCreate(1024*1024);
	for(i=0;i<iter;i++)
	    {
	    j=0;
	    while((alloc[j] = smMalloc(r,1024)) != NULL && j < 1023) j++;
	    if (j < 950)
		{
		smDestroy(r);
		return -1;
		}
	    k = j;
	    while(k > 0)
		{
		k--;
		smFree(alloc[k]);
		}
	    }
	smDestroy(r);

    return iter*j;
    }
Exemplo n.º 2
0
void __attribute__((weak)) __appInit(void)
{
    Result rc;

    // Initialize default services.
    rc = smInitialize();
    if (R_FAILED(rc))
        fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));

    rc = appletInitialize();
    if (R_FAILED(rc))
        fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_AM));

    if (__nx_applet_type != AppletType_None) {
        rc = hidInitialize();
        if (R_FAILED(rc))
            fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID));
    }

    rc = timeInitialize();
    if (R_FAILED(rc))
        fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_Time));

    rc = fsInitialize();
    if (R_FAILED(rc))
        fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));

    fsdevMountSdmc();
}
Exemplo n.º 3
0
long long
test(char** tname)
{
    int i;
    pSmRegion r;
    int iter;
    int j,k,l,t;
    void* alloc[1024];
    int cnt[1024];

    smInitialize();

    *tname = "smmalloc-07 reference counting (randomized free order)";
    srand(time(NULL));
    iter = 300;
    r = smCreate(1024*1024);
    for(i=0; i<iter; i++)
    {
        j=0;
        /** allocate **/
        while((alloc[j] = smMalloc(r,1 + rand()%8192)) != NULL && j < 1023)
        {
            cnt[j++] = 1;
        }
        if (j < 120)
        {
            smDestroy(r);
            return -1;
        }
        /** link **/
        for(k=0; k<1024; k++)
        {
            l = rand()%j;
            smLinkTo(alloc[l]);
            cnt[l]++;
        }
        /** free **/
        t = j + 1024;
        for(k=0; k<t*4/5; k++)
        {
            while (cnt[(l = rand()%j)] == 0)
                ;
            smFree(alloc[l]);
            cnt[l]--;
            if (!cnt[l]) alloc[l] = NULL;
        }
        for(k=0; k<j; k++)
        {
            if (alloc[k])
            {
                for(l=0; l<cnt[k]; l++) smFree(alloc[k]);
            }
            alloc[k] = NULL;
        }
    }
    smDestroy(r);

    return iter*t;
}
Exemplo n.º 4
0
long long
test(char** tname)
    {
    int i;
    pSmRegion r;
    int iter;
    int j,k,l;
    void* alloc[1024];

	smInitialize();

	*tname = "smmalloc-05 malloc/free 1MB, free order = random, size=1K";
	srand(time(NULL));
	iter = 300;
	r = smCreate(1024*1024);
	for(i=0;i<iter;i++)
	    {
	    j=0;
	    while((alloc[j] = smMalloc(r,1024)) != NULL && j < 1023) j++;
	    if (j < 950)
		{
		smDestroy(r);
		return -1;
		}
	    for(k=0;k<j*4/5;k++)
		{
		while (alloc[(l = rand()%j)] == NULL)
		    ;
		smFree(alloc[l]);
		alloc[l] = NULL;
		}
	    for(k=0;k<j;k++)
		{
		if (alloc[k]) smFree(alloc[k]);
		alloc[k] = NULL;
		}
	    }
	smDestroy(r);

    return iter*j;
    }