diff mbox

[4/5] uefirtvariable: Add new test for UEFI runtime SetVariable, subtest 4

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

Commit Message

Ivan Hu Dec. 5, 2012, 11 a.m. UTC
This test tests the UEFI runtime service SetVariable interface.
SetVariable when the DataSize is 0. The expected return status
is EFI_NOT_FOUND.

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

Comments

Colin Ian King Dec. 5, 2012, 11:35 a.m. UTC | #1
On 05/12/12 11:00, Ivan Hu wrote:
> This test tests the UEFI runtime service SetVariable interface.
> SetVariable when the DataSize is 0. The expected return status
> is EFI_NOT_FOUND.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   src/uefi/uefirtvariable/uefirtvariable.c |   54 ++++++++++++++++++++++++++++++
>   1 file changed, 54 insertions(+)
>
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index b828ccc..3c50059 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -374,6 +374,36 @@ static int setvariable_checkvariable(fwts_framework *fw, uint32_t attributes, ui
>   	return FWTS_OK;
>   }
>
> +static int setvariable_checkvariable_notfound(fwts_framework *fw, uint16_t *varname, EFI_GUID *gtestguid)
> +{
> +	long ioret;
> +	struct efi_getvariable getvariable;
> +
> +	uint64_t status;
> +	uint8_t testdata[MAX_DATA_LENGTH];
> +	uint64_t getdatasize;
> +	uint32_t attributestest;
> +
> +	getvariable.VariableName = varname;
> +	getvariable.VendorGuid = gtestguid;
> +	getvariable.Attributes = &attributestest;
> +	getvariable.DataSize = &getdatasize;
> +	getvariable.Data = testdata;
> +	getvariable.status = &status;
> +
> +	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
> +
> +	/* expect the uefi runtime interface return EFI_NOT_FOUND */
> +	if (ioret == -1) {
> +		if (*getvariable.status == EFI_NOT_FOUND)
> +			return FWTS_OK;
> +	}
> +	fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +		"Failed to set variable with UEFI runtime service., "
> +		"expect the status return EFI_NOT_FOUND.");
> +	return FWTS_ERROR;
> +}
> +
>   static int setvariable_test1(fwts_framework *fw, uint32_t attributes, uint64_t datasize1,
>   							uint64_t datasize2, uint16_t *varname)
>   {
> @@ -507,6 +537,25 @@ static int setvariable_test3(fwts_framework *fw, uint32_t attributes)
>   	return FWTS_OK;
>   }
>
> +static int setvariable_test4(fwts_framework *fw, uint32_t attributes)
> +{
> +	uint64_t datasize = 10;
> +	uint8_t datadiff = 0;
> +
> +	if (setvariable_insertvariable(fw, attributes, datasize, variablenametest,
> +						&gtestguid1, datadiff) == FWTS_ERROR)
> +		return FWTS_ERROR;
> +
> +	if (setvariable_insertvariable(fw, attributes, 0, variablenametest,
> +						&gtestguid1, datadiff) == FWTS_ERROR)
> +		return FWTS_ERROR;
> +
> +	if (setvariable_checkvariable_notfound(fw, variablenametest, &gtestguid1) == FWTS_ERROR)
> +		return FWTS_ERROR;
> +
> +	return FWTS_OK;
> +}
> +
>   static int uefirtvariable_test1(fwts_framework *fw)
>   {
>   	uint64_t index;
> @@ -557,6 +606,11 @@ static int uefirtvariable_test3(fwts_framework *fw)
>   			return FWTS_ERROR;
>   	}
>
> +	for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
> +		if (setvariable_test4(fw, attributesarray[index]) == FWTS_ERROR)
> +			return FWTS_ERROR;
> +	}
> +
>   	fwts_passed(fw, "UEFI runtime service SetVariable interface test passed.");
>
>   	return FWTS_OK;
>
Acked-by: Colin King <colin.king@canonical.com>
Keng-Yu Lin Dec. 10, 2012, 8:02 a.m. UTC | #2
On Wed, Dec 5, 2012 at 7:00 PM, Ivan Hu <ivan.hu@canonical.com> wrote:
> This test tests the UEFI runtime service SetVariable interface.
> SetVariable when the DataSize is 0. The expected return status
> is EFI_NOT_FOUND.
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/uefi/uefirtvariable/uefirtvariable.c |   54 ++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
>
> diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
> index b828ccc..3c50059 100644
> --- a/src/uefi/uefirtvariable/uefirtvariable.c
> +++ b/src/uefi/uefirtvariable/uefirtvariable.c
> @@ -374,6 +374,36 @@ static int setvariable_checkvariable(fwts_framework *fw, uint32_t attributes, ui
>         return FWTS_OK;
>  }
>
> +static int setvariable_checkvariable_notfound(fwts_framework *fw, uint16_t *varname, EFI_GUID *gtestguid)
> +{
> +       long ioret;
> +       struct efi_getvariable getvariable;
> +
> +       uint64_t status;
> +       uint8_t testdata[MAX_DATA_LENGTH];
> +       uint64_t getdatasize;
> +       uint32_t attributestest;
> +
> +       getvariable.VariableName = varname;
> +       getvariable.VendorGuid = gtestguid;
> +       getvariable.Attributes = &attributestest;
> +       getvariable.DataSize = &getdatasize;
> +       getvariable.Data = testdata;
> +       getvariable.status = &status;
> +
> +       ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
> +
> +       /* expect the uefi runtime interface return EFI_NOT_FOUND */
> +       if (ioret == -1) {
> +               if (*getvariable.status == EFI_NOT_FOUND)
> +                       return FWTS_OK;
> +       }
> +       fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
> +               "Failed to set variable with UEFI runtime service., "
> +               "expect the status return EFI_NOT_FOUND.");
> +       return FWTS_ERROR;
> +}
> +
>  static int setvariable_test1(fwts_framework *fw, uint32_t attributes, uint64_t datasize1,
>                                                         uint64_t datasize2, uint16_t *varname)
>  {
> @@ -507,6 +537,25 @@ static int setvariable_test3(fwts_framework *fw, uint32_t attributes)
>         return FWTS_OK;
>  }
>
> +static int setvariable_test4(fwts_framework *fw, uint32_t attributes)
> +{
> +       uint64_t datasize = 10;
> +       uint8_t datadiff = 0;
> +
> +       if (setvariable_insertvariable(fw, attributes, datasize, variablenametest,
> +                                               &gtestguid1, datadiff) == FWTS_ERROR)
> +               return FWTS_ERROR;
> +
> +       if (setvariable_insertvariable(fw, attributes, 0, variablenametest,
> +                                               &gtestguid1, datadiff) == FWTS_ERROR)
> +               return FWTS_ERROR;
> +
> +       if (setvariable_checkvariable_notfound(fw, variablenametest, &gtestguid1) == FWTS_ERROR)
> +               return FWTS_ERROR;
> +
> +       return FWTS_OK;
> +}
> +
>  static int uefirtvariable_test1(fwts_framework *fw)
>  {
>         uint64_t index;
> @@ -557,6 +606,11 @@ static int uefirtvariable_test3(fwts_framework *fw)
>                         return FWTS_ERROR;
>         }
>
> +       for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
> +               if (setvariable_test4(fw, attributesarray[index]) == FWTS_ERROR)
> +                       return FWTS_ERROR;
> +       }
> +
>         fwts_passed(fw, "UEFI runtime service SetVariable interface test passed.");
>
>         return FWTS_OK;
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index b828ccc..3c50059 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -374,6 +374,36 @@  static int setvariable_checkvariable(fwts_framework *fw, uint32_t attributes, ui
 	return FWTS_OK;
 }
 
