Просмотр исходного кода

[test] Rewrite X.509 tests using okx()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 лет назад
Родитель
Сommit
cc018ca7d4
1 измененных файлов: 145 добавлений и 61 удалений
  1. 145
    61
      src/tests/x509_test.c

+ 145
- 61
src/tests/x509_test.c Просмотреть файл

@@ -701,118 +701,183 @@ static time_t test_ca_expired = 2205014905ULL; /* Wed Nov 16 00:08:25 2039 */
701 701
  * Report certificate parsing test result
702 702
  *
703 703
  * @v crt		Test certificate
704
+ * @v file		Test code file
705
+ * @v line		Test code line
704 706
  */
705
-#define x509_certificate_ok( crt ) do {					\
706
-	ok ( x509_certificate ( (crt)->data, (crt)->len,		\
707
-				&(crt)->cert ) == 0 );			\
708
-	} while ( 0 )
707
+static void x509_certificate_okx ( struct x509_test_certificate *crt,
708
+				   const char *file, unsigned int line ) {
709
+
710
+	okx ( x509_certificate ( crt->data, crt->len, &crt->cert ) == 0,
711
+	      file, line );
712
+}
713
+#define x509_certificate_ok( crt ) \
714
+	x509_certificate_okx ( crt, __FILE__, __LINE__ )
709 715
 
710 716
 /**
711 717
  * Report cached certificate parsing test result
712 718
  *
713 719
  * @v crt		Test certificate
720
+ * @v file		Test code file
721
+ * @v line		Test code line
714 722
  */
715
-#define x509_cached_ok( crt ) do {					\
716
-	struct x509_certificate *temp;					\
717
-	ok ( x509_certificate ( (crt)->data, (crt)->len,		\
718
-				&temp ) == 0 );				\
719
-	ok ( temp == (crt)->cert );					\
720
-	x509_put ( temp );						\
721
-	} while ( 0 )
723
+static void x509_cached_okx ( struct x509_test_certificate *crt,
724
+			      const char *file, unsigned int line ) {
725
+	struct x509_certificate *temp;
726
+
727
+	okx ( x509_certificate ( crt->data, crt->len, &temp ) == 0,
728
+	      file, line );
729
+	okx ( temp == crt->cert, file, line );
730
+	x509_put ( temp );
731
+}
732
+#define x509_cached_ok( crt ) x509_cached_okx ( crt, __FILE__, __LINE__ )
722 733
 
723 734
 /**
724 735
  * Report certificate fingerprint test result
725 736
  *
726 737
  * @v crt		Test certificate
738
+ * @v file		Test code file
739
+ * @v line		Test code line
727 740
  */
728
-#define x509_fingerprint_ok( crt ) do {					\
729
-	uint8_t fingerprint[ x509_test_algorithm.digestsize ];		\
730
-	x509_fingerprint ( (crt)->cert, &x509_test_algorithm,		\
731
-			   fingerprint );				\
732
-	ok ( memcmp ( fingerprint, (crt)->fingerprint,			\
733
-		      sizeof ( fingerprint ) ) == 0 );			\
734
-	} while ( 0 )
741
+static void x509_fingerprint_okx ( struct x509_test_certificate *crt,
742
+				   const char *file, unsigned int line ) {
743
+	uint8_t fingerprint[ x509_test_algorithm.digestsize ];
744
+
745
+	x509_fingerprint ( crt->cert, &x509_test_algorithm, fingerprint );
746
+	okx ( memcmp ( fingerprint, crt->fingerprint,
747
+		       sizeof ( fingerprint ) ) == 0, file, line );
748
+}
749
+#define x509_fingerprint_ok( crt ) \
750
+	x509_fingerprint_okx ( crt, __FILE__, __LINE__ )
735 751
 
736 752
 /**
737 753
  * Report certificate issuer validation test result
738 754
  *
739 755
  * @v crt		Test certificate
740 756
  * @v issuer		Test issuer
757
+ * @v file		Test code file
758
+ * @v line		Test code line
741 759
  */
742
-#define x509_check_issuer_ok( crt, issuer ) do {			\
743
-	ok ( x509_check_issuer ( (crt)->cert, (issuer)->cert ) == 0 );	\
744
-	} while ( 0 )
760
+static void x509_check_issuer_okx ( struct x509_test_certificate *crt,
761
+				    struct x509_test_certificate *issuer,
762
+				    const char *file, unsigned int line ) {
763
+
764
+	okx ( x509_check_issuer ( crt->cert, issuer->cert ) == 0, file, line );
765
+}
766
+#define x509_check_issuer_ok( crt, issuer ) \
767
+	x509_check_issuer_okx ( crt, issuer, __FILE__, __LINE__ )
745 768
 
