diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-02-22 13:48:12 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-02-22 13:57:10 +1000 |
commit | 4ea183d215d575ae96f8f437334b3f07b9719e45 (patch) | |
tree | 5dbd07076ad26dc6c1535cf1abae029291bd757f /tests/auto | |
parent | 8aee382e71af5281e4403339596e0a07ab5463cb (diff) |
Unit tests and bug fixes for QCLVector.
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qcl/tst_qcl.cl | 5 | ||||
-rw-r--r-- | tests/auto/qcl/tst_qcl.cpp | 55 |
2 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/qcl/tst_qcl.cl b/tests/auto/qcl/tst_qcl.cl index f8d7319..ab719be 100644 --- a/tests/auto/qcl/tst_qcl.cl +++ b/tests/auto/qcl/tst_qcl.cl @@ -101,3 +101,8 @@ __kernel void storeMat4(__global __write_only float4 *output, float16 input) output[2] = input.hi.lo; output[3] = input.hi.hi; } + +__kernel void addToVector(__global float *vector, float value) +{ + vector[get_global_id(0)] += value; +} diff --git a/tests/auto/qcl/tst_qcl.cpp b/tests/auto/qcl/tst_qcl.cpp index bb60c81..b03b933 100644 --- a/tests/auto/qcl/tst_qcl.cpp +++ b/tests/auto/qcl/tst_qcl.cpp @@ -58,6 +58,7 @@ private slots: void initTestCase(); void buildProgram(); void argumentPassing(); + void vectorBuffer(); private: QCLContext context; @@ -170,6 +171,60 @@ void tst_QCL::argumentPassing() QCOMPARE(buf[15], 16.0f); } +static float constVectorAt(const QCLVector<float>& vector, int index) +{ + return vector[index]; +} + +// Test the QCLVector<T> class. +void tst_QCL::vectorBuffer() +{ + QCLVector<float> vector1; + QVERIFY(vector1.isNull()); + QVERIFY(vector1.isEmpty()); + QCOMPARE(vector1.size(), 0); + QVERIFY(vector1.memoryId() == 0); + QVERIFY(vector1.context() == 0); + QVERIFY(!vector1.isMapped()); + + vector1 = context.createVector<float>(100); + QVERIFY(!vector1.isNull()); + QVERIFY(!vector1.isEmpty()); + QCOMPARE(vector1.size(), 100); + QVERIFY(vector1.memoryId() != 0); + QVERIFY(vector1.context() == &context); + QVERIFY(!vector1.isMapped()); + + for (int index = 0; index < 100; ++index) + vector1[index] = float(index); + QVERIFY(vector1.isMapped()); + + vector1.unmap(); + QVERIFY(!vector1.isMapped()); + for (int index = 0; index < 100; ++index) + QCOMPARE(vector1[index], float(index)); + QVERIFY(vector1.isMapped()); + + QCLKernel addToVector = program.createKernel("addToVector"); + addToVector.setGlobalWorkSize(vector1.size()); + addToVector(vector1, 42.0f); + QVERIFY(!vector1.isMapped()); + + for (int index = 0; index < 100; ++index) { + QCOMPARE(constVectorAt(vector1, index), float(index + 42)); + QCOMPARE(vector1[index], float(index + 42)); + } + QVERIFY(vector1.isMapped()); + + vector1.release(); + QVERIFY(vector1.isNull()); + QVERIFY(vector1.isEmpty()); + QCOMPARE(vector1.size(), 0); + QVERIFY(vector1.memoryId() == 0); + QVERIFY(vector1.context() == 0); + QVERIFY(!vector1.isMapped()); +} + QTEST_MAIN(tst_QCL) #include "tst_qcl.moc" |