From: Martin Wilck <mwilck@xxxxxxxx> Add some tests for the consistency checks in the VPD. Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> --- tests/vpd.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tests/vpd.c b/tests/vpd.c index 8e730d3..d42e109 100644 --- a/tests/vpd.c +++ b/tests/vpd.c @@ -9,6 +9,7 @@ #include <stdint.h> #include <stdlib.h> #include <unistd.h> +#include <errno.h> #include <stdarg.h> #include <stddef.h> #include <setjmp.h> @@ -500,6 +501,27 @@ static void test_vpd_naa_ ## naa ## _ ## wlen(void **state) \ test_id, vt->wwid); \ } +/** + * test_cpd_naa_NAA_badlen_BAD() - test detection of bad length fields + * @NAA: Network Name Authority (2, 3, 5, 16) + * @BAD: Value for designator length field + * @ERR: Expected error code + */ +#define make_test_vpd_naa_badlen(NAA, BAD, ERR) \ +static void test_vpd_naa_##NAA##_badlen_##BAD(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, 3, NAA, 0); \ + \ + vt->vpdbuf[7] = BAD; \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, 0, vt->wwid, 40); \ + assert_int_equal(-ret, -ERR); \ +} + /** * test_vpd_eui_LEN_WLEN() - test code for VPD 83, EUI64 * @LEN: EUI64 length (8, 12, or 16) @@ -532,6 +554,27 @@ static void test_vpd_eui_ ## len ## _ ## wlen ## _ ## sml(void **state) \ test_id, vt->wwid); \ } +/** + * test_cpd_eui_LEN_badlen_BAD() - test detection of bad length fields + * @NAA: correct length(8, 12, 16) + * @BAD: value for designator length field + * @ERR: expected error code + */ +#define make_test_vpd_eui_badlen(LEN, BAD, ERR) \ +static void test_vpd_eui_badlen_##LEN##_##BAD(void **state) \ +{ \ + struct vpdtest *vt = *state; \ + int n, ret; \ + \ + n = create_vpd83(vt->vpdbuf, sizeof(vt->vpdbuf), test_id, 2, 0, LEN); \ + \ + vt->vpdbuf[7] = BAD; \ + will_return(__wrap_ioctl, n); \ + will_return(__wrap_ioctl, vt->vpdbuf); \ + ret = get_vpd_sgio(10, 0x83, 0, vt->wwid, 40); \ + assert_int_equal(-ret, -ERR); \ +} + /** * test_vpd80_SIZE_LEN_WLEN() - test code for VPD 80 * @SIZE, @LEN: see create_vpd80() @@ -621,6 +664,13 @@ make_test_vpd_eui(8, 17, 0); make_test_vpd_eui(8, 16, 0); make_test_vpd_eui(8, 10, 0); +make_test_vpd_eui_badlen(8, 8, 17); +make_test_vpd_eui_badlen(8, 12, -EOVERFLOW); +make_test_vpd_eui_badlen(8, 9, -EOVERFLOW); +make_test_vpd_eui_badlen(8, 7, -EINVAL); +make_test_vpd_eui_badlen(8, 4, -EINVAL); +make_test_vpd_eui_badlen(8, 0, -EINVAL); + /* 96 bit, WWID size: 26 */ make_test_vpd_eui(12, 32, 0); make_test_vpd_eui(12, 26, 0); @@ -628,12 +678,27 @@ make_test_vpd_eui(12, 25, 0); make_test_vpd_eui(12, 20, 0); make_test_vpd_eui(12, 10, 0); +make_test_vpd_eui_badlen(12, 12, 25); +make_test_vpd_eui_badlen(12, 16, -EOVERFLOW); +make_test_vpd_eui_badlen(12, 13, -EOVERFLOW); +make_test_vpd_eui_badlen(12, 11, -EINVAL); +/* non-fatal */ +make_test_vpd_eui_badlen(12, 8, 17); +make_test_vpd_eui_badlen(12, 0, -EINVAL); + /* 128 bit, WWID size: 34 */ make_test_vpd_eui(16, 40, 0); make_test_vpd_eui(16, 34, 0); make_test_vpd_eui(16, 33, 0); make_test_vpd_eui(16, 20, 0); +make_test_vpd_eui_badlen(16, 16, 33); +make_test_vpd_eui_badlen(16, 17, -EOVERFLOW); +make_test_vpd_eui_badlen(16, 15, -EINVAL); +/* non-fatal */ +make_test_vpd_eui_badlen(16, 12, 25); +make_test_vpd_eui_badlen(16, 0, -EINVAL); + /* NAA IEEE registered extended (36), WWID size: 34 */ make_test_vpd_naa(6, 40); make_test_vpd_naa(6, 34); @@ -641,12 +706,27 @@ make_test_vpd_naa(6, 33); make_test_vpd_naa(6, 32); make_test_vpd_naa(6, 20); +/* NAA IEEE registered extended with bad designator length */ +make_test_vpd_naa_badlen(6, 16, 33); +make_test_vpd_naa_badlen(6, 15, -EINVAL); +make_test_vpd_naa_badlen(6, 8, -EINVAL); +make_test_vpd_naa_badlen(6, 17, -EOVERFLOW); +make_test_vpd_naa_badlen(6, 0, -EINVAL); + /* NAA IEEE registered (35), WWID size: 18 */ make_test_vpd_naa(5, 20); make_test_vpd_naa(5, 18); make_test_vpd_naa(5, 17); make_test_vpd_naa(5, 16); +/* NAA IEEE registered with bad designator length */ +make_test_vpd_naa_badlen(5, 8, 17); +make_test_vpd_naa_badlen(5, 7, -EINVAL); +make_test_vpd_naa_badlen(5, 4, -EINVAL); +make_test_vpd_naa_badlen(5, 16, -EOVERFLOW); +make_test_vpd_naa_badlen(5, 9, -EOVERFLOW); +make_test_vpd_naa_badlen(5, 0, -EINVAL); + /* NAA local (33), WWID size: 18 */ make_test_vpd_naa(3, 20); make_test_vpd_naa(3, 18); @@ -741,24 +821,52 @@ static int test_vpd(void) cmocka_unit_test(test_vpd_eui_8_17_0), cmocka_unit_test(test_vpd_eui_8_16_0), cmocka_unit_test(test_vpd_eui_8_10_0), + cmocka_unit_test(test_vpd_eui_badlen_8_8), + cmocka_unit_test(test_vpd_eui_badlen_8_12), + cmocka_unit_test(test_vpd_eui_badlen_8_9), + cmocka_unit_test(test_vpd_eui_badlen_8_7), + cmocka_unit_test(test_vpd_eui_badlen_8_4), + cmocka_unit_test(test_vpd_eui_badlen_8_0), cmocka_unit_test(test_vpd_eui_12_32_0), cmocka_unit_test(test_vpd_eui_12_26_0), cmocka_unit_test(test_vpd_eui_12_25_0), cmocka_unit_test(test_vpd_eui_12_20_0), cmocka_unit_test(test_vpd_eui_12_10_0), + cmocka_unit_test(test_vpd_eui_badlen_12_12), + cmocka_unit_test(test_vpd_eui_badlen_12_16), + cmocka_unit_test(test_vpd_eui_badlen_12_13), + cmocka_unit_test(test_vpd_eui_badlen_12_11), + cmocka_unit_test(test_vpd_eui_badlen_12_8), + cmocka_unit_test(test_vpd_eui_badlen_12_0), cmocka_unit_test(test_vpd_eui_16_40_0), cmocka_unit_test(test_vpd_eui_16_34_0), cmocka_unit_test(test_vpd_eui_16_33_0), cmocka_unit_test(test_vpd_eui_16_20_0), + cmocka_unit_test(test_vpd_eui_badlen_16_16), + cmocka_unit_test(test_vpd_eui_badlen_16_17), + cmocka_unit_test(test_vpd_eui_badlen_16_15), + cmocka_unit_test(test_vpd_eui_badlen_16_12), + cmocka_unit_test(test_vpd_eui_badlen_16_0), cmocka_unit_test(test_vpd_naa_6_40), cmocka_unit_test(test_vpd_naa_6_34), cmocka_unit_test(test_vpd_naa_6_33), cmocka_unit_test(test_vpd_naa_6_32), cmocka_unit_test(test_vpd_naa_6_20), + cmocka_unit_test(test_vpd_naa_6_badlen_16), + cmocka_unit_test(test_vpd_naa_6_badlen_15), + cmocka_unit_test(test_vpd_naa_6_badlen_8), + cmocka_unit_test(test_vpd_naa_6_badlen_17), + cmocka_unit_test(test_vpd_naa_6_badlen_0), cmocka_unit_test(test_vpd_naa_5_20), cmocka_unit_test(test_vpd_naa_5_18), cmocka_unit_test(test_vpd_naa_5_17), cmocka_unit_test(test_vpd_naa_5_16), + cmocka_unit_test(test_vpd_naa_5_badlen_8), + cmocka_unit_test(test_vpd_naa_5_badlen_7), + cmocka_unit_test(test_vpd_naa_5_badlen_4), + cmocka_unit_test(test_vpd_naa_5_badlen_16), + cmocka_unit_test(test_vpd_naa_5_badlen_9), + cmocka_unit_test(test_vpd_naa_5_badlen_0), cmocka_unit_test(test_vpd_naa_3_20), cmocka_unit_test(test_vpd_naa_3_18), cmocka_unit_test(test_vpd_naa_3_17), -- 2.33.1 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel