Ejemplo n.º 1
0
/*
 * Unit test framework entry point for this set of unit tests.
 *
 */
void testMem_runTests() {
  pcsl_mem_initialize(NULL, 5000);

  testAllocation();
  testMalloc();
  testAllocateChunk();
  /*
   * comment out this test. The implementation changes the
   * specified max size, to align with a page
   * need revisit: what the new max size is. So we can't
   * compare against it.
   */
  /*
  testModifyChunkSize();
  */
  testDoubleInit();
  testHeapSize();
  testCalloc();
  testRealloc();
  testStrdup();

  pcsl_mem_finalize();
}
Ejemplo n.º 2
0
void afk_testJigsaw(
    AFK_Computer *computer,
    const AFK_ConfigSettings& settings)
{
    boost::random::random_device rdev;
    srand(rdev());

    /* Make a jigsaw with a plausible shape size, and allocate lots
     * of pieces out of it in multiple iterations.  Upon each of
     * these simulated frames, check that the set of available
     * pieces appears sane and hasn't gotten trampled, etc.
     * TODO -- Improvements:
     * - Test a 3D one too (pull out the test into a function I
     * can call with several)
     * - Multi-threaded test
     * - Test OpenCL program that writes known values to the jigsaw
     * texture -- verify that the values come out OK and don't
     * trample each other either.
     */
    const int testIterations = 50;

    AFK_JigsawMemoryAllocation testAllocation(
        {
            AFK_JigsawMemoryAllocation::Entry(
                {
                    AFK_JigsawImageDescriptor(
                        afk_vec3<int>(9, 9, 1),
                        AFK_JigsawFormat::FLOAT32_4,
                        AFK_JigsawDimensions::TWO,
                        AFK_JigsawBufferUsage::CL_ONLY,
                        GL_NEAREST)
                },
                4,
                1.0f),
        },
        settings.concurrency,
        computer->useFake3DImages(settings),
        1.0f,
        computer->getFirstDeviceProps());

    AFK_JigsawCollection testCollection(
        computer,
        testAllocation.at(0),
        computer->getFirstDeviceProps(),
        0);

    AFK_Frame frame;
    frame.increment();
    testCollection.flip(frame);

    for (int i = 0; i < testIterations; ++i)
    {
        int piecesThisFrame = rand() % (settings.concurrency * testAllocation.at(0).getPieceCount() / 4);
        afk_out << "Test frame " << frame << ": Getting " << piecesThisFrame << " pieces" << std::endl;

        /* Here, I map each piece that I've drawn to its timestamp. */
        boost::unordered_map<AFK_JigsawPiece, AFK_Frame> piecesMap;

        try
        {
            for (int p = 0; p < piecesThisFrame; ++p)
            {
                AFK_JigsawPiece jigsawPiece;
                AFK_Frame pieceFrame;
    
                testCollection.grab(0, &jigsawPiece, &pieceFrame, 1);
                afk_out << "Grabbed piece " << jigsawPiece << " with frame " << pieceFrame << std::endl;

                auto existing = piecesMap.find(jigsawPiece);
                if (existing != piecesMap.end()) assert(existing->second != pieceFrame);
                piecesMap[jigsawPiece] = pieceFrame;
            }
        }
        catch (AFK_Exception& e)
        {
            if (e.getMessage() == "Jigsaw ran out of room")
            {
                /* I'll forgive this. */
                afk_out << "Out of room -- OK -- continuing" << std::endl;
            }
            else
            {
                throw e;
            }
        }

        frame.increment();
        testCollection.flip(frame);
        testCollection.printStats(afk_out, "Test jigsaw");
    }

    afk_out << "Jigsaw test completed" << std::endl;
}