diff mbox

[2/2] uefirtvariable: add stress test for UEFI runtime interface GetNextVariableName

Message ID 1356595611-24199-1-git-send-email-ivan.hu@canonical.com
State Accepted
Headers show

Commit Message

Ivan Hu Dec. 27, 2012, 8:06 a.m. UTC
This stress test tests the UEFI runtime interface GetNextVariableName by
calling multiple times.

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

Comments

Colin Ian King Dec. 27, 2012, 7:53 p.m. UTC | #1
On 27/12/12 08:06, Ivan Hu wrote:
> This stress test tests the UEFI runtime interface GetNextVariableName by
> calling multiple times.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   src/uefi/uefirtvariable/uefirtvariable.c |   84 ++++++++++++++++++++++++++++++
>   1 file changed, 84 insertions(+)
>
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index a8b9326..73d1049 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -718,6 +718,85 @@ static int do_queryvariableinfo(uint64_t *status, uint64_t *remvarstoragesize, u
>   	return FWTS_OK;
>   }
>
> +static int getnextvariable_multitest(fwts_framework *fw, uint32_t multitesttime)
> +{
> +	long ioret;
> +	uint64_t status;
> +	uint32_t i;
> +
> +	struct efi_setvariable setvariable;
> +
> +	uint64_t dataindex, datasize = 10;
> +	uint8_t data[MAX_DATA_LENGTH];
> +
> +	struct efi_getnextvariablename getnextvariablename;
> +	uint64_t variablenamesize = MAX_DATA_LENGTH;
> +	uint16_t variablename[MAX_DATA_LENGTH];
> +	EFI_GUID vendorguid;
> +
> +	for (dataindex = 0; dataindex < datasize; dataindex++)
> +		data[dataindex] = (uint8_t)dataindex;
> +	data[dataindex] = '\0';
> +
> +	setvariable.VariableName = variablenametest;
> +	setvariable.VendorGuid = &gtestguid1;
> +	setvariable.Attributes = attributes;
> +	setvariable.DataSize = datasize;
> +	setvariable.Data = data;
> +	setvariable.status = &status;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to set variable with UEFI runtime service.");
> +		return FWTS_ERROR;
> +	}
> +
> +	getnextvariablename.VariableNameSize = &variablenamesize;
> +	getnextvariablename.VariableName = variablename;
> +	getnextvariablename.VendorGuid = &vendorguid;
> +	getnextvariablename.status = &status;
> +
> +	for (i = 0; i < multitesttime; i++) {
> +		variablename[0] = '\0';
> +		variablenamesize = MAX_DATA_LENGTH;
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
> +
> +		if (ioret == -1) {
> +			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName",
> +				"Failed to get next variable name with UEFI runtime service.");
> +			goto err_restore_env;
> +		}
> +	};
> +
> +	setvariable.DataSize = 0;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to set variable with UEFI runtime service.");
> +		return FWTS_ERROR;
> +	}
> +
> +	return FWTS_OK;
> +
> +err_restore_env:
> +
> +	setvariable.DataSize = 0;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to delete variable with UEFI runtime service.");
> +	}
> +
> +	return FWTS_ERROR;
> +}
> +
> +
>   static int uefirtvariable_test1(fwts_framework *fw)
>   {
>   	uint64_t datasize = 10;
> @@ -813,6 +892,11 @@ static int uefirtvariable_test5(fwts_framework *fw)
>   		return FWTS_ERROR;
>   	fwts_passed(fw, "GetVariable on getting the variable multiple times passed.");
>
> +	fwts_log_info(fw, "Testing GetNextVariableName on getting the variable multiple times.");
> +	if (getnextvariable_multitest(fw, multitesttime) == FWTS_ERROR)
> +		return FWTS_ERROR;
> +	fwts_passed(fw, "GetNextVariableName on getting the next variable name multiple times passed.");
> +
>   	return FWTS_OK;
>
>   }
>
Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung Jan. 2, 2013, 3:13 a.m. UTC | #2
On 12/27/2012 04:06 PM, Ivan Hu wrote:
> This stress test tests the UEFI runtime interface GetNextVariableName by
> calling multiple times.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   src/uefi/uefirtvariable/uefirtvariable.c |   84 ++++++++++++++++++++++++++++++
>   1 file changed, 84 insertions(+)
>
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index a8b9326..73d1049 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -718,6 +718,85 @@ static int do_queryvariableinfo(uint64_t *status, uint64_t *remvarstoragesize, u
>   	return FWTS_OK;
>   }
>
> +static int getnextvariable_multitest(fwts_framework *fw, uint32_t multitesttime)
> +{
> +	long ioret;
> +	uint64_t status;
> +	uint32_t i;
> +
> +	struct efi_setvariable setvariable;
> +
> +	uint64_t dataindex, datasize = 10;
> +	uint8_t data[MAX_DATA_LENGTH];
> +
> +	struct efi_getnextvariablename getnextvariablename;
> +	uint64_t variablenamesize = MAX_DATA_LENGTH;
> +	uint16_t variablename[MAX_DATA_LENGTH];
> +	EFI_GUID vendorguid;
> +
> +	for (dataindex = 0; dataindex < datasize; dataindex++)
> +		data[dataindex] = (uint8_t)dataindex;
> +	data[dataindex] = '\0';
> +
> +	setvariable.VariableName = variablenametest;
> +	setvariable.VendorGuid = &gtestguid1;
> +	setvariable.Attributes = attributes;
> +	setvariable.DataSize = datasize;
> +	setvariable.Data = data;
> +	setvariable.status = &status;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to set variable with UEFI runtime service.");
> +		return FWTS_ERROR;
> +	}
> +
> +	getnextvariablename.VariableNameSize = &variablenamesize;
> +	getnextvariablename.VariableName = variablename;
> +	getnextvariablename.VendorGuid = &vendorguid;
> +	getnextvariablename.status = &status;
> +
> +	for (i = 0; i < multitesttime; i++) {
> +		variablename[0] = '\0';
> +		variablenamesize = MAX_DATA_LENGTH;
> +		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
> +
> +		if (ioret == -1) {
> +			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName",
> +				"Failed to get next variable name with UEFI runtime service.");
> +			goto err_restore_env;
> +		}
> +	};
> +
> +	setvariable.DataSize = 0;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to set variable with UEFI runtime service.");
> +		return FWTS_ERROR;
> +	}
> +
> +	return FWTS_OK;
> +
> +err_restore_env:
> +
> +	setvariable.DataSize = 0;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
> +
> +	if (ioret == -1) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +			"Failed to delete variable with UEFI runtime service.");
> +	}
> +
> +	return FWTS_ERROR;
> +}
> +
> +
>   static int uefirtvariable_test1(fwts_framework *fw)
>   {
>   	uint64_t datasize = 10;
> @@ -813,6 +892,11 @@ static int uefirtvariable_test5(fwts_framework *fw)
>   		return FWTS_ERROR;
>   	fwts_passed(fw, "GetVariable on getting the variable multiple times passed.");
>
> +	fwts_log_info(fw, "Testing GetNextVariableName on getting the variable multiple times.");
> +	if (getnextvariable_multitest(fw, multitesttime) == FWTS_ERROR)
> +		return FWTS_ERROR;
> +	fwts_passed(fw, "GetNextVariableName on getting the next variable name multiple times passed.");
> +
>   	return FWTS_OK;
>
>   }
>
Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index a8b9326..73d1049 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -718,6 +718,85 @@  static int do_queryvariableinfo(uint64_t *status, uint64_t *remvarstoragesize, u
 	return FWTS_OK;
 }
 
