Skip to content

Commit

Permalink
Merge pull request #713 from kbevers/travis-c89
Browse files Browse the repository at this point in the history
Add -std=c89 to travis targets
  • Loading branch information
kbevers committed Dec 17, 2017
2 parents 74ae4b0 + 80a5172 commit 95f8e74
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
107 changes: 53 additions & 54 deletions src/multistresstest.c
Expand Up @@ -32,10 +32,10 @@
#include "proj_api.h"

#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#include <pthread.h>
#include <unistd.h>
#endif

#define num_threads 10
Expand All @@ -49,10 +49,10 @@ typedef struct {

double src_x, src_y, src_z;
double dst_x, dst_y, dst_z;

int dst_error;
int skip;
} TestItem;
} TestItem;

TestItem test_list[] = {
{
Expand Down Expand Up @@ -161,7 +161,7 @@ TestItem test_list[] = {
0, 0
},
{
//Bad projection (invalid ellipsoid parameter +R_A=0)
/* Bad projection (invalid ellipsoid parameter +R_A=0) */
"+proj=utm +zone=11 +datum=WGS84",
"+proj=merc +datum=potsdam +R_A=0",
150000.0, 3000000.0, 0.0,
Expand Down Expand Up @@ -192,7 +192,7 @@ static projPJ* custom_pj_init_plus_ctx(projCtx ctx, const char* def)
static void TestThread()

{
int i, test_count = sizeof(test_list) / sizeof(TestItem);
int i, test_count = sizeof(test_list) / sizeof(TestItem);
int repeat_count = num_iterations;
int i_iter;

Expand All @@ -201,11 +201,10 @@ static void TestThread()
/* -------------------------------------------------------------------- */
projPJ *src_pj_list, *dst_pj_list;
projCtx ctx = pj_ctx_alloc();
// projCtx ctx = pj_get_default_ctx();


src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));
dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));

if(!reinit_every_iteration)
{
for( i = 0; i < test_count; i++ )
Expand All @@ -216,11 +215,11 @@ static void TestThread()
dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def );
}
}

/* -------------------------------------------------------------------- */
/* Perform tests - over and over. */
/* -------------------------------------------------------------------- */

