summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/plcd/utests/src/plcd_utests.c
blob: 3e999f20e9066673c85a440d0d5a0a551076c587 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hpav_utests.c
 * \brief   Unitary tests for plcd
 * \ingroup Cleopatre - plcd
 *
 * This file content all the unitary tests for plcd,
 * (interface between the PLC driver and the Linux filesystem).
 */

#include <check.h>
#include <stdio.h>
#include <string.h>

#include <stdlib.h>
#include <sys/time.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <netinet/ether.h>

#include <inttypes.h>
#include <fcntl.h>
#include <signal.h>

#include <unistd.h>
#include <pthread.h>
#include <linux/if_tun.h>

#include "plcd.h"
#include "plcd_utests.h"

#define DEBUG   1


#ifdef DEBUG
#define TRACE(...) printf("PLCD UTESTS: " __VA_ARGS__)
#else
#define TRACE(...)
#endif

/** local variables */
plcd_ctx_t plcd_ctx;
plcd_ctx_t *ctx = &plcd_ctx;

#if 0
/* fixtures - run before and after each unit test */
void setup(void)
{
}

void teardown(void)
{
}
#endif

/* --- TEST PROCEDURES --- */

/** test procedures */
START_TEST (test_plcd_init)
{
    int ret;

    /* zero-out plcd ctx */
    memset(ctx, 0x0, sizeof(plcd_ctx_t));

    //Check arguments
    ret = plcd_init(ctx);
    fail_if( 0 != ret, "plcd_init fail");

    TRACE("ctx->hardware_info_path=%s\n", ctx->hardware_info_path);
    TRACE("ctx->hpav_info_path=%s\n", ctx->hpav_info_path);
    TRACE("ctx->hpav_conf_path=%s\n", ctx->hpav_conf_path);

    fail_if( strcmp(ctx->hardware_info_path, LIBSPID_HARDWARE_INFO_PATH) != 0,
                "hardware_info_path was not correctly initialized" );
    fail_if( strcmp(ctx->hpav_info_path, LIBSPID_HPAV_INFO_PATH) != 0,
                "hpav_info_path was not correctly initialized" );
    fail_if( strcmp(ctx->hpav_conf_path, LIBSPID_HPAV_CONF_PATH) != 0,
                "hpav_conf_path was not correctly initialized" );

    /* close netlink fd opened in plcd_init() */
    plcd_uninit (ctx);
}
END_TEST

extern Suite* plcd_suite(void)
{
    Suite *s = suite_create("PLCD");
    TCase *tc_core = tcase_create("Core");

    //Test plcd_init
    tcase_add_test(tc_core, test_plcd_init);

    suite_add_tcase(s, tc_core);
    return s;
}

int main(void)
{
    int number_failed = 0;
    Suite *s;

    //Run plcd tests
    s = plcd_suite();

    SRunner *sr = srunner_create(s);
    //srunner_set_fork_status (sr, CK_NOFORK);
    srunner_set_fork_status (sr, CK_FORK);
    srunner_run_all(sr, CK_NORMAL);
    number_failed = srunner_ntests_failed(sr);
    srunner_free(sr);

    return (number_failed == 0) ? 0 : -1;
}