Add conditional platform context creation & usage

Add another layer of abstraction before calling platform setup and teardown.
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function
index 9295bfa..e716318 100644
--- a/tests/suites/helpers.function
+++ b/tests/suites/helpers.function
@@ -109,7 +109,9 @@
 }
 test_info;
 
+#if defined(MBEDTLS_PLATFORM_C)
 mbedtls_platform_context platform_ctx;
+#endif
 
 /*----------------------------------------------------------------------------*/
 /* Helper flags for complex dependencies */
@@ -128,6 +130,23 @@
 
 /*----------------------------------------------------------------------------*/
 /* Helper Functions */
+static int platform_setup()
+{
+#if defined(MBEDTLS_PLATFORM_C)
+    if( mbedtls_platform_setup( &platform_ctx ) )
+    {
+        return -1;
+    }
+#endif /* MBEDTLS_PLATFORM_C */
+    return 0;
+}
+
+static void platform_teardown()
+{
+#if defined(MBEDTLS_PLATFORM_C)
+    mbedtls_platform_teardown( &platform_ctx );
+#endif /* MBEDTLS_PLATFORM_C */
+}
 
 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
 static int redirect_output( FILE** out_stream, const char* path )
diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function
index 9dd792d..e5b4043 100644
--- a/tests/suites/main_test.function
+++ b/tests/suites/main_test.function
@@ -282,7 +282,7 @@
     !defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
     unsigned char alloc_buf[1000000];
 #endif 
-    if( mbedtls_platform_setup( &platform_ctx ) )
+    if( platform_setup() )
     {
         mbedtls_fprintf( stderr, "FATAL: Failed to initialize platform" );
         return -1;
@@ -301,7 +301,7 @@
     if( pointer != NULL )
     {
         mbedtls_fprintf( stderr, "all-bits-zero is not a NULL pointer\n" );
-        mbedtls_platform_teardown( &platform_ctx );
+        platform_teardown();
         return( 1 );
     }
 
@@ -311,7 +311,7 @@
     if( run_test_snprintf() != 0 )
     {
         mbedtls_fprintf( stderr, "the snprintf implementation is broken\n" );
-        mbedtls_platform_teardown( &platform_ctx );
+        platform_teardown();
         return( 0 );
     }
 
@@ -328,7 +328,7 @@
                  strcmp(next_arg, "-h" ) == 0 )
         {
             mbedtls_fprintf( stdout, USAGE );
-            mbedtls_platform_teardown( &platform_ctx );
+            platform_teardown();
             mbedtls_exit( EXIT_SUCCESS );
         }
         else
@@ -368,7 +368,7 @@
         {
             mbedtls_fprintf( stderr, "Failed to open test file: %s\n",
                              test_filename );
-            mbedtls_platform_teardown( &platform_ctx );
+            platform_teardown();
             return( 1 );
         }
 
@@ -378,7 +378,7 @@
             {
                 mbedtls_fprintf( stderr,
                     "FATAL: Dep count larger than zero at start of loop\n" );
-                mbedtls_platform_teardown( &platform_ctx );
+                platform_teardown();
                 mbedtls_exit( MBEDTLS_EXIT_FAILURE );
             }
             unmet_dep_count = 0;
@@ -415,7 +415,7 @@
                         if(  unmet_dependencies[ unmet_dep_count ] == NULL )
                         {
                             mbedtls_fprintf( stderr, "FATAL: Out of memory\n" );
-                            mbedtls_platform_teardown( &platform_ctx );
+                            platform_teardown();
                             mbedtls_exit( MBEDTLS_EXIT_FAILURE );
                         }
                         unmet_dep_count++;
@@ -441,8 +441,8 @@
                     stdout_fd = redirect_output( &stdout, "/dev/null" );
                     if( stdout_fd == -1 )
                     {
+                        platform_teardown();
                         /* Redirection has failed with no stdout so exit */
-                        mbedtls_platform_teardown( &platform_ctx );
                         exit( 1 );
                     }
                 }
@@ -454,7 +454,7 @@
                 if( !option_verbose && restore_output( &stdout, stdout_fd ) )
                 {
                         /* Redirection has failed with no stdout so exit */
-                        mbedtls_platform_teardown( &platform_ctx );
+                        platform_teardown();
                         exit( 1 );
                 }
 #endif /* __unix__ || __APPLE__ __MACH__ */
@@ -506,7 +506,7 @@
             {
                 mbedtls_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
                 fclose( file );
-                mbedtls_platform_teardown( &platform_ctx );
+                platform_teardown();
                 mbedtls_exit( 2 );
             }
             else
@@ -518,7 +518,7 @@
             {
                 mbedtls_fprintf( stderr, "Should be empty %d\n",
                                  (int) strlen( buf ) );
-                mbedtls_platform_teardown( &platform_ctx );
+                platform_teardown();
                 return( 1 );
             }
         }
@@ -551,6 +551,6 @@
         close_output( stdout );
 #endif /* __unix__ || __APPLE__ __MACH__ */
 
-    mbedtls_platform_teardown( &platform_ctx );
+    platform_teardown();
     return( total_errors != 0 );
 }