Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions libnvme/test/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,41 @@ static bool test_update_and_retrieve(struct libnvme_global_ctx *ctx)
return pass;
}

static bool test_special_chars(struct libnvme_global_ctx *ctx)
{
/*
* Attribute values are free-form text -- only device and attribute
* names are validated, never the value. Verify a value with spaces,
* double quotes, an apostrophe and punctuation round-trips
* byte-for-byte.
*/
const char *special = "ACME Corp \"prod\" team's box !@#%";
char *value = NULL;
bool pass = true;
int ret;

printf("test_special_chars:\n");

ret = libnvmf_registry_update(ctx, "nvme5", "owner", special);
if (ret) {
printf(" - update returned %d [FAIL]\n", ret);
return false;
}

ret = libnvmf_registry_retrieve(ctx, "nvme5", "owner", &value);
if (ret || !value || strcmp(value, special) != 0) {
printf(" - expected '%s', got '%s' ret=%d [FAIL]\n",
special, value ? value : "(null)", ret);
pass = false;
} else {
printf(" - round-trip '%s' [PASS]\n", value);
}

free(value);
libnvmf_registry_delete(ctx, "nvme5");
return pass;
}

static bool test_delete(struct libnvme_global_ctx *ctx)
{
char *value = NULL;
Expand Down Expand Up @@ -448,6 +483,7 @@ int main(int argc, char *argv[])

pass &= test_create(ctx);
pass &= test_update_and_retrieve(ctx);
pass &= test_special_chars(ctx);
pass &= test_delete(ctx);
pass &= test_retrieve_missing(ctx);
pass &= test_device_for_each(ctx);
Expand Down
Loading