[PATCH 2/2] fwts: uefi: clean up all test variable before doing the uefirtvariable test (LP: #1313554)

Ivan Hu ivan.hu at canonical.com
Mon Apr 28 08:07:03 UTC 2014


Try to delete all the test variables that used by the uefirtvariable test,
before doing the uefirtvariable tests. Make sure there are no preexisting
test variables that cause the the uefirtvariable test fail, when the
variable tests accidentally stopped, terminated by the buggy firmware, power
fail etc.

Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c |   31 ++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index 6e40542..7ddfeb1 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -59,6 +59,33 @@ static uint32_t attributes =
 	FWTS_UEFI_VAR_BOOTSERVICE_ACCESS |
 	FWTS_UEFI_VAR_RUNTIME_ACCESS;
 static uint16_t variablenametest[] = {'T', 'e', 's', 't', 'v', 'a', 'r', '\0'};
+static uint16_t variablenametest2[] = {'T', 'e', 's', 't', 'v', 'a', 'r', ' ', '\0'};
+static uint16_t variablenametest3[] = {'T', 'e', 's', 't', 'v', 'a', '\0'};
+
+static void uefirtvariable_env_cleanup(void)
+{
+	struct efi_setvariable setvariable;
+	uint64_t status;
+	uint8_t data = 0;
+
+	setvariable.VariableName = variablenametest;
+	setvariable.VendorGuid = &gtestguid1;
+	setvariable.Attributes = 0;
+	setvariable.DataSize = 0;
+	setvariable.Data = &data;
+	setvariable.status = &status;
+	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	setvariable.VariableName = variablenametest2;
+	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	setvariable.VariableName = variablenametest3;
+	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	setvariable.VariableName = variablenametest;
+	setvariable.VendorGuid = &gtestguid2;
+	ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+}
 
 static int uefirtvariable_init(fwts_framework *fw)
 {
@@ -78,6 +105,8 @@ static int uefirtvariable_init(fwts_framework *fw)
 		return FWTS_ABORTED;
 	}
 
+	uefirtvariable_env_cleanup();
+
 	return FWTS_OK;
 }
 
@@ -1044,8 +1073,6 @@ static int setvariable_test3(fwts_framework *fw)
 	int ret;
 	uint64_t datasize = 10;
 	uint8_t datadiff1 = 0, datadiff2 = 1, datadiff3 = 2;
-	uint16_t variablenametest2[] = {'T', 'e', 's', 't', 'v', 'a', 'r', ' ', '\0'};
-	uint16_t variablenametest3[] = {'T', 'e', 's', 't', 'v', 'a', '\0'};
 
 	ret = setvariable_insertvariable(fw, attributes, datasize,
 		variablenametest2, &gtestguid1, datadiff2);
-- 
1.7.9.5




More information about the fwts-devel mailing list