summaryrefslogtreecommitdiff
path: root/src/p11-tests.c
blob: 900338e7e6eb406b82c1ea293180982d4d8cf39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


#include "p11-tests.h"
#include "compat.h"

#include <stdio.h>
#include <stdlib.h>

#include <openssl/err.h>
#include <openssl/evp.h>

int p11t_test_unexpected = 1;
int p11t_test_write_session = 0;

static void
usage()
{
	fprintf(stderr, "usage: p11-tests [-f config] module\n");
	exit(2);
}

int
main(int argc, char* argv[])
{
	const char *config = NULL;
	int ch;

	while((ch = getopt(argc, argv, "f:svz")) != -1)
	{
		switch(ch)
		{
		case 'f':
			config = optarg;
			break;
		case 's':
			p11t_test_write_session = 1;
			break;
		case 'v':
			p11t_check_verbose = 1;
			break;
		case 'z':
			p11t_test_unexpected = 0;
			break;
		case '?':
		default:
			usage();
			break;
		}
	}

	argc -= optind;
	argv += optind;

	if(argc != 1)
		usage();

	if(config)
		p11t_config_parse(config);

	ERR_load_crypto_strings();
	OpenSSL_add_all_digests();

	/* Basic module tests */
	p11t_module_load(argv[0]);
	p11t_module_initialize();

	p11t_slot_tests();
	p11t_session_tests();
	p11t_object_tests();
	p11t_key_tests();
	p11t_certificate_tests();
	p11t_rsa_tests();
	p11t_dsa_tests();

	/* Remaining module tests */
	p11t_module_finalize();
	p11t_module_unload();

	p11t_slot_cleanup();
	p11t_config_cleanup();

	return 0;
}