<commit_before>/*-------------------------------------------------------------------------
 * drawElements Internal Test Module
 * ---------------------------------
 *
 * Copyright 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief ASTC tests.
 *//*--------------------------------------------------------------------*/

#include "ditAstcTests.hpp"

#include "tcuCompressedTexture.hpp"
#include "tcuAstcUtil.hpp"

#include "deUniquePtr.hpp"
#include "deStringUtil.hpp"

namespace dit
{

using std::string;
using std::vector;
using namespace tcu;

namespace
{

class AstcCase : public tcu::TestCase
{
public:
								AstcCase		(tcu::TestContext& testCtx, CompressedTexFormat format);

	IterateResult				iterate			(void);

private:
	const CompressedTexFormat	m_format;
};

static const string getASTCFormatShortName (CompressedTexFormat format)
{
	DE_ASSERT(isAstcFormat(format));
	const IVec3 blockSize = getBlockPixelSize(format);
	DE_ASSERT(blockSize.z() == 1);

	return de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isAstcSRGBFormat(format) ? "_srgb" : "");
}

AstcCase::AstcCase (tcu::TestContext& testCtx, CompressedTexFormat format)
	: tcu::TestCase	(testCtx, getASTCFormatShortName(format).c_str(), "")
	, m_format		(format)
{
}

void testDecompress (CompressedTexFormat format, size_t numBlocks, const deUint8* data)
{
	const IVec3			blockPixelSize		= getBlockPixelSize(format);

	for (int astcModeNdx = 0; astcModeNdx < TexDecompressionParams::ASTCMODE_LAST; astcModeNdx++)
	{
		const TexDecompressionParams	decompressionParams		((TexDecompressionParams::AstcMode)astcModeNdx);
		const TextureFormat				uncompressedFormat		= getUncompressedFormat(format);
		TextureLevel					texture					(uncompressedFormat, blockPixelSize.x()*(int)numBlocks, blockPixelSize.y());

		decompress(texture.getAccess(), format, data, decompressionParams);
	}
}

void verifyBlocksValid (CompressedTexFormat format, TexDecompressionParams::AstcMode mode, size_t numBlocks, const deUint8* data)
{
	for (size_t blockNdx = 0; blockNdx < numBlocks; blockNdx++)
		TCU_CHECK(astc::isValidBlock(data + blockNdx*astc::BLOCK_SIZE_BYTES, format, mode));
}

inline size_t getNumBlocksFromBytes (size_t numBytes)
{
	TCU_CHECK(numBytes % astc::BLOCK_SIZE_BYTES == 0);
	return (numBytes / astc::BLOCK_SIZE_BYTES);
}

AstcCase::IterateResult AstcCase::iterate (void)
{
	vector<deUint8> generatedData;

	// Verify that can generate & decode data with all BlockTestType's
	for (int blockTestTypeNdx = 0; blockTestTypeNdx < astc::BLOCK_TEST_TYPE_LAST; blockTestTypeNdx++)
	{
		const astc::BlockTestType	blockTestType	= (const astc::BlockTestType)blockTestTypeNdx;

		if (astc::isBlockTestTypeHDROnly(blockTestType) && isAstcSRGBFormat(m_format))
			continue;

		generatedData.clear();
		astc::generateBlockCaseTestData(generatedData, m_format, blockTestType);

		testDecompress(m_format, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);

		// All but random case should generate only valid blocks
		if (blockTestType != astc::BLOCK_TEST_TYPE_RANDOM)
		{
			verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);

			if (!astc::isBlockTestTypeHDROnly(blockTestType))
				verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);
		}
	}

	// Verify generating void extent blocks (format-independent)
	{
		const size_t		numBlocks		= 1024;

		generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES);
		astc::generateDummyVoidExtentBlocks(&generatedData[0], numBlocks);
<commit_msg>Fix ASTC framework tests am: e43e099<commit_after>/*-------------------------------------------------------------------------
 * drawElements Internal Test Module
 * ---------------------------------
 *
 * Copyright 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief ASTC tests.
 *//*--------------------------------------------------------------------*/

