Blame tests/utils.h

Packit Service 4684c1
/*
Packit Service 4684c1
 * Copyright (C) 2004-2016 Free Software Foundation, Inc.
Packit Service 4684c1
 * Copyright (C) 2016 Red Hat, Inc.
Packit Service 4684c1
 *
Packit Service 4684c1
 * Author: Simon Josefsson, Nikos Mavrogiannopoulos
Packit Service 4684c1
 *
Packit Service 4684c1
 * This file is part of GnuTLS.
Packit Service 4684c1
 *
Packit Service 4684c1
 * GnuTLS is free software; you can redistribute it and/or modify it
Packit Service 4684c1
 * under the terms of the GNU General Public License as published by
Packit Service 4684c1
 * the Free Software Foundation; either version 3 of the License, or
Packit Service 4684c1
 * (at your option) any later version.
Packit Service 4684c1
 *
Packit Service 4684c1
 * GnuTLS is distributed in the hope that it will be useful, but
Packit Service 4684c1
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4684c1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4684c1
 * General Public License for more details.
Packit Service 4684c1
 *
Packit Service 4684c1
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 4684c1
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit Service 4684c1
 */
Packit Service 4684c1
Packit Service 4684c1
#ifndef GNUTLS_TESTS_UTILS_H
Packit Service 4684c1
#define GNUTLS_TESTS_UTILS_H
Packit Service 4684c1
Packit Service 4684c1
#include <stdio.h>
Packit Service 4684c1
#include <stdlib.h>
Packit Service 4684c1
#include <signal.h>
Packit Service 4684c1
#include <string.h>
Packit Service 4684c1
#include <stdarg.h>
Packit Service 4684c1
#include <gnutls/gnutls.h>
Packit Service 4684c1
#include <gnutls/pkcs11.h>
Packit Service 4684c1
Packit Service 4684c1
#ifndef __attribute__
Packit Service 4684c1
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
Packit Service 4684c1
#define __attribute__(Spec)	/* empty */
Packit Service 4684c1
#endif
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#ifdef NDEBUG
Packit Service 4684c1
# error tests cannot be compiled with NDEBUG defined
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
#ifndef FALLTHROUGH
Packit Service 4684c1
#if _GNUTLS_GCC_VERSION >= 70100
Packit Service 4684c1
# define FALLTHROUGH      __attribute__ ((fallthrough))
Packit Service 4684c1
#else
Packit Service 4684c1
# define FALLTHROUGH
Packit Service 4684c1
#endif
Packit Service 4684c1
#endif
Packit Service 4684c1
Packit Service 4684c1
/* number of elements within an array */
Packit Service 4684c1
#define countof(a) (sizeof(a)/sizeof(*(a)))
Packit Service 4684c1
Packit Service 4684c1
inline static int global_init(void)
Packit Service 4684c1
{
Packit Service 4684c1
#ifdef ENABLE_PKCS11
Packit Service 4684c1
	gnutls_pkcs11_init(GNUTLS_PKCS11_FLAG_MANUAL, NULL);
Packit Service 4684c1
#endif
Packit Service 4684c1
	return gnutls_global_init();
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
extern int debug;
Packit Service 4684c1
extern int error_count;
Packit Service 4684c1
extern int break_on_error;
Packit Service 4684c1
Packit Service 4684c1
extern const char *pkcs3;
Packit Service 4684c1
extern const char *pkcs3_2048;
Packit Service 4684c1
extern const char *pkcs3_3072;
Packit Service 4684c1
Packit Service 4684c1
#define fail(format, ...) \
Packit Service 4684c1
    _fail("%s:%d: "format, __func__, __LINE__, ##__VA_ARGS__)
Packit Service 4684c1
Packit Service 4684c1
extern void _fail(const char *format, ...)
Packit Service 4684c1
    __attribute__ ((format(printf, 1, 2)));
Packit Service 4684c1
extern void fail_ignore(const char *format, ...)
Packit Service 4684c1
    __attribute__ ((format(printf, 1, 2)));
Packit Service 4684c1
extern void success(const char *format, ...)
Packit Service 4684c1
    __attribute__ ((format(printf, 1, 2)));
Packit Service 4684c1
Packit Service 4684c1
/* assumes test_name is defined */
Packit Service 4684c1
#define test_fail(fmt, ...) \
Packit Service 4684c1
	fail("%s: "fmt, test_name, ##__VA_ARGS__)
Packit Service 4684c1
Packit Service 4684c1
#define test_success(fmt, ...) \
Packit Service 4684c1
	success("%s: "fmt, test_name, ##__VA_ARGS__)
Packit Service 4684c1
Packit Service 4684c1
extern void c_print(const unsigned char *str, size_t len);
Packit Service 4684c1
extern void escapeprint(const char *str, size_t len);
Packit Service 4684c1
extern void hexprint(const void *str, size_t len);
Packit Service 4684c1
extern void binprint(const void *str, size_t len);
Packit Service 4684c1
int disable_system_calls(void);
Packit Service 4684c1
void sec_sleep(int sec);
Packit Service 4684c1
Packit Service 4684c1
int
Packit Service 4684c1
test_cli_serv_anon(gnutls_anon_server_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_anon_client_credentials_t client_cred,
Packit Service 4684c1
	      const char *prio);
Packit Service 4684c1
Packit Service 4684c1
int
Packit Service 4684c1
test_cli_serv_psk(gnutls_psk_server_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_psk_client_credentials_t client_cred,
Packit Service 4684c1
	      const char *prio);
Packit Service 4684c1
Packit Service 4684c1
typedef void callback_func(gnutls_session_t, void *priv);
Packit Service 4684c1
void test_cli_serv(gnutls_certificate_credentials_t server_cred,
Packit Service 4684c1
		   gnutls_certificate_credentials_t client_cred,
Packit Service 4684c1
		   const char *prio, const char *host,
Packit Service 4684c1
		   void *priv,
Packit Service 4684c1
		   callback_func * client_cb, callback_func * server_cb);
Packit Service 4684c1
Packit Service 4684c1
int
Packit Service 4684c1
_test_cli_serv(gnutls_certificate_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_certificate_credentials_t client_cred,
Packit Service 4684c1
	      const char *serv_prio, const char *cli_prio,
Packit Service 4684c1
	      const char *host,
Packit Service 4684c1
	      void *priv, callback_func *client_cb, callback_func *server_cb,
Packit Service 4684c1
	      unsigned expect_verification_failure,
Packit Service 4684c1
	      unsigned require_cert,
Packit Service 4684c1
	      int serv_err,
Packit Service 4684c1
	      int cli_err);
Packit Service 4684c1
Packit Service 4684c1
void print_dh_params_info(gnutls_session_t);
Packit Service 4684c1
Packit Service 4684c1
void
Packit Service 4684c1
test_cli_serv_cert(gnutls_certificate_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_certificate_credentials_t client_cred,
Packit Service 4684c1
	      const char *serv_prio, const char *cli_prio, const char *host);
Packit Service 4684c1
Packit Service 4684c1
void
Packit Service 4684c1
test_cli_serv_expect(gnutls_certificate_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_certificate_credentials_t client_cred,
Packit Service 4684c1
	      const char *serv_prio, const char *cli_prio, const char *host,
Packit Service 4684c1
	      int serv_err, int cli_err);
Packit Service 4684c1
Packit Service 4684c1
/* verification failed */
Packit Service 4684c1
unsigned
Packit Service 4684c1
test_cli_serv_vf(gnutls_certificate_credentials_t server_cred,
Packit Service 4684c1
	      gnutls_certificate_credentials_t client_cred,
Packit Service 4684c1
	      const char *prio, const char *host);
Packit Service 4684c1
Packit Service 4684c1
#define TMPNAME_SIZE 128
Packit Service 4684c1
char *get_tmpname(char s[TMPNAME_SIZE]);
Packit Service 4684c1
void track_temp_files(void);
Packit Service 4684c1
void delete_temp_files(void);
Packit Service 4684c1
Packit Service 4684c1
/* This must be implemented elsewhere. */
Packit Service 4684c1
extern void doit(void);
Packit Service 4684c1
Packit Service 4684c1
/* calls fail() if status indicates an error  */
Packit Service 4684c1
inline static void _check_wait_status(int status, unsigned sigonly)
Packit Service 4684c1
{
Packit Service 4684c1
#if defined WEXITSTATUS && defined WIFSIGNALED
Packit Service 4684c1
	if (WEXITSTATUS(status) != 0 ||
Packit Service 4684c1
	    (WIFSIGNALED(status) && WTERMSIG(status) != SIGTERM)) {
Packit Service 4684c1
		if (WIFSIGNALED(status)) {
Packit Service 4684c1
			fail("Child died with signal %d\n", WTERMSIG(status));
Packit Service 4684c1
		} else {
Packit Service 4684c1
			if (!sigonly) {
Packit Service 4684c1
				if (WEXITSTATUS(status) == 77)
Packit Service 4684c1
					exit(77);
Packit Service 4684c1
				fail("Child died with status %d\n",
Packit Service 4684c1
				     WEXITSTATUS(status));
Packit Service 4684c1
			}
Packit Service 4684c1
		}
Packit Service 4684c1
	}
Packit Service 4684c1
#endif
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
inline static void check_wait_status(int status)
Packit Service 4684c1
{
Packit Service 4684c1
	_check_wait_status(status, 0);
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
inline static void check_wait_status_for_sig(int status)
Packit Service 4684c1
{
Packit Service 4684c1
	_check_wait_status(status, 1);
Packit Service 4684c1
}
Packit Service 4684c1
Packit Service 4684c1
#endif /* GNUTLS_TESTS_UTILS_H */