xref: /aosp_15_r20/external/deqp/modules/internal/ditImageIOTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Internal Test Module
3*35238bceSAndroid Build Coastguard Worker  * ---------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Image IO tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "ditImageIOTests.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "tcuResource.hpp"
26*35238bceSAndroid Build Coastguard Worker #include "tcuImageIO.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuFormatUtil.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "deString.h"
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace dit
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
37*35238bceSAndroid Build Coastguard Worker 
38*35238bceSAndroid Build Coastguard Worker // \todo [2013-05-28 pyry] Image output cases!
39*35238bceSAndroid Build Coastguard Worker 
40*35238bceSAndroid Build Coastguard Worker class ImageReadCase : public tcu::TestCase
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker public:
ImageReadCase(tcu::TestContext & testCtx,const char * name,const char * filename,uint32_t expectedHash)43*35238bceSAndroid Build Coastguard Worker     ImageReadCase(tcu::TestContext &testCtx, const char *name, const char *filename, uint32_t expectedHash)
44*35238bceSAndroid Build Coastguard Worker         : TestCase(testCtx, name, filename)
45*35238bceSAndroid Build Coastguard Worker         , m_filename(filename)
46*35238bceSAndroid Build Coastguard Worker         , m_expectedHash(expectedHash)
47*35238bceSAndroid Build Coastguard Worker     {
48*35238bceSAndroid Build Coastguard Worker     }
49*35238bceSAndroid Build Coastguard Worker 
iterate(void)50*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void)
51*35238bceSAndroid Build Coastguard Worker     {
52*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Loading image from file '" << m_filename << "'"
53*35238bceSAndroid Build Coastguard Worker                            << TestLog::EndMessage;
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker         tcu::TextureLevel texture;
56*35238bceSAndroid Build Coastguard Worker         tcu::ImageIO::loadImage(texture, m_testCtx.getArchive(), m_filename.c_str());
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker         m_testCtx.getLog() << TestLog::Message << "Loaded " << texture.getWidth() << "x" << texture.getHeight() << "x"
59*35238bceSAndroid Build Coastguard Worker                            << texture.getDepth() << " image with format " << texture.getFormat() << TestLog::EndMessage;
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker         // Check that layout is as expected
62*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(texture.getAccess().getRowPitch() == texture.getWidth() * texture.getFormat().getPixelSize());
63*35238bceSAndroid Build Coastguard Worker         TCU_CHECK(texture.getAccess().getSlicePitch() ==
64*35238bceSAndroid Build Coastguard Worker                   texture.getAccess().getRowPitch() * texture.getAccess().getHeight());
65*35238bceSAndroid Build Coastguard Worker 
66*35238bceSAndroid Build Coastguard Worker         const int imageSize = texture.getAccess().getSlicePitch() * texture.getDepth();
67*35238bceSAndroid Build Coastguard Worker         const uint32_t hash = deMemoryHash(texture.getAccess().getDataPtr(), imageSize);
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker         if (hash != m_expectedHash)
70*35238bceSAndroid Build Coastguard Worker         {
71*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Message << "ERROR: expected hash " << tcu::toHex(m_expectedHash) << ", got "
72*35238bceSAndroid Build Coastguard Worker                                << tcu::toHex(hash) << TestLog::EndMessage;
73*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog() << TestLog::Image("Image", "Loaded image", texture.getAccess());
74*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Hash check failed");
75*35238bceSAndroid Build Coastguard Worker         }
76*35238bceSAndroid Build Coastguard Worker         else
77*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
78*35238bceSAndroid Build Coastguard Worker 
79*35238bceSAndroid Build Coastguard Worker         return STOP;
80*35238bceSAndroid Build Coastguard Worker     }
81*35238bceSAndroid Build Coastguard Worker 
82*35238bceSAndroid Build Coastguard Worker private:
83*35238bceSAndroid Build Coastguard Worker     const std::string m_filename;
84*35238bceSAndroid Build Coastguard Worker     const uint32_t m_expectedHash;
85*35238bceSAndroid Build Coastguard Worker };
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker class ImageReadTests : public tcu::TestCaseGroup
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker public:
ImageReadTests(tcu::TestContext & testCtx)90*35238bceSAndroid Build Coastguard Worker     ImageReadTests(tcu::TestContext &testCtx) : TestCaseGroup(testCtx, "read", "Image read tests")
91*35238bceSAndroid Build Coastguard Worker     {
92*35238bceSAndroid Build Coastguard Worker     }
93*35238bceSAndroid Build Coastguard Worker 
init(void)94*35238bceSAndroid Build Coastguard Worker     void init(void)
95*35238bceSAndroid Build Coastguard Worker     {
96*35238bceSAndroid Build Coastguard Worker         addChild(new ImageReadCase(m_testCtx, "rgb24_256x256", "internal/data/imageio/rgb24_256x256.png", 0x6efad777));
97*35238bceSAndroid Build Coastguard Worker         addChild(new ImageReadCase(m_testCtx, "rgb24_209x181", "internal/data/imageio/rgb24_209x181.png", 0xfd6ea668));
98*35238bceSAndroid Build Coastguard Worker         addChild(
99*35238bceSAndroid Build Coastguard Worker             new ImageReadCase(m_testCtx, "rgba32_256x256", "internal/data/imageio/rgba32_256x256.png", 0xcf4883da));
100*35238bceSAndroid Build Coastguard Worker         addChild(
101*35238bceSAndroid Build Coastguard Worker             new ImageReadCase(m_testCtx, "rgba32_207x219", "internal/data/imageio/rgba32_207x219.png", 0x404ba06b));
102*35238bceSAndroid Build Coastguard Worker     }
103*35238bceSAndroid Build Coastguard Worker };
104*35238bceSAndroid Build Coastguard Worker 
ImageIOTests(tcu::TestContext & testCtx)105*35238bceSAndroid Build Coastguard Worker ImageIOTests::ImageIOTests(tcu::TestContext &testCtx) : TestCaseGroup(testCtx, "image_io", "Image read and write tests")
106*35238bceSAndroid Build Coastguard Worker {
107*35238bceSAndroid Build Coastguard Worker }
108*35238bceSAndroid Build Coastguard Worker 
~ImageIOTests(void)109*35238bceSAndroid Build Coastguard Worker ImageIOTests::~ImageIOTests(void)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker }
112*35238bceSAndroid Build Coastguard Worker 
init(void)113*35238bceSAndroid Build Coastguard Worker void ImageIOTests::init(void)
114*35238bceSAndroid Build Coastguard Worker {
115*35238bceSAndroid Build Coastguard Worker     addChild(new ImageReadTests(m_testCtx));
116*35238bceSAndroid Build Coastguard Worker }
117*35238bceSAndroid Build Coastguard Worker 
118*35238bceSAndroid Build Coastguard Worker } // namespace dit
119