[Skiboot] [PATCH v6 08/20] secvar/test: update API tests for new secvar struct

Eric Richter erichte at linux.ibm.com
Thu Sep 17 02:21:19 AEST 2020


From: Eric Richter <erichte at linux.vnet.ibm.com>

This patch adjusts the API unit tests to use the secvar struct rather than
the old secvar_node. Where applicable, some manual allocations have also been
replaced with the util functions.

Signed-off-by: Eric Richter <erichte at linux.ibm.com>
---
 libstb/secvar/test/secvar-test-enqueue.c |  6 +++---
 libstb/secvar/test/secvar-test-getvar.c  | 21 +++++--------------
 libstb/secvar/test/secvar-test-nextvar.c | 26 ++++++------------------
 3 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/libstb/secvar/test/secvar-test-enqueue.c b/libstb/secvar/test/secvar-test-enqueue.c
index 61c22d16..b4b2c140 100644
--- a/libstb/secvar/test/secvar-test-enqueue.c
+++ b/libstb/secvar/test/secvar-test-enqueue.c
@@ -16,7 +16,7 @@ int run_test(void)
 {
 	int64_t rc;
 
-	struct secvar_node *node;
+	struct secvar *var;
 	char key[1024] = {0};
 
 	uint64_t data_size = 128;
@@ -106,8 +106,8 @@ int run_test(void)
 	rc = secvar_enqueue(key, 4, data, data_size);
 	ASSERT(rc == OPAL_SUCCESS);
 	ASSERT(list_length(&update_bank) == 3); // should not increase
-	node = list_tail(&update_bank, struct secvar_node, link);
-	ASSERT(!memcmp(node->var->key, key, 4))	// should be at end
+	var = list_tail(&update_bank, struct secvar, link);
+	ASSERT(!memcmp(var->key, key, 4))	// should be at end
 
 	// Unstage the variable update
 	rc = secvar_enqueue(key, 4, NULL, 0);
diff --git a/libstb/secvar/test/secvar-test-getvar.c b/libstb/secvar/test/secvar-test-getvar.c
index 53885ea1..a2e06681 100644
--- a/libstb/secvar/test/secvar-test-getvar.c
+++ b/libstb/secvar/test/secvar-test-getvar.c
@@ -14,32 +14,25 @@ int run_test(void)
 {
 	int64_t rc;
 
-	uint64_t size = 4;
+	uint64_t size;
 	char *temp = zalloc(100);
 	char key[1024] = {0};
 
-	struct secvar_node *node = zalloc(sizeof(struct secvar_node));
-	struct secvar *var = zalloc(sizeof(struct secvar) + 1024); // over-allocate for now, this should be rewritten
+	struct secvar *var;
 	size_t data_size = sizeof("foobar");
 	char *data = zalloc(data_size);
 	uint64_t key_len = 4;
 	memcpy(data, "foobar", data_size);
-
 	memcpy(key, "test", 4);
 
 	// List should be empty at start
-	rc = secvar_get(key, key_len, data, &data_size);
+	rc = secvar_get(key, key_len, temp, &size);
 	ASSERT(rc == OPAL_EMPTY);
 	ASSERT(list_length(&variable_bank) == 0);
 
 	// Manually add variables, and check get_variable call
-	var->key_len = key_len;
-	memcpy(var->key, key, key_len);
-	var->data_size = data_size;
-	memcpy(var->data, data, data_size);
-
-	node->var = var;
-	list_add_tail(&variable_bank, &node->link);
+	var = new_secvar(key, key_len, data, data_size, 0);
+	list_add_tail(&variable_bank, &var->link);
 
 	ASSERT(list_length(&variable_bank) == 1);
 
@@ -88,10 +81,6 @@ int run_test(void)
 	ASSERT(rc == OPAL_RESOURCE);
 	secvar_ready = 1;
 
-	list_del(&node->link);
-
-	free(var);
-	free(node);
 	free(data);
 	free(temp);
 
diff --git a/libstb/secvar/test/secvar-test-nextvar.c b/libstb/secvar/test/secvar-test-nextvar.c
index 0b3dea45..dcd9e9d5 100644
--- a/libstb/secvar/test/secvar-test-nextvar.c
+++ b/libstb/secvar/test/secvar-test-nextvar.c
@@ -10,37 +10,23 @@ int run_test(void)
 	int64_t rc;
 
 	struct secvar *tmpvar;
-	struct secvar_node *tmpnode;
 
 	char key[1024] = {0};
 	uint64_t key_len = 16;
 
-
 	// Load up the bank with some variables.
 	// If these fail, we have bigger issues.
 	ASSERT(list_length(&variable_bank) == 0);
-	tmpvar = zalloc(sizeof(struct secvar) + 6);
-	tmpnode = zalloc(sizeof(struct secvar_node));
-	memcpy(tmpvar->key, "test1", 6); // ascii w/ null
-	tmpvar->key_len = 6;
-	tmpnode->var = tmpvar;
-	list_add_tail(&variable_bank, &tmpnode->link);
+	tmpvar = new_secvar("test1", 6, NULL, 0, 0);
+	list_add_tail(&variable_bank, &tmpvar->link);
 	ASSERT(list_length(&variable_bank) == 1);
 
-	tmpvar = zalloc(sizeof(struct secvar) + 5);
-	tmpnode = zalloc(sizeof(struct secvar_node));
-	memcpy(tmpvar->key, "test2", 5); // ascii w/o null
-	tmpvar->key_len = 5;
-	tmpnode->var = tmpvar;
-	list_add_tail(&variable_bank, &tmpnode->link);
+	tmpvar = new_secvar("test2", 5, NULL, 0, 0);  // ascii w/o null
+	list_add_tail(&variable_bank, &tmpvar->link);
 	ASSERT(list_length(&variable_bank) == 2);
 
-	tmpvar = zalloc(sizeof(struct secvar) + 5*2);
-	tmpnode = zalloc(sizeof(struct secvar_node));
-	memcpy(tmpvar->key, L"test3", 5*2); // wide char "unicode"
-	tmpvar->key_len = 10;
-	tmpnode->var = tmpvar;
-	list_add_tail(&variable_bank, &tmpnode->link);
+	tmpvar = new_secvar((const char*) L"test3", 5*2, NULL, 0, 0); // wide char "unicode"
+	list_add_tail(&variable_bank, &tmpvar->link);
 	ASSERT(list_length(&variable_bank) == 3);
 
 	// Test sequential nexts
-- 
2.21.1



More information about the Skiboot mailing list