PolarSSL v1.3.9
test_suite_debug.c
Go to the documentation of this file.
1#if !defined(POLARSSL_CONFIG_FILE)
2#include <polarssl/config.h>
3#else
4#include POLARSSL_CONFIG_FILE
5#endif
6
7#ifdef POLARSSL_DEBUG_C
8#ifdef POLARSSL_SSL_TLS_C
9
10#include <polarssl/debug.h>
11
12struct buffer_data
13{
14 char buf[2000];
15 char *ptr;
16};
17
18void string_debug(void *data, int level, const char *str)
19{
20 struct buffer_data *buffer = (struct buffer_data *) data;
21 ((void) level);
22
23 memcpy(buffer->ptr, str, strlen(str));
24 buffer->ptr += strlen(str);
25
26 /* Detect if debug messages output partial lines and mark them */
27 if( *(buffer->ptr - 1) != '\n' )
28 {
29 *buffer->ptr = '*';
30 buffer->ptr++;
31 }
32}
33#endif /* POLARSSL_DEBUG_C */
34#endif /* POLARSSL_SSL_TLS_C */
35
36
37#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
38#include "polarssl/memory.h"
39#endif
40
41#if defined(POLARSSL_PLATFORM_C)
42#include "polarssl/platform.h"
43#else
44#define polarssl_malloc malloc
45#define polarssl_free free
46#endif
47
48#ifdef _MSC_VER
49#include <basetsd.h>
50typedef UINT32 uint32_t;
51#else
52#include <inttypes.h>
53#endif
54
55#include <assert.h>
56#include <stdlib.h>
57#include <string.h>
58
59/*
60 * 32-bit integer manipulation macros (big endian)
61 */
62#ifndef GET_UINT32_BE
63#define GET_UINT32_BE(n,b,i) \
64{ \
65 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
66 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
67 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
68 | ( (uint32_t) (b)[(i) + 3] ); \
69}
70#endif
71
72#ifndef PUT_UINT32_BE
73#define PUT_UINT32_BE(n,b,i) \
74{ \
75 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
76 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
77 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
78 (b)[(i) + 3] = (unsigned char) ( (n) ); \
79}
80#endif
81
82static int unhexify(unsigned char *obuf, const char *ibuf)
83{
84 unsigned char c, c2;
85 int len = strlen(ibuf) / 2;
86 assert(!(strlen(ibuf) %1)); // must be even number of bytes
87
88 while (*ibuf != 0)
89 {
90 c = *ibuf++;
91 if( c >= '0' && c <= '9' )
92 c -= '0';
93 else if( c >= 'a' && c <= 'f' )
94 c -= 'a' - 10;
95 else if( c >= 'A' && c <= 'F' )
96 c -= 'A' - 10;
97 else
98 assert( 0 );
99
100 c2 = *ibuf++;
101 if( c2 >= '0' && c2 <= '9' )
102 c2 -= '0';
103 else if( c2 >= 'a' && c2 <= 'f' )
104 c2 -= 'a' - 10;
105 else if( c2 >= 'A' && c2 <= 'F' )
106 c2 -= 'A' - 10;
107 else
108 assert( 0 );
109
110 *obuf++ = ( c << 4 ) | c2;
111 }
112
113 return len;
114}
115
116static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
117{
118 unsigned char l, h;
119
120 while (len != 0)
121 {
122 h = (*ibuf) / 16;
123 l = (*ibuf) % 16;
124
125 if( h < 10 )
126 *obuf++ = '0' + h;
127 else
128 *obuf++ = 'a' + h - 10;
129
130 if( l < 10 )
131 *obuf++ = '0' + l;
132 else
133 *obuf++ = 'a' + l - 10;
134
135 ++ibuf;
136 len--;
137 }
138}
139
147static unsigned char *zero_alloc( size_t len )
148{
149 void *p;
150 size_t actual_len = len != 0 ? len : 1;
151
152 p = polarssl_malloc( actual_len );
153 assert( p != NULL );
154
155 memset( p, 0x00, actual_len );
156
157 return( p );
158}
159
170static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
171{
172 unsigned char *obuf;
173
174 *olen = strlen(ibuf) / 2;
175
176 if( *olen == 0 )
177 return( zero_alloc( *olen ) );
178
179 obuf = polarssl_malloc( *olen );
180 assert( obuf != NULL );
181
182 (void) unhexify( obuf, ibuf );
183
184 return( obuf );
185}
186
196static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
197{
198#if !defined(__OpenBSD__)
199 size_t i;
200
201 if( rng_state != NULL )
202 rng_state = NULL;
203
204 for( i = 0; i < len; ++i )
205 output[i] = rand();
206#else
207 if( rng_state != NULL )
208 rng_state = NULL;
209
210 arc4random_buf( output, len );
211#endif /* !OpenBSD */
212
213 return( 0 );
214}
215
221static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
222{
223 if( rng_state != NULL )
224 rng_state = NULL;
225
226 memset( output, 0, len );
227
228 return( 0 );
229}
230
231typedef struct
232{
233 unsigned char *buf;
234 size_t length;
236
248static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
249{
250 rnd_buf_info *info = (rnd_buf_info *) rng_state;
251 size_t use_len;
252
253 if( rng_state == NULL )
254 return( rnd_std_rand( NULL, output, len ) );
255
256 use_len = len;
257 if( len > info->length )
258 use_len = info->length;
259
260 if( use_len )
261 {
262 memcpy( output, info->buf, use_len );
263 info->buf += use_len;
264 info->length -= use_len;
265 }
266
267 if( len - use_len > 0 )
268 return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
269
270 return( 0 );
271}
272
280typedef struct
281{
282 uint32_t key[16];
283 uint32_t v0, v1;
285
294static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
295{
296 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
297 uint32_t i, *k, sum, delta=0x9E3779B9;
298 unsigned char result[4], *out = output;
299
300 if( rng_state == NULL )
301 return( rnd_std_rand( NULL, output, len ) );
302
303 k = info->key;
304
305 while( len > 0 )
306 {
307 size_t use_len = ( len > 4 ) ? 4 : len;
308 sum = 0;
309
310 for( i = 0; i < 32; i++ )
311 {
312 info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
313 sum += delta;
314 info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
315 }
316
317 PUT_UINT32_BE( info->v0, result, 0 );
318 memcpy( out, result, use_len );
319 len -= use_len;
320 out += 4;
321 }
322
323 return( 0 );
324}
325
326
327#include <stdio.h>
328#include <string.h>
329
330#if defined(POLARSSL_PLATFORM_C)
331#include "polarssl/platform.h"
332#else
333#define polarssl_printf printf
334#define polarssl_malloc malloc
335#define polarssl_free free
336#endif
337
338static int test_errors = 0;
339
340#ifdef POLARSSL_DEBUG_C
341#ifdef POLARSSL_SSL_TLS_C
342
343#define TEST_SUITE_ACTIVE
344
345static int test_assert( int correct, const char *test )
346{
347 if( correct )
348 return( 0 );
349
350 test_errors++;
351 if( test_errors == 1 )
352 printf( "FAILED\n" );
353 printf( " %s\n", test );
354
355 return( 1 );
356}
357
358#define TEST_ASSERT( TEST ) \
359 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
360 if( test_errors) goto exit; \
361 } while (0)
362
363int verify_string( char **str )
364{
365 if( (*str)[0] != '"' ||
366 (*str)[strlen( *str ) - 1] != '"' )
367 {
368 printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
369 return( -1 );
370 }
371
372 (*str)++;
373 (*str)[strlen( *str ) - 1] = '\0';
374
375 return( 0 );
376}
377
378int verify_int( char *str, int *value )
379{
380 size_t i;
381 int minus = 0;
382 int digits = 1;
383 int hex = 0;
384
385 for( i = 0; i < strlen( str ); i++ )
386 {
387 if( i == 0 && str[i] == '-' )
388 {
389 minus = 1;
390 continue;
391 }
392
393 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
394 str[i - 1] == '0' && str[i] == 'x' )
395 {
396 hex = 1;
397 continue;
398 }
399
400 if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
401 ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
402 ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
403 {
404 digits = 0;
405 break;
406 }
407 }
408
409 if( digits )
410 {
411 if( hex )
412 *value = strtol( str, NULL, 16 );
413 else
414 *value = strtol( str, NULL, 10 );
415
416 return( 0 );
417 }
418
419 if( strcmp( str, "-0xFFFF" ) == 0 )
420 {
421 *value = ( -0xFFFF );
422 return( 0 );
423 }
424 if( strcmp( str, "POLARSSL_DEBUG_LOG_FULL" ) == 0 )
425 {
426 *value = ( POLARSSL_DEBUG_LOG_FULL );
427 return( 0 );
428 }
429 if( strcmp( str, "POLARSSL_DEBUG_LOG_RAW" ) == 0 )
430 {
431 *value = ( POLARSSL_DEBUG_LOG_RAW );
432 return( 0 );
433 }
434
435
436 printf( "Expected integer for parameter and got: %s\n", str );
437 return( -1 );
438}
439
440void test_suite_debug_print_msg_threshold( int threshold, int level, char *file, int line,
441 char *result_str )
442{
443 ssl_context ssl;
444 struct buffer_data buffer;
445
446 memset( &ssl, 0, sizeof( ssl_context ) );
447 memset( buffer.buf, 0, 2000 );
448 buffer.ptr = buffer.buf;
449
451 debug_set_threshold( threshold );
452 ssl_set_dbg(&ssl, string_debug, &buffer);
453
454 debug_print_msg( &ssl, level, file, line,
455 debug_fmt("Text message, 2 == %d", 2 ) );
456
457 TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
458
459exit:
460 return;
461}
462
463void test_suite_debug_print_ret( int mode, char *file, int line, char *text, int value,
464 char *result_str )
465{
466 ssl_context ssl;
467 struct buffer_data buffer;
468
469 memset( &ssl, 0, sizeof( ssl_context ) );
470 memset( buffer.buf, 0, 2000 );
471 buffer.ptr = buffer.buf;
472
473 debug_set_log_mode( mode );
474 ssl_set_dbg(&ssl, string_debug, &buffer);
475
476 debug_print_ret( &ssl, 0, file, line, text, value);
477
478 TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
479
480exit:
481 return;
482}
483
484void test_suite_debug_print_buf( int mode, char *file, int line, char *text,
485 char *data_string, char *result_str )
486{
487 unsigned char data[10000];
488 ssl_context ssl;
489 struct buffer_data buffer;
490 size_t data_len;
491
492 memset( &data, 0, sizeof( data ) );
493 memset( &ssl, 0, sizeof( ssl_context ) );
494 memset( buffer.buf, 0, 2000 );
495 buffer.ptr = buffer.buf;
496
497 data_len = unhexify( data, data_string );
498
499 debug_set_log_mode( mode );
500 ssl_set_dbg(&ssl, string_debug, &buffer);
501
502 debug_print_buf( &ssl, 0, file, line, text, data, data_len );
503
504 TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
505
506exit:
507 return;
508}
509
510#ifdef POLARSSL_FS_IO
511#ifdef POLARSSL_X509_CRT_PARSE_C
512void test_suite_debug_print_crt( int mode, char *crt_file, char *file, int line,
513 char *prefix, char *result_str )
514{
515 x509_crt crt;
516 ssl_context ssl;
517 struct buffer_data buffer;
518
519 x509_crt_init( &crt );
520 memset( &ssl, 0, sizeof( ssl_context ) );
521 memset( buffer.buf, 0, 2000 );
522 buffer.ptr = buffer.buf;
523
524 debug_set_log_mode( mode );
525 ssl_set_dbg(&ssl, string_debug, &buffer);
526
527 TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
528 debug_print_crt( &ssl, 0, file, line, prefix, &crt);
529
530 TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
531
532exit:
533 x509_crt_free( &crt );
534}
535#endif /* POLARSSL_FS_IO */
536#endif /* POLARSSL_X509_CRT_PARSE_C */
537
538#ifdef POLARSSL_BIGNUM_C
539void test_suite_debug_print_mpi( int mode, int radix, char *value, char *file, int line,
540 char *prefix, char *result_str )
541{
542 ssl_context ssl;
543 struct buffer_data buffer;
544 mpi val;
545
546 mpi_init( &val );
547
548 memset( &ssl, 0, sizeof( ssl_context ) );
549 memset( buffer.buf, 0, 2000 );
550 buffer.ptr = buffer.buf;
551
552 TEST_ASSERT( mpi_read_string( &val, radix, value ) == 0 );
553
554 debug_set_log_mode( mode );
555 ssl_set_dbg(&ssl, string_debug, &buffer);
556
557 debug_print_mpi( &ssl, 0, file, line, prefix, &val);
558
559 TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
560
561exit:
562 mpi_free( &val );
563}
564#endif /* POLARSSL_BIGNUM_C */
565
566
567#endif /* POLARSSL_DEBUG_C */
568#endif /* POLARSSL_SSL_TLS_C */
569
570
571int dep_check( char *str )
572{
573 if( str == NULL )
574 return( 1 );
575
576 if( strcmp( str, "POLARSSL_BASE64_C" ) == 0 )
577 {
578#if defined(POLARSSL_BASE64_C)
579 return( 0 );
580#else
581 return( 1 );
582#endif
583 }
584 if( strcmp( str, "POLARSSL_ECP_C" ) == 0 )
585 {
586#if defined(POLARSSL_ECP_C)
587 return( 0 );
588#else
589 return( 1 );
590#endif
591 }
592 if( strcmp( str, "POLARSSL_RSA_C" ) == 0 )
593 {
594#if defined(POLARSSL_RSA_C)
595 return( 0 );
596#else
597 return( 1 );
598#endif
599 }
600 if( strcmp( str, "POLARSSL_PEM_PARSE_C" ) == 0 )
601 {
602#if defined(POLARSSL_PEM_PARSE_C)
603 return( 0 );
604#else
605 return( 1 );
606#endif
607 }
608 if( strcmp( str, "POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
609 {
610#if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
611 return( 0 );
612#else
613 return( 1 );
614#endif
615 }
616
617
618 return( 1 );
619}
620
621int dispatch_test(int cnt, char *params[50])
622{
623 int ret;
624 ((void) cnt);
625 ((void) params);
626
627#if defined(TEST_SUITE_ACTIVE)
628 if( strcmp( params[0], "debug_print_msg_threshold" ) == 0 )
629 {
630
631 int param1;
632 int param2;
633 char *param3 = params[3];
634 int param4;
635 char *param5 = params[5];
636
637 if( cnt != 6 )
638 {
639 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 6 );
640 return( 2 );
641 }
642
643 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
644 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
645 if( verify_string( &param3 ) != 0 ) return( 2 );
646 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
647 if( verify_string( &param5 ) != 0 ) return( 2 );
648
649 test_suite_debug_print_msg_threshold( param1, param2, param3, param4, param5 );
650 return ( 0 );
651
652 return ( 3 );
653 }
654 else
655 if( strcmp( params[0], "debug_print_ret" ) == 0 )
656 {
657
658 int param1;
659 char *param2 = params[2];
660 int param3;
661 char *param4 = params[4];
662 int param5;
663 char *param6 = params[6];
664
665 if( cnt != 7 )
666 {
667 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
668 return( 2 );
669 }
670
671 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
672 if( verify_string( &param2 ) != 0 ) return( 2 );
673 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
674 if( verify_string( &param4 ) != 0 ) return( 2 );
675 if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
676 if( verify_string( &param6 ) != 0 ) return( 2 );
677
678 test_suite_debug_print_ret( param1, param2, param3, param4, param5, param6 );
679 return ( 0 );
680
681 return ( 3 );
682 }
683 else
684 if( strcmp( params[0], "debug_print_buf" ) == 0 )
685 {
686
687 int param1;
688 char *param2 = params[2];
689 int param3;
690 char *param4 = params[4];
691 char *param5 = params[5];
692 char *param6 = params[6];
693
694 if( cnt != 7 )
695 {
696 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
697 return( 2 );
698 }
699
700 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
701 if( verify_string( &param2 ) != 0 ) return( 2 );
702 if( verify_int( params[3], &param3 ) != 0 ) return( 2 );
703 if( verify_string( &param4 ) != 0 ) return( 2 );
704 if( verify_string( &param5 ) != 0 ) return( 2 );
705 if( verify_string( &param6 ) != 0 ) return( 2 );
706
707 test_suite_debug_print_buf( param1, param2, param3, param4, param5, param6 );
708 return ( 0 );
709
710 return ( 3 );
711 }
712 else
713 if( strcmp( params[0], "debug_print_crt" ) == 0 )
714 {
715 #ifdef POLARSSL_FS_IO
716 #ifdef POLARSSL_X509_CRT_PARSE_C
717
718 int param1;
719 char *param2 = params[2];
720 char *param3 = params[3];
721 int param4;
722 char *param5 = params[5];
723 char *param6 = params[6];
724
725 if( cnt != 7 )
726 {
727 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 7 );
728 return( 2 );
729 }
730
731 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
732 if( verify_string( &param2 ) != 0 ) return( 2 );
733 if( verify_string( &param3 ) != 0 ) return( 2 );
734 if( verify_int( params[4], &param4 ) != 0 ) return( 2 );
735 if( verify_string( &param5 ) != 0 ) return( 2 );
736 if( verify_string( &param6 ) != 0 ) return( 2 );
737
738 test_suite_debug_print_crt( param1, param2, param3, param4, param5, param6 );
739 return ( 0 );
740 #endif /* POLARSSL_FS_IO */
741 #endif /* POLARSSL_X509_CRT_PARSE_C */
742
743 return ( 3 );
744 }
745 else
746 if( strcmp( params[0], "debug_print_mpi" ) == 0 )
747 {
748 #ifdef POLARSSL_BIGNUM_C
749
750 int param1;
751 int param2;
752 char *param3 = params[3];
753 char *param4 = params[4];
754 int param5;
755 char *param6 = params[6];
756 char *param7 = params[7];
757
758 if( cnt != 8 )
759 {
760 fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 8 );
761 return( 2 );
762 }
763
764 if( verify_int( params[1], &param1 ) != 0 ) return( 2 );
765 if( verify_int( params[2], &param2 ) != 0 ) return( 2 );
766 if( verify_string( &param3 ) != 0 ) return( 2 );
767 if( verify_string( &param4 ) != 0 ) return( 2 );
768 if( verify_int( params[5], &param5 ) != 0 ) return( 2 );
769 if( verify_string( &param6 ) != 0 ) return( 2 );
770 if( verify_string( &param7 ) != 0 ) return( 2 );
771
772 test_suite_debug_print_mpi( param1, param2, param3, param4, param5, param6, param7 );
773 return ( 0 );
774 #endif /* POLARSSL_BIGNUM_C */
775
776 return ( 3 );
777 }
778 else
779
780 {
781 fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
782 fflush( stdout );
783 return( 1 );
784 }
785#else
786 return( 3 );
787#endif
788 return( ret );
789}
790
791int get_line( FILE *f, char *buf, size_t len )
792{
793 char *ret;
794
795 ret = fgets( buf, len, f );
796 if( ret == NULL )
797 return( -1 );
798
799 if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
800 buf[strlen(buf) - 1] = '\0';
801 if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
802 buf[strlen(buf) - 1] = '\0';
803
804 return( 0 );
805}
806
807int parse_arguments( char *buf, size_t len, char *params[50] )
808{
809 int cnt = 0, i;
810 char *cur = buf;
811 char *p = buf, *q;
812
813 params[cnt++] = cur;
814
815 while( *p != '\0' && p < buf + len )
816 {
817 if( *p == '\\' )
818 {
819 p++;
820 p++;
821 continue;
822 }
823 if( *p == ':' )
824 {
825 if( p + 1 < buf + len )
826 {
827 cur = p + 1;
828 params[cnt++] = cur;
829 }
830 *p = '\0';
831 }
832
833 p++;
834 }
835
836 // Replace newlines, question marks and colons in strings
837 for( i = 0; i < cnt; i++ )
838 {
839 p = params[i];
840 q = params[i];
841
842 while( *p != '\0' )
843 {
844 if( *p == '\\' && *(p + 1) == 'n' )
845 {
846 p += 2;
847 *(q++) = '\n';
848 }
849 else if( *p == '\\' && *(p + 1) == ':' )
850 {
851 p += 2;
852 *(q++) = ':';
853 }
854 else if( *p == '\\' && *(p + 1) == '?' )
855 {
856 p += 2;
857 *(q++) = '?';
858 }
859 else
860 *(q++) = *(p++);
861 }
862 *q = '\0';
863 }
864
865 return( cnt );
866}
867
868int main()
869{
870 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
871 const char *filename = "/builddir/build/BUILD/polarssl-1.3.9/tests/suites/test_suite_debug.data";
872 FILE *file;
873 char buf[5000];
874 char *params[50];
875
876#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
877 unsigned char alloc_buf[1000000];
878 memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
879#endif
880
881 file = fopen( filename, "r" );
882 if( file == NULL )
883 {
884 fprintf( stderr, "Failed to open\n" );
885 return( 1 );
886 }
887
888 while( !feof( file ) )
889 {
890 int skip = 0;
891
892 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
893 break;
894 fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
895 fprintf( stdout, " " );
896 for( i = strlen( buf ) + 1; i < 67; i++ )
897 fprintf( stdout, "." );
898 fprintf( stdout, " " );
899 fflush( stdout );
900
901 total_tests++;
902
903 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
904 break;
905 cnt = parse_arguments( buf, strlen(buf), params );
906
907 if( strcmp( params[0], "depends_on" ) == 0 )
908 {
909 for( i = 1; i < cnt; i++ )
910 if( dep_check( params[i] ) != 0 )
911 skip = 1;
912
913 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
914 break;
915 cnt = parse_arguments( buf, strlen(buf), params );
916 }
917
918 if( skip == 0 )
919 {
920 test_errors = 0;
921 ret = dispatch_test( cnt, params );
922 }
923
924 if( skip == 1 || ret == 3 )
925 {
926 total_skipped++;
927 fprintf( stdout, "----\n" );
928 fflush( stdout );
929 }
930 else if( ret == 0 && test_errors == 0 )
931 {
932 fprintf( stdout, "PASS\n" );
933 fflush( stdout );
934 }
935 else if( ret == 2 )
936 {
937 fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
938 fclose(file);
939 exit( 2 );
940 }
941 else
942 total_errors++;
943
944 if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
945 break;
946 if( strlen(buf) != 0 )
947 {
948 fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
949 return( 1 );
950 }
951 }
952 fclose(file);
953
954 fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
955 if( total_errors == 0 )
956 fprintf( stdout, "PASSED" );
957 else
958 fprintf( stdout, "FAILED" );
959
960 fprintf( stdout, " (%d / %d tests (%d skipped))\n",
961 total_tests - total_errors, total_tests, total_skipped );
962
963#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
964#if defined(POLARSSL_MEMORY_DEBUG)
965 memory_buffer_alloc_status();
966#endif
968#endif
969
970 return( total_errors != 0 );
971}
972
973
void mpi_init(mpi *X)
Initialize one MPI.
int mpi_read_string(mpi *X, int radix, const char *s)
Import from an ASCII string.
void mpi_free(mpi *X)
Unallocate one MPI.
Configuration options (set of defines)
Debug functions.
void debug_set_threshold(int threshold)
Set the level threshold to handle globally.
void debug_set_log_mode(int log_mode)
Set the log mode for the debug functions globally (Default value: POLARSSL_DEBUG_DFL_MODE)
#define POLARSSL_DEBUG_LOG_FULL
Include file:line in log lines.
Definition debug.h:42
void debug_print_buf(const ssl_context *ssl, int level, const char *file, int line, const char *text, unsigned char *buf, size_t len)
void debug_print_msg(const ssl_context *ssl, int level, const char *file, int line, const char *text)
char * debug_fmt(const char *format,...)
void debug_print_crt(const ssl_context *ssl, int level, const char *file, int line, const char *text, const x509_crt *crt)
void debug_print_mpi(const ssl_context *ssl, int level, const char *file, int line, const char *text, const mpi *X)
#define POLARSSL_DEBUG_LOG_RAW
Only log raw debug lines.
Definition debug.h:43
void debug_print_ret(const ssl_context *ssl, int level, const char *file, int line, const char *text, int ret)
void x509_crt_init(x509_crt *crt)
Initialize a certificate (chain)
int x509_crt_parse_file(x509_crt *chain, const char *path)
Load one or more certificates and add them to the chained list.
void x509_crt_free(x509_crt *crt)
Unallocate all certificate data.
Memory allocation layer (Deprecated to platform layer)
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
PolarSSL Platform abstraction layer.
void ssl_set_dbg(ssl_context *ssl, void(*f_dbg)(void *, int, const char *), void *p_dbg)
Set the debug callback.
Container for an X.509 certificate.
Definition x509_crt.h:58
MPI structure.
Definition bignum.h:183
unsigned char * buf
Info structure for the pseudo random function.
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
int dep_check(char *str)
int dispatch_test(int cnt, char *params[50])
#define polarssl_malloc
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
int parse_arguments(char *buf, size_t len, char *params[50])
#define PUT_UINT32_BE(n, b, i)
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
int get_line(FILE *f, char *buf, size_t len)
static int test_errors
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
static int unhexify(unsigned char *obuf, const char *ibuf)
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int main()
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
int verify_int(char *str, int *value)
static int test_assert(int correct, const char *test)
int verify_string(char **str)
#define TEST_ASSERT(TEST)