Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: crosstest/test_calling_conv_main.cpp

Issue 444443002: Subzero: Align the stack at the point of function calls. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: First round of comments. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===- subzero/crosstest/test_calling_conv_main.cpp - Driver for tests ----===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the driver for cross testing the compatibility of
11 // calling conventions.
12 //
13 //===----------------------------------------------------------------------===//
14
15 /* crosstest.py --test=test_calling_conv.cpp \
16 --driver=test_calling_conv_main.cpp --prefix=Subzero_ \
17 --output=test_calling_conv */
18
19 #include <cstring>
20 #include <iostream>
21 #include <sstream>
22
23 #include "test_calling_conv.h"
24
25 namespace Subzero_ {
26 #include "test_calling_conv.h"
27 }
28
29 // The crosstest code consists of caller / callee function pairs.
30 //
31 // The caller function initializes a list of arguments and calls the
32 // function located at Callee.
33 //
34 // The callee function writes the argument numbered ArgNum into the
35 // location pointed to by Buf.
36 //
37 // testCaller() tests that caller function compiled by Subzero and llc
38 // pass arguments to the callee in the same way. The Caller() and
39 // Subzero_Caller() functions both call the same callee (which has been
40 // compiled by llc). The result in the global buffer is compared to
41 // check it is the same value after the calls by both callers.
42 //
43 // testCallee() runs the same kind of test, except that the functions
44 // Callee() and Subzero_Callee() are being tested to ensure that both
45 // functions receive arguments from the caller in the same way. The
46 // caller is compiled by llc.
47 //
48 // Some crosstest functions allocate local arrays as part of the test.
49 // The fakeUse function is used to ensure that array allocations are not
50 // dead code eliminated.
51
52 size_t ArgNum, Subzero_ArgNum;
53 CalleePtrTy Callee, Subzero_Callee;
54 char *Buf, *Subzero_Buf;
55
56 const static size_t BUF_SIZE = 16;
57
58 std::string bufAsString(const char Buf[BUF_SIZE]) {
59 std::ostringstream OS;
60 for (size_t i = 0; i < BUF_SIZE; ++i) {
61 if (i > 0)
62 OS << " ";
63 OS << (unsigned) Buf[i];
64 }
65 return OS.str();
66 }
67
68 void testCaller(size_t &TotalTests, size_t &Passes, size_t &Failures) {
69 static struct {
70 const char *CallerName, *CalleeName;
71 size_t Args;
72 void (*Caller)(void);
73 void (*Subzero_Caller)(void);
74 CalleePtrTy Callee;
75 } Funcs[] = {
76 #define X(caller, callee, argc) \
77 { \
78 STR(caller), STR(callee), argc, &caller, &Subzero_::caller, \
79 reinterpret_cast<CalleePtrTy>(&callee), \
80 } \
81 ,
82 TEST_FUNC_TABLE
83 #undef X
84 };
85
86 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
87
88 for (size_t f = 0; f < NumFuncs; ++f) {
89 char BufLlc[BUF_SIZE], BufSz[BUF_SIZE];
90 Callee = Subzero_Callee = Funcs[f].Callee;
91
92 for (size_t i = 0; i < Funcs[f].Args; ++i) {
93 memset(BufLlc, 0xff, sizeof(BufLlc));
94 memset(BufSz, 0xff, sizeof(BufSz));
95
96 ArgNum = Subzero_ArgNum = i;
97
98 Buf = BufLlc;
99 Funcs[f].Caller();
100
101 Buf = BufSz;
102 Funcs[f].Subzero_Caller();
103
104 ++TotalTests;
105 if (!memcmp(BufLlc, BufSz, sizeof(BufLlc))) {
106 ++Passes;
107 } else {
108 ++Failures;
109 std::cout << "testCaller(Caller=" << Funcs[f].CallerName << ", ";
110 std::cout << "Callee=" << Funcs[f].CalleeName << ", ";
111 std::cout << "ArgNum=" << ArgNum << ")\n";
112 std::cout << "sz =" << bufAsString(BufSz) << "\n";
113 std::cout << "llc=" << bufAsString(BufLlc) << "\n";
114 }
115 }
116 }
117 }
118
119 void testCallee(size_t &TotalTests, size_t &Passes, size_t &Failures) {
120 static struct {
121 const char *CallerName, *CalleeName;
122 size_t Args;
123 void (*Caller)(void);
124 CalleePtrTy Callee, Subzero_Callee;
125 } Funcs[] = {
126 #define X(caller, callee, argc) \
127 { \
128 STR(caller), STR(callee), argc, &caller, \
129 reinterpret_cast<CalleePtrTy>(&callee), \
130 reinterpret_cast<CalleePtrTy>(&Subzero_::callee) \
131 } \
132 ,
133 TEST_FUNC_TABLE
134 #undef X
135 };
136
137 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
138
139 for (size_t f = 0; f < NumFuncs; ++f) {
140 char BufLlc[BUF_SIZE], BufSz[BUF_SIZE];
141 Buf = BufLlc;
142 Subzero_Buf = BufSz;
143
144 for (size_t i = 0; i < Funcs[f].Args; ++i) {
145 memset(BufLlc, 0xff, sizeof(BufLlc));
146 memset(BufSz, 0xff, sizeof(BufSz));
147
148 ArgNum = Subzero_ArgNum = i;
149
150 Callee = Funcs[f].Callee;
151 Funcs[f].Caller();
152
153 Callee = Funcs[f].Subzero_Callee;
154 Funcs[f].Caller();
155
156 ++TotalTests;
157 if (!memcmp(BufLlc, BufSz, sizeof(BufLlc))) {
158 ++Passes;
159 } else {
160 ++Failures;
161 std::cout << "testCallee(Caller=" << Funcs[f].CallerName << ", ";
162 std::cout << "Callee=" << Funcs[f].CalleeName << ", ";
163 std::cout << "ArgNum=" << ArgNum << ")\n";
164 std::cout << "sz =" << bufAsString(BufSz) << "\n";
165 std::cout << "llc=" << bufAsString(BufLlc) << "\n";
166 }
167 }
168 }
169 }
170
171 int main(int argc, char *argv[]) {
172 size_t TotalTests = 0;
173 size_t Passes = 0;
174 size_t Failures = 0;
175
176 testCaller(TotalTests, Passes, Failures);
177 testCallee(TotalTests, Passes, Failures);
178
179 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
180 << " Failures=" << Failures << "\n";
181
182 return Failures;
183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698