diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2015-07-09 21:25:56 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2015-07-09 21:25:56 +0200 |
| commit | 9f10ff75e863d121294c199ab4df77abaa6328d5 (patch) | |
| tree | d34339916ab7ecb2bfe199f5dc3728e162e89d94 | |
| parent | 9f05b2dd07712d35fe3fa78934631b6a0142891f (diff) | |
| download | PROJ-9f10ff75e863d121294c199ab4df77abaa6328d5.tar.gz PROJ-9f10ff75e863d121294c199ab4df77abaa6328d5.zip | |
Improve multistresstest.c (and run it with Travis) and test228.c
| -rw-r--r-- | .travis.yml | 5 | ||||
| -rw-r--r-- | src/multistresstest.c | 101 | ||||
| -rw-r--r-- | src/test228.c | 14 |
3 files changed, 80 insertions, 40 deletions
diff --git a/.travis.yml b/.travis.yml index 50cc80b1..24be7a6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,11 @@ install: - make install - find /tmp/proj_autoconf_install_nad - make check + - cd src + - make multistresstest + - make test228 + - cd .. + - PROJ_LIB=../nad src/multistresstest - cd .. # autoconf build with grids and coverage - CFLAGS="--coverage" LDFLAGS="-lgcov" ./configure diff --git a/src/multistresstest.c b/src/multistresstest.c index e9da3323..8c5df18f 100644 --- a/src/multistresstest.c +++ b/src/multistresstest.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "proj_api.h" #ifdef _WIN32 @@ -39,7 +40,8 @@ #define num_threads 10 #define num_iterations 1000000 -#define reinit_every_iteration 0 +static int reinit_every_iteration=0; +static int add_no_defs = 0; typedef struct { const char *src_def; @@ -138,6 +140,19 @@ TestItem test_list[] = { static volatile int active_thread_count = 0; +static projPJ* custom_pj_init_plus_ctx(projCtx ctx, const char* def) +{ + if( add_no_defs ) + { + char szBuffer[256]; + strcpy(szBuffer, def); + strcat(szBuffer, " +no_defs"); + return pj_init_plus_ctx(ctx, szBuffer); + } + else + return pj_init_plus_ctx(ctx, def); +} + /************************************************************************/ /* TestThread() */ /************************************************************************/ @@ -159,15 +174,16 @@ static void TestThread() src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); -#if reinit_every_iteration == 0 - for( i = 0; i < test_count; i++ ) + if(!reinit_every_iteration) { - TestItem *test = test_list + i; + for( i = 0; i < test_count; i++ ) + { + TestItem *test = test_list + i; - src_pj_list[i] = pj_init_plus_ctx( ctx, test->src_def ); - dst_pj_list[i] = pj_init_plus_ctx( ctx, test->dst_def ); + src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def ); + dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def ); + } } -#endif /* -------------------------------------------------------------------- */ /* Perform tests - over and over. */ @@ -180,30 +196,30 @@ static void TestThread() TestItem *test = test_list + i; double x, y, z; int error; - int skipTest = test->skip; - + x = test->src_x; y = test->src_y; z = test->src_z; -#if reinit_every_iteration == 1 - src_pj_list[i] = pj_init_plus_ctx( ctx, test->src_def ); - dst_pj_list[i] = pj_init_plus_ctx( ctx, test->dst_def ); - + if( reinit_every_iteration ) { - 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" ); + src_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->src_def ); + dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def ); - if (skipTest) { - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); - continue; + 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" ); + + if (skipTest) + { + pj_free( src_pj_list[i] ); + pj_free( dst_pj_list[i] ); + continue; + } } } -#endif if ( test->skip ) continue; @@ -229,23 +245,25 @@ static void TestThread() x-test->dst_x, y-test->dst_y, z-test->dst_z); } -#if reinit_every_iteration == 1 - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); -#endif + if( reinit_every_iteration ) + { + pj_free( src_pj_list[i] ); + pj_free( dst_pj_list[i] ); + } } } /* -------------------------------------------------------------------- */ /* Cleanup */ /* -------------------------------------------------------------------- */ -#if reinit_every_iteration == 0 - for( i = 0; i < test_count; i++ ) + if( !reinit_every_iteration ) { - pj_free( src_pj_list[i] ); - pj_free( dst_pj_list[i] ); + for( i = 0; i < test_count; i++ ) + { + pj_free( src_pj_list[i] ); + pj_free( dst_pj_list[i] ); + } } -#endif free( src_pj_list ); free( dst_pj_list ); @@ -305,8 +323,8 @@ int do_main(void) projPJ src_pj, dst_pj; - src_pj = pj_init_plus( test->src_def ); - dst_pj = pj_init_plus( test->dst_def ); + src_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->src_def ); + dst_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->dst_def ); if( src_pj == NULL ) { @@ -400,14 +418,25 @@ int do_main(void) int main( int argc, char **argv ) { + int i; + for(i=0;i<argc;i++) + { + if( strcmp(argv[i], "-reinit") == 0 ) + reinit_every_iteration = 1; + else if( strcmp(argv[i], "-add_no_defs") == 0 ) + add_no_defs = 1; + } + #ifdef _WIN32 /* This is an incredible weirdness but with mingw cross-compiler */ /* 1. - b/a; where double a = 6378206.4; and double b = 6356583.8; */ /* does not evaluate the same in the main thread or in a thread forked */ /* by CreateThread(), so run the main in a thread... */ - HANDLE thread = CreateThread(NULL, 0, do_main, NULL, 0, NULL); - WaitForSingleObject(thread, INFINITE); - CloseHandle( thread ); + { + HANDLE thread = CreateThread(NULL, 0, do_main, NULL, 0, NULL); + WaitForSingleObject(thread, INFINITE); + CloseHandle( thread ); + } #else do_main(); #endif diff --git a/src/test228.c b/src/test228.c index 464c5736..cdfc8650 100644 --- a/src/test228.c +++ b/src/test228.c @@ -15,14 +15,18 @@ int main(int argc, char* argv[]) #include <assert.h> #include <unistd.h> -volatile int go_on = 1; +volatile int run = 0; +volatile int started = 0; void* thread_main(void* unused) { projCtx p_proj_ctxt; projPJ p_WGS84_proj; projPJ p_OSGB36_proj; - + + __sync_add_and_fetch(&started, 1); + while(run == 0); + p_proj_ctxt=pj_ctx_alloc(); p_WGS84_proj=pj_init_plus_ctx(p_proj_ctxt,"+proj=longlat " "+ellps=WGS84 +datum=WGS84 +no_defs"); @@ -30,7 +34,7 @@ void* thread_main(void* unused) "+proj=longlat +ellps=airy +datum=OSGB36 +nadgrids=OSTN02_NTv2.gsb " "+no_defs"); - while(go_on) + while(run) { double x, y; int proj_ret; @@ -61,9 +65,11 @@ int main(int argc, char* argv[]) pthread_create(&tid1, &attr1, thread_main, NULL); pthread_create(&tid2, &attr2, thread_main, NULL); + while(started != 2); + run = 1; for(i=0;i<2;i++) sleep(1); - go_on = 0; + run = 0; return 0; } |
