1 /* version.c - This version test should be run first.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This file is part of Libgcrypt.
6 Libgcrypt is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 Libgcrypt is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 /* This test should be run first because due to a failing config.links
22 script or bad configure parameters the just build libgcrypt may
23 crash in case MPI function for specific CPU revisions have been
24 enabled. Running this test first will print out information so to
25 make it easier to figure out the problem. */
37 #include "../src/gcrypt-int.h"
43 test_get_config (void)
47 string = gcry_get_config (0, NULL);
49 fail ("gcry_get_config does not return anything: %s\n",
50 gpg_strerror (gpg_error_from_syserror ()));
51 else if ( !strchr (string, '\n') )
52 fail ("gcry_get_config(0, NULL) did not return multiple lines\n");
55 string = gcry_get_config (0, "version");
57 fail ("gcry_get_config(\"version\") returned NULL: %s\n",
58 gpg_strerror (gpg_error_from_syserror ()));
59 else if ( strchr (string, '\n') )
60 fail ("gcry_get_config(\"version\") returned more than one line\n");
61 else if ( strncmp (string, "version:", 8) )
62 fail ("gcry_get_config(\"version\") returned wrong line\n");
64 /* Test an item which is not the first. */
66 string = gcry_get_config (0, "cpu-arch");
68 fail ("gcry_get_config(\"cpu-arch\") returned NULL: %s\n",
69 gpg_strerror (gpg_error_from_syserror ()));
70 else if ( strchr (string, '\n') )
71 fail ("gcry_get_config(\"cpu-arch\") returned more than one line\n");
72 else if ( strncmp (string, "cpu-arch:", 9) )
73 fail ("gcry_get_config(\"cpu-arch\") returned wrong line\n");
75 /* Test that an unknown item return sthe correct error. */
77 string = gcry_get_config (0, "no-such-item");
79 fail ("gcry_get_config(\"no-such-item\") returned something\n");
81 fail ("gcry_get_config(\"no-such-item\") returned wrong error: %s\n",
82 gpg_strerror (gpg_error_from_syserror ()));
89 main (int argc, char **argv)
96 while (argc && last_argc != argc )
99 if (!strcmp (*argv, "--"))
104 else if (!strcmp (*argv, "--verbose"))
109 else if (!strcmp (*argv, "--debug"))
114 else if (!strcmp (*argv, "--disable-hwf"))
120 if (gcry_control (GCRYCTL_DISABLE_HWF, *argv, NULL))
123 ": unknown hardware feature '%s' - option ignored\n",
131 xgcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
133 xgcry_control (GCRYCTL_DISABLE_SECMEM, 0);
134 if (strcmp (GCRYPT_VERSION, gcry_check_version (NULL)))
136 int oops = !gcry_check_version (GCRYPT_VERSION);
137 fprintf (stderr, PGM ": %sversion mismatch; pgm=%s, library=%s\n",
138 oops? "":"warning: ", GCRYPT_VERSION, gcry_check_version (NULL));
143 xgcry_control (GCRYCTL_PRINT_CONFIG, NULL);