fchosttest.c 5.6 KB
Newer Older
O
Osier Yang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <config.h>

22
#include "virstring.h"
O
Osier Yang 已提交
23 24 25
#include "virutil.h"
#include "testutils.h"

26 27
#define VIR_FROM_THIS VIR_FROM_NONE

28 29 30
static char *fchost_prefix;

#define TEST_FC_HOST_PREFIX fchost_prefix
O
Osier Yang 已提交
31
#define TEST_FC_HOST_NUM 5
32
#define TEST_FC_HOST_NUM_NO_FAB 6
O
Osier Yang 已提交
33 34 35 36 37 38

/* Test virIsCapableFCHost */
static int
test1(const void *data ATTRIBUTE_UNUSED)
{
    if (virIsCapableFCHost(TEST_FC_HOST_PREFIX,
39 40 41
                           TEST_FC_HOST_NUM) &&
        virIsCapableFCHost(TEST_FC_HOST_PREFIX,
                           TEST_FC_HOST_NUM_NO_FAB))
O
Osier Yang 已提交
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
        return 0;

    return -1;
}

/* Test virIsCapableVport */
static int
test2(const void *data ATTRIBUTE_UNUSED)
{
    if (virIsCapableVport(TEST_FC_HOST_PREFIX,
                          TEST_FC_HOST_NUM))
        return 0;

    return -1;
}

/* Test virReadFCHost */
static int
test3(const void *data ATTRIBUTE_UNUSED)
{
    const char *expect_wwnn = "2001001b32a9da4e";
    const char *expect_wwpn = "2101001b32a9da4e";
    const char *expect_fabric_wwn = "2001000dec9877c1";
    const char *expect_max_vports = "127";
    const char *expect_vports = "0";
    char *wwnn = NULL;
    char *wwpn = NULL;
    char *fabric_wwn = NULL;
    char *max_vports = NULL;
    char *vports = NULL;
    int ret = -1;

74 75
    if (!(wwnn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
                               "node_name")))
O
Osier Yang 已提交
76 77
        return -1;

78 79
    if (!(wwpn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
                               "port_name")))
O
Osier Yang 已提交
80 81
        goto cleanup;

82 83
    if (!(fabric_wwn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
                                     "fabric_name")))
O
Osier Yang 已提交
84 85
        goto cleanup;

86 87
    if (!(max_vports = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
                                     "max_npiv_vports")))
O
Osier Yang 已提交
88 89 90
        goto cleanup;


91 92
    if (!(vports = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
                                 "npiv_vports_inuse")))
O
Osier Yang 已提交
93 94 95 96 97 98 99 100 101 102
        goto cleanup;

    if (STRNEQ(expect_wwnn, wwnn) ||
        STRNEQ(expect_wwpn, wwpn) ||
        STRNEQ(expect_fabric_wwn, fabric_wwn) ||
        STRNEQ(expect_max_vports, max_vports) ||
        STRNEQ(expect_vports, vports))
        goto cleanup;

    ret = 0;
103
 cleanup:
O
Osier Yang 已提交
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
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
    VIR_FREE(fabric_wwn);
    VIR_FREE(max_vports);
    VIR_FREE(vports);
    return ret;
}

/* Test virGetFCHostNameByWWN */
static int
test4(const void *data ATTRIBUTE_UNUSED)
{
    const char *expect_hostname = "host5";
    char *hostname = NULL;
    int ret = -1;

    if (!(hostname = virGetFCHostNameByWWN(TEST_FC_HOST_PREFIX,
                                           "2001001b32a9da4e",
                                           "2101001b32a9da4e")))
        return -1;

    if (STRNEQ(hostname, expect_hostname))
        goto cleanup;

    ret = 0;
129
 cleanup:
O
Osier Yang 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    VIR_FREE(hostname);
    return ret;
}

/* Test virFindFCHostCapableVport (host4 is not Online) */
static int
test5(const void *data ATTRIBUTE_UNUSED)
{
    const char *expect_hostname = "host5";
    char *hostname = NULL;
    int ret = -1;

    if (!(hostname = virFindFCHostCapableVport(TEST_FC_HOST_PREFIX)))
        return -1;

    if (STRNEQ(hostname, expect_hostname))
        goto cleanup;

    ret = 0;
149
 cleanup:
O
Osier Yang 已提交
150 151 152 153
    VIR_FREE(hostname);
    return ret;
}

154 155 156 157 158 159 160 161
/* Test virReadFCHost fabric name optional */
static int
test6(const void *data ATTRIBUTE_UNUSED)
{
    const char *expect_wwnn = "2002001b32a9da4e";
    const char *expect_wwpn = "2102001b32a9da4e";
    char *wwnn = NULL;
    char *wwpn = NULL;
J
John Ferlan 已提交
162
    char *fabric_wwn = NULL;
163 164 165 166 167 168 169 170 171 172
    int ret = -1;

    if (!(wwnn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
                               "node_name")))
        return -1;

    if (!(wwpn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
                               "port_name")))
        goto cleanup;

J
John Ferlan 已提交
173 174 175
    if ((fabric_wwn = virReadFCHost(TEST_FC_HOST_PREFIX,
                                    TEST_FC_HOST_NUM_NO_FAB,
                                    "fabric_name")))
176 177 178 179 180 181 182 183 184 185
        goto cleanup;

    if (STRNEQ(expect_wwnn, wwnn) ||
        STRNEQ(expect_wwpn, wwpn))
        goto cleanup;

    ret = 0;
 cleanup:
    VIR_FREE(wwnn);
    VIR_FREE(wwpn);
J
John Ferlan 已提交
186
    VIR_FREE(fabric_wwn);
187 188 189
    return ret;
}

O
Osier Yang 已提交
190 191 192 193 194
static int
mymain(void)
{
    int ret = 0;

195 196 197 198 199 200
    if (virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir,
                    "fchostdata/fc_host/") < 0) {
        ret = -1;
        goto cleanup;
    }

201
    if (virTestRun("test1", test1, NULL) < 0)
O
Osier Yang 已提交
202
        ret = -1;
203
    if (virTestRun("test2", test2, NULL) < 0)
O
Osier Yang 已提交
204
        ret = -1;
205
    if (virTestRun("test3", test3, NULL) < 0)
O
Osier Yang 已提交
206
        ret = -1;
207
    if (virTestRun("test4", test4, NULL) < 0)
O
Osier Yang 已提交
208
        ret = -1;
209
    if (virTestRun("test5", test5, NULL) < 0)
O
Osier Yang 已提交
210
        ret = -1;
211 212
    if (virTestRun("test6", test6, NULL) < 0)
        ret = -1;
O
Osier Yang 已提交
213

214
 cleanup:
215
    VIR_FREE(fchost_prefix);
O
Osier Yang 已提交
216 217 218 219
    return ret;
}

VIRT_TEST_MAIN(mymain)