summaryrefslogtreecommitdiff
path: root/src/lib/tests/tpm_test.c
blob: 98d4fab36ba7eb7857e3a0f4fe58ade68c8a7dcb (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Ouroboros - Copyright (C) 2016 - 2024
 *
 * Tests for the threadpool manager
 *
 *    Dimitri Staessens <dimitri@ouroboros.rocks>
 *    Sander Vrijders   <sander@ouroboros.rocks>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program 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., http://www.fsf.org/about/contact/.
 */


#include "tpm.c"

#include <ouroboros/test.h>

static void * test_func(void * o)
{
        (void) o;

        while(1)
                sleep(1);

        return NULL;
}

static int test_tpm_create_destroy(void)
{
        struct tpm *tpm;

        TEST_START();

        tpm = tpm_create(2, 2, &test_func, NULL);
        if (tpm == NULL) {
                printf("Failed to initialize TPM.\n");
                goto fail;
        }

        tpm_destroy(tpm);

        TEST_SUCCESS();

        return TEST_RC_SUCCESS;
 fail:
        TEST_FAIL();
        return TEST_RC_FAIL;
}

static int test_tpm_start_stop(void * (* fn)(void *),
                               void * o)
{
        struct tpm *tpm;

        TEST_START();

        tpm = tpm_create(2, 2, fn, o);
        if (tpm == NULL) {
                printf("Failed to initialize TPM.\n");
                goto fail_create;
        }

        if (tpm_start(tpm) < 0) {
                printf("Failed to start TPM.\n");
                goto fail_start;
        }

        tpm_stop(tpm);

        tpm_destroy(tpm);

        TEST_SUCCESS();

        return TEST_RC_SUCCESS;
 fail_start:
        tpm_destroy(tpm);
 fail_create:
        TEST_FAIL();
        return TEST_RC_FAIL;
}

int tpm_test(int     argc,
             char ** argv)
{
        int ret = 0;

        (void) argc;
        (void) argv;

        ret |= test_tpm_create_destroy();
        ret |= test_tpm_start_stop(&test_func, NULL);

        return ret;
}