Skip to content

Commit e30db2a

Browse files
committed
test suite fixes to prep for enabling additional warnings
fixes to allow clean compilation of test suite with addtional clang warnings enabled.
1 parent 602604c commit e30db2a

20 files changed

+81
-73
lines changed

tests/bsdtestharness.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ main(int argc, char *argv[])
9393

9494
#endif
9595
int i;
96-
char** newargv = calloc(argc, sizeof(void*));
96+
char** newargv = calloc((size_t)argc, sizeof(void*));
9797
for (i = 1; i < argc; ++i) {
9898
newargv[i-1] = argv[i];
9999
}

tests/bsdtests.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ _test_uint32(const char* file, long line, const char* desc, uint32_t actual, uin
154154
}
155155

156156
void
157-
test_uint32_format(long actual, long expected, const char *format, ...)
157+
test_uint32_format(uint32_t actual, uint32_t expected, const char *format, ...)
158158
{
159159
GENERATE_DESC
160160
_test_uint32(NULL, 0, desc, actual, expected);
@@ -284,7 +284,10 @@ test_double_less_than_or_equal_format(double val, double max_expected, const cha
284284
void
285285
_test_double_equal(const char* file, long line, const char* desc, double val, double expected)
286286
{
287+
#pragma clang diagnostic push
288+
#pragma clang diagnostic ignored "-Wfloat-equal"
287289
_test_print(file, line, desc, (val == expected), "%f", val, "%f", expected);
290+
#pragma clang diagnostic pop
288291
}
289292

290293

@@ -296,20 +299,20 @@ test_double_equal_format(double val, double expected, const char *format, ...)
296299
}
297300

298301
void
299-
_test_errno(const char* file, long line, const char* desc, long actual, long expected)
302+
_test_errno(const char* file, long line, const char* desc, int actual, int expected)
300303
{
301304
char* actual_str;
302305
char* expected_str;
303-
asprintf(&actual_str, "%ld\t%s", actual, actual ? strerror(actual) : "");
304-
asprintf(&expected_str, "%ld\t%s", expected, expected ? strerror(expected) : "");
306+
asprintf(&actual_str, "%d\t%s", actual, actual ? strerror(actual) : "");
307+
asprintf(&expected_str, "%d\t%s", expected, expected ? strerror(expected) : "");
305308
_test_print(file, line, desc,
306309
(actual == expected), "%s", actual_str, "%s", expected_str);
307310
free(actual_str);
308311
free(expected_str);
309312
}
310313

311314
void
312-
test_errno_format(long actual, long expected, const char *format, ...)
315+
test_errno_format(int actual, int expected, const char *format, ...)
313316
{
314317
GENERATE_DESC
315318
_test_errno(NULL, 0, desc, actual, expected);
@@ -477,7 +480,7 @@ void
477480
test_stop_after_delay(void *delay)
478481
{
479482
if (delay != NULL) {
480-
sleep((int)(intptr_t)delay);
483+
sleep((uint)(intptr_t)delay);
481484
}
482485

483486
test_leaks(NULL);

tests/bsdtests.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ void test_ptr_format(const void* actual, const void* expected, const char *forma
8181

8282
void _test_uint32(const char* file, long line, const char* desc, uint32_t actual, uint32_t expected);
8383
#define test_uint32(a,b,c) _test_uint32(__SOURCE_FILE__, __LINE__, a, b, c)
84-
void test_uint32_format(long actual, long expected, const char *format, ...) __printflike(3,4);
84+
void test_uint32_format(uint32_t actual, uint32_t expected, const char *format, ...) __printflike(3,4);
8585

8686
void _test_int32(const char* file, long line, const char* desc, int32_t actual, int32_t expected);
8787
#define test_int32(a,b,c) _test_int32(__SOURCE_FILE__, __LINE__, a, b, c)
88-
void test_sint32_format(int32_t actual, int32_t expected, const char* format, ...) __printflike(3,4);
88+
void test_int32_format(int32_t actual, int32_t expected, const char* format, ...) __printflike(3,4);
8989

9090
void _test_long(const char* file, long line, const char* desc, long actual, long expected);
9191
#define test_long(a,b,c) _test_long(__SOURCE_FILE__, __LINE__, a, b, c)
@@ -123,9 +123,9 @@ void _test_double_equal(const char* file, long line, const char* desc, double va
123123
#define test_double_equal(d, v, m) _test_double_equal(__SOURCE_FILE__, __LINE__, d, v, m)
124124
void test_double_equal_format(double val, double expected, const char *format, ...) __printflike(3,4);
125125

126-
void _test_errno(const char* file, long line, const char* desc, long actual, long expected);
126+
void _test_errno(const char* file, long line, const char* desc, int actual, int expected);
127127
#define test_errno(a,b,c) _test_errno(__SOURCE_FILE__, __LINE__, a, b, c)
128-
void test_errno_format(long actual, long expected, const char *format, ...) __printflike(3,4);
128+
void test_errno_format(int actual, int expected, const char *format, ...) __printflike(3,4);
129129

130130
#ifndef __linux__
131131
void _test_mach_error(const char* file, long line, const char* desc, mach_error_t actual, mach_error_t expected);

tests/dispatch_after.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232

3333
#include "dispatch_test.h"
3434

35-
void
35+
static void
3636
done(void *arg /*__unused */)
3737
{
38+
(void)arg;
3839
sleep(1);
3940
test_stop();
4041
}
4142

42-
void
43+
static void
4344
test_after(void)
4445
{
4546
__block dispatch_time_t time_a_min, time_a, time_a_max;
@@ -49,29 +50,29 @@ test_after(void)
4950
dispatch_test_start("Dispatch After");
5051

5152
dispatch_async(dispatch_get_main_queue(), ^{
52-
time_a_min = dispatch_time(0, 5.5*NSEC_PER_SEC);
53-
time_a = dispatch_time(0, 6*NSEC_PER_SEC);
54-
time_a_max = dispatch_time(0, 6.5*NSEC_PER_SEC);
53+
time_a_min = dispatch_time(0, (int64_t)(5.5*NSEC_PER_SEC));
54+
time_a = dispatch_time(0, (int64_t)(6*NSEC_PER_SEC));
55+
time_a_max = dispatch_time(0, (int64_t)(6.5*NSEC_PER_SEC));
5556
dispatch_after(time_a, dispatch_get_main_queue(), ^{
5657
dispatch_time_t now_a = dispatch_time(0, 0);
57-
test_long_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min);
58-
test_long_less_than("must finish faster than 6.5s", 0, time_a_max - now_a);
58+
test_long_less_than("can't finish faster than 5.5s", 0, (long)(now_a - time_a_min));
59+
test_long_less_than("must finish faster than 6.5s", 0, (long)(time_a_max - now_a));
5960

60-
time_b_min = dispatch_time(0, 1.5*NSEC_PER_SEC);
61-
time_b = dispatch_time(0, 2*NSEC_PER_SEC);
62-
time_b_max = dispatch_time(0, 2.5*NSEC_PER_SEC);
61+
time_b_min = dispatch_time(0, (int64_t)(1.5*NSEC_PER_SEC));
62+
time_b = dispatch_time(0, (int64_t)(2*NSEC_PER_SEC));
63+
time_b_max = dispatch_time(0, (int64_t)(2.5*NSEC_PER_SEC));
6364
dispatch_after(time_b, dispatch_get_main_queue(), ^{
6465
dispatch_time_t now_b = dispatch_time(0, 0);
65-
test_long_less_than("can't finish faster than 1.5s", 0, now_b - time_b_min);
66-
test_long_less_than("must finish faster than 2.5s", 0, time_b_max - now_b);
66+
test_long_less_than("can't finish faster than 1.5s", 0, (long)(now_b - time_b_min));
67+
test_long_less_than("must finish faster than 2.5s", 0, (long)(time_b_max - now_b));
6768

6869
time_c_min = dispatch_time(0, 0*NSEC_PER_SEC);
6970
time_c = dispatch_time(0, 0*NSEC_PER_SEC);
70-
time_c_max = dispatch_time(0, .5*NSEC_PER_SEC);
71+
time_c_max = dispatch_time(0, (int64_t)(.5*NSEC_PER_SEC));
7172
dispatch_after(time_c, dispatch_get_main_queue(), ^{
7273
dispatch_time_t now_c = dispatch_time(0, 0);
73-
test_long_less_than("can't finish faster than 0s", 0, now_c - time_c_min);
74-
test_long_less_than("must finish faster than .5s", 0, time_c_max - now_c);
74+
test_long_less_than("can't finish faster than 0s", 0, (long)(now_c - time_c_min));
75+
test_long_less_than("must finish faster than .5s", 0, (long)(time_c_max - now_c));
7576

7677
dispatch_async_f(dispatch_get_main_queue(), NULL, done);
7778
});

tests/dispatch_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <bsdtests.h>
2424
#include "dispatch_test.h"
2525

26-
void
26+
static void
2727
work(void *context __attribute__((unused)))
2828
{
2929
test_stop();

tests/dispatch_apply.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static volatile int all_done = 0;
4747
* the optimizer from cutting the whole thing out as dead code.
4848
*/
4949
static volatile unsigned int busythread_useless;
50-
void busythread(void *ignored)
50+
static void busythread(void *ignored)
5151
{
5252
(void)ignored;
5353
/* prevent i and j been optimized out */
@@ -73,16 +73,16 @@ void busythread(void *ignored)
7373
* <rdar://problem/10718199> dispatch_apply should not block waiting on other
7474
* threads while calling thread is available
7575
*/
76-
void test_apply_contended(dispatch_queue_t dq)
76+
static void test_apply_contended(dispatch_queue_t dq)
7777
{
7878
uint32_t activecpu;
7979
#ifdef __linux__
80-
activecpu = sysconf(_SC_NPROCESSORS_ONLN);
80+
activecpu = (uint32_t)sysconf(_SC_NPROCESSORS_ONLN);
8181
#else
8282
size_t s = sizeof(activecpu);
8383
sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0);
8484
#endif
85-
int tIndex, n_threads = activecpu;
85+
int tIndex, n_threads = (int)activecpu;
8686
dispatch_group_t grp = dispatch_group_create();
8787

8888
for(tIndex = 0; tIndex < n_threads; tIndex++) {
@@ -97,11 +97,11 @@ void test_apply_contended(dispatch_queue_t dq)
9797
volatile __block int32_t count = 0;
9898
const int32_t final = 32;
9999

100-
unsigned int before = busy_threads_started;
100+
int32_t before = busy_threads_started;
101101
dispatch_apply(final, dq, ^(size_t i __attribute__((unused))) {
102102
OSAtomicIncrement32(&count);
103103
});
104-
unsigned int after = busy_threads_finished;
104+
int32_t after = busy_threads_finished;
105105

106106
test_long("contended: threads started before apply", before, n_threads);
107107
test_long("contended: count", count, final);

tests/dispatch_c99.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <bsdtests.h>
3333
#include "dispatch_test.h"
3434

35-
void
35+
static void
3636
work(void *context __attribute__((unused)))
3737
{
3838
test_stop();

tests/dispatch_data.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include <stdio.h>
22+
#include <stdlib.h>
2223

2324
#include <dispatch/dispatch.h>
2425
#ifdef __APPLE__
@@ -59,7 +60,7 @@ test_concat(void)
5960
dispatch_release(data2);
6061

6162
test_long("Data size of concatenated dispatch data",
62-
dispatch_data_get_size(concat), 34);
63+
(long)dispatch_data_get_size(concat), 34);
6364

6465
const void* contig;
6566
size_t contig_size;
@@ -68,7 +69,7 @@ test_concat(void)
6869

6970
dispatch_release(concat);
7071
dispatch_release(contig_data);
71-
test_long("Contiguous memory size", contig_size, 34);
72+
test_long("Contiguous memory size", (long)contig_size, 34);
7273
dispatch_async(dispatch_get_main_queue(), ^{
7374
test_long("buffer2 destroyed", buffer2_destroyed, true);
7475
dispatch_group_leave(g);

tests/dispatch_group.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
static void test_group_notify(void*);
4545

46-
dispatch_group_t
47-
create_group(size_t count, int delay)
46+
static dispatch_group_t
47+
create_group(size_t count, unsigned int delay)
4848
{
4949
size_t i;
5050

@@ -143,7 +143,7 @@ test_group_notify2(long cycle, dispatch_group_t tested)
143143
dispatch_group_async(group, q, ^{
144144
// Seems to trigger a little more reliably with some work being
145145
// done in this block
146-
eh = sin(M_1_PI / cycle);
146+
eh = (float)sin(M_1_PI / cycle);
147147
});
148148
}
149149
dispatch_group_leave(group);

tests/dispatch_io_net.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern char **environ;
4848
#endif
4949

5050
#ifdef __linux__
51-
#define _NSGetExecutablePath(ef,bs) (*(bs)=snprintf(ef,*(bs),"%s",argv[0]),0)
51+
#define _NSGetExecutablePath(ef,bs) (*(bs)=(size_t)snprintf(ef,*(bs),"%s",argv[0]),0)
5252
#endif
5353

5454
#if DISPATCHTEST_IO
@@ -79,9 +79,9 @@ main(int argc, char** argv)
7979
test_stop();
8080
}
8181

82-
memcpy(&server.sin_addr, he->h_addr_list[0], he->h_length);
82+
memcpy(&server.sin_addr, he->h_addr_list[0], (size_t)he->h_length);
8383
server.sin_family = AF_INET;
84-
server.sin_port = atoi(argv[1]);
84+
server.sin_port = (in_port_t)atoi(argv[1]);
8585

8686
fprintf(stderr, "Client-connecting on port ... %d\n", server.sin_port);
8787

@@ -111,7 +111,7 @@ main(int argc, char** argv)
111111
test_errno("client-fstat", errno, 0);
112112
test_stop();
113113
}
114-
size_t size = sb.st_size;
114+
size_t size = (size_t)sb.st_size;
115115

116116
__block dispatch_data_t g_d1 = dispatch_data_empty;
117117
__block dispatch_data_t g_d2 = dispatch_data_empty;
@@ -123,7 +123,7 @@ main(int argc, char** argv)
123123
^(dispatch_data_t d1, int error) {
124124
test_errno("Client-dict-read error", error, 0);
125125
test_long("Client-dict-dispatch data size",
126-
dispatch_data_get_size(d1), size);
126+
(long)dispatch_data_get_size(d1), (long)size);
127127
dispatch_retain(d1);
128128
g_d1 = d1;
129129
dispatch_group_leave(g);
@@ -146,8 +146,8 @@ main(int argc, char** argv)
146146
dispatch_read(sockfd, SIZE_MAX, dispatch_get_global_queue(0, 0), b);
147147
test_group_wait(g);
148148
test_errno("Client-read error", g_error, 0);
149-
test_long("Client-dispatch data size", dispatch_data_get_size(g_d2),
150-
size);
149+
test_long("Client-dispatch data size", (long)dispatch_data_get_size(g_d2),
150+
(long)size);
151151

152152
size_t dict_contig_size, socket_contig_size;
153153
const void *dict_contig_buf, *socket_contig_buf;
@@ -201,7 +201,7 @@ main(int argc, char** argv)
201201
addr1.sin_port);
202202

203203
char exec_filename [256] = {};
204-
uint32_t bufsize = 256;
204+
size_t bufsize = 256;
205205

206206
if (_NSGetExecutablePath(exec_filename, &bufsize) == -1) {
207207
fprintf(stderr, "Failed to get path name for running executable\n");
@@ -250,16 +250,16 @@ main(int argc, char** argv)
250250
test_errno("fstat", errno, 0);
251251
goto stop_test;
252252
}
253-
size_t size = sb.st_size;
253+
size_t size = (size_t)sb.st_size;
254254

255255
dispatch_group_t g = dispatch_group_create();
256256
dispatch_group_enter(g);
257257
dispatch_read(read_fd, size, dispatch_get_global_queue(0, 0),
258258
^(dispatch_data_t d, int r_err){
259259
fprintf(stderr, "Server-dispatch_read()\n");
260260
test_errno("Server-read error", r_err, 0);
261-
test_long("Server-dispatch data size", dispatch_data_get_size(d),
262-
size);
261+
test_long("Server-dispatch data size", (long)dispatch_data_get_size(d),
262+
(long)size);
263263

264264
// convenience method handlers should only be called once
265265
if (dispatch_data_get_size(d)!= size) {

tests/dispatch_queue_finalizer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030

3131
void *ctxt_magic = NULL;
3232

33-
void
33+
static void
3434
finalize(void *ctxt)
3535
{
3636
test_ptr_null("finalizer ran", NULL);
3737
test_ptr("correct context", ctxt, ctxt_magic);
3838
test_stop();
3939
}
4040

41-
void
41+
static void
4242
never_call(void *ctxt)
4343
{
4444
test_ptr_notnull("never_call should not run", NULL);

0 commit comments

Comments
 (0)