From c869c0f240bf7fa5d73d21c09b469bbc3baba28e Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Fri, 29 May 2026 21:50:31 +1000 Subject: [PATCH] unit/zap: zap_*_int and zap_*_int_key Sponsored-by: TrueNAS Reviewed-by: Alexander Motin Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #18630 --- tests/unit/test_zap.c | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/unit/test_zap.c b/tests/unit/test_zap.c index 2c232218860..ae5f23f2bb4 100644 --- a/tests/unit/test_zap.c +++ b/tests/unit/test_zap.c @@ -499,6 +499,94 @@ test_zap_increment(const MunitParameter params[], void *data) /* ========== */ +/* + * zap_add_int/zap_remove_int/zap_lookup_int: single uint64_t value, + * stringified to form the key. + */ +static MunitResult +test_zap_int(const MunitParameter params[], void *data) +{ + (void) data; + + dnode_t *dn = mock_zap_create_params(params, "type"); + dmu_tx_t *tx = (dmu_tx_t *)mock_tx_create(); + + /* Add some ints. */ + unit_ok(zap_add_int_by_dnode(dn, 5, tx)); + unit_ok(zap_add_int_by_dnode(dn, 17, tx)); + + /* Confirm they're there. */ + unit_ok(zap_lookup_int_by_dnode(dn, 17)); + unit_ok(zap_lookup_int_by_dnode(dn, 5)); + + /* But not something we didn't add. */ + unit_err(zap_lookup_int_by_dnode(dn, 23), ENOENT); + + /* Adding something that already exists fails. */ + unit_err(zap_add_int_by_dnode(dn, 17, tx), EEXIST); + + /* Removing it works, and then it can't be found. */ + unit_ok(zap_remove_int_by_dnode(dn, 17, tx)); + unit_err(zap_lookup_int_by_dnode(dn, 17), ENOENT); + + /* Add it can be added back. */ + unit_ok(zap_add_int_by_dnode(dn, 17, tx)); + unit_ok(zap_lookup_int_by_dnode(dn, 17)); + + mock_tx_destroy((mock_dmu_tx_t *)tx); + unit_true(mock_zap_is_params(dn, params, "type")); + mock_zap_destroy(dn); + + return (MUNIT_OK); +} + +/* zap_*_int_key: like zap_*_int, but with separate value. */ +static MunitResult +test_zap_int_keys(const MunitParameter params[], void *data) +{ + (void) data; + + dnode_t *dn = mock_zap_create_params(params, "type"); + dmu_tx_t *tx = (dmu_tx_t *)mock_tx_create(); + + /* Add some ints. */ + unit_ok(zap_add_int_key_by_dnode(dn, 5, 17, tx)); + unit_ok(zap_add_int_key_by_dnode(dn, 23, 35, tx)); + + /* Confirm they're there. */ + uint64_t r = 0; + unit_ok(zap_lookup_int_key_by_dnode(dn, 5, &r)); + unit_eq(r, 17); + unit_ok(zap_lookup_int_key_by_dnode(dn, 23, &r)); + unit_eq(r, 35); + + /* But not something we didn't add. */ + unit_err(zap_lookup_int_key_by_dnode(dn, 79, &r), ENOENT); + + /* Adding something that already exists fails. */ + unit_err(zap_add_int_key_by_dnode(dn, 23, 51, tx), EEXIST); + + /* Updating it works though. */ + unit_ok(zap_update_int_key_by_dnode(dn, 23, 51, tx)); + + /* Removing it works, and then it can't be found. */ + unit_ok(zap_remove_int_by_dnode(dn, 23, tx)); + unit_err(zap_lookup_int_key_by_dnode(dn, 23, &r), ENOENT); + + /* Add it can be added back. */ + unit_ok(zap_add_int_key_by_dnode(dn, 23, 11, tx)); + unit_ok(zap_lookup_int_key_by_dnode(dn, 23, &r)); + unit_eq(r, 11); + + mock_tx_destroy((mock_dmu_tx_t *)tx); + unit_true(mock_zap_is_params(dn, params, "type")); + mock_zap_destroy(dn); + + return (MUNIT_OK); +} + +/* ========== */ + /* * Separate stats tests for each ZAP type, since they are about internals and * so can and will produce different results. @@ -911,6 +999,9 @@ static const MunitTest zap_tests[] = { UNIT_TEST_ZAP_TYPES("zap_increment", test_zap_increment), + UNIT_TEST_ZAP_TYPES("zap_int", test_zap_int), + UNIT_TEST_ZAP_TYPES("zap_int_keys", test_zap_int_keys), + UNIT_TEST("microzap_stats", test_microzap_stats), UNIT_TEST("fatzap_stats", test_fatzap_stats),