-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBenchmark.c
724 lines (605 loc) · 21.6 KB
/
Benchmark.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/*
* About:
* A simple ELF benchmarking application for Motorola P2K phones.
*
* Author:
* EXL
*
* License:
* MIT
*
* Application type:
* GUI + ATI + Java Heap
*/
#include <loader.h>
#include <apps.h>
#include <uis.h>
#include <mem.h>
#include <utilities.h>
#include "Benchmark.h"
#include "icons/icon_benchmark_48x48.h"
#define TIMER_FAST_TRIGGER_MS (1)
#define TIMER_POPUP_DELAY_MS (50)
#define TIMER_EXIT_DELAY_MS (100)
typedef enum {
APP_STATE_ANY,
APP_STATE_INIT,
APP_STATE_MAIN,
APP_STATE_POPUP,
APP_STATE_VIEW,
APP_STATE_MAX
} APP_STATE_T;
typedef enum {
APP_TIMER_EXIT = 0xE398,
APP_TIMER_EXIT_FAST,
APP_TIMER_DO_BENCHMARK
} APP_TIMER_T;
typedef enum {
APP_RESOURCE_NAME,
APP_RESOURCE_ICON_BENCHMARK,
APP_RESOURCE_MAX
} APP_RESOURCES_T;
typedef enum {
APP_MENU_ITEM_FIRST,
APP_MENU_ITEM_BENCH_CPU = APP_MENU_ITEM_FIRST,
APP_MENU_ITEM_BENCH_GPU,
APP_MENU_ITEM_BENCH_RAM_SUAPI,
APP_MENU_ITEM_BENCH_RAM_UIS,
APP_MENU_ITEM_BENCH_HEAP,
APP_MENU_ITEM_BENCH_DISK,
APP_MENU_ITEM_HELP,
APP_MENU_ITEM_ABOUT,
APP_MENU_ITEM_EXIT,
APP_MENU_ITEM_MAX
} APP_MENU_ITEM_T;
typedef enum {
APP_POPUP_PLEASE_WAIT
} APP_POPUP_T;
typedef enum {
APP_VIEW_HELP,
APP_VIEW_ABOUT,
APP_VIEW_CPU_RESULTS,
APP_VIEW_GPU_RESULTS,
APP_VIEW_RAM_RESULTS,
APP_VIEW_HEAP_RESULTS,
APP_VIEW_DISK_RESULTS
} APP_VIEW_T;
typedef struct {
APPLICATION_T app; /* Must be first. */
RESOURCE_ID resources[APP_RESOURCE_MAX];
APP_POPUP_T popup;
APP_VIEW_T view;
APP_MENU_ITEM_T menu_current_item_index;
BOOL flag_from_select;
BENCHMARK_RESULTS_CPU_T cpu_result;
BENCHMARK_RESULTS_GPU_T gpu_result;
BENCHMARK_RESULTS_RAM_T ram_result;
BENCHMARK_RESULTS_HEAP_T heap_result;
WCHAR *all_disks_result;
} APP_INSTANCE_T;
#if defined(EP1)
UINT32 Register(const char *elf_path_uri, const char *args, UINT32 ev_code); /* ElfPack 1.x entry point. */
#elif defined(EP2)
ldrElf *_start(WCHAR *uri, WCHAR *arguments); /* ElfPack 2.x entry point. */
#elif defined(EM1)
int _main(ElfLoaderApp ela); /* ElfPack 1.x M*CORE entry point. */
#elif defined(EM2)
UINT32 ELF_Entry(ldrElf *elf, WCHAR *arguments); /* ElfPack 2.x M*CORE entry point. */
#endif
static UINT32 ApplicationStart(EVENT_STACK_T *ev_st, REG_ID_T reg_id, void *reg_hdl);
static UINT32 ApplicationStop(EVENT_STACK_T *ev_st, APPLICATION_T *app);
static UINT32 InitResourses(RESOURCE_ID *resources);
static UINT32 FreeResourses(RESOURCE_ID *resources);
static UINT32 HandleStateEnter(EVENT_STACK_T *ev_st, APPLICATION_T *app, ENTER_STATE_TYPE_T state);
static UINT32 HandleStateExit(EVENT_STACK_T *ev_st, APPLICATION_T *app, EXIT_STATE_TYPE_T state);
static UINT32 DeleteDialog(APPLICATION_T *app);
static UINT32 HandleEventTimerExpired(EVENT_STACK_T *ev_st, APPLICATION_T *app);
static UINT32 HandleEventSelect(EVENT_STACK_T *ev_st, APPLICATION_T *app);
static UINT32 HandleEventBack(EVENT_STACK_T *ev_st, APPLICATION_T *app);
static LIST_ENTRY_T *CreateList(EVENT_STACK_T *ev_st, APPLICATION_T *app, UINT32 start, UINT32 count);
const char g_app_name[APP_NAME_LEN] = "Benchmark";
static const WCHAR g_str_app_name[] = L"Benchmark";
static const WCHAR g_str_menu_bench_cpu[] = L"CPU (MCU)";
static const WCHAR g_str_menu_bench_ipu[] = L"GPU (IPU)";
static const WCHAR g_str_menu_bench_ram_suapi[] = L"RAM (SUAPI)";
static const WCHAR g_str_menu_bench_ram_uis[] = L"RAM (UIS)";
static const WCHAR g_str_menu_bench_heap[] = L"HEAP (J2ME)";
static const WCHAR g_str_menu_bench_disk[] = L"DISK (IO)";
static const WCHAR g_str_menu_help[] = L"Help...";
static const WCHAR g_str_menu_about[] = L"About...";
static const WCHAR g_str_menu_exit[] = L"Exit";
static const WCHAR g_str_popup_wait_p1[] = L"Benchmarking in progress!";
static const WCHAR g_str_popup_wait_p2[] = L"Please wait...";
static const WCHAR g_str_view_help[] = L"Help";
static const WCHAR g_str_view_cpu_results[] = L"CPU Results";
static const WCHAR g_str_view_cpu_bogomips[] = L"BogoMIPS:";
static const WCHAR g_str_view_cpu_dhrystone[] = L"Dhrystone 2.1:";
static const WCHAR g_str_view_ram_results[] = L"RAM Results";
static const WCHAR g_str_view_mem_total[] = L"Total available:";
static const WCHAR g_str_view_ram_top[] = L"Top 6 blocks:";
static const WCHAR g_str_view_heap_results[] = L"Java Heap Results";
static const WCHAR g_str_view_gpu_results[] = L"GPU Results";
static const WCHAR g_str_view_gpu_fps[] = L"Average FPS:";
static const WCHAR g_str_view_gpu_properties[] = L"Properties:";
static const WCHAR g_str_view_todo[] = L"Not yet implemented, sorry!";
static const WCHAR g_str_view_disk_results[] = L"Disk Results";
static const WCHAR g_str_help_content_p1[] =
L"A simple ELF benchmarking application for Motorola P2K phones.\n\n"
L"CPU (MCU) - contains two BogoMIPS and Dhrystone benchmarks.\n\n"
L"GPU (IPU) - consists a procedural stress Flame test at different resolutions and a video driver information.\n\n"
L"RAM (SUAPI) - calculates free system memory for ELFs and TOP-6 blocks of maximum size using SUAPI allocators.\n\n"
L"RAM (UIS) - calculates free system memory for ELFs and TOP-6 blocks of maximum size using UIS allocators.\n\n"
L"HEAP (J2ME) - shows free Java Heap memory for ELFs, test requires Heap functions in the ELF library to work.\n\n"
L"DISK (IO) - test read/write speeds on the phone's file systems disks.\n\n"
L"This benchmark is convenient to use with the Overclock.elf application.";
static const WCHAR g_str_about_content_p1[] = L"Version: 1.0";
static const WCHAR g_str_about_content_p2[] = L"\x00A9 EXL, 28-Aug-2023.";
static const WCHAR g_str_about_content_p3[] = L"https://github.com/EXL/P2kElfs/tree/master/Benchmark";
static const WCHAR g_str_about_content_p4[] = L" "; /* HACK: gap */
#if defined(EP2)
static ldrElf g_app_elf;
#elif defined(EM1)
static ElfLoaderApp g_app_elf = { 0 };
#elif defined(EM2)
static ldrElf *g_app_elf = NULL;
#endif
static EVENT_HANDLER_ENTRY_T g_state_any_hdls[] = {
{ EV_REVOKE_TOKEN, APP_HandleUITokenRevoked },
{ EV_TIMER_EXPIRED, HandleEventTimerExpired },
{ STATE_HANDLERS_END, NULL }
};
static EVENT_HANDLER_ENTRY_T g_state_init_hdls[] = {
{ EV_GRANT_TOKEN, APP_HandleUITokenGranted },
{ STATE_HANDLERS_END, NULL }
};
static EVENT_HANDLER_ENTRY_T g_state_main_hdls[] = {
{ EV_DONE, ApplicationStop },
{ EV_DIALOG_DONE, ApplicationStop },
{ EV_SELECT, HandleEventSelect },
{ STATE_HANDLERS_END, NULL }
};
static EVENT_HANDLER_ENTRY_T g_state_popup_hdls[] = {
{ EV_DONE, HandleEventBack },
{ EV_DIALOG_DONE, HandleEventBack },
{ STATE_HANDLERS_END, NULL }
};
static const STATE_HANDLERS_ENTRY_T g_state_table_hdls[] = {
{ APP_STATE_ANY, NULL, NULL, g_state_any_hdls },
{ APP_STATE_INIT, NULL, NULL, g_state_init_hdls },
{ APP_STATE_MAIN, HandleStateEnter, NULL, g_state_main_hdls },
{ APP_STATE_POPUP, HandleStateEnter, HandleStateExit, g_state_popup_hdls },
{ APP_STATE_VIEW, HandleStateEnter, HandleStateExit, g_state_popup_hdls } /* Same as popups. */
};
#if defined(EP1)
UINT32 Register(const char *elf_path_uri, const char *args, UINT32 ev_code) {
UINT32 status;
UINT32 ev_code_base;
ev_code_base = ev_code;
status = APP_Register(&ev_code_base, 1, g_state_table_hdls, APP_STATE_MAX, (void *) ApplicationStart);
LdrStartApp(ev_code_base);
return status;
}
#elif defined(EP2)
ldrElf *_start(WCHAR *uri, WCHAR *arguments) {
UINT32 status;
UINT32 ev_code_base;
UINT32 reserve;
if (ldrIsLoaded(g_app_name)) {
cprint("Benchmark: Error! Application has already been loaded!\n");
return NULL;
}
status = RESULT_OK;
ev_code_base = ldrRequestEventBase();
reserve = ev_code_base + 1;
reserve = ldrInitEventHandlersTbl(g_state_any_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_init_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_main_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_popup_hdls, reserve);
status |= APP_Register(&ev_code_base, 1, g_state_table_hdls, APP_STATE_MAX, (void *) ApplicationStart);
status |= ldrSendEvent(ev_code_base);
g_app_elf.name = (char *) g_app_name;
return (status == RESULT_OK) ? &g_app_elf : NULL;
}
#elif defined(EM1)
int _main(ElfLoaderApp ela) {
UINT32 status;
status = RESULT_OK;
memcpy((void *) &g_app_elf, (void *) &ela, sizeof(ElfLoaderApp));
status = APP_Register(&g_app_elf.evcode, 1, g_state_table_hdls, APP_STATE_MAX, (void *) ApplicationStart);
LoaderShowApp(&g_app_elf);
return RESULT_FAIL;
}
#elif defined(EM2)
UINT32 ELF_Entry(ldrElf *elf, WCHAR *arguments) {
UINT32 status;
UINT32 reserve;
status = RESULT_OK;
g_app_elf = elf;
g_app_elf->name = (char *) g_app_name;
if (ldrIsLoaded(g_app_elf->name)) {
PFprintf("%s: Application already loaded.\n", g_app_elf->name);
return RESULT_FAIL;
}
reserve = g_app_elf->evbase + 1;
reserve = ldrInitEventHandlersTbl(g_state_any_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_init_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_main_hdls, reserve);
reserve = ldrInitEventHandlersTbl(g_state_popup_hdls, reserve);
status |= APP_Register(&g_app_elf->evbase, 1, g_state_table_hdls, APP_STATE_MAX, (void *) ApplicationStart);
if (status == RESULT_OK) {
PFprintf("%s: Application has been registered successfully.\n", g_app_elf->name);
status |= ldrSendEvent(g_app_elf->evbase);
} else {
PFprintf("%s: Cannot register application.\n", g_app_elf->name);
}
return status;
}
#endif
static UINT32 ApplicationStart(EVENT_STACK_T *ev_st, REG_ID_T reg_id, void *reg_hdl) {
UINT32 status;
APP_INSTANCE_T *app_instance;
status = RESULT_FAIL;
if (AFW_InquireRoutingStackByRegId(reg_id) != RESULT_OK) {
app_instance = (APP_INSTANCE_T *) APP_InitAppData((void *) APP_HandleEvent, sizeof(APP_INSTANCE_T),
reg_id, 0, 1, 1, 1, 1, 0);
InitResourses(app_instance->resources);
app_instance->menu_current_item_index = APP_MENU_ITEM_FIRST;
app_instance->popup = APP_POPUP_PLEASE_WAIT;
app_instance->view = APP_VIEW_ABOUT;
app_instance->flag_from_select = FALSE;
app_instance->all_disks_result = suAllocMem(RESULT_STRING * 10, NULL);
status = APP_Start(ev_st, &app_instance->app, APP_STATE_MAIN,
g_state_table_hdls, ApplicationStop, g_app_name, 0);
#if defined(EP2)
g_app_elf.app = (APPLICATION_T *) app_instance;
#elif defined(EM2)
g_app_elf->app = &app_instance->app;
#endif
}
return status;
}
static UINT32 ApplicationStop(EVENT_STACK_T *ev_st, APPLICATION_T *app) {
UINT32 status;
APP_INSTANCE_T *app_instance;
status = RESULT_OK;
app_instance = (APP_INSTANCE_T *) app;
APP_ConsumeEv(ev_st, app);
DeleteDialog(app);
FreeResourses(app_instance->resources);
suFreeMem(app_instance->all_disks_result);
status |= APP_Exit(ev_st, app, 0);
#if defined(EP1)
LdrUnloadELF(&Lib);
#elif defined(EP2)
ldrUnloadElf();
#elif defined(EM1)
LoaderEndApp(&g_app_elf);
#elif defined(EM2)
ldrUnloadElf(g_app_elf);
#endif
return status;
}
static UINT32 InitResourses(RESOURCE_ID *resources) {
UINT32 status;
status = RESULT_OK;
status |= DRM_CreateResource(&resources[APP_RESOURCE_NAME], RES_TYPE_STRING,
(void *) g_str_app_name, (u_strlen(g_str_app_name) + 1) * sizeof(WCHAR));
status |= DRM_CreateResource(&resources[APP_RESOURCE_ICON_BENCHMARK], RES_TYPE_GRAPHICS,
(void *) benchmark_48x48_gif, sizeof(benchmark_48x48_gif));
return status;
}
static UINT32 FreeResourses(RESOURCE_ID *resources) {
UINT32 status;
UINT32 i;
status = RESULT_OK;
for (i = 0; i < APP_RESOURCE_MAX; ++i) {
if (resources[i]) {
status |= DRM_ClearResource(resources[i]);
}
}
return status;
}
static UINT32 HandleStateEnter(EVENT_STACK_T *ev_st, APPLICATION_T *app, ENTER_STATE_TYPE_T state) {
APP_INSTANCE_T *app_instance;
SU_PORT_T port;
CONTENT_T content;
UIS_DIALOG_T dialog;
APP_STATE_T app_state;
UINT8 notice_type;
LIST_ENTRY_T *list;
if (state != ENTER_STATE_ENTER) {
if (app->state != APP_STATE_MAIN) {
return RESULT_OK;
}
}
app_instance = (APP_INSTANCE_T *) app;
DeleteDialog(app);
port = app->port;
app_state = app->state;
dialog = DialogType_None;
memclr(&content, sizeof(CONTENT_T));
switch (app_state) {
case APP_STATE_MAIN:
list = CreateList(ev_st, app, 1, APP_MENU_ITEM_MAX);
if (list != NULL) {
dialog = UIS_CreateStaticList(&port, 0, APP_MENU_ITEM_MAX, 0, list, FALSE, 2, NULL,
app_instance->resources[APP_RESOURCE_NAME]);
suFreeMem(list);
/* Insert cursor to proper position. */
if (app_instance->flag_from_select) {
if (app_instance->menu_current_item_index != APP_MENU_ITEM_FIRST) {
APP_UtilAddEvChangeListPosition(ev_st, app, app_instance->menu_current_item_index + 1,
NULL, NULL, NULL);
UIS_HandleEvent(dialog, ev_st);
}
app_instance->flag_from_select = FALSE;
}
}
break;
case APP_STATE_POPUP:
switch (app_instance->popup) {
default:
case APP_POPUP_PLEASE_WAIT:
notice_type = NOTICE_TYPE_WAIT;
UIS_MakeContentFromString("MCq0NMCq1", &content, g_str_popup_wait_p1, g_str_popup_wait_p2);
APP_UtilStartTimer(TIMER_POPUP_DELAY_MS, APP_TIMER_DO_BENCHMARK, app);
break;
}
dialog = UIS_CreateTransientNotice(&port, &content, notice_type);
break;
case APP_STATE_VIEW:
switch (app_instance->view) {
default:
case APP_VIEW_HELP:
UIS_MakeContentFromString("q0Nq1", &content, g_str_view_help, g_str_help_content_p1);
break;
case APP_VIEW_ABOUT:
UIS_MakeContentFromString("q0NMCp1NMCq2NMCq3NMCq4NMCq5NMCq6", &content, g_str_app_name,
app_instance->resources[APP_RESOURCE_ICON_BENCHMARK],
g_str_about_content_p1, g_str_about_content_p2, g_str_about_content_p3,
g_str_about_content_p4, g_str_about_content_p4);
break;
case APP_VIEW_CPU_RESULTS:
UIS_MakeContentFromString(
"q0Nq1NSq2NSq3N NRq4NSq5NSq6NSq7", &content, g_str_view_cpu_results,
g_str_view_cpu_bogomips,
app_instance->cpu_result.bogo_time,
app_instance->cpu_result.bogo_mips,
g_str_view_cpu_dhrystone,
app_instance->cpu_result.dhrys_time,
app_instance->cpu_result.dhrys_score,
app_instance->cpu_result.dhrys_mips
);
break;
case APP_VIEW_GPU_RESULTS:
#if defined(EM1) || defined(EM2)
UIS_MakeContentFromString("q0Nq1", &content, g_str_view_gpu_results, g_str_view_todo);
#else
UIS_MakeContentFromString(
"q0Nq1NSq2NSq3NSq4NSq5NSq6NSq7N NRq8NSq9", &content, g_str_view_gpu_results,
g_str_view_gpu_fps,
app_instance->gpu_result.fps_pass1,
app_instance->gpu_result.fms_pass1,
app_instance->gpu_result.fps_pass2,
app_instance->gpu_result.fms_pass2,
app_instance->gpu_result.fps_pass3,
app_instance->gpu_result.fms_pass3,
g_str_view_gpu_properties,
app_instance->gpu_result.properties
);
#endif
break;
case APP_VIEW_RAM_RESULTS:
UIS_MakeContentFromString(
"q0Nq1NSq2N NRq3NSq4NSq5NSq6NSq7NSq8NSq9", &content, g_str_view_ram_results,
g_str_view_mem_total,
app_instance->ram_result.total,
g_str_view_ram_top,
app_instance->ram_result.blocks[0],
app_instance->ram_result.blocks[1],
app_instance->ram_result.blocks[2],
app_instance->ram_result.blocks[3],
app_instance->ram_result.blocks[4],
app_instance->ram_result.blocks[5]
);
break;
case APP_VIEW_HEAP_RESULTS:
UIS_MakeContentFromString(
"q0Nq1NSq2NSq3", &content, g_str_view_heap_results,
g_str_view_mem_total,
app_instance->heap_result.total,
app_instance->heap_result.desc
);
break;
case APP_VIEW_DISK_RESULTS:
UIS_MakeContentFromString(
"q0Nq1", &content, g_str_view_disk_results, app_instance->all_disks_result
);
break;
}
dialog = UIS_CreateViewer(&port, &content, NULL);
break;
default:
break;
}
if (dialog == DialogType_None) {
return RESULT_FAIL;
}
app->dialog = dialog;
return RESULT_OK;
}
static UINT32 HandleStateExit(EVENT_STACK_T *ev_st, APPLICATION_T *app, EXIT_STATE_TYPE_T state) {
if (state == EXIT_STATE_EXIT) {
DeleteDialog(app);
return RESULT_OK;
}
return RESULT_FAIL;
}
static UINT32 DeleteDialog(APPLICATION_T *app) {
if (app->dialog != DialogType_None) {
UIS_Delete(app->dialog);
app->dialog = DialogType_None;
return RESULT_OK;
}
return RESULT_FAIL;
}
static UINT32 HandleEventTimerExpired(EVENT_STACK_T *ev_st, APPLICATION_T *app) {
EVENT_T *event;
APP_TIMER_T timer_id;
APP_INSTANCE_T *app_instance;
app_instance = (APP_INSTANCE_T *) app;
event = AFW_GetEv(ev_st);
timer_id = ((DL_TIMER_DATA_T *) event->attachment)->ID;
switch (timer_id) {
case APP_TIMER_EXIT:
/* No break here. */
case APP_TIMER_EXIT_FAST:
/* Play an exit sound using quiet speaker. */
DL_AudPlayTone(0x00, 0xFF);
return ApplicationStop(ev_st, app);
break;
case APP_TIMER_DO_BENCHMARK:
switch (app_instance->menu_current_item_index) {
case APP_MENU_ITEM_BENCH_CPU:
app_instance->view = APP_VIEW_CPU_RESULTS;
BogoMIPS(&app_instance->cpu_result);
Dhrystone(&app_instance->cpu_result);
break;
case APP_MENU_ITEM_BENCH_GPU:
app_instance->view = APP_VIEW_GPU_RESULTS;
Bench_GPU_Passes(BITMAP_WIDTH_LOW, BITMAP_HEIGHT_LOW,
app_instance->gpu_result.fps_pass1,
app_instance->gpu_result.fms_pass1,
app_instance->gpu_result.properties);
Bench_GPU_Passes(BITMAP_WIDTH_MID, BITMAP_HEIGHT_MID,
app_instance->gpu_result.fps_pass2,
app_instance->gpu_result.fms_pass2,
app_instance->gpu_result.properties);
Bench_GPU_Passes(BITMAP_WIDTH_HIGH, BITMAP_WIDTH_HIGH,
app_instance->gpu_result.fps_pass3,
app_instance->gpu_result.fms_pass3,
app_instance->gpu_result.properties);
break;
case APP_MENU_ITEM_BENCH_RAM_SUAPI:
app_instance->view = APP_VIEW_RAM_RESULTS;
TotalRamSize(&app_instance->ram_result, FALSE);
TopOfBiggestRamBlocks(&app_instance->ram_result, FALSE);
break;
case APP_MENU_ITEM_BENCH_RAM_UIS:
app_instance->view = APP_VIEW_RAM_RESULTS;
TotalRamSize(&app_instance->ram_result, TRUE);
TopOfBiggestRamBlocks(&app_instance->ram_result, TRUE);
break;
case APP_MENU_ITEM_BENCH_HEAP:
app_instance->view = APP_VIEW_HEAP_RESULTS;
if (TotalHeapSize(&app_instance->heap_result) != RESULT_OK) {
u_strcpy(app_instance->heap_result.desc, L"Error: Java Heap");
u_strcpy(app_instance->heap_result.total, L"Error: Java Heap");
}
break;
case APP_MENU_ITEM_BENCH_DISK:
app_instance->view = APP_VIEW_DISK_RESULTS;
DisksResult(app_instance->all_disks_result);
break;
default:
break;
}
APP_UtilChangeState(APP_STATE_VIEW, ev_st, app);
break;
default:
break;
}
return RESULT_OK;
}
static UINT32 HandleEventSelect(EVENT_STACK_T *ev_st, APPLICATION_T *app) {
UINT32 status;
APP_INSTANCE_T *app_instance;
EVENT_T *event;
status = RESULT_OK;
app_instance = (APP_INSTANCE_T *) app;
event = AFW_GetEv(ev_st);
app_instance->flag_from_select = TRUE;
app_instance->menu_current_item_index = event->data.index - 1;
switch (app_instance->menu_current_item_index) {
case APP_MENU_ITEM_BENCH_CPU:
case APP_MENU_ITEM_BENCH_GPU:
case APP_MENU_ITEM_BENCH_RAM_SUAPI:
case APP_MENU_ITEM_BENCH_RAM_UIS:
case APP_MENU_ITEM_BENCH_HEAP:
case APP_MENU_ITEM_BENCH_DISK:
status |= APP_UtilChangeState(APP_STATE_POPUP, ev_st, app);
break;
case APP_MENU_ITEM_HELP:
app_instance->view = APP_VIEW_HELP;
status |= APP_UtilChangeState(APP_STATE_VIEW, ev_st, app);
break;
case APP_MENU_ITEM_ABOUT:
app_instance->view = APP_VIEW_ABOUT;
status |= APP_UtilChangeState(APP_STATE_VIEW, ev_st, app);
break;
case APP_MENU_ITEM_EXIT:
status |= APP_UtilStartTimer(TIMER_EXIT_DELAY_MS, APP_TIMER_EXIT, app);
break;
default:
break;
}
return status;
}
static UINT32 HandleEventBack(EVENT_STACK_T *ev_st, APPLICATION_T *app) {
UINT32 status;
status = RESULT_OK;
status |= APP_UtilChangeState(APP_STATE_MAIN, ev_st, app);
return status;
}
static LIST_ENTRY_T *CreateList(EVENT_STACK_T *ev_st, APPLICATION_T *app, UINT32 start, UINT32 count) {
UINT32 status;
INT32 result;
UINT32 i;
LIST_ENTRY_T *list_elements;
status = RESULT_OK;
result = RESULT_OK;
if (count == 0) {
return NULL;
}
list_elements = (LIST_ENTRY_T *) suAllocMem(sizeof(LIST_ENTRY_T) * count, &result);
if (result != RESULT_OK) {
return NULL;
}
for (i = 0; i < count; ++i) {
memclr(&list_elements[i], sizeof(LIST_ENTRY_T));
list_elements[i].editable = FALSE;
list_elements[i].content.static_entry.formatting = TRUE;
}
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_CPU].content.static_entry.text,
g_str_menu_bench_cpu);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_GPU].content.static_entry.text,
g_str_menu_bench_ipu);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_RAM_SUAPI].content.static_entry.text,
g_str_menu_bench_ram_suapi);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_RAM_UIS].content.static_entry.text,
g_str_menu_bench_ram_uis);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_HEAP].content.static_entry.text,
g_str_menu_bench_heap);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_BENCH_DISK].content.static_entry.text,
g_str_menu_bench_disk);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_HELP].content.static_entry.text,
g_str_menu_help);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_ABOUT].content.static_entry.text,
g_str_menu_about);
status |= UIS_MakeContentFromString("Mq0",
&list_elements[APP_MENU_ITEM_EXIT].content.static_entry.text,
g_str_menu_exit);
if (status != RESULT_OK) {
suFreeMem(list_elements);
return NULL;
}
return list_elements;
}