#include "ditAstcTests.hpp"

#include "tcuCompressedTexture.hpp"
#include "tcuAstcUtil.hpp"

#include "deUniquePtr.hpp"
#include "deStringUtil.hpp"

namespace dit
{

using std::string;
using std::vector;
using namespace tcu;

namespace
{

class AstcCase : public tcu::TestCase
{
public:
								AstcCase		(tcu::TestContext& testCtx, CompressedTexFormat format);

	IterateResult				iterate			(void);

private:
	const CompressedTexFormat	m_format;
};

static const string getASTCFormatShortName (CompressedTexFormat format)
{
	DE_ASSERT(isAstcFormat(format));
	const IVec3 blockSize = getBlockPixelSize(format);
	DE_ASSERT(blockSize.z() == 1);

	return de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isAstcSRGBFormat(format) ? "_srgb" : "");
}

AstcCase::AstcCase (tcu::TestContext& testCtx, CompressedTexFormat format)
	: tcu::TestCase	(testCtx, getASTCFormatShortName(format).c_str(), "")
	, m_format		(format)
{
}

void testDecompress (CompressedTexFormat format, size_t numBlocks, const deUint8* data)
{
	const IVec3			blockPixelSize		= getBlockPixelSize(format);

	for (int astcModeNdx = 0; astcModeNdx < TexDecompressionParams::ASTCMODE_LAST; astcModeNdx++)
	{
		const TexDecompressionParams	decompressionParams		((TexDecompressionParams::AstcMode)astcModeNdx);
		const TextureFormat				uncompressedFormat		= getUncompressedFormat(format);
		TextureLevel					texture					(uncompressedFormat, blockPixelSize.x()*(int)numBlocks, blockPixelSize.y());

		decompress(texture.getAccess(), format, data, decompressionParams);
	}
}

void verifyBlocksValid (CompressedTexFormat format, TexDecompressionParams::AstcMode mode, size_t numBlocks, const deUint8* data)
{
	for (size_t blockNdx = 0; blockNdx < numBlocks; blockNdx++)
		TCU_CHECK(astc::isValidBlock(data + blockNdx*astc::BLOCK_SIZE_BYTES, format, mode));
}

inline size_t getNumBlocksFromBytes (size_t numBytes)
{
	TCU_CHECK(numBytes % astc::BLOCK_SIZE_BYTES == 0);
	return (numBytes / astc::BLOCK_SIZE_BYTES);
}

AstcCase::IterateResult AstcCase::iterate (void)
{
	vector<deUint8> generatedData;

	// Verify that can generate & decode data with all BlockTestType's
	for (int blockTestTypeNdx = 0; blockTestTypeNdx < astc::BLOCK_TEST_TYPE_LAST; blockTestTypeNdx++)
	{
		const astc::BlockTestType	blockTestType	= (const astc::BlockTestType)blockTestTypeNdx;

		if (astc::isBlockTestTypeHDROnly(blockTestType) && isAstcSRGBFormat(m_format))
			continue;

		generatedData.clear();
		astc::generateBlockCaseTestData(generatedData, m_format, blockTestType);

		testDecompress(m_format, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);

		// All but random case should generate only valid blocks
		if (blockTestType != astc::BLOCK_TEST_TYPE_RANDOM)
		{
			verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);

			// \note CEMS generates HDR blocks as well
			if (!astc::isBlockTestTypeHDROnly(blockTestType) &&
				(blockTestType != astc::BLOCK_TEST_TYPE_CEMS))
				verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);
		}
	}

	// Verify generating void extent blocks (format-independent)
	{
		const size_t		numBlocks		= 1024;

		generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES);
		astc::generateDummyVoidExtentBlocks(&generatedData[0], numBlocks);

{'fraction_non_alphanumeric': 0.14476458186929023, 'fraction_numerical': 0.0066760365425158116, 'mean_word_length': 4.573759791122716, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4605500', 'n_tokens_mistral': 2833, 'n_tokens_neox': 2671, 'n_words': 618}