Skip to content

Commit 8cd5324

Browse files
authored
Merge pull request #293 from atrick/master
Reapply "Fix compilation warnings in extended test suite".
2 parents 837f2bd + d14ffcd commit 8cd5324

12 files changed

+129
-77
lines changed

tests/bsdtests.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ test_long_format(long actual, long expected, const char* format, ...)
188188
_test_long(NULL, 0, desc, actual, expected);
189189
}
190190

191+
void
192+
_test_sizet(const char* file, long line, const char* desc, size_t actual, size_t expected)
193+
{
194+
_test_print(file, line, desc,
195+
(actual == expected), "%zd", actual, "%zd", expected);
196+
}
197+
198+
void
199+
test_sizet_format(size_t actual, size_t expected, const char* format, ...)
200+
{
201+
GENERATE_DESC
202+
_test_sizet(NULL, 0, desc, actual, expected);
203+
}
204+
191205
void
192206
_test_uint64(const char* file, long line, const char* desc, uint64_t actual, uint64_t expected)
193207
{
@@ -255,6 +269,32 @@ test_long_greater_than_or_equal_format(long actual, long expected_max, const cha
255269
_test_long_greater_than_or_equal(NULL, 0, desc, actual, expected_max);
256270
}
257271

272+
void
273+
_test_sizet_less_than(const char* file, long line, const char* desc, size_t actual, size_t expected_max)
274+
{
275+
_test_print(file, line, desc, (actual < expected_max), "%zd", actual, "<%zd", expected_max);
276+
}
277+
278+
void
279+
test_sizet_less_than_format(size_t actual, size_t expected_max, const char* format, ...)
280+
{
281+
GENERATE_DESC
282+
_test_sizet_less_than(NULL, 0, desc, actual, expected_max);
283+
}
284+
285+
void
286+
_test_sizet_less_than_or_equal(const char* file, long line, const char* desc, size_t actual, size_t expected_max)
287+
{
288+
_test_print(file, line, desc, (actual <= expected_max), "%zd", actual, "<=%zd", expected_max);
289+
}
290+
291+
void
292+
test_sizet_less_than_or_equal_format(size_t actual, size_t expected_max, const char* format, ...)
293+
{
294+
GENERATE_DESC
295+
_test_sizet_less_than_or_equal(NULL, 0, desc, actual, expected_max);
296+
}
297+
258298
void
259299
_test_double_less_than(const char* file, long line, const char* desc, double val, double max_expected)
260300
{

tests/bsdtests.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ void _test_long(const char* file, long line, const char* desc, long actual, long
9191
#define test_long(a,b,c) _test_long(__SOURCE_FILE__, __LINE__, a, b, c)
9292
void test_long_format(long actual, long expected, const char *format, ...) __printflike(3,4);
9393

94+
void _test_sizet(const char* file, long line, const char* desc, size_t actual, size_t expected);
95+
#define test_sizet(a,b,c) _test_sizet(__SOURCE_FILE__, __LINE__, a, b, c)
96+
void test_sizet_format(size_t actual, size_t expected, const char *format, ...) __printflike(3,4);
97+
9498
void _test_uint64(const char* file, long line, const char* desc, uint64_t actual, uint64_t expected);
9599
#define test_uint64(a,b,c) _test_uint64(__SOURCE_FILE__, __LINE__, a, b, c)
96100
void test_uint64_format(uint64_t actual, uint64_t expected, const char* desc, ...);
@@ -111,6 +115,14 @@ void _test_long_greater_than_or_equal(const char* file, long line, const char* d
111115
#define test_long_greater_than_or_equal(a,b,c) _test_long_greater_than_or_equal(__SOURCE_FILE__, __LINE__, a, b, c)
112116
void test_long_greater_than_or_equal_format(long actual, long expected_min, const char *format, ...) __printflike(3,4);
113117

118+
void _test_sizet_less_than(const char* file, long line, const char* desc, size_t actual, size_t max_expected);
119+
#define test_sizet_less_than(a,b,c) _test_sizet_less_than(__SOURCE_FILE__, __LINE__, a, b, c)
120+
void test_sizet_less_than_format(size_t actual, size_t max_expected, const char *format, ...) __printflike(3,4);
121+
122+
void _test_sizet_less_than_or_equal(const char* file, long line, const char* desc, size_t actual, size_t max_expected);
123+
#define test_sizet_less_than_or_equal(a,b,c) _test_sizet_less_than_or_equal(__SOURCE_FILE__, __LINE__, a, b, c)
124+
void test_sizet_less_than_or_equal_format(size_t actual, size_t max_expected, const char *format, ...) __printflike(3,4);
125+
114126
void _test_double_less_than_or_equal(const char* file, long line, const char* desc, double val, double max_expected);
115127
#define test_double_less_than_or_equal(d, v, m) _test_double_less_than_or_equal(__SOURCE_FILE__, __LINE__, d, v, m)
116128
void test_double_less_than_or_equal_format(double val, double max_expected, const char *format, ...) __printflike(3,4);

tests/dispatch_cascade.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ union {
3737
char padding[64];
3838
} indices[BLOCKS];
3939

40-
size_t iterations = QUEUES * BLOCKS * 0.25;
40+
size_t iterations = (QUEUES * BLOCKS) / 4;
4141

4242
static void
4343
noop(void *ctxt __attribute__((unused)))
@@ -57,7 +57,7 @@ cleanup(void *ctxt __attribute__((unused)))
5757
exit(0);
5858
}
5959

60-
void
60+
static void
6161
histogram(void)
6262
{
6363
size_t counts[QUEUES] = {};
@@ -92,7 +92,7 @@ histogram(void)
9292
}
9393
}
9494

95-
void
95+
static void
9696
cascade(void* context)
9797
{
9898
size_t idx, *idxptr = context;

tests/dispatch_concur.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ test_concur_async(size_t n, size_t qw)
101101
if (qw > 1) {
102102
size_t concurrency = MIN(n * workers, qw);
103103
if (done > min_acceptable_concurrency) {
104-
test_long_less_than_or_equal("concurrently completed workers", done, concurrency);
104+
test_sizet_less_than_or_equal("concurrently completed workers", done, concurrency);
105105
} else {
106-
test_long("concurrently completed workers", done, concurrency);
106+
test_sizet("concurrently completed workers", done, concurrency);
107107
}
108108
} else {
109-
test_long_less_than_or_equal("concurrently completed workers", done, 1);
109+
test_sizet_less_than_or_equal("concurrently completed workers", done, 1);
110110
}
111111

112112
for (i = 0, mc = mcs; i < n; i++, mc++) {
@@ -116,9 +116,9 @@ test_concur_async(size_t n, size_t qw)
116116

117117
size_t expect = MIN(n, qw);
118118
if (max_concur > min_acceptable_concurrency) {
119-
test_long_less_than_or_equal("max submission concurrency", max_concur, expect);
119+
test_sizet_less_than_or_equal("max submission concurrency", max_concur, expect);
120120
} else {
121-
test_long("max submission concurrency", max_concur, expect);
121+
test_sizet("max submission concurrency", max_concur, expect);
122122
}
123123

124124
dispatch_group_wait(gw, DISPATCH_TIME_FOREVER);
@@ -159,9 +159,9 @@ test_concur_sync(size_t n, size_t qw)
159159

160160
size_t expect = qw == 1 ? 1 : n;
161161
if (max_concur > min_acceptable_concurrency) {
162-
test_long_less_than_or_equal("max sync concurrency", max_concur, expect);
162+
test_sizet_less_than_or_equal("max sync concurrency", max_concur, expect);
163163
} else {
164-
test_long("max sync concurrency", max_concur, expect);
164+
test_sizet("max sync concurrency", max_concur, expect);
165165
}
166166
}
167167

@@ -190,9 +190,9 @@ test_concur_apply(size_t n, size_t qw)
190190

191191
size_t expect = MIN(n, qw);
192192
if (max_concur > min_acceptable_concurrency) {
193-
test_long_less_than_or_equal("max apply concurrency", max_concur, expect);
193+
test_sizet_less_than_or_equal("max apply concurrency", max_concur, expect);
194194
} else {
195-
test_long("max apply concurrency", max_concur, expect);
195+
test_sizet("max apply concurrency", max_concur, expect);
196196
}
197197
}
198198

@@ -231,19 +231,19 @@ main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
231231
dispatch_test_start("Dispatch Private Concurrent/Wide Queue"); // <rdar://problem/8049506&8169448&8186485>
232232

233233
#ifdef __linux__
234-
activecpu = sysconf(_SC_NPROCESSORS_ONLN);
234+
activecpu = (uint32_t)sysconf(_SC_NPROCESSORS_ONLN);
235235
#else
236236
size_t s = sizeof(activecpu);
237237
sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0);
238238
#endif
239239
size_t n = activecpu / 2 > 1 ? activecpu / 2 : 1, w = activecpu * 2;
240-
min_acceptable_concurrency = n;
240+
min_acceptable_concurrency = (uint32_t)n;
241241
dispatch_queue_t tq, ttq;
242242
long qw, tqw, ttqw;
243243
const char *ql, *tql, *ttql;
244244
size_t qi, tqi, ttqi;
245245
long qws[] = {
246-
0, LONG_MAX, w, 1, // 0 <=> global queue
246+
0, LONG_MAX, (long)w, 1, // 0 <=> global queue
247247
};
248248

249249
g = dispatch_group_create();
@@ -262,16 +262,16 @@ main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
262262
"queue hierarchy: %s -> %s -> %s\n",
263263
use_group_async ? "_group" : "", ql, tql, ttql);
264264
fflush(stdout);
265-
test_concur_async(n, MIN(qw, MIN(tqw, ttqw)));
265+
test_concur_async(n, (size_t)MIN(qw, MIN(tqw, ttqw)));
266266
}
267267
fprintf(stdout, "Testing dispatch_sync on "
268268
"queue hierarchy: %s -> %s -> %s\n", ql, tql, ttql);
269269
fflush(stdout);
270-
test_concur_sync(w, MIN(qw, MIN(tqw, ttqw)));
270+
test_concur_sync(w, (size_t)MIN(qw, MIN(tqw, ttqw)));
271271
fprintf(stdout, "Testing dispatch_apply on "
272272
"queue hierarchy: %s -> %s -> %s\n", ql, tql, ttql);
273273
fflush(stdout);
274-
test_concur_apply(activecpu, MIN(qw, MIN(tqw, ttqw)));
274+
test_concur_apply(activecpu, (size_t)MIN(qw, MIN(tqw, ttqw)));
275275
dispatch_release(q);
276276
}
277277
dispatch_release(tq);

