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

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: Comments round 3 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
« no previous file with comments | « crosstest/test_calling_conv.def ('k') | src/IceInstX8632.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 functions, as compiled by Subzero and
38 // llc, 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 that 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 size_t ArgNum, Subzero_ArgNum;
49 CalleePtrTy Callee, Subzero_Callee;
50 char *Buf, *Subzero_Buf;
51
52 const static size_t BUF_SIZE = 16;
53
54 std::string bufAsString(const char Buf[BUF_SIZE]) {
55 std::ostringstream OS;
56 for (size_t i = 0; i < BUF_SIZE; ++i) {
57 if (i > 0)
58 OS << " ";
59 OS << (unsigned) Buf[i];
60 }
61 return OS.str();
62 }
63
64 void testCaller(size_t &TotalTests, size_t &Passes, size_t &Failures) {
65 static struct {
66 const char *CallerName, *CalleeName;
67 size_t Args;
68 void (*Caller)(void);
69 void (*Subzero_Caller)(void);
70 CalleePtrTy Callee;
71 } Funcs[] = {
72 #define X(caller, callee, argc) \
73 { \
74 STR(caller), STR(callee), argc, &caller, &Subzero_::caller, \
75 reinterpret_cast<CalleePtrTy>(&callee), \
76 } \
77 ,
78 TEST_FUNC_TABLE
79 #undef X
80 };
81
82 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
83
84 for (size_t f = 0; f < NumFuncs; ++f) {
85 char BufLlc[BUF_SIZE], BufSz[BUF_SIZE];
86 Callee = Subzero_Callee = Funcs[f].Callee;
87
88 for (size_t i = 0; i < Funcs[f].Args; ++i) {
89 memset(BufLlc, 0xff, sizeof(BufLlc));
90 memset(BufSz, 0xff, sizeof(BufSz));
91
92 ArgNum = Subzero_ArgNum = i;
93
94 Buf = BufLlc;
95 Funcs[f].Caller();
96
97 Buf = BufSz;
98 Funcs[f].Subzero_Caller();
99
100 ++TotalTests;
101 if (!memcmp(BufLlc, BufSz, sizeof(BufLlc))) {
102 ++Passes;
103 } else {
104 ++Failures;
105 std::cout << "testCaller(Caller=" << Funcs[f].CallerName
106 << ", Callee=" << Funcs[f].CalleeName << ", ArgNum=" << ArgNum
107 << ")\nsz =" << bufAsString(BufSz)
108 << "\nllc=" << bufAsString(BufLlc) << "\n";
109 }
110 }
111 }
112 }
113
114 void testCallee(size_t &TotalTests, size_t &Passes, size_t &Failures) {
115 static struct {
116 const char *CallerName, *CalleeName;
117 size_t Args;
118 void (*Caller)(void);
119 CalleePtrTy Callee, Subzero_Callee;
120 } Funcs[] = {
121 #define X(caller, callee, argc) \
122 { \
123 STR(caller), STR(callee), argc, &caller, \
124 reinterpret_cast<CalleePtrTy>(&callee), \
125 reinterpret_cast<CalleePtrTy>(&Subzero_::callee) \
126 } \
127 ,
128 TEST_FUNC_TABLE
129 #undef X
130 };
131
132 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
133
134 for (size_t f = 0; f < NumFuncs; ++f) {
135 char BufLlc[BUF_SIZE], BufSz[BUF_SIZE];
136 Buf = BufLlc;
137 Subzero_Buf = BufSz;
138
139 for (size_t i = 0; i < Funcs[f].Args; ++i) {
140 memset(BufLlc, 0xff, sizeof(BufLlc));
141 memset(BufSz, 0xff, sizeof(BufSz));
142
143 ArgNum = Subzero_ArgNum = i;
144
145 Callee = Funcs[f].Callee;
146 Funcs[f].Caller();
147
148 Callee = Funcs[f].Subzero_Callee;
149 Funcs[f].Caller();
150
151 ++TotalTests;
152 if (!memcmp(BufLlc, BufSz, sizeof(BufLlc))) {
153 ++Passes;
154 } else {
155 ++Failures;
156 std::cout << "testCallee(Caller=" << Funcs[f].CallerName
157 << ", Callee=" << Funcs[f].CalleeName << ", ArgNum=" << ArgNum
158 << ")\nsz =" << bufAsString(BufSz)
159 << "\nllc=" << bufAsString(BufLlc) << "\n";
160 }
161 }
162 }
163 }
164
165 int main(int argc, char *argv[]) {
166 size_t TotalTests = 0;
167 size_t Passes = 0;
168 size_t Failures = 0;
169
170 testCaller(TotalTests, Passes, Failures);
171 testCallee(TotalTests, Passes, Failures);
172
173 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
174 << " Failures=" << Failures << "\n";
175
176 return Failures;
177 }
OLDNEW
« no previous file with comments | « crosstest/test_calling_conv.def ('k') | src/IceInstX8632.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698