diff options
author | Oliver O'Halloran <oohall@gmail.com> | 2016-08-17 15:32:54 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-08-30 16:59:47 +1000 |
commit | 2b426c488eae5b5ba175ba6a8434d288582347fa (patch) | |
tree | 0612311f179cfb2626082691370f9fd64ee9fcc2 /core/test | |
parent | 9a002d1e89a0808337db70017ec5fe121bf59460 (diff) | |
download | skiboot-2b426c488eae5b5ba175ba6a8434d288582347fa.zip skiboot-2b426c488eae5b5ba175ba6a8434d288582347fa.tar.gz skiboot-2b426c488eae5b5ba175ba6a8434d288582347fa.tar.bz2 |
core/test: add tests for nvram_query()
Adds some basic functionality tests for nvram_query() to the core test
suite.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/test')
-rw-r--r-- | core/test/run-nvram-format.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/core/test/run-nvram-format.c b/core/test/run-nvram-format.c index b8ba698..4bf3ae0 100644 --- a/core/test/run-nvram-format.c +++ b/core/test/run-nvram-format.c @@ -18,11 +18,25 @@ #include "../nvram-format.c" +static char *nvram_reset(void *nvram_image, int size) +{ + struct chrp_nvram_hdr *h = nvram_image; + + /* entire partition used by one key */ + assert(nvram_format(nvram_image, size) == 0); + memset((char *) h + sizeof(*h), 0, NVRAM_SIZE_FW_PRIV - sizeof(*h)); + assert(nvram_check(nvram_image, size) == 0); + + return (char *) h + sizeof(*h); +} + int main(void) { char *nvram_image; size_t sz; struct chrp_nvram_hdr *h; + char *data; + const char *result; /* 1024 bytes is too small for our NVRAM */ nvram_image = malloc(1024); @@ -111,6 +125,38 @@ int main(void) h->cksum = chrp_nv_cksum(h); assert(nvram_check(nvram_image,128*1024) != 0); + /* test nvram_query() */ + + /* does an empty partition break us? */ + data = nvram_reset(nvram_image, 128*1024); + assert(nvram_query("test") == NULL); + + /* does a zero length key break us? */ + data = nvram_reset(nvram_image, 128*1024); + data[0] = '='; + assert(nvram_query("test") == NULL); + + /* does a missing = break us? */ + data = nvram_reset(nvram_image, 128*1024); + data[0] = 'a'; + assert(nvram_query("test") == NULL); + + /* does an empty value break us? */ + data = nvram_reset(nvram_image, 128*1024); + data[0] = 'a'; + data[1] = '='; + result = nvram_query("a"); + assert(result); + assert(strlen(result) == 0); + + /* do we trip over malformed keys? */ + data = nvram_reset(nvram_image, 128*1024); +#define TEST_1 "a\0a=\0test=test\0" + memcpy(data, TEST_1, sizeof(TEST_1)); + result = nvram_query("test"); + assert(result); + assert(strcmp(result, "test") == 0); + free(nvram_image); return 0; |