+static int getnextvariable_multitest(fwts_framework *fw, uint32_t multitesttime)
+{
+	long ioret;
+	uint64_t status;
+	uint32_t i;
+
+	struct efi_setvariable setvariable;
+
+	uint64_t dataindex, datasize = 10;
+	uint8_t data[MAX_DATA_LENGTH];
+
+	struct efi_getnextvariablename getnextvariablename;
+	uint64_t variablenamesize = MAX_DATA_LENGTH;
+	uint16_t variablename[MAX_DATA_LENGTH];
+	EFI_GUID vendorguid;
+
+	for (dataindex = 0; dataindex < datasize; dataindex++)
+		data[dataindex] = (uint8_t)dataindex;
+	data[dataindex] = '\0';
+
+	setvariable.VariableName = variablenametest;
+	setvariable.VendorGuid = &gtestguid1;
+	setvariable.Attributes = attributes;
+	setvariable.DataSize = datasize;
+	setvariable.Data = data;
+	setvariable.status = &status;
+
+	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	if (ioret == -1) {
+		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
+			"Failed to set variable with UEFI runtime service.");
+		return FWTS_ERROR;
+	}
+
+	getnextvariablename.VariableNameSize = &variablenamesize;
+	getnextvariablename.VariableName = variablename;
+	getnextvariablename.VendorGuid = &vendorguid;
+	getnextvariablename.status = &status;
+
+	for (i = 0; i < multitesttime; i++) {
+		variablename[0] = '\0';
+		variablenamesize = MAX_DATA_LENGTH;
+		ioret = ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename);
+
+		if (ioret == -1) {
+			fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVariableName",
+				"Failed to get next variable name with UEFI runtime service.");
+			goto err_restore_env;
+		}
+	};
+
+	setvariable.DataSize = 0;
+
+	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	if (ioret == -1) {
+		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
+			"Failed to set variable with UEFI runtime service.");
+		return FWTS_ERROR;
+	}
+
+	return FWTS_OK;
+
+err_restore_env:
+
+	setvariable.DataSize = 0;
+
+	ioret = ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable);
+
+	if (ioret == -1) {
+		fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
+			"Failed to delete variable with UEFI runtime service.");
+	}
+
+	return FWTS_ERROR;
+}
+
+
 static int uefirtvariable_test1(fwts_framework *fw)
 {
 	uint64_t datasize = 10;
@@ -813,6 +892,11 @@  static int uefirtvariable_test5(fwts_framework *fw)
 		return FWTS_ERROR;
 	fwts_passed(fw, "GetVariable on getting the variable multiple times passed.");
 
+	fwts_log_info(fw, "Testing GetNextVariableName on getting the variable multiple times.");
+	if (getnextvariable_multitest(fw, multitesttime) == FWTS_ERROR)
+		return FWTS_ERROR;
+	fwts_passed(fw, "GetNextVariableName on getting the next variable name multiple times passed.");
+
 	return FWTS_OK;
 
 }