Exemplo n.º 1
0
    virtual inline void   fastSeed(uint64_t seed){
        int i;

        prng.s[0] =  seed;
        prng.s[1] = ~seed;/* Guarantees one of the elements will be non-zero. */

        /**
         * Escape from zero-land (see xorshift128+ paper). Approximately 20
         * iterations required according to the graph.
         */

        for(i=0;i<20;i++){
            fastRandom();
        }
    }
Exemplo n.º 2
0
void InvariantDataRealloc(bool aligned, size_t maxAllocSize, bool checkData)
{
    Harness::FastRandom fastRandom(1);
    size_t size = 0, start = 0;
    char *ptr = NULL,
        // master to create copies and compare ralloc result against it
        *master = (char*)Tmalloc(2*maxAllocSize);

    ASSERT(master, NULL);
    ASSERT(!(2*maxAllocSize%sizeof(unsigned short)),
           "The loop below expects that 2*maxAllocSize contains sizeof(unsigned short)");
    for (size_t k = 0; k<2*maxAllocSize; k+=sizeof(unsigned short))
        *(unsigned short*)(master+k) = fastRandom.get();

    for (int i=0; i<100; i++) {
        // don't want sizeNew==0 here
        const size_t sizeNew = fastRandom.get() % (maxAllocSize-1) + 1;
        char *ptrNew = aligned?
            (char*)Taligned_realloc(ptr, sizeNew, choose_random_alignment())
            : (char*)Trealloc(ptr, sizeNew);
        ASSERT(ptrNew, NULL);
        // check that old data not changed
        if (checkData)
            ASSERT(!memcmp(ptrNew, master+start, min(size, sizeNew)), "broken data");

        // prepare fresh data, copying them from random position in master
        size = sizeNew;
        ptr = ptrNew;
        if (checkData) {
            start = fastRandom.get() % maxAllocSize;
            memcpy(ptr, master+start, size);
        }
    }
    if (aligned)
        Taligned_realloc(ptr, 0, choose_random_alignment());
    else
        Trealloc(ptr, 0);
    Tfree(master);
}