+static int setvariable_checkvariable_notfound(fwts_framework *fw, uint16_t *varname, EFI_GUID *gtestguid)
+{
+	long ioret;
+	struct efi_getvariable getvariable;
+
+	uint64_t status;
+	uint8_t testdata[MAX_DATA_LENGTH];
+	uint64_t getdatasize;
+	uint32_t attributestest;
+
+	getvariable.VariableName = varname;
+	getvariable.VendorGuid = gtestguid;
+	getvariable.Attributes = &attributestest;
+	getvariable.DataSize = &getdatasize;
+	getvariable.Data = testdata;
+	getvariable.status = &status;
+
+	ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable);
+
+	/* expect the uefi runtime interface return EFI_NOT_FOUND */
+	if (ioret == -1) {
+		if (*getvariable.status == EFI_NOT_FOUND)
+			return FWTS_OK;
+	}
+	fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable",
+		"Failed to set variable with UEFI runtime service., "
+		"expect the status return EFI_NOT_FOUND.");
+	return FWTS_ERROR;
+}
+
 static int setvariable_test1(fwts_framework *fw, uint32_t attributes, uint64_t datasize1,
 							uint64_t datasize2, uint16_t *varname)
 {
@@ -507,6 +537,25 @@  static int setvariable_test3(fwts_framework *fw, uint32_t attributes)
 	return FWTS_OK;
 }
 
+static int setvariable_test4(fwts_framework *fw, uint32_t attributes)
+{
+	uint64_t datasize = 10;
+	uint8_t datadiff = 0;
+
+	if (setvariable_insertvariable(fw, attributes, datasize, variablenametest,
+						&gtestguid1, datadiff) == FWTS_ERROR)
+		return FWTS_ERROR;
+
+	if (setvariable_insertvariable(fw, attributes, 0, variablenametest,
+						&gtestguid1, datadiff) == FWTS_ERROR)
+		return FWTS_ERROR;
+
+	if (setvariable_checkvariable_notfound(fw, variablenametest, &gtestguid1) == FWTS_ERROR)
+		return FWTS_ERROR;
+
+	return FWTS_OK;
+}
+
 static int uefirtvariable_test1(fwts_framework *fw)
 {
 	uint64_t index;
@@ -557,6 +606,11 @@  static int uefirtvariable_test3(fwts_framework *fw)
 			return FWTS_ERROR;
 	}
 
+	for (index = 0; index < (sizeof(attributesarray)/(sizeof attributesarray[0])); index++) {
+		if (setvariable_test4(fw, attributesarray[index]) == FWTS_ERROR)
+			return FWTS_ERROR;
+	}
+
 	fwts_passed(fw, "UEFI runtime service SetVariable interface test passed.");
 
 	return FWTS_OK;