Skip to content

test suite fixes to prep for enabling additional warnings #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/bsdtestharness.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ main(int argc, char *argv[])

#endif
int i;
char** newargv = calloc(argc, sizeof(void*));
char** newargv = calloc((size_t)argc, sizeof(void*));
for (i = 1; i < argc; ++i) {
newargv[i-1] = argv[i];
}
Expand Down
15 changes: 9 additions & 6 deletions tests/bsdtests.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ _test_uint32(const char* file, long line, const char* desc, uint32_t actual, uin
}

void
test_uint32_format(long actual, long expected, const char *format, ...)
test_uint32_format(uint32_t actual, uint32_t expected, const char *format, ...)
{
GENERATE_DESC
_test_uint32(NULL, 0, desc, actual, expected);
Expand Down Expand Up @@ -284,7 +284,10 @@ test_double_less_than_or_equal_format(double val, double max_expected, const cha
void
_test_double_equal(const char* file, long line, const char* desc, double val, double expected)
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfloat-equal"
_test_print(file, line, desc, (val == expected), "%f", val, "%f", expected);
#pragma clang diagnostic pop
}


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

void
_test_errno(const char* file, long line, const char* desc, long actual, long expected)
_test_errno(const char* file, long line, const char* desc, int actual, int expected)
{
char* actual_str;
char* expected_str;
asprintf(&actual_str, "%ld\t%s", actual, actual ? strerror(actual) : "");
asprintf(&expected_str, "%ld\t%s", expected, expected ? strerror(expected) : "");
asprintf(&actual_str, "%d\t%s", actual, actual ? strerror(actual) : "");
asprintf(&expected_str, "%d\t%s", expected, expected ? strerror(expected) : "");
_test_print(file, line, desc,
(actual == expected), "%s", actual_str, "%s", expected_str);
free(actual_str);
free(expected_str);
}

void
test_errno_format(long actual, long expected, const char *format, ...)
test_errno_format(int actual, int expected, const char *format, ...)
{
GENERATE_DESC
_test_errno(NULL, 0, desc, actual, expected);
Expand Down Expand Up @@ -477,7 +480,7 @@ void
test_stop_after_delay(void *delay)
{
if (delay != NULL) {
sleep((int)(intptr_t)delay);
sleep((uint)(intptr_t)delay);
}

test_leaks(NULL);
Expand Down
8 changes: 4 additions & 4 deletions tests/bsdtests.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ void test_ptr_format(const void* actual, const void* expected, const char *forma

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

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

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

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

#ifndef __linux__
void _test_mach_error(const char* file, long line, const char* desc, mach_error_t actual, mach_error_t expected);
Expand Down
31 changes: 16 additions & 15 deletions tests/dispatch_after.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@

#include "dispatch_test.h"

void
static void
done(void *arg /*__unused */)
{
(void)arg;
sleep(1);
test_stop();
}

void
static void
test_after(void)
{
__block dispatch_time_t time_a_min, time_a, time_a_max;
Expand All @@ -49,29 +50,29 @@ test_after(void)
dispatch_test_start("Dispatch After");

dispatch_async(dispatch_get_main_queue(), ^{
time_a_min = dispatch_time(0, 5.5*NSEC_PER_SEC);
time_a = dispatch_time(0, 6*NSEC_PER_SEC);
time_a_max = dispatch_time(0, 6.5*NSEC_PER_SEC);
time_a_min = dispatch_time(0, (int64_t)(5.5*NSEC_PER_SEC));
time_a = dispatch_time(0, (int64_t)(6*NSEC_PER_SEC));
time_a_max = dispatch_time(0, (int64_t)(6.5*NSEC_PER_SEC));
dispatch_after(time_a, dispatch_get_main_queue(), ^{
dispatch_time_t now_a = dispatch_time(0, 0);
test_long_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min);
test_long_less_than("must finish faster than 6.5s", 0, time_a_max - now_a);
test_long_less_than("can't finish faster than 5.5s", 0, (long)(now_a - time_a_min));
test_long_less_than("must finish faster than 6.5s", 0, (long)(time_a_max - now_a));

time_b_min = dispatch_time(0, 1.5*NSEC_PER_SEC);
time_b = dispatch_time(0, 2*NSEC_PER_SEC);
time_b_max = dispatch_time(0, 2.5*NSEC_PER_SEC);
time_b_min = dispatch_time(0, (int64_t)(1.5*NSEC_PER_SEC));
time_b = dispatch_time(0, (int64_t)(2*NSEC_PER_SEC));
time_b_max = dispatch_time(0, (int64_t)(2.5*NSEC_PER_SEC));
dispatch_after(time_b, dispatch_get_main_queue(), ^{
dispatch_time_t now_b = dispatch_time(0, 0);
test_long_less_than("can't finish faster than 1.5s", 0, now_b - time_b_min);
test_long_less_than("must finish faster than 2.5s", 0, time_b_max - now_b);
test_long_less_than("can't finish faster than 1.5s", 0, (long)(now_b - time_b_min));
test_long_less_than("must finish faster than 2.5s", 0, (long)(time_b_max - now_b));

time_c_min = dispatch_time(0, 0*NSEC_PER_SEC);
time_c = dispatch_time(0, 0*NSEC_PER_SEC);
time_c_max = dispatch_time(0, .5*NSEC_PER_SEC);
time_c_max = dispatch_time(0, (int64_t)(.5*NSEC_PER_SEC));
dispatch_after(time_c, dispatch_get_main_queue(), ^{
dispatch_time_t now_c = dispatch_time(0, 0);
test_long_less_than("can't finish faster than 0s", 0, now_c - time_c_min);
test_long_less_than("must finish faster than .5s", 0, time_c_max - now_c);
test_long_less_than("can't finish faster than 0s", 0, (long)(now_c - time_c_min));
test_long_less_than("must finish faster than .5s", 0, (long)(time_c_max - now_c));

dispatch_async_f(dispatch_get_main_queue(), NULL, done);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/dispatch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <bsdtests.h>
#include "dispatch_test.h"

void
static void
work(void *context __attribute__((unused)))
{
test_stop();
Expand Down
12 changes: 6 additions & 6 deletions tests/dispatch_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static volatile int all_done = 0;
* the optimizer from cutting the whole thing out as dead code.
*/
static volatile unsigned int busythread_useless;
void busythread(void *ignored)
static void busythread(void *ignored)
{
(void)ignored;
/* prevent i and j been optimized out */
Expand All @@ -73,16 +73,16 @@ void busythread(void *ignored)
* <rdar://problem/10718199> dispatch_apply should not block waiting on other
* threads while calling thread is available
*/
void test_apply_contended(dispatch_queue_t dq)
static void test_apply_contended(dispatch_queue_t dq)
{
uint32_t activecpu;
#ifdef __linux__
activecpu = sysconf(_SC_NPROCESSORS_ONLN);
activecpu = (uint32_t)sysconf(_SC_NPROCESSORS_ONLN);
#else
size_t s = sizeof(activecpu);
sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0);
#endif
int tIndex, n_threads = activecpu;
int tIndex, n_threads = (int)activecpu;
dispatch_group_t grp = dispatch_group_create();

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

unsigned int before = busy_threads_started;
int32_t before = busy_threads_started;
dispatch_apply(final, dq, ^(size_t i __attribute__((unused))) {
OSAtomicIncrement32(&count);
});
unsigned int after = busy_threads_finished;
int32_t after = busy_threads_finished;

test_long("contended: threads started before apply", before, n_threads);
test_long("contended: count", count, final);
Expand Down
10 changes: 1 addition & 9 deletions tests/dispatch_c99.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@
#include <dispatch/dispatch.h>
#include <stdlib.h>

#ifdef __linux__
// On Linux normally comes from libbsd overlay files,
// but the headers are not c99 compliant so we compile
// this test case without $(BSD_OVERLAY_CFLAGS)
#define __printflike(a,b) __attribute__((format(printf, a, b)))
#include <inttypes.h>
#endif

#include <bsdtests.h>
#include "dispatch_test.h"

void
static void
work(void *context __attribute__((unused)))
{
test_stop();
Expand Down
5 changes: 3 additions & 2 deletions tests/dispatch_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include <stdio.h>
#include <stdlib.h>

#include <dispatch/dispatch.h>
#ifdef __APPLE__
Expand Down Expand Up @@ -59,7 +60,7 @@ test_concat(void)
dispatch_release(data2);

test_long("Data size of concatenated dispatch data",
dispatch_data_get_size(concat), 34);
(long)dispatch_data_get_size(concat), 34);

const void* contig;
size_t contig_size;
Expand All @@ -68,7 +69,7 @@ test_concat(void)

dispatch_release(concat);
dispatch_release(contig_data);
test_long("Contiguous memory size", contig_size, 34);
test_long("Contiguous memory size", (long)contig_size, 34);
dispatch_async(dispatch_get_main_queue(), ^{
test_long("buffer2 destroyed", buffer2_destroyed, true);
dispatch_group_leave(g);
Expand Down
6 changes: 3 additions & 3 deletions tests/dispatch_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

static void test_group_notify(void*);

dispatch_group_t
create_group(size_t count, int delay)
static dispatch_group_t
create_group(size_t count, unsigned int delay)
{
size_t i;

Expand Down Expand Up @@ -143,7 +143,7 @@ test_group_notify2(long cycle, dispatch_group_t tested)
dispatch_group_async(group, q, ^{
// Seems to trigger a little more reliably with some work being
// done in this block
eh = sin(M_1_PI / cycle);
eh = (float)sin(M_1_PI / cycle);
});
}
dispatch_group_leave(group);
Expand Down
22 changes: 11 additions & 11 deletions tests/dispatch_io_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern char **environ;
#endif

#ifdef __linux__
#define _NSGetExecutablePath(ef,bs) (*(bs)=snprintf(ef,*(bs),"%s",argv[0]),0)
#define _NSGetExecutablePath(ef,bs) (*(bs)=(size_t)snprintf(ef,*(bs),"%s",argv[0]),0)
#endif

#if DISPATCHTEST_IO
Expand Down Expand Up @@ -79,9 +79,9 @@ main(int argc, char** argv)
test_stop();
}

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

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

Expand Down Expand Up @@ -111,7 +111,7 @@ main(int argc, char** argv)
test_errno("client-fstat", errno, 0);
test_stop();
}
size_t size = sb.st_size;
size_t size = (size_t)sb.st_size;

__block dispatch_data_t g_d1 = dispatch_data_empty;
__block dispatch_data_t g_d2 = dispatch_data_empty;
Expand All @@ -123,7 +123,7 @@ main(int argc, char** argv)
^(dispatch_data_t d1, int error) {
test_errno("Client-dict-read error", error, 0);
test_long("Client-dict-dispatch data size",
dispatch_data_get_size(d1), size);
(long)dispatch_data_get_size(d1), (long)size);
dispatch_retain(d1);
g_d1 = d1;
dispatch_group_leave(g);
Expand All @@ -146,8 +146,8 @@ main(int argc, char** argv)
dispatch_read(sockfd, SIZE_MAX, dispatch_get_global_queue(0, 0), b);
test_group_wait(g);
test_errno("Client-read error", g_error, 0);
test_long("Client-dispatch data size", dispatch_data_get_size(g_d2),
size);
test_long("Client-dispatch data size", (long)dispatch_data_get_size(g_d2),
(long)size);

size_t dict_contig_size, socket_contig_size;
const void *dict_contig_buf, *socket_contig_buf;
Expand Down Expand Up @@ -201,7 +201,7 @@ main(int argc, char** argv)
addr1.sin_port);

char exec_filename [256] = {};
uint32_t bufsize = 256;
size_t bufsize = 256;

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

dispatch_group_t g = dispatch_group_create();
dispatch_group_enter(g);
dispatch_read(read_fd, size, dispatch_get_global_queue(0, 0),
^(dispatch_data_t d, int r_err){
fprintf(stderr, "Server-dispatch_read()\n");
test_errno("Server-read error", r_err, 0);
test_long("Server-dispatch data size", dispatch_data_get_size(d),
size);
test_long("Server-dispatch data size", (long)dispatch_data_get_size(d),
(long)size);

// convenience method handlers should only be called once
if (dispatch_data_get_size(d)!= size) {
Expand Down
4 changes: 2 additions & 2 deletions tests/dispatch_queue_finalizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

void *ctxt_magic = NULL;

void
static void
finalize(void *ctxt)
{
test_ptr_null("finalizer ran", NULL);
test_ptr("correct context", ctxt, ctxt_magic);
test_stop();
}

void
static void
never_call(void *ctxt)
{
test_ptr_notnull("never_call should not run", NULL);
Expand Down
Loading