1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "gtest/gtest.h"
18 
19 #include "berberis/calling_conventions/calling_conventions_x86_32.h"
20 
21 namespace berberis::x86_32 {
22 
23 namespace {
24 
TEST(CallingConventions_x86_32,Smoke)25 TEST(CallingConventions_x86_32, Smoke) {
26   CallingConventions conv;
27   ArgLocation loc;
28 
29   loc = conv.GetNextArgLoc(1, 1);
30   EXPECT_EQ(kArgLocationStack, loc.kind);
31   EXPECT_EQ(0u, loc.offset);
32 
33   loc = conv.GetNextArgLoc(2, 2);
34   EXPECT_EQ(kArgLocationStack, loc.kind);
35   EXPECT_EQ(4u, loc.offset);
36 
37   loc = conv.GetNextArgLoc(8, 8);
38   EXPECT_EQ(kArgLocationStack, loc.kind);
39   EXPECT_EQ(8u, loc.offset);
40 
41   loc = conv.GetNextArgLoc(4, 4);
42   EXPECT_EQ(kArgLocationStack, loc.kind);
43   EXPECT_EQ(16u, loc.offset);
44 
45   loc = conv.GetNextArgLoc(1, 1);
46   EXPECT_EQ(kArgLocationStack, loc.kind);
47   EXPECT_EQ(20u, loc.offset);
48 
49   loc = conv.GetNextArgLoc(8, 8);
50   EXPECT_EQ(kArgLocationStack, loc.kind);
51   EXPECT_EQ(24u, loc.offset);
52 
53   loc = conv.GetNextArgLoc(4, 4);
54   EXPECT_EQ(kArgLocationStack, loc.kind);
55   EXPECT_EQ(32u, loc.offset);
56 
57   loc = conv.GetNextArgLoc(8, 8);
58   EXPECT_EQ(kArgLocationStack, loc.kind);
59   EXPECT_EQ(40u, loc.offset);
60 
61   loc = conv.GetNextArgLoc(4, 4);
62   EXPECT_EQ(kArgLocationStack, loc.kind);
63   EXPECT_EQ(48u, loc.offset);
64 
65   loc = conv.GetIntResLoc(1);
66   EXPECT_EQ(kArgLocationIntOut, loc.kind);
67   EXPECT_EQ(0u, loc.offset);
68 
69   loc = conv.GetFpResLoc(8);
70   EXPECT_EQ(kArgLocationFp, loc.kind);
71   EXPECT_EQ(0u, loc.offset);
72 }
73 
74 }  // namespace
75 
76 }  // namespace berberis::x86_32
77