746 769
 /**
747 770
  * Report certificate issuer validation failure test result
748 771
  *
749 772
  * @v crt		Test certificate
750 773
  * @v issuer		Test issuer
774
+ * @v file		Test code file
775
+ * @v line		Test code line
751 776
  */
752
-#define x509_check_issuer_fail_ok( crt, issuer ) do {			\
753
-	ok ( x509_check_issuer ( (crt)->cert, (issuer)->cert ) != 0 );	\
754
-	} while ( 0 )
777
+static void x509_check_issuer_fail_okx ( struct x509_test_certificate *crt,
778
+					 struct x509_test_certificate *issuer,
779
+					 const char *file, unsigned int line ) {
780
+
781
+	okx ( x509_check_issuer ( crt->cert, issuer->cert ) != 0,
782
+	      file, line );
783
+}
784
+#define x509_check_issuer_fail_ok( crt, issuer ) \
785
+	x509_check_issuer_fail_okx ( crt, issuer, __FILE__, __LINE__ )
755 786
 
756 787
 /**
757 788
  * Report certificate root validation test result
758 789
  *
759 790
  * @v crt		Test certificate
760 791
  * @v root		Test root certificate store
792
+ * @v file		Test code file
793
+ * @v line		Test code line
761 794
  */
762
-#define x509_check_root_ok( crt, root ) do {				\
763
-	ok ( x509_check_root ( (crt)->cert, root ) == 0 );		\
764
-	} while ( 0 )
795
+static void x509_check_root_okx ( struct x509_test_certificate *crt,
796
+				  struct x509_root *root, const char *file,
797
+				  unsigned int line ) {
798
+
799
+	okx ( x509_check_root ( crt->cert, root ) == 0, file, line );
800
+}
801
+#define x509_check_root_ok( crt, root ) \
802
+	x509_check_root_okx ( crt, root, __FILE__, __LINE__ )
765 803
 
766 804
 /**
767 805
  * Report certificate root validation failure test result
768 806
  *
769 807
  * @v crt		Test certificate
770 808
  * @v root		Test root certificate store
809
+ * @v file		Test code file
810
+ * @v line		Test code line
771 811
  */
772
-#define x509_check_root_fail_ok( crt, root ) do {			\
773
-	ok ( x509_check_root ( (crt)->cert, root ) != 0 );		\
774
-	} while ( 0 )
812
+static void x509_check_root_fail_okx ( struct x509_test_certificate *crt,
813
+				       struct x509_root *root,
814
+				       const char *file, unsigned int line ) {
815
+
816
+	okx ( x509_check_root ( crt->cert, root ) != 0, file, line );
817
+}
818
+#define x509_check_root_fail_ok( crt, root ) \
819
+	x509_check_root_fail_okx ( crt, root, __FILE__, __LINE__ )
775 820
 
776 821
 /**
777 822
  * Report certificate time validation test result
778 823
  *
779 824
  * @v crt		Test certificate
780 825
  * @v time		Test time
826
+ * @v file		Test code file
827
+ * @v line		Test code line
781 828
  */
782
-#define x509_check_time_ok( crt, time ) do {				\
783
-	ok ( x509_check_time ( (crt)->cert, time ) == 0 );		\
784
-	} while ( 0 )
829
+static void x509_check_time_okx ( struct x509_test_certificate *crt,
830
+				  time_t time, const char *file,
831
+				  unsigned int line ) {
832
+
833
+	okx ( x509_check_time ( crt->cert, time ) == 0, file, line );
834
+}
835
+#define x509_check_time_ok( crt, time ) \
836
+	x509_check_time_okx ( crt, time, __FILE__, __LINE__ )
785 837
 
786 838
 /**
787 839
  * Report certificate time validation failure test result
788 840
  *
789 841
  * @v crt		Test certificate
790 842
  * @v time		Test time
843
+ * @v file		Test code file
844
+ * @v line		Test code line
791 845
  */
792
-#define x509_check_time_fail_ok( crt, time ) do {			\
793
-	ok ( x509_check_time ( (crt)->cert, time ) != 0 );		\
794
-	} while ( 0 )
846
+static void x509_check_time_fail_okx ( struct x509_test_certificate *crt,
847
+				       time_t time, const char *file,
848
+				       unsigned int line ) {
849
+
850
+	okx ( x509_check_time ( crt->cert, time ) != 0, file, line );
851
+}
852
+#define x509_check_time_fail_ok( crt, time ) \
853
+	x509_check_time_fail_okx ( crt, time, __FILE__, __LINE__ )
795 854
 
796 855
 /**
797 856
  * Report certificate chain parsing test result
798 857
  *
799 858
  * @v chn		Test certificate chain
859
+ * @v file		Test code file
860
+ * @v line		Test code line
800 861
  */
