-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtester.c
249 lines (212 loc) · 5.9 KB
/
tester.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
/*
* This file is part of tframetest.
*
* Copyright (c) 2023-2025 Tuxera Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef __linux__
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif
#endif
#include <limits.h>
#include <stdlib.h>
#include "tester.h"
#include "timing.h"
static inline size_t tester_frame_write(const platform_t *platform,
const char *path, frame_t *frame,
size_t num, test_completion_t *comp)
{
char name[PATH_MAX + 1];
size_t ret;
platform_handle_t f;
snprintf(name, PATH_MAX, "%s/frame%.6zu.tst", path, num);
name[PATH_MAX] = 0;
f = platform->open(name,
PLATFORM_OPEN_CREATE | PLATFORM_OPEN_WRITE |
PLATFORM_OPEN_DIRECT,
0666);
if (f <= 0)
return 0;
comp->open = timing_start();
ret = frame_write(platform, f, frame);
comp->io = timing_start();
platform->close(f);
comp->close = timing_start();
/* Faking the output! */
if (!ret && !frame->size)
return 1;
return ret;
}
static inline size_t tester_frame_read(const platform_t *platform,
const char *path, frame_t *frame,
size_t num, test_completion_t *comp)
{
char name[PATH_MAX + 1];
size_t ret;
platform_handle_t f;
snprintf(name, PATH_MAX, "%s/frame%.6zu.tst", path, num);
name[PATH_MAX] = 0;
f = platform->open(name, PLATFORM_OPEN_READ | PLATFORM_OPEN_DIRECT,
0666);
if (f <= 0)
return 0;
comp->open = timing_start();
ret = frame_read(platform, f, frame);
comp->io = timing_start();
platform->close(f);
comp->close = timing_start();
/* Faking the output! */
if (!ret && !frame->size)
return 1;
return ret;
}
frame_t *tester_get_frame_read(const platform_t *platform, const char *path)
{
char name[PATH_MAX + 1];
snprintf(name, PATH_MAX, "%s/frame%.6lu.tst", path, 0UL);
name[PATH_MAX] = 0;
return frame_from_file(platform, name);
}
static inline void shuffle_array(size_t *arr, size_t size)
{
size_t i;
if (!arr || size <= 1)
return;
for (i = size - 1; i >= 1; i--) {
size_t j = rand() % size;
size_t tmp;
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
test_result_t tester_run_write(const platform_t *platform, const char *path,
frame_t *frame, size_t start_frame,
size_t frames, size_t fps, test_mode_t mode)
{
test_result_t res = { 0 };
size_t i;
size_t budget;
size_t end_frame;
size_t *seq = NULL;
res.completion = platform->calloc(frames, sizeof(*res.completion));
if (!res.completion)
return res;
budget = fps ? (SEC_IN_NS / fps) : 0;
end_frame = start_frame + frames;
if (mode == TEST_MODE_RANDOM) {
seq = platform->malloc(sizeof(*seq) * frames);
if (!seq)
return res;
for (i = 0; i < frames; i++)
seq[i] = start_frame + i;
shuffle_array(seq, frames);
}
for (i = start_frame; i < end_frame; i++) {
uint64_t frame_start = timing_start();
size_t frame_idx;
res.completion[i - start_frame].start = frame_start;
switch (mode) {
case TEST_MODE_REVERSE:
frame_idx = end_frame - i + start_frame - 1;
break;
case TEST_MODE_RANDOM:
frame_idx = seq[i - start_frame];
break;
case TEST_MODE_NORM:
default:
frame_idx = i;
break;
}
if (!tester_frame_write(platform, path, frame, frame_idx,
&res.completion[i - start_frame]))
break;
res.completion[i - start_frame].frame = timing_start();
++res.frames_written;
res.bytes_written += frame->size;
/* If fps limit is enabled loop until frame budget is gone */
if (fps && budget) {
uint64_t frame_elapsed = timing_elapsed(frame_start);
while (frame_elapsed < budget) {
platform->usleep(100);
frame_elapsed = timing_elapsed(frame_start);
}
}
}
if (seq)
platform->free(seq);
return res;
}
test_result_t tester_run_read(const platform_t *platform, const char *path,
frame_t *frame, size_t start_frame, size_t frames,
size_t fps, test_mode_t mode)
{
test_result_t res = { 0 };
size_t i;
size_t budget;
size_t end_frame;
size_t *seq = NULL;
res.completion = platform->calloc(frames, sizeof(*res.completion));
if (!res.completion)
return res;
budget = fps ? (SEC_IN_NS / fps) : 0;
end_frame = start_frame + frames;
if (mode == TEST_MODE_RANDOM) {
seq = platform->malloc(sizeof(*seq) * frames);
if (!seq)
return res;
for (i = 0; i < frames; i++)
seq[i] = i + start_frame;
shuffle_array(seq, frames);
}
for (i = start_frame; i < start_frame + frames; i++) {
uint64_t frame_start = timing_start();
size_t frame_idx;
res.completion[i - start_frame].start = frame_start;
switch (mode) {
case TEST_MODE_REVERSE:
frame_idx = end_frame - i + start_frame - 1;
break;
case TEST_MODE_RANDOM:
frame_idx = seq[i - start_frame];
break;
case TEST_MODE_NORM:
default:
frame_idx = i;
break;
}
if (!tester_frame_read(platform, path, frame, frame_idx,
&res.completion[i - start_frame]))
return res;
res.completion[i - start_frame].frame = timing_start();
++res.frames_written;
res.bytes_written += frame->size;
/* If fps limit is enabled loop until frame budget is gone */
if (fps && budget) {
uint64_t frame_elapsed = timing_elapsed(frame_start);
while (frame_elapsed < budget) {
platform->usleep(100);
frame_elapsed = timing_elapsed(frame_start);
}
}
}
if (seq)
platform->free(seq);
return res;
}