Add platform setup and teardown calls to test suites

Add a global platform context variable available for tests
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index eef41c7..9295bfa 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -109,6 +109,7 @@
 }
 test_info;
 
+mbedtls_platform_context platform_ctx;
 
 /*----------------------------------------------------------------------------*/
 /* Helper flags for complex dependencies */
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index 042085f..9dd792d 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -281,6 +281,14 @@
 #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
     !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
     unsigned char alloc_buf[1000000];
+#endif 
+    if( mbedtls_platform_setup( &platform_ctx ) )
+    {
+        mbedtls_fprintf( stderr, "FATAL: Failed to initialize platform" );
+        return -1;
+    }
+#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
+    !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
     mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
 #endif
 
@@ -293,6 +301,7 @@
     if( pointer != NULL )
     {
         mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
+        mbedtls_platform_teardown( &platform_ctx );
         return( 1 );
     }
 
@@ -302,6 +311,7 @@
     if( run_test_snprintf() != 0 )
     {
         mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
+        mbedtls_platform_teardown( &platform_ctx );
         return( 0 );
     }
 
@@ -318,6 +328,7 @@
                  strcmp(next_arg, "-h" ) == 0 )
         {
             mbedtls_fprintf( stdout, USAGE );
+            mbedtls_platform_teardown( &platform_ctx );
             mbedtls_exit( EXIT_SUCCESS );
         }
         else
@@ -357,6 +368,7 @@
         {
             mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
                              test_filename );
+            mbedtls_platform_teardown( &platform_ctx );
             return( 1 );
         }
 
@@ -366,6 +378,7 @@
             {
                 mbedtls_fprintf( stderr,
                     "FATAL: Dep count larger than zero at start of loop\n" );
+                mbedtls_platform_teardown( &platform_ctx );
                 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
             }
             unmet_dep_count = 0;
@@ -402,6 +415,7 @@
                         if(  unmet_dependencies[ unmet_dep_count ] == NULL )
                         {
                             mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
+                            mbedtls_platform_teardown( &platform_ctx );
                             mbedtls_exit( MBEDTLS_EXIT_FAILURE );
                         }
                         unmet_dep_count++;
@@ -428,6 +442,7 @@
                     if( stdout_fd == -1 )
                     {
                         /* Redirection has failed with no stdout so exit */
+                        mbedtls_platform_teardown( &platform_ctx );
                         exit( 1 );
                     }
                 }
@@ -439,6 +454,7 @@
                 if( !option_verbose && restore_output( &stdout, stdout_fd ) )
                 {
                         /* Redirection has failed with no stdout so exit */
+                        mbedtls_platform_teardown( &platform_ctx );
                         exit( 1 );
                 }
 #endif /* __unix__ || __APPLE__ __MACH__ */
@@ -490,6 +506,7 @@
             {
                 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
                 fclose( file );
+                mbedtls_platform_teardown( &platform_ctx );
                 mbedtls_exit( 2 );
             }
             else
@@ -501,6 +518,7 @@
             {
                 mbedtls_fprintf( stderr, "Should be empty %d\n",
                                  (int) strlen( buf ) );
+                mbedtls_platform_teardown( &platform_ctx );
                 return( 1 );
             }
         }
@@ -533,5 +551,6 @@
         close_output( stdout );
 #endif /* __unix__ || __APPLE__ __MACH__ */
 
+    mbedtls_platform_teardown( &platform_ctx );
     return( total_errors != 0 );
 }