801
-#define x509_chain_ok( chn ) do {					\
802
-	unsigned int i;							\
803
-	struct x509_certificate *first;					\
804
-	(chn)->chain = x509_alloc_chain();				\
805
-	ok ( (chn)->chain != NULL );					\
806
-	for ( i = 0 ; i < (chn)->count ; i++ ) {			\
807
-		ok ( x509_append ( (chn)->chain,			\
808
-				   (chn)->certs[i]->cert ) == 0 );	\
809
-	}								\
810
-	first = x509_first ( (chn)->chain );				\
811
-	ok ( first != NULL );						\
812
-	ok ( first->raw.len == (chn)->certs[0]->len );			\
813
-	ok ( memcmp ( first->raw.data, (chn)->certs[0]->data,		\
814
-		      first->raw.len ) == 0 );				\
815
-	} while ( 0 )
862
+static void x509_chain_okx ( struct x509_test_chain *chn, const char *file,
863
+			     unsigned int line ) {
864
+	unsigned int i;
865
+	struct x509_certificate *first;
866
+
867
+	chn->chain = x509_alloc_chain();
868
+	okx ( chn->chain != NULL, file, line );
869
+	for ( i = 0 ; i < chn->count ; i++ ) {
870
+		okx ( x509_append ( chn->chain, chn->certs[i]->cert ) == 0,
871
+		      file, line );
872
+	}
873
+	first = x509_first ( chn->chain );
874
+	okx ( first != NULL, file, line );
875
+	okx ( first->raw.len == chn->certs[0]->len, file, line );
876
+	okx ( memcmp ( first->raw.data, chn->certs[0]->data,
877
+		       first->raw.len ) == 0, file, line );
878
+}
879
+#define x509_chain_ok( chn ) \
880
+	x509_chain_okx ( chn, __FILE__, __LINE__ )
816 881
 
817 882
 /**
818 883
  * Report certificate chain validation test result
@@ -821,12 +886,20 @@ static time_t test_ca_expired = 2205014905ULL; /* Wed Nov 16 00:08:25 2039 */
821 886
  * @v time		Test certificate validation time
822 887
  * @v store		Test certificate store
823 888
  * @v root		Test root certificate list
889
+ * @v file		Test code file
890
+ * @v line		Test code line
824 891
  */
825
-#define x509_validate_chain_ok( chn, time, store, root ) do {		\
826
-	x509_invalidate_chain ( (chn)->chain );				\
827
-	ok ( x509_validate_chain ( (chn)->chain, (time),		\
828
-				   (store), (root) ) == 0 );		\
829
-	} while ( 0 )
892
+static void x509_validate_chain_okx ( struct x509_test_chain *chn, time_t time,
893
+				      struct x509_chain *store,
894
+				      struct x509_root *root, const char *file,
895
+				      unsigned int line ) {
896
+
897
+	x509_invalidate_chain ( chn->chain );
898
+	okx ( x509_validate_chain ( chn->chain, time, store, root ) == 0,
899
+	      file, line );
900
+}
901
+#define x509_validate_chain_ok( chn, time, store, root ) \
902
+	x509_validate_chain_okx ( chn, time, store, root, __FILE__, __LINE__ )
830 903
 
831 904
 /**
832 905
  * Report certificate chain validation failure test result
@@ -835,12 +908,23 @@ static time_t test_ca_expired = 2205014905ULL; /* Wed Nov 16 00:08:25 2039 */
835 908
  * @v time		Test certificate validation time
836 909
  * @v store		Test certificate store
837 910
  * @v root		Test root certificate list
911
+ * @v file		Test code file
912
+ * @v line		Test code line
838 913
  */
839
-#define x509_validate_chain_fail_ok( chn, time, store, root ) do {	\
840
-	x509_invalidate_chain ( (chn)->chain );				\
841
-	ok ( x509_validate_chain ( (chn)->chain, (time),		\
842
-				   (store), (root) ) != 0 );		\
843
-	} while ( 0 )
914
+static void x509_validate_chain_fail_okx ( struct x509_test_chain *chn,
915
+					   time_t time,
916
+					   struct x509_chain *store,
917
+					   struct x509_root *root,
918
+					   const char *file,
919
+					   unsigned int line ) {
920
+
921
+	x509_invalidate_chain ( chn->chain );
922
+	okx ( x509_validate_chain ( chn->chain, time, store, root ) != 0,
923
+	      file, line );
924
+}
925
+#define x509_validate_chain_fail_ok( chn, time, store, root )		\
926
+	x509_validate_chain_fail_okx ( chn, time, store, root,		\
927
+				       __FILE__, __LINE__ )
844 928
 
845 929
 /**
846 930
  * Perform X.509 self-tests

Загрузка…
Отмена
Сохранить