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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784
|
/* Set BROKEN to 1 to treat broken behavior as success */
#define BROKEN 1
#define VERBOSITY 2
#include <stdbool.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include "cmocka-compat.h"
#include "mt-udev-wrap.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <sys/sysmacros.h>
#include "structs.h"
#include "structs_vec.h"
#include "config.h"
#include "debug.h"
#include "defaults.h"
#include "pgpolicies.h"
#include "test-lib.h"
#include "print.h"
#include "util.h"
#include "foreign.h"
#define N_CONF_FILES 2
static const char template[] = "/tmp/hwtable-XXXXXX";
struct key_value {
const char *key;
const char *value;
};
struct hwt_state {
char *tmpname;
char *dirname;
FILE *config_file;
FILE *conf_dir_file[N_CONF_FILES];
struct vectors *vecs;
void (*test)(const struct hwt_state *);
const char *test_name;
};
#define SET_TEST_FUNC(hwt, func) do { \
hwt->test = func; \
hwt->test_name = #func; \
} while (0)
static struct config *_conf;
struct udev *udev;
int logsink = LOGSINK_STDERR_WITHOUT_TIME;
struct config *get_multipath_config(void)
{
return _conf;
}
void put_multipath_config(void *arg)
{}
void make_config_file_path(char *buf, int buflen,
const struct hwt_state *hwt, int i)
{
static const char fn_template[] = "%s/test-%02d.conf";
if (i == -1)
/* main config file */
snprintf(buf, buflen, fn_template, hwt->tmpname, 0);
else
snprintf(buf, buflen, fn_template, hwt->dirname, i);
}
static void reset_vecs(struct vectors *vecs)
{
remove_maps(vecs);
free_pathvec(vecs->pathvec, FREE_PATHS);
vecs->pathvec = vector_alloc();
assert_ptr_not_equal(vecs->pathvec, NULL);
vecs->mpvec = vector_alloc();
assert_ptr_not_equal(vecs->mpvec, NULL);
}
static void free_hwt(struct hwt_state *hwt)
{
char buf[PATH_MAX];
int i;
if (hwt->config_file != NULL)
fclose(hwt->config_file);
for (i = 0; i < N_CONF_FILES; i++) {
if (hwt->conf_dir_file[i] != NULL)
fclose(hwt->conf_dir_file[i]);
}
if (hwt->tmpname != NULL) {
make_config_file_path(buf, sizeof(buf), hwt, -1);
unlink(buf);
rmdir(hwt->tmpname);
free(hwt->tmpname);
}
if (hwt->dirname != NULL) {
for (i = 0; i < N_CONF_FILES; i++) {
make_config_file_path(buf, sizeof(buf), hwt, i);
unlink(buf);
}
rmdir(hwt->dirname);
free(hwt->dirname);
}
if (hwt->vecs != NULL) {
if (hwt->vecs->mpvec != NULL)
remove_maps(hwt->vecs);
if (hwt->vecs->pathvec != NULL)
free_pathvec(hwt->vecs->pathvec, FREE_PATHS);
pthread_mutex_destroy(&hwt->vecs->lock.mutex);
free(hwt->vecs);
}
free(hwt);
}
static int setup(void **state)
{
struct hwt_state *hwt;
char buf[PATH_MAX];
int i;
*state = NULL;
hwt = calloc(1, sizeof(*hwt));
if (hwt == NULL)
return -1;
snprintf(buf, sizeof(buf), "%s", template);
if (mkdtemp(buf) == NULL) {
condlog(0, "mkdtemp: %s", strerror(errno));
goto err;
}
hwt->tmpname = strdup(buf);
hwt->dirname = strdup(TESTCONFDIR);
if (mkdir(hwt->dirname, 0744) != 0) {
condlog(0, "mkdir %s: %s", hwt->dirname, strerror(errno));
goto err;
}
make_config_file_path(buf, sizeof(buf), hwt, -1);
hwt->config_file = fopen(buf, "w+");
if (hwt->config_file == NULL)
goto err;
for (i = 0; i < N_CONF_FILES; i++) {
make_config_file_path(buf, sizeof(buf), hwt, i);
hwt->conf_dir_file[i] = fopen(buf, "w+");
if (hwt->conf_dir_file[i] == NULL)
goto err;
}
hwt->vecs = calloc(1, sizeof(*hwt->vecs));
if (hwt->vecs == NULL)
goto err;
pthread_mutex_init(&hwt->vecs->lock.mutex, NULL);
hwt->vecs->pathvec = vector_alloc();
hwt->vecs->mpvec = vector_alloc();
if (hwt->vecs->pathvec == NULL || hwt->vecs->mpvec == NULL)
goto err;
*state = hwt;
return 0;
err:
free_hwt(hwt);
return -1;
}
static int teardown(void **state)
{
if (state == NULL || *state == NULL)
return -1;
free_hwt(*state);
*state = NULL;
cleanup_prio();
cleanup_checkers();
cleanup_foreign();
return 0;
}
/*
* Helpers for creating the config file(s)
*/
static void reset_config(FILE *ff)
{
if (ff == NULL)
return;
rewind(ff);
if (ftruncate(fileno(ff), 0) == -1)
condlog(1, "ftruncate: %s", strerror(errno));
}
static void reset_configs(const struct hwt_state *hwt)
{
int i;
reset_config(hwt->config_file);
for (i = 0; i < N_CONF_FILES; i++)
reset_config(hwt->conf_dir_file[i]);
}
static void write_key_values(FILE *ff, int nkv, const struct key_value *kv)
{
int i;
for (i = 0; i < nkv; i++) {
if (strchr(kv[i].value, ' ') == NULL &&
strchr(kv[i].value, '\"') == NULL)
fprintf(ff, "\t%s %s\n", kv[i].key, kv[i].value);
else
fprintf(ff, "\t%s \"%s\"\n", kv[i].key, kv[i].value);
}
}
static void begin_section(FILE *ff, const char *section)
{
fprintf(ff, "%s {\n", section);
}
static void end_section(FILE *ff)
{
fprintf(ff, "}\n");
}
static void write_section(FILE *ff, const char *section,
int nkv, const struct key_value *kv)
{
begin_section(ff, section);
write_key_values(ff, nkv, kv);
end_section(ff);
}
static void write_defaults(const struct hwt_state *hwt)
{
static const char bindings_name[] = "bindings";
static struct key_value defaults[] = {
{ "config_dir", NULL },
{ "bindings_file", NULL },
{ "multipath_dir", NULL },
{ "detect_prio", "no" },
{ "detect_checker", "no" },
};
char buf[sizeof(template) + sizeof(bindings_name)];
char dirbuf[PATH_MAX];
snprintf(buf, sizeof(buf), "%s/%s", hwt->tmpname, bindings_name);
defaults[0].value = hwt->dirname;
defaults[1].value = buf;
assert_ptr_not_equal(getcwd(dirbuf, sizeof(dirbuf)), NULL);
strncat(dirbuf, "/lib", sizeof(dirbuf) - 5);
defaults[2].value = dirbuf;
write_section(hwt->config_file, "defaults",
ARRAY_SIZE(defaults), defaults);
}
static void begin_config(const struct hwt_state *hwt)
{
reset_configs(hwt);
write_defaults(hwt);
}
static void begin_section_all(const struct hwt_state *hwt, const char *section)
{
int i;
begin_section(hwt->config_file, section);
for (i = 0; i < N_CONF_FILES; i++)
begin_section(hwt->conf_dir_file[i], section);
}
static void end_section_all(const struct hwt_state *hwt)
{
int i;
end_section(hwt->config_file);
for (i = 0; i < N_CONF_FILES; i++)
end_section(hwt->conf_dir_file[i]);
}
static void finish_config(const struct hwt_state *hwt)
{
int i;
fflush(hwt->config_file);
for (i = 0; i < N_CONF_FILES; i++) {
fflush(hwt->conf_dir_file[i]);
}
}
static void write_device(FILE *ff, int nkv, const struct key_value *kv)
{
write_section(ff, "device", nkv, kv);
}
/*
* Some macros to avoid boilerplate code
*/
#define CHECK_STATE(state) ({ \
assert_ptr_not_equal(state, NULL); \
assert_ptr_not_equal(*(state), NULL); \
*state; })
#define WRITE_EMPTY_CONF(hwt) do { \
begin_config(hwt); \
finish_config(hwt); \
} while (0)
#define WRITE_ONE_DEVICE(hwt, kv) do { \
begin_config(hwt); \
begin_section_all(hwt, "devices"); \
write_device(hwt->config_file, ARRAY_SIZE(kv), kv); \
end_section_all(hwt); \
finish_config(hwt); \
} while (0)
#define WRITE_TWO_DEVICES(hwt, kv1, kv2) do { \
begin_config(hwt); \
begin_section_all(hwt, "devices"); \
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1); \
write_device(hwt->config_file, ARRAY_SIZE(kv2), kv2); \
end_section_all(hwt); \
finish_config(hwt); \
} while (0)
#define WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2) do { \
begin_config(hwt); \
begin_section_all(hwt, "devices"); \
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1); \
write_device(hwt->conf_dir_file[0], \
ARRAY_SIZE(kv2), kv2); \
end_section_all(hwt); \
finish_config(hwt); \
} while (0)
#define LOAD_CONFIG(hwt) ({ \
char buf[PATH_MAX]; \
struct config *__cf; \
\
make_config_file_path(buf, sizeof(buf), hwt, -1); \
__cf = load_config(buf); \
assert_ptr_not_equal(__cf, NULL); \
assert_ptr_not_equal(__cf->hwtable, NULL); \
__cf->verbosity = VERBOSITY; \
__cf; })
#define FREE_CONFIG(conf) do { \
free_config(conf); \
conf = NULL; \
} while (0)
static void replace_config(const struct hwt_state *hwt,
const char *conf_str)
{
FREE_CONFIG(_conf);
reset_configs(hwt);
fprintf(hwt->config_file, "%s", conf_str);
fflush(hwt->config_file);
_conf = LOAD_CONFIG(hwt);
}
#define TEST_PROP(prop, val) do { \
if (val == NULL) \
assert_ptr_equal(prop, NULL); \
else { \
assert_ptr_not_equal(prop, NULL); \
assert_string_equal(prop, val); \
} \
} while (0)
#if BROKEN
#define TEST_PROP_BROKEN(name, prop, bad, good) do { \
condlog(1, "%s: WARNING: Broken test for %s == \"%s\" on line %d, should be \"%s\"", \
__func__, name, bad ? bad : "NULL", \
__LINE__, good ? good : "NULL"); \
TEST_PROP(prop, bad); \
} while (0)
#else
#define TEST_PROP_BROKEN(name, prop, bad, good) TEST_PROP(prop, good)
#endif
/*
* Some predefined key/value pairs
*/
static const char _wwid[] = "wwid";
static const char _vendor[] = "vendor";
static const char _product[] = "product";
static const char _prio[] = "prio";
static const char _checker[] = "path_checker";
static const char _vpd_vnd[] = "vpd_vendor";
static const char _uid_attr[] = "uid_attribute";
static const char _bl_product[] = "product_blacklist";
static const char _minio[] = "rr_min_io_rq";
static const char _no_path_retry[] = "no_path_retry";
/* Device identifiers */
static const struct key_value vnd_foo = { _vendor, "foo" };
static const struct key_value prd_bar = { _product, "bar" };
static const struct key_value prd_bam = { _product, "bam" };
static const struct key_value prd_baq = { _product, "\"bar\"" };
static const struct key_value prd_baqq = { _product, "\"\"bar\"\"" };
static const struct key_value prd_barz = { _product, "barz" };
static const struct key_value vnd_boo = { _vendor, "boo" };
static const struct key_value prd_baz = { _product, "baz" };
static const struct key_value wwid_test = { _wwid, default_wwid };
/* Regular expressions */
static const struct key_value vnd__oo = { _vendor, ".oo" };
static const struct key_value vnd_t_oo = { _vendor, "^.oo" };
static const struct key_value prd_ba_ = { _product, "ba." };
static const struct key_value prd_ba_s = { _product, "(bar|baz|ba\\.)$" };
/* Pathological cases, see below */
static const struct key_value prd_barx = { _product, "ba[[rxy]" };
static const struct key_value prd_bazy = { _product, "ba[zy]" };
static const struct key_value prd_bazy1 = { _product, "ba(z|y)" };
/* Properties */
static const struct key_value prio_emc = { _prio, "emc" };
static const struct key_value prio_hds = { _prio, "hds" };
static const struct key_value prio_rdac = { _prio, "rdac" };
static const struct key_value chk_hp = { _checker, "hp_sw" };
static const struct key_value vpd_hp3par = { _vpd_vnd, "hp3par" };
static const struct key_value uid_baz = { _uid_attr, "BAZ_ATTR" };
static const struct key_value bl_bar = { _bl_product, "bar" };
static const struct key_value bl_baz = { _bl_product, "baz" };
static const struct key_value bl_barx = { _bl_product, "ba[[rxy]" };
static const struct key_value bl_bazy = { _bl_product, "ba[zy]" };
static const struct key_value minio_99 = { _minio, "99" };
static const struct key_value npr_37 = { _no_path_retry, "37" };
static const struct key_value npr_queue = { _no_path_retry, "queue" };
/***** BEGIN TESTS SECTION *****/
/*
* Dump the configuration, substitute the dumped configuration
* for the current one, and verify that the result is identical.
*/
static void replicate_config(const struct hwt_state *hwt, bool local)
{
char *cfg1, *cfg2;
vector hwtable;
struct config *conf;
condlog(3, "--- %s: replicating %s configuration", __func__,
local ? "local" : "full");
conf = get_multipath_config();
if (!local)
/* "full" configuration */
cfg1 = snprint_config(conf, NULL, NULL, NULL);
else {
/* "local" configuration */
hwtable = get_used_hwes(hwt->vecs->pathvec);
cfg1 = snprint_config(conf, NULL, hwtable, hwt->vecs->mpvec);
vector_free(hwtable);
}
assert_non_null(cfg1);
put_multipath_config(conf);
replace_config(hwt, cfg1);
/*
* The local configuration adds multipath entries, and may move device
* entries for local devices to the end of the list. Identical config
* strings therefore can't be expected in the "local" case.
* That doesn't matter. The important thing is that, with the reloaded
* configuration, the test case still passes.
*/
if (local) {
free(cfg1);
return;
}
conf = get_multipath_config();
cfg2 = snprint_config(conf, NULL, NULL, NULL);
assert_non_null(cfg2);
put_multipath_config(conf);
// #define DBG_CONFIG 1
#ifdef DBG_CONFIG
#define DUMP_CFG_STR(x) do { \
FILE *tmp = fopen("/tmp/hwtable-" #x ".txt", "w"); \
fprintf(tmp, "%s", x); \
fclose(tmp); \
} while (0)
DUMP_CFG_STR(cfg1);
DUMP_CFG_STR(cfg2);
#endif
assert_uint_equal(strlen(cfg2), strlen(cfg1));
assert_string_equal(cfg2, cfg1);
free(cfg1);
free(cfg2);
}
/*
* Run hwt->test three times; once with the constructed configuration,
* once after re-reading the full dumped configuration, and once with the
* dumped local configuration.
*
* Expected: test passes every time.
*/
static void test_driver(void **state)
{
const struct hwt_state *hwt;
hwt = CHECK_STATE(state);
_conf = LOAD_CONFIG(hwt);
hwt->test(hwt);
replicate_config(hwt, false);
reset_vecs(hwt->vecs);
hwt->test(hwt);
replicate_config(hwt, true);
reset_vecs(hwt->vecs);
hwt->test(hwt);
reset_vecs(hwt->vecs);
FREE_CONFIG(_conf);
}
/*
* Sanity check for the test itself, because defaults may be changed
* in libmultipath.
*
* Our checking for match or non-match relies on the defaults being
* different from what our device sections contain.
*/
static void test_sanity_globals(void **state)
{
assert_string_not_equal(prio_emc.value, DEFAULT_PRIO);
assert_string_not_equal(prio_hds.value, DEFAULT_PRIO);
assert_string_not_equal(chk_hp.value, DEFAULT_CHECKER);
assert_int_not_equal(MULTIBUS, DEFAULT_PGPOLICY);
assert_int_not_equal(NO_PATH_RETRY_QUEUE, DEFAULT_NO_PATH_RETRY);
assert_int_not_equal(atoi(minio_99.value), DEFAULT_MINIO_RQ);
assert_int_not_equal(atoi(npr_37.value), DEFAULT_NO_PATH_RETRY);
}
/*
* Regression test for internal hwtable. NVME is an example of two entries
* in the built-in hwtable, one if which matches a subset of the other.
*/
static void test_internal_nvme(const struct hwt_state *hwt)
{
struct path *pp;
struct multipath *mp;
/*
* Generic NVMe: expect defaults for pgpolicy and no_path_retry
*/
pp = mock_path("NVME", "NoName");
mp = mock_multipath(pp);
assert_ptr_not_equal(mp, NULL);
TEST_PROP(checker_name(&pp->checker), NONE);
TEST_PROP(pp->uid_attribute, DEFAULT_NVME_UID_ATTRIBUTE);
assert_int_equal(mp->pgpolicy, GROUP_BY_PRIO);
assert_int_equal(mp->no_path_retry, DEFAULT_NO_PATH_RETRY);
assert_int_equal(mp->retain_hwhandler, RETAIN_HWHANDLER_OFF);
/*
* NetApp NVMe: expect special values for pgpolicy and no_path_retry
*/
pp = mock_path_wwid("NVME", "NetApp ONTAP Controller",
default_wwid_1);
mp = mock_multipath(pp);
assert_ptr_not_equal(mp, NULL);
TEST_PROP(checker_name(&pp->checker), NONE);
TEST_PROP(pp->uid_attribute, "ID_WWN");
assert_int_equal(mp->pgpolicy, GROUP_BY_PRIO);
assert_int_equal(mp->no_path_retry, NO_PATH_RETRY_QUEUE);
assert_int_equal(mp->retain_hwhandler, RETAIN_HWHANDLER_OFF);
}
static int setup_internal_nvme(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_EMPTY_CONF(hwt);
SET_TEST_FUNC(hwt, test_internal_nvme);
return 0;
}
/*
* Device section with a simple entry with double quotes ('foo:"bar"')
*/
static void test_quoted_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:"bar" matches */
pp = mock_path(vnd_foo.value, prd_baq.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
/* foo:bar doesn't match */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
}
static int setup_quoted_hwe(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv[] = { vnd_foo, prd_baqq, prio_emc };
WRITE_ONE_DEVICE(hwt, kv);
SET_TEST_FUNC(hwt, test_quoted_hwe);
return 0;
}
/*
* Device section with a single simple entry ("foo:bar")
*/
static void test_string_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar matches */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
/* boo:bar doesn't match */
pp = mock_path(vnd_boo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
}
static int setup_string_hwe(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv[] = { vnd_foo, prd_bar, prio_emc };
WRITE_ONE_DEVICE(hwt, kv);
SET_TEST_FUNC(hwt, test_string_hwe);
return 0;
}
/*
* Device section with a broken entry (no product)
* It should be ignored.
*/
static void test_broken_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar doesn't match, as hwentry is ignored */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
/* boo:bar doesn't match */
pp = mock_path(vnd_boo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
}
static int setup_broken_hwe(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv[] = { vnd_foo, prio_emc };
WRITE_ONE_DEVICE(hwt, kv);
SET_TEST_FUNC(hwt, test_broken_hwe);
return 0;
}
/*
* Like test_broken_hwe, but in config_dir file.
*/
static int setup_broken_hwe_dir(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv[] = { vnd_foo, prio_emc };
begin_config(hwt);
begin_section_all(hwt, "devices");
write_device(hwt->conf_dir_file[0], ARRAY_SIZE(kv), kv);
end_section_all(hwt);
finish_config(hwt);
hwt->test = test_broken_hwe;
hwt->test_name = "test_broken_hwe_dir";
return 0;
}
/*
* Device section with a single regex entry ("^.foo:(bar|baz|ba\.)$")
*/
static void test_regex_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar matches */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
/* foo:baz matches */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
/* boo:baz matches */
pp = mock_path(vnd_boo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
/* foo:BAR doesn't match */
pp = mock_path(vnd_foo.value, "BAR");
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
/* bboo:bar doesn't match */
pp = mock_path("bboo", prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
}
static int setup_regex_hwe(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv[] = { vnd_t_oo, prd_ba_s, prio_emc };
WRITE_ONE_DEVICE(hwt, kv);
SET_TEST_FUNC(hwt, test_regex_hwe);
return 0;
}
/*
* Two device entries, kv1 is a regex match ("^.foo:(bar|baz|ba\.)$"),
* kv2 a string match (foo:bar) which matches a subset of the regex.
* Both are added to the main config file.
*
* Expected: Devices matching both get properties from both, kv2 taking
* precedence. Devices matching kv1 only just get props from kv1.
*/
static void test_regex_string_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz matches kv1 */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* boo:baz matches kv1 */
pp = mock_path(vnd_boo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .oo:ba. matches kv1 */
pp = mock_path(vnd__oo.value, prd_ba_.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .foo:(bar|baz|ba\.) doesn't match */
pp = mock_path(vnd__oo.value, prd_ba_s.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches kv2 and kv1 */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_regex_string_hwe(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv1[] = { vnd_t_oo, prd_ba_s, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
WRITE_TWO_DEVICES(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_regex_string_hwe);
return 0;
}
/*
* Two device entries, kv1 is a regex match ("^.foo:(bar|baz|ba\.)$"),
* kv2 a string match (foo:bar) which matches a subset of the regex.
* kv1 is added to the main config file, kv2 to a config_dir file.
* This case is more important as you may think, because it's equivalent
* to kv1 being in the built-in hwtable and kv2 in multipath.conf.
*
* Expected: Devices matching kv2 (and thus, both) get properties
* from both, kv2 taking precedence.
* Devices matching kv1 only just get props from kv1.
*/
static void test_regex_string_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz matches kv1 */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* boo:baz matches kv1 */
pp = mock_path(vnd_boo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .oo:ba. matches kv1 */
pp = mock_path(vnd__oo.value, prd_ba_.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .oo:(bar|baz|ba\.)$ doesn't match */
pp = mock_path(vnd__oo.value, prd_ba_s.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches kv2 */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
/* Later match takes prio */
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_regex_string_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_t_oo, prd_ba_s, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_regex_string_hwe_dir);
return 0;
}
/*
* Three device entries, kv1 is a regex match and kv2 and kv3 string
* matches, where kv3 is a substring of kv2. All in different config
* files.
*
* Expected: Devices matching kv3 get props from all, devices matching
* kv2 from kv2 and kv1, and devices matching kv1 only just from kv1.
*/
static void test_regex_2_strings_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz matches kv1 */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* boo:baz doesn't match */
pp = mock_path(vnd_boo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches kv2 and kv1 */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(pp->uid_attribute, uid_baz.value);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* foo:barz matches kv3 and kv2 and kv1 */
pp = mock_path_flags(vnd_foo.value, prd_barz.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_rdac.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(pp->uid_attribute, uid_baz.value);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_regex_2_strings_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_ba_, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, uid_baz };
const struct key_value kv3[] = { vnd_foo, prd_barz,
prio_rdac, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "devices");
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1);
write_device(hwt->conf_dir_file[0], ARRAY_SIZE(kv2), kv2);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv3), kv3);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_regex_2_strings_hwe_dir);
return 0;
}
/*
* Like test_regex_string_hwe_dir, but the order of kv1 and kv2 is exchanged.
*
* Expected: Devices matching kv1 (and thus, both) get properties
* from both, kv1 taking precedence.
* Devices matching kv1 only just get props from kv1.
*/
static void test_string_regex_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar matches kv2 and kv1 */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* foo:baz matches kv1 */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* boo:baz matches kv1 */
pp = mock_path(vnd_boo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .oo:ba. matches kv1 */
pp = mock_path(vnd__oo.value, prd_ba_.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* .oo:(bar|baz|ba\.)$ doesn't match */
pp = mock_path(vnd__oo.value, prd_ba_s.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
}
static int setup_string_regex_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_t_oo, prd_ba_s, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv2, kv1);
SET_TEST_FUNC(hwt, test_string_regex_hwe_dir);
return 0;
}
/*
* Two identical device entries kv1 and kv2, trivial regex ("string").
* Both are added to the main config file.
* These entries are NOT merged.
* This could happen in a large multipath.conf file.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_strings_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_strings_hwe(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_ident_strings_hwe);
return 0;
}
/*
* Two identical device entries kv1 and kv2, trivial regex ("string").
* Both are added to an extra config file.
* This could happen in a large multipath.conf file.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_strings_both_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_strings_both_dir(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "devices");
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv1), kv1);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_2_ident_strings_both_dir);
return 0;
}
/*
* Two identical device entries kv1 and kv2, trivial regex ("string").
* Both are added to an extra config file.
* An empty entry kv0 with the same string exists in the main config file.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_strings_both_dir_w_prev(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_strings_both_dir_w_prev(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kv0[] = { vnd_foo, prd_bar };
const struct key_value kv1[] = { vnd_foo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
begin_config(hwt);
begin_section_all(hwt, "devices");
write_device(hwt->config_file, ARRAY_SIZE(kv0), kv0);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv1), kv1);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_2_ident_strings_both_dir_w_prev);
return 0;
}
/*
* Two identical device entries kv1 and kv2, trivial regex ("string").
* kv1 is added to the main config file, kv2 to a config_dir file.
* These entries are merged.
* This case is more important as you may think, because it's equivalent
* to kv1 being in the built-in hwtable and kv2 in multipath.conf.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_strings_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_strings_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_ident_strings_hwe_dir);
return 0;
}
/*
* Like test_2_ident_strings_hwe_dir, but this time the config_dir file
* contains an additional, empty entry (kv0).
*
* Expected: matching devices get props from kv1 and kv2, kv2 taking precedence.
*/
static void test_3_ident_strings_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_3_ident_strings_hwe_dir(void **state)
{
const struct key_value kv0[] = { vnd_foo, prd_bar };
const struct key_value kv1[] = { vnd_foo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "devices");
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv0), kv0);
write_device(hwt->conf_dir_file[1], ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_3_ident_strings_hwe_dir);
return 0;
}
/*
* Two identical device entries kv1 and kv2, non-trival regex that matches
* itself (string ".oo" matches regex ".oo").
* kv1 is added to the main config file, kv2 to a config_dir file.
* This case is more important as you may think, because it's equivalent
* to kv1 being in the built-in hwtable and kv2 in multipath.conf.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_self_matching_re_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_self_matching_re_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd__oo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd__oo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_ident_self_matching_re_hwe_dir);
return 0;
}
/*
* Two identical device entries kv1 and kv2, non-trival regex that matches
* itself (string ".oo" matches regex ".oo").
* kv1 and kv2 are added to the main config file.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void test_2_ident_self_matching_re_hwe(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_self_matching_re_hwe(void **state)
{
const struct key_value kv1[] = { vnd__oo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd__oo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_ident_self_matching_re_hwe);
return 0;
}
/*
* Two identical device entries kv1 and kv2, non-trival regex that doesn't
* match itself (string "^.oo" doesn't match regex "^.oo").
* kv1 is added to the main config file, kv2 to a config_dir file.
* This case is more important as you may think, see above.
*
* Expected: matching devices get props from both, kv2 taking precedence.
*/
static void
test_2_ident_not_self_matching_re_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:baz doesn't match */
pp = mock_path(vnd_foo.value, prd_baz.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
/* foo:bar matches both */
pp = mock_path_flags(vnd_foo.value, prd_bar.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_ident_not_self_matching_re_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_t_oo, prd_bar, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_t_oo, prd_bar, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_ident_not_self_matching_re_hwe_dir);
return 0;
}
/*
* Two different non-trivial regexes kv1, kv2. The 1st one matches the 2nd, but
* it doesn't match all possible strings matching the second.
* ("ba[zy]" matches regex "ba[[rxy]", but "baz" does not).
*
* Expected: Devices matching both regexes get properties from both, kv2
* taking precedence. Devices matching just one regex get properties from
* that one regex only.
*/
static void test_2_matching_res_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar matches k1 only */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* foo:bay matches k1 and k2 */
pp = mock_path_flags(vnd_foo.value, "bay", USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
/* foo:baz matches k2 only. */
pp = mock_path_flags(vnd_foo.value, prd_baz.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
}
static int setup_2_matching_res_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_barx, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bazy, prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_matching_res_hwe_dir);
return 0;
}
/*
* Two different non-trivial regexes which match the same set of strings.
* But they don't match each other.
* "baz" matches both regex "ba[zy]" and "ba(z|y)"
*
* Expected: matching devices get properties from both, kv2 taking precedence.
*/
static void test_2_nonmatching_res_hwe_dir(const struct hwt_state *hwt)
{
struct path *pp;
/* foo:bar doesn't match */
pp = mock_path(vnd_foo.value, prd_bar.value);
TEST_PROP(prio_name(&pp->prio), DEFAULT_PRIO);
assert_int_equal(pp->vpd_vendor_id, 0);
TEST_PROP(checker_name(&pp->checker), DEFAULT_CHECKER);
pp = mock_path_flags(vnd_foo.value, prd_baz.value, USE_VPD_VND);
TEST_PROP(prio_name(&pp->prio), prio_hds.value);
assert_int_equal(pp->vpd_vendor_id, VPD_VP_HP3PAR);
TEST_PROP(checker_name(&pp->checker), chk_hp.value);
}
static int setup_2_nonmatching_res_hwe_dir(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bazy, prio_emc, chk_hp };
const struct key_value kv2[] = { vnd_foo, prd_bazy1,
prio_hds, vpd_hp3par };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES_W_DIR(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_2_nonmatching_res_hwe_dir);
return 0;
}
/*
* Simple blacklist test.
*
* NOTE: test failures in blacklisting tests will manifest as cmocka errors
* "Could not get value to mock function XYZ", because pathinfo() takes
* different code paths for blacklisted devices.
*/
static void test_blacklist(const struct hwt_state *hwt)
{
mock_path_flags(vnd_foo.value, prd_bar.value, BL_BY_DEVICE);
mock_path(vnd_foo.value, prd_baz.value);
}
static int setup_blacklist(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "blacklist");
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist);
return 0;
}
/*
* Simple blacklist test with regex and exception
*/
static void test_blacklist_regex(const struct hwt_state *hwt)
{
mock_path(vnd_foo.value, prd_bar.value);
mock_path_flags(vnd_foo.value, prd_baz.value, BL_BY_DEVICE);
mock_path(vnd_foo.value, prd_bam.value);
}
static int setup_blacklist_regex(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_ba_s };
const struct key_value kv2[] = { vnd_foo, prd_bar };
struct hwt_state *hwt = CHECK_STATE(state);
hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "blacklist");
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1);
end_section_all(hwt);
begin_section_all(hwt, "blacklist_exceptions");
write_device(hwt->conf_dir_file[0], ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist_regex);
return 0;
}
/*
* Simple blacklist test with regex and exception
* config file order inverted wrt test_blacklist_regex
*/
static int setup_blacklist_regex_inv(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_ba_s };
const struct key_value kv2[] = { vnd_foo, prd_bar };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "blacklist");
write_device(hwt->conf_dir_file[0], ARRAY_SIZE(kv1), kv1);
end_section_all(hwt);
begin_section_all(hwt, "blacklist_exceptions");
write_device(hwt->config_file, ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist_regex);
return 0;
}
/*
* Simple blacklist test with regex and exception
* config file order inverted wrt test_blacklist_regex
*/
static void test_blacklist_regex_matching(const struct hwt_state *hwt)
{
mock_path_flags(vnd_foo.value, prd_bar.value, BL_BY_DEVICE);
mock_path_flags(vnd_foo.value, prd_baz.value, BL_BY_DEVICE);
mock_path(vnd_foo.value, prd_bam.value);
}
static int setup_blacklist_regex_matching(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_barx };
const struct key_value kv2[] = { vnd_foo, prd_bazy };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "blacklist");
write_device(hwt->config_file, ARRAY_SIZE(kv1), kv1);
write_device(hwt->conf_dir_file[0], ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist_regex_matching);
return 0;
}
/*
* Test for blacklisting by WWID
*
* Note that default_wwid is a substring of default_wwid_1. Because
* matching is done by regex, both paths are blacklisted.
*/
static void test_blacklist_wwid(const struct hwt_state *hwt)
{
mock_path_flags(vnd_foo.value, prd_bar.value, BL_BY_WWID);
mock_path_wwid_flags(vnd_foo.value, prd_baz.value, default_wwid_1,
BL_BY_WWID);
}
static int setup_blacklist_wwid(void **state)
{
const struct key_value kv[] = { wwid_test };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
write_section(hwt->config_file, "blacklist", ARRAY_SIZE(kv), kv);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist_wwid);
return 0;
}
/*
* Test for blacklisting by WWID
*
* Here the blacklist contains only default_wwid_1. Thus the path
* with default_wwid is NOT blacklisted.
*/
static void test_blacklist_wwid_1(const struct hwt_state *hwt)
{
mock_path(vnd_foo.value, prd_bar.value);
mock_path_wwid_flags(vnd_foo.value, prd_baz.value, default_wwid_1,
BL_BY_WWID);
}
static int setup_blacklist_wwid_1(void **state)
{
const struct key_value kv[] = { { _wwid, default_wwid_1 }, };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
write_section(hwt->config_file, "blacklist", ARRAY_SIZE(kv), kv);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_blacklist_wwid_1);
return 0;
}
/*
* Test for product_blacklist. Two entries blacklisting each other.
*
* Expected: Both are blacklisted.
*/
static void test_product_blacklist(const struct hwt_state *hwt)
{
mock_path_flags(vnd_foo.value, prd_baz.value, BL_BY_DEVICE);
mock_path_flags(vnd_foo.value, prd_bar.value, BL_BY_DEVICE);
mock_path(vnd_foo.value, prd_bam.value);
}
static int setup_product_blacklist(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar, bl_baz };
const struct key_value kv2[] = { vnd_foo, prd_baz, bl_bar };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_product_blacklist);
return 0;
}
/*
* Test for product_blacklist. The second regex "matches" the first.
* This is a pathological example.
*
* Expected: "foo:bar", "foo:baz" are blacklisted.
*/
static void test_product_blacklist_matching(const struct hwt_state *hwt)
{
mock_path_flags(vnd_foo.value, prd_bar.value, BL_BY_DEVICE);
mock_path_flags(vnd_foo.value, prd_baz.value, BL_BY_DEVICE);
mock_path(vnd_foo.value, prd_bam.value);
}
static int setup_product_blacklist_matching(void **state)
{
const struct key_value kv1[] = { vnd_foo, prd_bar, bl_barx };
const struct key_value kv2[] = { vnd_foo, prd_baz, bl_bazy };
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_TWO_DEVICES(hwt, kv1, kv2);
SET_TEST_FUNC(hwt, test_product_blacklist_matching);
return 0;
}
/*
* Basic test for multipath-based configuration.
*
* Expected: properties, including pp->prio, are taken from multipath
* section.
*/
static void test_multipath_config(const struct hwt_state *hwt)
{
struct path *pp;
struct multipath *mp;
pp = mock_path(vnd_foo.value, prd_bar.value);
mp = mock_multipath(pp);
assert_ptr_not_equal(mp->mpe, NULL);
TEST_PROP(prio_name(&pp->prio), prio_rdac.value);
assert_int_equal(mp->minio, atoi(minio_99.value));
TEST_PROP(pp->uid_attribute, uid_baz.value);
/* test different wwid */
pp = mock_path_wwid(vnd_foo.value, prd_bar.value, default_wwid_1);
mp = mock_multipath(pp);
// assert_ptr_equal(mp->mpe, NULL);
TEST_PROP(prio_name(&pp->prio), prio_emc.value);
assert_int_equal(mp->minio, DEFAULT_MINIO_RQ);
TEST_PROP(pp->uid_attribute, uid_baz.value);
}
static int setup_multipath_config(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
const struct key_value kvm[] = { wwid_test, prio_rdac, minio_99 };
const struct key_value kvp[] = { vnd_foo, prd_bar, prio_emc, uid_baz };
begin_config(hwt);
begin_section_all(hwt, "devices");
write_section(hwt->conf_dir_file[0], "device", ARRAY_SIZE(kvp), kvp);
end_section_all(hwt);
begin_section_all(hwt, "multipaths");
write_section(hwt->config_file, "multipath", ARRAY_SIZE(kvm), kvm);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_multipath_config);
return 0;
}
/*
* Basic test for multipath-based configuration. Two sections for the same wwid.
*
* Expected: properties are taken from both multipath sections, later taking
* precedence
*/
static void test_multipath_config_2(const struct hwt_state *hwt)
{
struct path *pp;
struct multipath *mp;
pp = mock_path(vnd_foo.value, prd_bar.value);
mp = mock_multipath(pp);
assert_ptr_not_equal(mp, NULL);
assert_ptr_not_equal(mp->mpe, NULL);
TEST_PROP(prio_name(&pp->prio), prio_rdac.value);
assert_int_equal(mp->minio, atoi(minio_99.value));
assert_int_equal(mp->no_path_retry, atoi(npr_37.value));
}
static int setup_multipath_config_2(void **state)
{
const struct key_value kv1[] = { wwid_test, prio_rdac, npr_queue };
const struct key_value kv2[] = { wwid_test, minio_99, npr_37 };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "multipaths");
write_section(hwt->config_file, "multipath", ARRAY_SIZE(kv1), kv1);
write_section(hwt->conf_dir_file[1], "multipath", ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_multipath_config_2);
return 0;
}
/*
* Same as test_multipath_config_2, both entries in the same config file.
*
* Expected: properties are taken from both multipath sections.
*/
static void test_multipath_config_3(const struct hwt_state *hwt)
{
struct path *pp;
struct multipath *mp;
pp = mock_path(vnd_foo.value, prd_bar.value);
mp = mock_multipath(pp);
assert_ptr_not_equal(mp, NULL);
assert_ptr_not_equal(mp->mpe, NULL);
TEST_PROP(prio_name(&pp->prio), prio_rdac.value);
assert_int_equal(mp->minio, atoi(minio_99.value));
assert_int_equal(mp->no_path_retry, atoi(npr_37.value));
}
static int setup_multipath_config_3(void **state)
{
const struct key_value kv1[] = { wwid_test, prio_rdac, npr_queue };
const struct key_value kv2[] = { wwid_test, minio_99, npr_37 };
struct hwt_state *hwt = CHECK_STATE(state);
begin_config(hwt);
begin_section_all(hwt, "multipaths");
write_section(hwt->config_file, "multipath", ARRAY_SIZE(kv1), kv1);
write_section(hwt->config_file, "multipath", ARRAY_SIZE(kv2), kv2);
end_section_all(hwt);
finish_config(hwt);
SET_TEST_FUNC(hwt, test_multipath_config_3);
return 0;
}
/*
* Test for device with "hidden" attribute
*/
static void test_hidden(const struct hwt_state *hwt)
{
mock_path_flags("NVME", "NoName", DEV_HIDDEN|BL_MASK);
}
static int setup_hidden(void **state)
{
struct hwt_state *hwt = CHECK_STATE(state);
WRITE_EMPTY_CONF(hwt);
SET_TEST_FUNC(hwt, test_hidden);
return 0;
}
/*
* Create wrapper functions around test_driver() to avoid that cmocka
* always uses the same test name. That makes it easier to read test results.
*/
#define define_test(x) \
static void run_##x(void **state) \
{ \
return test_driver(state); \
}
define_test(string_hwe)
define_test(broken_hwe)
define_test(broken_hwe_dir)
define_test(quoted_hwe)
define_test(internal_nvme)
define_test(regex_hwe)
define_test(regex_string_hwe)
define_test(regex_string_hwe_dir)
define_test(regex_2_strings_hwe_dir)
define_test(string_regex_hwe_dir)
define_test(2_ident_strings_hwe)
define_test(2_ident_strings_both_dir)
define_test(2_ident_strings_both_dir_w_prev)
define_test(2_ident_strings_hwe_dir)
define_test(3_ident_strings_hwe_dir)
define_test(2_ident_self_matching_re_hwe_dir)
define_test(2_ident_self_matching_re_hwe)
define_test(2_ident_not_self_matching_re_hwe_dir)
define_test(2_matching_res_hwe_dir)
define_test(2_nonmatching_res_hwe_dir)
define_test(blacklist)
define_test(blacklist_wwid)
define_test(blacklist_wwid_1)
define_test(blacklist_regex)
define_test(blacklist_regex_inv)
define_test(blacklist_regex_matching)
define_test(product_blacklist)
define_test(product_blacklist_matching)
define_test(multipath_config)
define_test(multipath_config_2)
define_test(multipath_config_3)
define_test(hidden)
#define test_entry(x) \
cmocka_unit_test_setup(run_##x, setup_##x)
static int test_hwtable(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_sanity_globals),
test_entry(internal_nvme),
test_entry(string_hwe),
test_entry(broken_hwe),
test_entry(broken_hwe_dir),
test_entry(quoted_hwe),
test_entry(regex_hwe),
test_entry(regex_string_hwe),
test_entry(regex_string_hwe_dir),
test_entry(regex_2_strings_hwe_dir),
test_entry(string_regex_hwe_dir),
test_entry(2_ident_strings_hwe),
test_entry(2_ident_strings_both_dir),
test_entry(2_ident_strings_both_dir_w_prev),
test_entry(2_ident_strings_hwe_dir),
test_entry(3_ident_strings_hwe_dir),
test_entry(2_ident_self_matching_re_hwe_dir),
test_entry(2_ident_self_matching_re_hwe),
test_entry(2_ident_not_self_matching_re_hwe_dir),
test_entry(2_matching_res_hwe_dir),
test_entry(2_nonmatching_res_hwe_dir),
test_entry(blacklist),
test_entry(blacklist_wwid),
test_entry(blacklist_wwid_1),
test_entry(blacklist_regex),
test_entry(blacklist_regex_inv),
test_entry(blacklist_regex_matching),
test_entry(product_blacklist),
test_entry(product_blacklist_matching),
test_entry(multipath_config),
test_entry(multipath_config_2),
test_entry(multipath_config_3),
test_entry(hidden),
};
return cmocka_run_group_tests(tests, setup, teardown);
}
int main(void)
{
int ret = 0;
/* We can't use init_test_verbosity in this test */
libmp_verbosity = VERBOSITY;
ret += test_hwtable();
return ret;
}
|