tests/dispatch_drift.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ main(int argc __attribute__((unused)), char* argv[] __attribute__((unused)))
4848
uint64_t interval = 1000000000 / 100;
4949
double interval_d = interval / 1000000000.0;
5050
// for 25 seconds
51-
unsigned int target = 25 / interval_d;
51+
unsigned int target = (unsigned int)(25.0 / interval_d);
5252

5353
dispatch_test_start("Dispatch Timer Drift");
5454

5555
dispatch_source_t t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
5656
test_ptr_notnull("dispatch_source_create", t);
5757

58-
dispatch_source_set_timer(t, dispatch_time(DISPATCH_TIME_NOW, interval), interval, 0);
58+
dispatch_source_set_timer(t, dispatch_time(DISPATCH_TIME_NOW, (int64_t)interval), interval, 0);
5959

6060
dispatch_source_set_event_handler(t, ^{
6161
struct timeval now_tv;

tests/dispatch_io.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#endif
5353
#endif
5454

55-
void
55+
static void
5656
test_fin(void *cxt)
5757
{
5858
test_ptr("test_fin run", cxt, cxt);
@@ -96,7 +96,7 @@ test_io_close(int with_timer, bool from_path)
9696
test_errno("fstat", errno, 0);
9797
test_stop();
9898
}
99-
const size_t size = sb.st_size / chunks;
99+
const size_t size = (size_t)sb.st_size / chunks;
100100
const int expected_error = with_timer? ECANCELED : 0;
101101
dispatch_source_t t = NULL;
102102
dispatch_group_t g = dispatch_group_create();
@@ -142,7 +142,7 @@ test_io_close(int with_timer, bool from_path)
142142
for (i = 0; i < chunks; i++) {
143143
data[i] = dispatch_data_empty;
144144
dispatch_group_enter(g);
145-
dispatch_io_read(io, i * size, size, dispatch_get_global_queue(0,0),
145+
dispatch_io_read(io, (off_t)(i * size), size, dispatch_get_global_queue(0,0),
146146
^(bool done, dispatch_data_t d, int error) {
147147
if (d) {
148148
chunk_size[i] += dispatch_data_get_size(d);
@@ -180,16 +180,16 @@ test_io_close(int with_timer, bool from_path)
180180
}
181181
for (i = 0; i < chunks; i++) {
182182
if (with_timer) {
183-
test_long_less_than("chunk size", chunk_size[i], size + 1);
183+
test_sizet_less_than("chunk size", chunk_size[i], size + 1);
184184
} else {
185-
test_long("chunk size", chunk_size[i], size);
185+
test_sizet("chunk size", chunk_size[i], size);
186186
}
187187
total += chunk_size[i];
188188
}
189189
if (with_timer) {
190-
test_long_less_than("total size", total, chunks * size + 1);
190+
test_sizet_less_than("total size", total, chunks * size + 1);
191191
} else {
192-
test_long("total size", total, chunks * size);
192+
test_sizet("total size", total, chunks * size);
193193
}
194194
}
195195

@@ -251,7 +251,7 @@ test_io_read_write(void)
251251
test_errno("fstat", errno, 0);
252252
test_stop();
253253
}
254-
const size_t siz_in = MIN(1024 * 1024, sb.st_size);
254+
const size_t siz_in = MIN(1024 * 1024, (size_t)sb.st_size);
255255

256256
int out = mkstemp(path_out);
257257
if (out == -1) {
@@ -283,19 +283,19 @@ test_io_read_write(void)
283283
dispatch_group_enter(g);
284284
dispatch_io_read(io_in, 0, siz_in, q,
285285
^(bool done_in, dispatch_data_t data_in, int err_in) {
286-
test_long_less_than("read size", dispatch_data_get_size(data_in),
286+
test_sizet_less_than("read size", dispatch_data_get_size(data_in),
287287
siz_in);
288288
if (data_in) {
289289
dispatch_group_enter(g);
290290
dispatch_io_write(io_out, 0, data_in, q,
291291
^(bool done_out, dispatch_data_t data_out, int err_out) {
292292
if (done_out) {
293293
test_errno("dispatch_io_write", err_out, 0);
294-
test_long("remaining write size",
294+
test_sizet("remaining write size",
295295
data_out ? dispatch_data_get_size(data_out) : 0, 0);
296296
dispatch_group_leave(g);
297297
} else {
298-
test_long_less_than("remaining write size",
298+
test_sizet_less_than("remaining write size",
299299
dispatch_data_get_size(data_out), siz_in);
300300
}
301301
});
@@ -321,7 +321,7 @@ test_io_read_write(void)
321321
}
322322
close(out);
323323
size_t siz_cmp = dispatch_data_get_size(cmp);
324-
test_long("readback size", siz_cmp, siz_in);
324+
test_sizet("readback size", siz_cmp, siz_in);
325325
const void *data_buf, *cmp_buf;
326326
dispatch_data_t data_map, cmp_map;
327327
data_map = dispatch_data_create_map(data, &data_buf, NULL);
@@ -378,7 +378,7 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
378378
}
379379
free(buffer);
380380
close(fd);
381-
process_data(r);
381+
process_data((size_t)r);
382382
});
383383
break;
384384
case DISPATCH_READ_ON_CONCURRENT_QUEUE:
@@ -455,7 +455,7 @@ test_read_dirs(char **paths, dispatch_queue_t queue, dispatch_group_t g,
455455
test_ptr_notnull("fts_open failed", tree);
456456
test_stop();
457457
}
458-
unsigned int files_opened = 0;
458+
int files_opened = 0;
459459
size_t size, total_size = 0;
460460
FTSENT *node;
461461
while ((node = fts_read(tree)) &&
@@ -465,11 +465,11 @@ test_read_dirs(char **paths, dispatch_queue_t queue, dispatch_group_t g,
465465
} else if (node->fts_info == FTS_F) {
466466
dispatch_group_enter(g);
467467
dispatch_semaphore_wait(s, DISPATCH_TIME_FOREVER);
468-
size = node->fts_statp->st_size;
468+
size = (size_t)node->fts_statp->st_size;
469469
total_size += size;
470470
files_opened++;
471471
test_async_read(node->fts_path, size, option, queue, ^(size_t len){
472-
OSAtomicAdd32(len, bytes);
472+
OSAtomicAdd32((int32_t)len, (volatile int32_t *)bytes);
473473
dispatch_semaphore_signal(s);
474474
dispatch_group_leave(g);
475475
});
@@ -485,7 +485,7 @@ test_read_dirs(char **paths, dispatch_queue_t queue, dispatch_group_t g,
485485
test_stop();
486486
}
487487
test_group_wait(g);
488-
test_long("total size", *bytes, total_size);
488+
test_sizet("total size", *bytes, total_size);
489489
return files_opened;
490490
}
491491

@@ -506,7 +506,7 @@ test_read_many_files(void)
506506
dispatch_semaphore_t s = dispatch_semaphore_create(maxopenfiles);
507507
uint64_t start;
508508
volatile uint32_t bytes;
509-
unsigned int files_read, i;
509+
int files_read, i;
510510

511511
const dispatch_queue_t queues[] = {
512512
[DISPATCH_ASYNC_READ_ON_CONCURRENT_QUEUE] =
@@ -546,7 +546,7 @@ test_read_many_files(void)
546546
l.rlim_cur = 2 * maxopenfiles + 256;
547547
setrlimit(RLIMIT_NOFILE, &l);
548548
}
549-
for (i = 0; i < sizeof(queues)/sizeof(dispatch_queue_t); ++i) {
549+
for (i = 0; i < (int)(sizeof(queues)/sizeof(dispatch_queue_t)); ++i) {
550550
fprintf(stdout, "%s:\n", names[i]);
551551
bytes = 0;
552552
start = mach_absolute_time();
@@ -610,7 +610,7 @@ test_io_from_io(void) // rdar://problem/8388909
610610
#else
611611
test_errno("error from write to write protected directory", err_out, EACCES);
612612
#endif
613-
test_long("unwritten data", dispatch_data_get_size(data_out), 256);
613+
test_sizet("unwritten data", dispatch_data_get_size(data_out), 256);
614614
if (!err_out && done) {
615615
test_stop();
616616
}
@@ -661,11 +661,11 @@ test_io_from_io(void) // rdar://problem/8388909
661661
^(bool done, dispatch_data_t data_out, int err_out) {
662662
if (done) {
663663
test_errno("dispatch_io_write", err_out, 0);
664-
test_long("remaining write size",
664+
test_sizet("remaining write size",
665665
data_out ? dispatch_data_get_size(data_out) : 0, 0);
666666
dispatch_group_leave(g);
667667
} else {
668-
test_long_less_than("remaining write size",
668+
test_sizet_less_than("remaining write size",
669669
dispatch_data_get_size(data_out), siz_in);
670670
}
671671
});
@@ -696,7 +696,7 @@ test_io_from_io(void) // rdar://problem/8388909
696696
dispatch_release(io2);
697697
test_group_wait(g);
698698
dispatch_release(g);
699-
test_long("readback size", dispatch_data_get_size(data_out), siz_in);
699+
test_sizet("readback size", dispatch_data_get_size(data_out), siz_in);
700700
dispatch_release(data_out);
701701
#endif
702702
}

0 commit comments

Comments
 (0)