• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Internal Test Module
3  * ---------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Seed builder tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "ditSeedBuilderTests.hpp"
25 
26 #include "tcuTestLog.hpp"
27 #include "tcuVector.hpp"
28 #include "tcuSeedBuilder.hpp"
29 
30 using tcu::IVec2;
31 using tcu::IVec3;
32 using tcu::IVec4;
33 using tcu::TestLog;
34 
35 namespace dit
36 {
37 namespace
38 {
39 
40 template<class T>
41 class SeedBuilderTest : public tcu::TestCase
42 {
43 public:
SeedBuilderTest(tcu::TestContext & testCtx,const T & value,deUint32 seed,const char * name,const char * description)44 	SeedBuilderTest (tcu::TestContext& testCtx, const T& value, deUint32 seed, const char* name, const char* description)
45 		: tcu::TestCase	(testCtx, name, description)
46 		, m_value		(value)
47 		, m_seed		(seed)
48 	{
49 	}
50 
iterate(void)51 	IterateResult iterate (void)
52 	{
53 		TestLog&			log		= m_testCtx.getLog();
54 		tcu::SeedBuilder	builder;
55 
56 		builder << m_value;
57 
58 		log << TestLog::Message << "Value: " << m_value << TestLog::EndMessage;
59 		log << TestLog::Message << "Expected seed: " << m_seed << TestLog::EndMessage;
60 		log << TestLog::Message << "Got seed: " << builder.get() << TestLog::EndMessage;
61 
62 		if (builder.get() != m_seed)
63 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid seed");
64 		else
65 			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
66 
67 		return STOP;
68 	}
69 
70 private:
71 	T			m_value;
72 	deUint32	m_seed;
73 };
74 
75 class SeedBuilderMultipleValuesTest : public tcu::TestCase
76 {
77 public:
SeedBuilderMultipleValuesTest(tcu::TestContext & testCtx)78 	SeedBuilderMultipleValuesTest (tcu::TestContext& testCtx)
79 		: tcu::TestCase(testCtx, "multiple_values", "Test that multiple values all change the seed.")
80 	{
81 	}
82 
iterate(void)83 	IterateResult iterate (void)
84 	{
85 		TestLog&			log			= m_testCtx.getLog();
86 		const deUint32		a			= 77740203u;
87 		const deUint32		b			= 3830824200u;
88 
89 		tcu::SeedBuilder	builderA;
90 		tcu::SeedBuilder	builderB;
91 		tcu::SeedBuilder	builderAB;
92 
93 		builderA << a;
94 		builderB << b;
95 
96 		builderAB << a << b;
97 
98 		log << TestLog::Message << "Value a: " << a << ", Seed a: " << builderA.get() << TestLog::EndMessage;
99 		log << TestLog::Message << "Value b: " << b << ", Seed b: " << builderB.get() << TestLog::EndMessage;
100 		log << TestLog::Message << "Seed ab: " << builderAB.get() << TestLog::EndMessage;
101 
102 		if (builderA.get() == builderAB.get())
103 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Seed seems to only depends on first value.");
104 		else if (builderB.get() == builderAB.get())
105 			m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Seed seems to only depends on second value.");
106 		else
107 			m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
108 
109 		return STOP;
110 	}
111 };
112 
113 class SeedBuilderTests : public tcu::TestCaseGroup
114 {
115 public:
SeedBuilderTests(tcu::TestContext & testCtx)116 	SeedBuilderTests (tcu::TestContext& testCtx)
117 		: tcu::TestCaseGroup(testCtx, "seed_builder", "Seed builder tests.")
118 	{
119 	}
120 
init(void)121 	void init (void)
122 	{
123 		addChild(new SeedBuilderTest<bool>(m_testCtx, true,  132088003u, "bool_true", "Seed from boolean true."));
124 		addChild(new SeedBuilderTest<bool>(m_testCtx, false,  50600761u, "bool_false", "Seed from boolean false."));
125 
126 		addChild(new SeedBuilderTest<deInt8>(m_testCtx,  0,  62533730u, "int8_zero", "Seed from int8 zero."));
127 		addChild(new SeedBuilderTest<deInt8>(m_testCtx,  1,  93914869u, "int8_one", "Seed from int8 one."));
128 		addChild(new SeedBuilderTest<deInt8>(m_testCtx, -1, 115002165u, "int8_minus_one", "Seed from int8 minus one."));
129 
130 		addChild(new SeedBuilderTest<deInt16>(m_testCtx,  0, 133071403u, "int16_zero", "Seed from int16 zero."));
131 		addChild(new SeedBuilderTest<deInt16>(m_testCtx,  1,  57421642u, "int16_one", "Seed from int16 one."));
132 		addChild(new SeedBuilderTest<deInt16>(m_testCtx, -1,  74389771u, "int16_minus_one", "Seed from int16 minus one."));
133 
134 		addChild(new SeedBuilderTest<deInt32>(m_testCtx,  0, 75951701u, "int32_zero", "Seed from int32 zero."));
135 		addChild(new SeedBuilderTest<deInt32>(m_testCtx,  1, 95780822u, "int32_one", "Seed from int32 one."));
136 		addChild(new SeedBuilderTest<deInt32>(m_testCtx, -1, 73949483u, "int32_minus_one", "Seed from int32 minus one."));
137 
138 		addChild(new SeedBuilderTest<deUint8>(m_testCtx, 0,		  3623298u, "uint8_zero", "Seed from uint8 zero."));
139 		addChild(new SeedBuilderTest<deUint8>(m_testCtx, 1,		102006549u, "uint8_one", "Seed from uint8 one."));
140 		addChild(new SeedBuilderTest<deUint8>(m_testCtx, 255,	 89633493u, "uint8_max", "Seed from uint8 max."));
141 
142 		addChild(new SeedBuilderTest<deUint16>(m_testCtx, 0,		 78413740u, "uint16_zero", "Seed from uint16 zero."));
143 		addChild(new SeedBuilderTest<deUint16>(m_testCtx, 1,		  3068621u, "uint16_one", "Seed from uint16 one."));
144 		addChild(new SeedBuilderTest<deUint16>(m_testCtx, 65535,	120448140u, "uint16_max", "Seed from uint16 max."));
145 
146 		addChild(new SeedBuilderTest<deUint32>(m_testCtx, 0u,			41006057u, "uint32_zero", "Seed from uint32 zero."));
147 		addChild(new SeedBuilderTest<deUint32>(m_testCtx, 1u,			54665834u, "uint32_one", "Seed from uint32 one."));
148 		addChild(new SeedBuilderTest<deUint32>(m_testCtx, 4294967295u,	43990167u, "uint32_max", "Seed from uint32 max."));
149 
150 		addChild(new SeedBuilderTest<float>(m_testCtx, 0.0f,	 41165361u, "float_zero", "Seed from float zero."));
151 		addChild(new SeedBuilderTest<float>(m_testCtx, -0.0f,	112541574u, "float_negative_zero", "Seed from float negative zero."));
152 		addChild(new SeedBuilderTest<float>(m_testCtx, 1.0f,	 44355905u, "float_one", "Seed from float one."));
153 		addChild(new SeedBuilderTest<float>(m_testCtx, -1.0f,	107334902u, "float_negative_one", "Seed from float negative one."));
154 
155 		addChild(new SeedBuilderTest<double>(m_testCtx, 0.0,	133470681u, "double_zero", "Seed from double zero."));
156 		addChild(new SeedBuilderTest<double>(m_testCtx, -0.0,	 53838958u, "double_negative_zero", "Seed from double negative zero."));
157 		addChild(new SeedBuilderTest<double>(m_testCtx, 1.0,	 16975104u, "double_one", "Seed from double one."));
158 		addChild(new SeedBuilderTest<double>(m_testCtx, -1.0,	 96606391u, "double_negative_one", "Seed from double negative one."));
159 
160 		addChild(new SeedBuilderTest<IVec2>(m_testCtx, IVec2(0),	 1111532u, "ivec2_zero", "Seed from zero vector."));
161 		addChild(new SeedBuilderTest<IVec3>(m_testCtx, IVec3(0),	22277704u, "ivec3_zero", "Seed from zero vector."));
162 		addChild(new SeedBuilderTest<IVec4>(m_testCtx, IVec4(0),	73989201u, "ivec4_zero", "Seed from zero vector."));
163 
164 		addChild(new SeedBuilderTest<IVec2>(m_testCtx, IVec2(1),	 12819708u, "ivec2_one", "Seed from one vector."));
165 		addChild(new SeedBuilderTest<IVec3>(m_testCtx, IVec3(1),	134047100u, "ivec3_one", "Seed from one vector."));
166 		addChild(new SeedBuilderTest<IVec4>(m_testCtx, IVec4(1),	 90609878u, "ivec4_one", "Seed from one vector."));
167 
168 		addChild(new SeedBuilderTest<IVec4>(m_testCtx, IVec4(1, 2, 3, 4),	 6202236u, "ivec4_1_2_3_4", "Seed from (1, 2, 3, 4) vector."));
169 		addChild(new SeedBuilderTest<IVec4>(m_testCtx, IVec4(4, 3, 2, 1),	26964618u, "ivec4_4_3_2_1", "Seed from (4, 3, 2, 1) vector."));
170 
171 		addChild(new SeedBuilderMultipleValuesTest(m_testCtx));
172 	}
173 };
174 
175 } // anonymous
176 
createSeedBuilderTests(tcu::TestContext & testCtx)177 tcu::TestCaseGroup* createSeedBuilderTests (tcu::TestContext& testCtx)
178 {
179 	return new SeedBuilderTests(testCtx);
180 }
181 
182 } // dit
183