Commit 00d5d657 authored by Tomi Korpipää's avatar Tomi Korpipää Committed by Pasi Keränen
Browse files

Adding WebGL conformance tests for TypedArrays


Several tests fail, but it is unclear if they fail because of V4VM, or 
tests themselves.

Change-Id: Ie6923c2b10a24052dc3022d07eccd899586efe42
Reviewed-by: default avatarPasi Keränen <pasi.keranen@digia.com>
Showing with 1943 additions and 0 deletions
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
function areArraysEqual(_a, _b)
{
try {
if (_a.length !== _b.length)
return false;
for (var i = 0; i < _a.length; i++)
if (_a[i] !== _b[i])
return false;
} catch (ex) {
return false;
}
return true;
}
function isMinusZero(n)
{
// the only way to tell 0 from -0 in JS is the fact that 1/-0 is
// -Infinity instead of Infinity
return n === 0 && 1/n < 0;
}
function isResultCorrect(_actual, _expected)
{
if (_expected === 0)
return _actual === _expected && (1/_actual) === (1/_expected);
if (_actual === _expected)
return true;
if (typeof(_expected) == "number" && isNaN(_expected))
return typeof(_actual) == "number" && isNaN(_actual);
if (Object.prototype.toString.call(_expected) == Object.prototype.toString.call([]))
return areArraysEqual(_actual, _expected);
return false;
}
function stringify(v)
{
if (v === 0 && 1/v < 0)
return "-0";
else return "" + v;
}
function evalAndLog(_a)
{
if (typeof _a != "string")
debug("WARN: tryAndLog() expects a string argument");
// Log first in case things go horribly wrong or this causes a sync event.
debug(_a);
var _av;
try {
_av = eval(_a);
} catch (e) {
return false;//testFailed(_a + " threw exception " + e);
}
return _av;
}
function shouldBe(_a, _b)
{
if (typeof _a != "string" || typeof _b != "string")
debug("WARN: shouldBe() expects string arguments");
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
var _bv = eval(_b);
if (exception) {
console.log(_a + " should be " + _bv + ". Threw exception " + exception);
return false;//testFailed(_a + " should be " + _bv + ". Threw exception " + exception);
} else if (isResultCorrect(_av, _bv)) {
return true;//testPassed(_a + " is " + _b);
} else if (typeof(_av) == typeof(_bv)) {
console.log(_a + " should be " + _bv + ". Was " + stringify(_av) + ".");
return false;//testFailed(_a + " should be " + _bv + ". Was " + stringify(_av) + ".");
} else {
console.log(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
return false;//testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
}
}
function shouldBeTrue(_a) { return shouldBe(_a, "true"); }
function shouldBeFalse(_a) { return shouldBe(_a, "false"); }
function shouldBeNaN(_a) { return shouldBe(_a, "NaN"); }
function shouldBeNull(_a) { return shouldBe(_a, "null"); }
function shouldBeEqualToString(a, b)
{
var unevaledString = '"' + b.replace(/"/g, "\"") + '"';
return shouldBe(a, unevaledString);
}
function shouldEvaluateTo(actual, expected) {
// A general-purpose comparator. 'actual' should be a string to be
// evaluated, as for shouldBe(). 'expected' may be any type and will be
// used without being eval'ed.
var retval = true;
if (expected == null) {
// Do this before the object test, since null is of type 'object'.
retval = shouldBeNull(actual);
if (!retval) return false;
} else if (typeof expected == "undefined") {
retval = shouldBeUndefined(actual);
if (!retval) return false;
} else if (typeof expected == "function") {
// All this fuss is to avoid the string-arg warning from shouldBe().
try {
actualValue = eval(actual);
} catch (e) {
return false;//testFailed("Evaluating " + actual + ": Threw exception " + e);
}
retval = shouldBe("'" + actualValue.toString().replace(/\n/g, "") + "'",
"'" + expected.toString().replace(/\n/g, "") + "'");
if (!retval) return false;
} else if (typeof expected == "object") {
retval = shouldBeTrue(actual + " == '" + expected + "'");
if (!retval) return false;
} else if (typeof expected == "string") {
retval = shouldBe(actual, expected);
if (!retval) return false;
} else if (typeof expected == "boolean") {
retval = shouldBe("typeof " + actual, "'boolean'");
if (!retval) return false;
if (expected) {
retval = shouldBeTrue(actual);
if (!retval) return false;
} else {
retval = shouldBeFalse(actual);
if (!retval) return false;
}
} else if (typeof expected == "number") {
retval = shouldBe(actual, stringify(expected));
if (!retval) return false;
} else {
debug(expected + " is unknown type " + typeof expected);
retval = shouldBeTrue(actual, "'" +expected.toString() + "'");
if (!retval) return false;
}
return retval;
}
function shouldBeNonZero(_a)
{
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
if (exception)
return false;//testFailed(_a + " should be non-zero. Threw exception " + exception);
else if (_av != 0)
return true;//testPassed(_a + " is non-zero.");
else
return false;//testFailed(_a + " should be non-zero. Was " + _av);
}
function shouldBeNonNull(_a)
{
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
if (exception)
return false;//testFailed(_a + " should be non-null. Threw exception " + exception);
else if (_av != null)
return true;//testPassed(_a + " is non-null.");
else
return false;//testFailed(_a + " should be non-null. Was " + _av);
}
function shouldBeUndefined(_a)
{
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
if (exception)
return false;//testFailed(_a + " should be undefined. Threw exception " + exception);
else if (typeof _av == "undefined")
return true;//testPassed(_a + " is undefined.");
else
return false;//testFailed(_a + " should be undefined. Was " + _av);
}
function shouldBeDefined(_a)
{
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
if (exception)
return false;//testFailed(_a + " should be defined. Threw exception " + exception);
else if (_av !== undefined)
return true;//testPassed(_a + " is defined.");
else
return false;//testFailed(_a + " should be defined. Was " + _av);
}
function shouldBeGreaterThanOrEqual(_a, _b) {
if (typeof _a != "string" || typeof _b != "string")
console.log("WARN: shouldBeGreaterThanOrEqual expects string arguments");
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
var _bv = eval(_b);
if (exception) {
console.log(_a + " should be >= " + _b + ". Threw exception " + exception);
return false;//testFailed(_a + " should be >= " + _b + ". Threw exception " + exception);
} else if (typeof _av == "undefined" || _av < _bv) {
console.log(_a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ").");
return false;//testFailed(_a + " should be >= " + _b + ". Was " + _av + " (of type " + typeof _av + ").");
} else {
return true;//testPassed(_a + " is >= " + _b);
}
}
function shouldThrow(_a, _e)
{
var exception;
var _av;
try {
_av = eval(_a);
} catch (e) {
exception = e;
}
var _ev;
if (_e)
_ev = eval(_e);
if (exception) {
if (typeof _e == "undefined" || exception == _ev)
return true;//testPassed(_a + " threw exception " + exception + ".");
else
return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Threw exception " + exception + ".");
} else if (typeof _av == "undefined")
return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was undefined.");
else
return false;//testFailed(_a + " should throw " + (typeof _e == "undefined" ? "an exception" : _ev) + ". Was " + _av + ".");
}
function assertMsg(assertion, msg) {
if (assertion) {
return true;//testPassed(msg);
} else {
console.log(msg);
return false;//testFailed(msg);
}
}
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCanvas3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.2
import QtCanvas3D 1.0
import QtTest 1.0
import "tst_conformance_typedarrays.js" as Content
// Covers the following WebGL conformance TypedArray tests:
// array-buffer-crash.html
// array-buffer-view-crash.html
// array-unit-tests.html
// array-large-array-tests.html
// data-view-crash.html
// data-view-test.html
// Doesn't cover the following TypedArray tests:
// typed-arrays-in-workers.html
Item {
id: top
height: 300
width: 300
Canvas3D {
onInitGL: Content.initGL(this, true, true)
}
/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
// array-buffer-crash.html
TestCase {
name: "Canvas3D_conformance_array_buffer_crash"
when: windowShown
function test_array_buffer_no_crash() {
verify(Content.createArray() !== null,
"Test ArrayBuffer.byteLength (new ArrayBuffer().byteLength)")
}
}
// array-buffer-view-crash.html
TestCase {
name: "Canvas3D_conformance_array_buffer_view_crash"
when: windowShown
function test_array_buffer_view_no_crash() {
verify(Content.createArrayView() !== null,
"Verify that constructing a typed array view with no arguments and fetching \
its length does not crash (new Uint32Array().length)")
}
}
// array-unit-tests.html
TestCase {
// Verifies the functionality of the new array-like objects in the TypedArray spec
name: "Canvas3D_conformance_array_unit_tests"
when: windowShown
function test_slice() {
verify(Content.testSlice());
}
function test_array_buffer_is_view() {
verify(Content.testArrayBufferIsViewMethod()); // Half the tests here fail. Something to check in V4VM?
}
function test_inheritance_hierarchy() {
verify(Content.testInheritanceHierarchy());
}
function test_typed_arrays() {
for (var i = 0; i < Content.testCases.length; i++) {
var testCase = Content.testCases[i];
Content.running(testCase.name);
var type = testCase.type;
var name = testCase.name;
if (testCase.unsigned) {
verify(Content.testSetAndGet10To1(type, name));
verify(Content.testConstructWithArrayOfUnsignedValues(type, name));
verify(Content.testConstructWithTypedArrayOfUnsignedValues(type, name));
} else {
verify(Content.testSetAndGetPos10ToNeg10(type, name));
verify(Content.testConstructWithArrayOfSignedValues(type, name));
verify(Content.testConstructWithTypedArrayOfSignedValues(type, name));
}
if (testCase.integral) {
verify(Content.testIntegralArrayTruncationBehavior(type, name, testCase.unsigned));
}
verify(Content.testGetWithOutOfRangeIndices(type, name));
verify(Content.testOffsetsAndSizes(type, name, testCase.elementSizeInBytes));
verify(Content.testSetFromTypedArray(type, name));
verify(Content.negativeTestSetFromTypedArray(type, name));
verify(Content.testSetFromArray(type, name));
verify(Content.negativeTestSetFromArray(type, name));
verify(Content.testSubarray(type, name));
//verify(Content.negativeTestSubarray(type, name)); // V4VM? Float32Array Subarray: Error: Invalid write to global property "subarray". Something to check in V4VM?
verify(Content.testSetBoundaryConditions(type,
name,
testCase.testValues,
testCase.expectedValues));
verify(Content.testConstructionBoundaryConditions(type,
name,
testCase.testValues,
testCase.expectedValues));
//verify(Content.testConstructionWithNullBuffer(type, name)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of Float32Array with null buffer should throw exception. Something to check in V4VM?
verify(Content.testConstructionWithOutOfRangeValues(type, name));
//verify(Content.testConstructionWithNegativeOutOfRangeValues(type, name)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of Float32Array with negative out-of-range values should throw an exception. Something to check in V4VM?
//verify(Content.testConstructionWithUnalignedOffset(type, name, testCase.elementSizeInBytes)); // V4VM? Construction of Int8Array with out-of-range values threw an exception. Something to check in V4VM?
//verify(Content.testConstructionWithUnalignedLength(type, name, testCase.elementSizeInBytes)); // V4VM? Construction of Int8Array with out-of-range values threw an exception. Something to check in V4VM?
//verify(Content.testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes)); // V4VM? Float32Array ConstructionBoundaryConditions: Construction of huge Float32Array should throw exception. Something to check in V4VM?
verify(Content.testConstructionWithBothArrayBufferAndLength(type, name, testCase.elementSizeInBytes));
verify(Content.testSubarrayWithOutOfRangeValues(type, name, testCase.elementSizeInBytes));
verify(Content.testSubarrayWithDefaultValues(type, name, testCase.elementSizeInBytes));
verify(Content.testSettingFromArrayWithOutOfRangeOffset(type, name));
verify(Content.testSettingFromFakeArrayWithOutOfRangeLength(type, name));
verify(Content.testSettingFromTypedArrayWithOutOfRangeOffset(type, name));
verify(Content.negativeTestGetAndSetMethods(type, name));
verify(Content.testNaNConversion(type, name));
}
}
}
// array-large-array-tests.html
TestCase {
name: "Canvas3D_conformance_array_large_array_tests"
when: windowShown
// Verifies allocation of large array buffers
function test_array_large_array() {
for (var i = 0; i < Content.testCases.length; i++) {
var testCase = Content.testCases[i];
Content.running(testCase.name);
var type = testCase.type;
var name = testCase.name;
//verify(Content.testConstructionOfHugeArray(type, name, testCase.elementSizeInBytes)); // V4VM? Float32Array: Construction of huge Float32Array should throw exception
}
}
}
// data-view-crash.html
TestCase {
name: "Canvas3D_conformance_data_view_crash"
when: windowShown
function test_data_view_crash() {
verify(Content.dataView(),
"Test that DataView does not crash with bad offset or length.")
}
}
// data-view-test.html
TestCase {
name: "Canvas3D_conformance_data_view_test"
when: windowShown
function test_data_view_test_1() {
verify(Content.runConstructorTests());
}
function test_data_view_test_2() {
//verify(Content.runGetTests()); // V4VM? view.getUint8(0) should be 0. Threw exception TypeError: Property 'getUint8' of object [object Object] is not a function
}
function test_data_view_test_3() {
//verify(Content.runSetTests()); // V4VM? view.setUint8(0, 0) fails
}
function test_data_view_test_4() {
//verify(Content.runIndexingTests()); // V4VM? view.getUint8(0) should be 1. Threw exception TypeError: Property 'getUint8' of object [object Object] is not a function
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment