]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Add (start of) self test suite.
authorSimon Josefsson <simon@josefsson.org>
Mon, 2 Aug 2004 21:28:30 +0000 (21:28 +0000)
committerSimon Josefsson <simon@josefsson.org>
Mon, 2 Aug 2004 21:28:30 +0000 (21:28 +0000)
Makefile.am
NEWS
configure.in
tests/Makefile [deleted file]
tests/Makefile.am [new file with mode: 0644]
tests/simple.c [new file with mode: 0644]
tests/utils.c [new file with mode: 0644]
tests/utils.h [new file with mode: 0644]

index 4302a318bdf615234deba61d53288e2ca3a86636..646c2344e41e6628604a17df8af08ac39e821f79 100644 (file)
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 
 EXTRA_DIST = ChangeLog NEWS INSTALL README THANKS COPYING COPYING.LIB
-SUBDIRS = includes lib libextra src doc
+SUBDIRS = includes lib libextra src doc tests
 
 ChangeLog:
        cvs2cl --utc -U .cvsusers --fsf -t -S --prune
diff --git a/NEWS b/NEWS
index 106ed9d34a3f710b4088a0ed5d9d4b75fc5558f7..3835b1e53738aa1c33b1449b0f91b52e67012973 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+Version 1.1.13
+- Added simple self test suite.
+
 Version 1.1.12 (02/08/2004)
 - Updated the SRP authentication to conform to the
   latest (yet unreleased) draft. Unfortunately this breaks
index 8c5b48269ffbffb473133cd753e389383d45583d..faae1a704e157abdc7888e6a798f6ad4847eaec9 100644 (file)
@@ -566,6 +566,7 @@ doc/Makefile src/x509/Makefile src/srp/Makefile src/openpgp/Makefile \
 src/cfg/Makefile src/cfg/platon/Makefile src/cfg/platon/str/Makefile \
 doc/tex/Makefile doc/tex/cover.tex doc/scripts/Makefile \
 doc/examples/Makefile lib/minitasn1/Makefile lib/x509/Makefile \
-includes/Makefile includes/gnutls/Makefile doc/manpages/Makefile])
+includes/Makefile includes/gnutls/Makefile doc/manpages/Makefile \
+tests/Makefile])
 
 AC_OUTPUT
diff --git a/tests/Makefile b/tests/Makefile
deleted file mode 100644 (file)
index 7549a80..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-LIBS=`../lib/libgnutls-config --libs`  -lgcrypt
-LIBS2=`../lib/libgnutls-config --libs` `../libextra/libgnutls-extra-config --libs` -lgcrypt -lopencdk
-CC=gcc
-CFLAGS=-O2 -I../libextra/ -I../ -I../lib/ `../lib/libgnutls-config --cflags` -I../lib/minitasn1/
-
-all: x509test opgptest
-
-x509test: x509_test.c
-       $(CC) $(CFLAGS) x509_test.c $(LIBS) -o x509test
-
-opgptest: openpgp_test.c
-       $(CC) $(CFLAGS) openpgp_test.c $(LIBS2) -o opgptest
-
-
-check: x509test
-       ./x509test
-       ./opgptest
-
-clean:
-       rm *~
-       rm *.o
-       rm x509test
-       rm opgptest
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..2ca2437
--- /dev/null
@@ -0,0 +1,51 @@
+## Process this file with automake to produce Makefile.in
+# Copyright (C) 2004 Free Software Foundation
+#
+# This file is part of GNUTLS.
+#
+# GNUTLS is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNUTLS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+AM_CPPFLAGS = -I../include
+AM_LDFLAGS = -no-install
+LDADD = ../lib/libgnutls.la libutils.la
+
+noinst_LTLIBRARIES = libutils.la
+libutils_la_SOURCES = utils.h utils.c
+
+TESTS = simple
+check_PROGRAMS = $(TESTS)
+
+# LIBS=`../lib/libgnutls-config --libs`  -lgcrypt
+# LIBS2=`../lib/libgnutls-config --libs` `../libextra/libgnutls-extra-config --libs` -lgcrypt -lopencdk
+# CC=gcc
+# CFLAGS=-O2 -I../libextra/ -I../ -I../lib/ `../lib/libgnutls-config --cflags` -I../lib/minitasn1/
+#
+# all: x509test opgptest
+#
+# x509test: x509_test.c
+#      $(CC) $(CFLAGS) x509_test.c $(LIBS) -o x509test
+#
+# opgptest: openpgp_test.c
+#      $(CC) $(CFLAGS) openpgp_test.c $(LIBS2) -o opgptest
+#
+# check: x509test
+#      ./x509test
+#      ./opgptest
+#
+# clean:
+#      rm *~
+#      rm *.o
+#      rm x509test
+#      rm opgptest
diff --git a/tests/simple.c b/tests/simple.c
new file mode 100644 (file)
index 0000000..2bf5360
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2004 Free Software Foundation
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "utils.h"
+
+void
+doit (void)
+{
+  if (debug)
+    {
+      printf ("GNUTLS header version %s.\n", LIBGNUTLS_VERSION);
+      printf ("GNUTLS library version %s.\n", gnutls_check_version (NULL));
+    }
+
+  if (gnutls_check_version (LIBGNUTLS_VERSION))
+    success ("gnutls_check_version OK\n");
+  else
+    fail ("gnutls_check_version OK\n");
+}
diff --git a/tests/utils.c b/tests/utils.c
new file mode 100644 (file)
index 0000000..bf49bcd
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2004 Free Software Foundation
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "utils.h"
+
+int debug = 0;
+int error_count = 0;
+int break_on_error = 0;
+
+void
+fail (const char *format, ...)
+{
+  va_list arg_ptr;
+
+  va_start (arg_ptr, format);
+  vfprintf (stderr, format, arg_ptr);
+  va_end (arg_ptr);
+  error_count++;
+  if (break_on_error)
+    exit (1);
+}
+
+void
+success (const char *format, ...)
+{
+  va_list arg_ptr;
+
+  va_start (arg_ptr, format);
+  if (debug)
+    vfprintf (stdout, format, arg_ptr);
+  va_end (arg_ptr);
+}
+
+void
+escapeprint (const char *str, size_t len)
+{
+  size_t i;
+
+  printf (" (length %d bytes):\n\t", len);
+  for (i = 0; i < len; i++)
+    {
+      if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') ||
+         ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') ||
+         ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9')
+         || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.')
+       printf ("%c", (str[i] & 0xFF));
+      else
+       printf ("\\x%02X", (str[i] & 0xFF));
+      if ((i + 1) % 16 == 0 && (i + 1) < len)
+       printf ("'\n\t'");
+    }
+  printf ("\n");
+}
+
+void
+hexprint (const char *str, size_t len)
+{
+  size_t i;
+
+  printf ("\t;; ");
+  for (i = 0; i < len; i++)
+    {
+      printf ("%02x ", (str[i] & 0xFF));
+      if ((i + 1) % 8 == 0)
+       printf (" ");
+      if ((i + 1) % 16 == 0 && i + 1 < len)
+       printf ("\n\t;; ");
+    }
+  printf ("\n");
+}
+
+void
+binprint (const char *str, size_t len)
+{
+  size_t i;
+
+  printf ("\t;; ");
+  for (i = 0; i < len; i++)
+    {
+      printf ("%d%d%d%d%d%d%d%d ",
+             (str[i] & 0xFF) & 0x80 ? 1 : 0,
+             (str[i] & 0xFF) & 0x40 ? 1 : 0,
+             (str[i] & 0xFF) & 0x20 ? 1 : 0,
+             (str[i] & 0xFF) & 0x10 ? 1 : 0,
+             (str[i] & 0xFF) & 0x08 ? 1 : 0,
+             (str[i] & 0xFF) & 0x04 ? 1 : 0,
+             (str[i] & 0xFF) & 0x02 ? 1 : 0, (str[i] & 0xFF) & 0x01 ? 1 : 0);
+      if ((i + 1) % 3 == 0)
+       printf (" ");
+      if ((i + 1) % 6 == 0 && i + 1 < len)
+       printf ("\n\t;; ");
+    }
+  printf ("\n");
+}
+
+int
+main (int argc, char *argv[])
+{
+  do
+    if (strcmp (argv[argc - 1], "-v") == 0 ||
+       strcmp (argv[argc - 1], "--verbose") == 0)
+      debug = 1;
+    else if (strcmp (argv[argc - 1], "-b") == 0 ||
+            strcmp (argv[argc - 1], "--break-on-error") == 0)
+      break_on_error = 1;
+    else if (strcmp (argv[argc - 1], "-h") == 0 ||
+            strcmp (argv[argc - 1], "-?") == 0 ||
+            strcmp (argv[argc - 1], "--help") == 0)
+      {
+       printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
+               argv[0]);
+       return 1;
+      }
+  while (argc-- > 1);
+
+  doit ();
+
+  if (debug)
+    printf ("Self test `%s' finished with %d errors\n", argv[0], error_count);
+
+  return error_count ? 1 : 0;
+}
diff --git a/tests/utils.h b/tests/utils.h
new file mode 100644 (file)
index 0000000..94b099c
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2004 Free Software Foundation
+ *
+ * This file is part of GNUTLS.
+ *
+ * GNUTLS is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GNUTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef UTILS_H
+# define UTILS_H
+
+# include <string.h>
+# include <stdarg.h>
+# include <gnutls/gnutls.h>
+
+extern int debug;
+extern int error_count;
+extern int break_on_error;
+
+extern void fail (const char *format, ...);
+extern void success (const char *format, ...);
+
+extern void escapeprint (const char *str, size_t len);
+extern void hexprint (const char *str, size_t len);
+extern void binprint (const char *str, size_t len);
+
+/* This must be implemented elsewhere. */
+extern void doit (void);
+
+#endif /* UTILS_H */