statstest.c 5.6 KB
Newer Older
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
#include "config.h"

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

#include "stats_linux.h"
#include "internal.h"

static void testQuietError(void *userData ATTRIBUTE_UNUSED, virErrorPtr error ATTRIBUTE_UNUSED)
{
    /* nada */
}

#ifdef __linux__
static int testDevice(const char *path, int expect)
{
    int actual = xenLinuxDomainDeviceID(NULL, 1, path);

    if (actual == expect) {
        fprintf(stderr, "%-14s == %-6d           OK\n", path, expect);
        return 0;
    } else {
        fprintf(stderr, "%-14s == %-6d (%-6d)  FAILED\n", path, expect, actual);
        return -1;
    }
}
#endif

int
main(void)
{
    int ret = 0;
#ifdef __linux__
    /* Some of our tests delibrately test failure cases, so
     * register a handler to stop error messages cluttering
     * up display
     */
    if (!getenv("DEBUG_TESTS"))
        virSetErrorFunc(NULL, testQuietError);

    /********************************
     * Xen paravirt disks
     ********************************/

    /* first valid disk */
    if (testDevice("xvda", 51712) < 0)
        ret = -1;
    if (testDevice("xvda1", 51713) < 0)
        ret = -1;
    if (testDevice("xvda15", 51727) < 0)
        ret = -1;
    /* Last valid disk */
    if (testDevice("xvdp", 51952) < 0)
        ret = -1;
    if (testDevice("xvdp1", 51953) < 0)
        ret = -1;
    if (testDevice("xvdp15", 51967) < 0)
        ret = -1;

    /* Disk letter to large */
    if (testDevice("xvdq", -1) < 0)
        ret = -1;
    /* missing disk letter */
    if (testDevice("xvd1", -1) < 0)
        ret = -1;
    /* partition to large */
    if (testDevice("xvda16", -1) < 0)
        ret = -1;
    /* partition to small */
    if (testDevice("xvda0", -1) < 0)
        ret = -1;
    /* leading zeros */
    if (testDevice("xvda01", -1) < 0)
        ret = -1;
    /* leading + */
    if (testDevice("xvda+1", -1) < 0)
        ret = -1;
    /* leading - */
    if (testDevice("xvda-1", -1) < 0)
        ret = -1;

    /********************************
     * IDE disks
     ********************************/

    /* odd numbered disk */
    if (testDevice("hda", 768) < 0)
        ret = -1;
    if (testDevice("hda1", 769) < 0)
        ret = -1;
    if (testDevice("hda63", 831) < 0)
        ret = -1;
    /* even number disk */
    if (testDevice("hdd", 5695) < 0)
        ret = -1;
    if (testDevice("hdd1", 5696) < 0)
        ret = -1;
    if (testDevice("hdd63", 5758) < 0)
        ret = -1;
    /* last valid disk */
    if (testDevice("hdt", 23359) < 0)
        ret = -1;
    if (testDevice("hdt1", 23360) < 0)
        ret = -1;
    if (testDevice("hdt63", 23422) < 0)
        ret = -1;

    /* Disk letter to large */
    if (testDevice("hdu", -1) < 0)
        ret = -1;
    /* missing disk letter */
    if (testDevice("hd1", -1) < 0)
        ret = -1;
    /* partition to large */
    if (testDevice("hda64", -1) < 0)
        ret = -1;
    /* partition to small */
    if (testDevice("hda0", -1) < 0)
        ret = -1;



    /********************************
     * SCSI disks
     ********************************/

    /* first valid disk */
    if (testDevice("sda", 2048) < 0)
        ret = -1;
    if (testDevice("sda1", 2049) < 0)
        ret = -1;
    if (testDevice("sda15", 2063) < 0)
        ret = -1;
    /* last valid disk of first SCSI major number */
    if (testDevice("sdp", 2288) < 0)
        ret = -1;
    if (testDevice("sdp1", 2289) < 0)
        ret = -1;
    if (testDevice("sdp15", 2303) < 0)
        ret = -1;
    /* first valid disk of second SCSI major number */
    if (testDevice("sdq", 16640) < 0)
        ret = -1;
    if (testDevice("sdq1", 16641) < 0)
        ret = -1;
    if (testDevice("sdq15", 16655) < 0)
        ret = -1;
    /* last valid single letter disk */
    if (testDevice("sdz", 16784) < 0)
        ret = -1;
    if (testDevice("sdz1", 16785) < 0)
        ret = -1;
    if (testDevice("sdz15", 16799) < 0)
        ret = -1;
    /* first valid dual letter disk */
    if (testDevice("sdaa", 16800) < 0)
        ret = -1;
    if (testDevice("sdaa1", 16801) < 0)
        ret = -1;
    if (testDevice("sdaa15", 16815) < 0)
        ret = -1;
    /* second valid dual letter disk */
    if (testDevice("sdab", 16816) < 0)
        ret = -1;
    if (testDevice("sdab1", 16817) < 0)
        ret = -1;
    if (testDevice("sdab15", 16831) < 0)
        ret = -1;
    /* first letter of second sequence of dual letter disk */
    if (testDevice("sdba", 17216) < 0)
        ret = -1;
    if (testDevice("sdba1", 17217) < 0)
        ret = -1;
    if (testDevice("sdba15", 17231) < 0)
        ret = -1;
    /* last valid dual letter disk */
    if (testDevice("sdiv", 34800) < 0)
        ret = -1;
    if (testDevice("sdiv1", 34801) < 0)
        ret = -1;
    if (testDevice("sdiv15", 34815) < 0)
        ret = -1;

    /* Disk letter to large */
    if (testDevice("sdix", -1) < 0)
        ret = -1;
    /* missing disk letter */
    if (testDevice("sd1", -1) < 0)
        ret = -1;
    /* partition to large */
    if (testDevice("sda16", -1) < 0)
        ret = -1;
    /* partition to small */
    if (testDevice("sda0", -1) < 0)
        ret = -1;


    /* Path stripping */
    if (testDevice("/dev", -1) < 0)
        ret = -1;
    if (testDevice("/dev/", -1) < 0)
        ret = -1;
    if (testDevice("/dev/xvd", -1) < 0)
        ret = -1;
    if (testDevice("/dev/xvda", 51712) < 0)
        ret = -1;
    if (testDevice("/dev/xvda1", 51713) < 0)
        ret = -1;
    if (testDevice("/dev/xvda15", 51727) < 0)
        ret = -1;

#endif
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

/*
 * Local variables:
 *  indent-tabs-mode: nil
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 * End:
 */