forked from RipleyTom/SpuTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
229 lines (202 loc) · 6.88 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sys_time.h>
#include <cell/spurs.h>
#include "spurs_helpers.h"
#include "test_avalanche.h"
#include "test_pingpong.h"
#include "test_mfc64.h"
#include "test_spu_inst.h"
#include "test_spinlock.h"
#include "test_block.h"
#define DO_A_TEST(name, function, reference) \
{ \
testnumber++; \
if (verbose) \
printf("Test #%d: %s\n", testnumber, name); \
time1 = get_time(); \
function; \
if (ret != 0) \
{ \
printf("Error %s: 0x%x\n", name, ret); \
return ret; \
} \
time2 = get_time(); \
printf("%s completed in %llu ms (PS3: %u ms)\n", name, (time2 - time1), reference); \
}
#define NUM_TESTS 10
enum tests
{
TEST_AVALANCHE,
TEST_PINGPONG,
TEST_SPU64WAR,
TEST_PPUSPU64WAR,
TEST_SPUINTEGER,
TEST_SPUFLOAT,
TEST_SPUSPINLOCK,
TEST_SPUPUTLLUC,
TEST_SPUPUTLLC,
TEST_SPUPUT,
};
#define AVALANCHE_NAME "SPU Task Avalanche"
#define PINGPONG_NAME "PPU/SPU Ping-Pong"
#define SPU64WAR_NAME "SPU MFC 64 Bits War"
#define PPUSPU64WAR_NAME "PPU/SPU MFC 64 Bits War"
#define SPUINTEGER_NAME "SPU Integer Perf"
#define SPUFLOAT_NAME "SPU Float Perf"
#define SPUSPINLOCK_NAME "SPU SpinLock"
#define SPUPUTLLUC_NAME "PUTLLUC Perf"
#define SPUPUTLLC_NAME "PUTLLC Perf"
#define SPUPUT_NAME "PUT Perf"
typedef struct
{
char character;
int test;
char *test_name;
} arg_test;
const arg_test arg_conv[NUM_TESTS] = {
{'A', TEST_AVALANCHE, AVALANCHE_NAME},
{'P', TEST_PINGPONG, PINGPONG_NAME},
{'S', TEST_SPU64WAR, SPU64WAR_NAME},
{'W', TEST_PPUSPU64WAR, PPUSPU64WAR_NAME},
{'I', TEST_SPUINTEGER, SPUINTEGER_NAME},
{'F', TEST_SPUFLOAT, SPUFLOAT_NAME},
{'L', TEST_SPUSPINLOCK, SPUSPINLOCK_NAME},
{'U', TEST_SPUPUTLLUC, SPUPUTLLUC_NAME},
{'T', TEST_SPUPUTLLC, SPUPUTLLC_NAME},
{'R', TEST_SPUPUT, SPUPUT_NAME}};
extern const CellSpursTaskBinInfo _binary_task_task_spuint_elf_taskbininfo;
extern const CellSpursTaskBinInfo _binary_task_task_spufloat_elf_taskbininfo;
extern const CellSpursTaskBinInfo _binary_task_task_putlluc_elf_taskbininfo;
extern const CellSpursTaskBinInfo _binary_task_task_putllc_elf_taskbininfo;
extern const CellSpursTaskBinInfo _binary_task_task_put_elf_taskbininfo;
bool verbose = false;
uint64_t get_time()
{
sys_time_sec_t secs;
sys_time_nsec_t nsecs;
sys_time_get_current_time(&secs, &nsecs);
return (secs * 1000ull) + (nsecs / 1000000);
}
int main(int argc, char *argv[])
{
printf("SPU Test v1.0.0 by GalCiv\n");
unsigned int seed = 12345678;
unsigned int repeat = 1;
bool tests_to_run[NUM_TESTS];
for (int index = 0; index < NUM_TESTS; index++)
tests_to_run[index] = true;
for (int index = 1; index < argc; index++)
{
if (strcmp(argv[index], "h") == 0)
{
printf("Usage:\n");
printf("spu_test <s seed> <r number> <t tests> <v> <h>\n");
printf("s seed : sets the seed used for random generation\n");
printf("r number : repeats the test <number> times\n");
printf("t tests : only include specified tests(see list below)\n");
printf("v : sets verbose mode on to return the results of tests(hash, final value, etc)\n");
printf("h : shows help\n");
printf("----\n");
printf("List of tests:\n");
for (int subdex = 0; subdex < NUM_TESTS; subdex++)
printf("%c %s\n", arg_conv[subdex].character, arg_conv[subdex].test_name);
return 0;
}
if (strcmp(argv[index], "t") == 0)
{
if ((index + 1) >= argc)
{
printf("t needs an argument describing the tests to use\n");
return -1;
}
index++;
for (int subdex = 0; subdex < NUM_TESTS; subdex++)
{
if (strchr(argv[index], arg_conv[subdex].character))
tests_to_run[subdex] = true;
else
tests_to_run[subdex] = false;
}
}
if (strcmp(argv[index], "v") == 0)
{
printf("Verbose mode on\n");
verbose = true;
continue;
}
if (strcmp(argv[index], "s") == 0)
{
if ((index + 1) >= argc)
{
printf("s needs a seed value\n");
return -1;
}
index++;
seed = (unsigned int)strtoul(argv[index], NULL, 10);
if (seed == 0L)
{
printf("%s is not a valid seed\n", argv[index]);
return -1;
}
printf("Using seed %u\n", seed);
continue;
}
if (strcmp(argv[index], "r") == 0)
{
if ((index + 1) >= argc)
{
printf("r needs a repeat value\n");
return -1;
}
index++;
repeat = (unsigned int)strtoul(argv[index], NULL, 10);
if (seed == 0L)
{
printf("%s is not a valid repeat value\n", argv[index]);
return -1;
}
printf("Repeating test loop %u times\n", repeat);
continue;
}
}
srand(seed);
CellSpurs2 *spurs2;
int ret = initialize_spurs(&spurs2);
if (ret != CELL_OK)
{
printf("Error initializing SPURS: 0x%x\n", ret);
return ret;
}
uint64_t time1, time2, timestart, timeend;
uint32_t testnumber = 0;
timestart = get_time();
for (unsigned int index = 0; index < repeat; index++)
{
if (tests_to_run[TEST_AVALANCHE])
DO_A_TEST(AVALANCHE_NAME, test_avalanche(spurs2), 2740);
if (tests_to_run[TEST_PINGPONG])
DO_A_TEST(PINGPONG_NAME, test_pingpong(spurs2), 3045);
if (tests_to_run[TEST_SPU64WAR])
DO_A_TEST(SPU64WAR_NAME, test_mfc64(spurs2, 6, 0), 3370);
if (tests_to_run[TEST_PPUSPU64WAR])
DO_A_TEST(PPUSPU64WAR_NAME, test_mfc64(spurs2, 6, 2), 4443);
if (tests_to_run[TEST_SPUINTEGER])
DO_A_TEST(SPUINTEGER_NAME, test_spu_inst(spurs2, &_binary_task_task_spuint_elf_taskbininfo), 8666);
if (tests_to_run[TEST_SPUFLOAT])
DO_A_TEST(SPUFLOAT_NAME, test_spu_inst(spurs2, &_binary_task_task_spufloat_elf_taskbininfo), 2379);
if (tests_to_run[TEST_SPUSPINLOCK])
DO_A_TEST(SPUSPINLOCK_NAME, test_spuspinlock(spurs2), 4409);
if (tests_to_run[TEST_SPUPUTLLUC])
DO_A_TEST(SPUPUTLLUC_NAME, test_block(spurs2, &_binary_task_task_putlluc_elf_taskbininfo), 3853);
if (tests_to_run[TEST_SPUPUTLLC])
DO_A_TEST(SPUPUTLLC_NAME, test_block(spurs2, &_binary_task_task_putllc_elf_taskbininfo), 3364);
if (tests_to_run[TEST_SPUPUT])
DO_A_TEST(SPUPUT_NAME, test_block(spurs2, &_binary_task_task_put_elf_taskbininfo), 3984);
}
timeend = get_time();
printf("--Completed %d tests in %u ms--\n", testnumber, timeend - timestart);
free_spurs(spurs2);
return 0;
}