OSDN Git Service

Use gtest for testing Subzero.
[android-x86/external-swiftshader.git] / src / Reactor / Main.cpp
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "Reactor.hpp"
16
17 #include "gtest/gtest.h"
18
19 using namespace sw;
20
21 int reference(int *p, int y)
22 {
23         int x = p[-1];
24         int z = 4;
25
26         for(int i = 0; i < 10; i++)
27         {
28                 z += (2 << i) - (i / 3);
29         }
30
31         int sum = x + y + z;
32
33         return sum;
34 }
35
36 TEST(SubzeroReactorSample, SubzeroReactor)
37 {
38         Routine *routine = nullptr;
39
40         {
41                 Function<Int(Pointer<Int>, Int)> function;
42                 {
43                         Pointer<Int> p = function.Arg<0>();
44                         Int x = p[-1];
45                         Int y = function.Arg<1>();
46                         Int z = 4;
47
48                         For(Int i = 0, i < 10, i++)
49                         {
50                                 z += (2 << i) - (i / 3);
51                         }
52
53                         Float4 v;
54                         v.z = As<Float>(z);
55                         z = As<Int>(Float(Float4(v.xzxx).y));
56
57                         Int sum = x + y + z;
58    
59                         Return(sum);
60                 }
61
62                 routine = function(L"one");
63
64                 if(routine)
65                 {
66                         int (*callable)(int*, int) = (int(*)(int*,int))routine->getEntry();
67                         int one[2] = {1, 0};
68                         int result = callable(&one[1], 2);
69                         EXPECT_EQ(result, reference(&one[1], 2));
70                 }
71         }
72
73         delete routine;
74 }
75
76 int main(int argc, char **argv)
77 {
78         ::testing::InitGoogleTest(&argc, argv);
79         return RUN_ALL_TESTS();
80 }