diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 17:39:31 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 17:39:31 +1000 |
commit | 7bcbf364a3c2dc9645ece54820be5f54e0c84af1 (patch) | |
tree | 01f65b6fc493f2715a7b74d1762faab76799afd8 /core/test/run-nvram-format.c | |
parent | e3e38fcc77e49378db230f06b5f38e3814229aae (diff) | |
download | skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.zip skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.tar.gz skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.tar.bz2 |
Expand nvram-format unit test to cover all error paths
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/test/run-nvram-format.c')
-rw-r--r-- | core/test/run-nvram-format.c | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/core/test/run-nvram-format.c b/core/test/run-nvram-format.c index 7fb4217..77b759b 100644 --- a/core/test/run-nvram-format.c +++ b/core/test/run-nvram-format.c @@ -21,11 +21,94 @@ int main(void) { char *nvram_image = malloc(0x100000); + size_t sz; + struct chrp_nvram_hdr *h; - nvram_format(nvram_image, 0x100000); - + assert(nvram_format(nvram_image, 0x100000) == 0); assert(nvram_check(nvram_image, 0x100000) == 0); free(nvram_image); + + /* 1024 bytes is too small for our NVRAM */ + nvram_image = malloc(1024); + assert(nvram_format(nvram_image, 1024)!=0); + free(nvram_image); + + /* 4096 bytes is too small for our NVRAM */ + nvram_image = malloc(4096); + assert(nvram_format(nvram_image, 4096)!=0); + free(nvram_image); + + /* 64k is too small for our NVRAM */ + nvram_image = malloc(0x10000); + assert(nvram_format(nvram_image, 0x10000)!=0); + free(nvram_image); + + /* 68k is too small for our NVRAM */ + nvram_image = malloc(68*1024); + assert(nvram_format(nvram_image, 68*1024)!=0); + free(nvram_image); + + /* 68k+16 bytes (nvram header) should generate empty free space */ + sz = NVRAM_SIZE_COMMON + NVRAM_SIZE_FW_PRIV + + sizeof(struct chrp_nvram_hdr); + nvram_image = malloc(sz); + assert(nvram_format(nvram_image, sz)==0); + assert(nvram_check(nvram_image, sz)==0); + assert(nvram_image[sz-13]==0); + assert(nvram_image[sz-14]==1); + free(nvram_image); + + /* 128k NVRAM check */ + nvram_image = malloc(128*1024); + assert(nvram_format(nvram_image, 128*1024)==0); + assert(nvram_check(nvram_image,128*1024)==0); + + /* Now, we corrupt it */ + nvram_image[0] = 0; + assert(nvram_check(nvram_image,128*1024) != 0); + + assert(nvram_format(nvram_image, 128*1024)==0); + /* corrupt the length of the partition */ + nvram_image[2] = 0; + nvram_image[3] = 0; + assert(nvram_check(nvram_image,128*1024) != 0); + + assert(nvram_format(nvram_image, 128*1024)==0); + /* corrupt the length of the partition */ + nvram_image[2] = 0; + nvram_image[3] = 0; + /* but reset checksum! */ + h = (struct chrp_nvram_hdr*)nvram_image; + h->cksum = chrp_nv_cksum(h); + assert(nvram_check(nvram_image,128*1024) != 0); + + assert(nvram_format(nvram_image, 128*1024)==0); + /* make the length insanely beyond end of nvram */ + nvram_image[2] = 42; + nvram_image[3] = 32; + /* but reset checksum! */ + h = (struct chrp_nvram_hdr*)nvram_image; + h->cksum = chrp_nv_cksum(h); + assert(nvram_check(nvram_image,128*1024) != 0); + + assert(nvram_format(nvram_image, 128*1024)==0); + /* remove skiboot partition */ + nvram_image[12] = '\0'; + /* but reset checksum! */ + h = (struct chrp_nvram_hdr*)nvram_image; + h->cksum = chrp_nv_cksum(h); + assert(nvram_check(nvram_image,128*1024) != 0); + + assert(nvram_format(nvram_image, 128*1024)==0); + /* remove common partition */ + nvram_image[NVRAM_SIZE_FW_PRIV+5] = '\0'; + /* but reset checksum! */ + h = (struct chrp_nvram_hdr*)(&nvram_image[NVRAM_SIZE_FW_PRIV]); + h->cksum = chrp_nv_cksum(h); + assert(nvram_check(nvram_image,128*1024) != 0); + + free(nvram_image); + return 0; } |