for( i_iter = 0; i_iter < repeat_count; i_iter++ )
{
for( i = 0; i < test_count; i++ )
Expand All @@ -240,7 +239,7 @@ static void TestThread()

{
int skipTest = (src_pj_list[i] == NULL || dst_pj_list[i] == NULL);

if ( skipTest != test->skip )
fprintf( stderr, "Threaded projection initialization does not match unthreaded initialization\n" );

Expand All @@ -256,23 +255,23 @@ static void TestThread()
if ( test->skip )
continue;

error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0,
error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0,
&x, &y, &z );


if( error != test->dst_error )
{
fprintf( stderr, "Got error %d, expected %d\n",
fprintf( stderr, "Got error %d, expected %d\n",
error, test->dst_error );
}

if( x != test->dst_x || y != test->dst_y || z != test->dst_z )
{
fprintf( stderr,
fprintf( stderr,
"Got %.15g,%.15g,%.15g\n"
"Expected %.15g,%.15g,%.15g\n"
"Diff %.15g,%.15g,%.15g\n",
x, y, z,
x, y, z,
test->dst_x, test->dst_y, test->dst_z,
x-test->dst_x, y-test->dst_y, z-test->dst_z);
}
Expand All @@ -296,13 +295,13 @@ static void TestThread()
pj_free( dst_pj_list[i] );
}
}

free( src_pj_list );
free( dst_pj_list );

pj_ctx_free( ctx );

printf( "%d iterations of the %d tests complete in thread X\n",
printf( "%d iterations of the %d tests complete in thread X\n",
repeat_count, test_count );

active_thread_count--;
Expand Down Expand Up @@ -348,7 +347,7 @@ static int do_main(void)
/* Our first pass is to establish the correct answers for all */
/* the tests. */
/* -------------------------------------------------------------------- */
int i, test_count = sizeof(test_list) / sizeof(TestItem);
int i, test_count = sizeof(test_list) / sizeof(TestItem);

for( i = 0; i < test_count; i++ )
{
Expand All @@ -374,16 +373,16 @@ static int do_main(void)
pj_free (src_pj);
continue;
}

test->dst_x = test->src_x;
test->dst_y = test->src_y;
test->dst_z = test->src_z;

test->dst_error = pj_transform( src_pj, dst_pj, 1, 0,
&(test->dst_x),
test->dst_error = pj_transform( src_pj, dst_pj, 1, 0,
&(test->dst_x),
&(test->dst_y),
&(test->dst_z) );

pj_free( src_pj );
pj_free( dst_pj );

Expand All @@ -401,47 +400,47 @@ static int do_main(void)
/* -------------------------------------------------------------------- */
#ifdef _WIN32

{ //Scoped to workaround lack of c99 support in VS
HANDLE ahThread[num_threads];
{ //Scoped to workaround lack of c99 support in VS
HANDLE ahThread[num_threads];

for( i = 0; i < num_threads; i++ )
{
active_thread_count++;
for( i = 0; i < num_threads; i++ )
{
active_thread_count++;

ahThread[i] = CreateThread(NULL, 0, WinTestThread, NULL, 0, NULL);

if (ahThread[i] == 0)
{
printf( "Thread creation failed.");
return 1;
}
}
ahThread[i] = CreateThread(NULL, 0, WinTestThread, NULL, 0, NULL);

printf( "%d test threads launched.\n", num_threads );
if (ahThread[i] == 0)
{
printf( "Thread creation failed.");
return 1;
}
}

WaitForMultipleObjects(num_threads, ahThread, TRUE, INFINITE);
}
printf( "%d test threads launched.\n", num_threads );

WaitForMultipleObjects(num_threads, ahThread, TRUE, INFINITE);
}

#else
{
pthread_t ahThread[num_threads];
pthread_attr_t hThreadAttr;
pthread_t ahThread[num_threads];
pthread_attr_t hThreadAttr;

pthread_attr_init( &hThreadAttr );
pthread_attr_setdetachstate( &hThreadAttr, PTHREAD_CREATE_DETACHED );
pthread_attr_init( &hThreadAttr );
pthread_attr_setdetachstate( &hThreadAttr, PTHREAD_CREATE_DETACHED );

for( i = 0; i < num_threads; i++ )
{
active_thread_count++;
for( i = 0; i < num_threads; i++ )
{
active_thread_count++;

pthread_create( &(ahThread[i]), &hThreadAttr,
PosixTestThread, NULL );
}
pthread_create( &(ahThread[i]), &hThreadAttr,
PosixTestThread, NULL );
}

printf( "%d test threads launched.\n", num_threads );
printf( "%d test threads launched.\n", num_threads );

while( active_thread_count > 0 )
sleep( 1 );
while( active_thread_count > 0 )
sleep( 1 );
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion travis/linux_clang/install.sh
Expand Up @@ -4,4 +4,4 @@ set -e

export CCACHE_CPP2=yes

CC="ccache clang" CFLAGS="-g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -Wfloat-conversion -fsanitize=address -O2" ./travis/install.sh
CC="ccache clang" CFLAGS="-std=c89 -g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -Wfloat-conversion -fsanitize=address -O2" ./travis/install.sh
2 changes: 1 addition & 1 deletion travis/linux_gcc/install.sh
Expand Up @@ -5,4 +5,4 @@ set -e
export CCACHE_CPP2=yes

# -Wfloat-conversion not available for gcc 4.8
CC="ccache gcc" CFLAGS="-g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -O2" ./travis/install.sh
CC="ccache gcc" CFLAGS="-std=c89 -g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -O2" ./travis/install.sh
2 changes: 1 addition & 1 deletion travis/osx/install.sh
Expand Up @@ -4,4 +4,4 @@ set -e

export CCACHE_CPP2=yes

CC="ccache clang" CFLAGS="-g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -Wfloat-conversion -O2" ./travis/install.sh
CC="ccache clang" CFLAGS="-std=c89 -g -Wall -Wextra -Werror -Wunused-parameter -Wmissing-prototypes -Wmissing-declarations -Wformat -Werror=format-security -Wshadow -Wfloat-conversion -O2" ./travis/install.sh

0 comments on commit 95f8e74

Please sign in to comment.