blob: d541424046edb855868f5cfecadda7681ed46d65 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/efi/testing/stub_runtime_services.h>
#include <stdio.h>
#include <numeric>
#include <string>
#include <string_view>
#include <efi/protocol/block-io.h>
#include <fbl/vector.h>
#include <gtest/gtest.h>
#include "gmock/gmock.h"
namespace efi {
namespace {
using ::testing::_;
using ::testing::ElementsAreArray;
using ::testing::Return;
using ::testing::StartsWith;
using ::testing::UnorderedElementsAreArray;
// Creating a second is OK as long as the first has gone out of scope.
TEST(StubRuntimeServices, CreateTwice) {
StubRuntimeServices();
StubRuntimeServices();
}
// Creating a second while the first is still up is a fatal error.
TEST(StubRuntimeServicesTest, CreateDuplicate) {
StubRuntimeServices stub;
ASSERT_DEATH(StubRuntimeServices(), "");
}
TEST(StubRuntimeServicesTest, NoVariablesSet) {
StubRuntimeServices stub;
char16_t buf[] = u"";
size_t buf_size = 1;
efi_guid vendor_guid = {};
uint32_t attr = 0;
uint8_t data[] = {0x00};
size_t data_size = 1;
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_UNSUPPORTED);
EXPECT_EQ(stub.GetVariable(buf, &vendor_guid, &attr, &data_size, data), EFI_UNSUPPORTED);
}
TEST(StubRuntimeServicesTest, SomeVariablesReturnCorrectErrors) {
StubRuntimeServices stub;
char16_t buf[] = u"";
size_t buf_size = sizeof(buf);
efi_guid vendor_guid = {};
uint32_t attr = 0;
uint8_t data[] = {0x00};
size_t data_size = 1;
char16_t test_var_name[] = u"test";
stub.SetVariables({});
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_NOT_FOUND);
EXPECT_EQ(stub.GetVariable(test_var_name, &vendor_guid, &attr, &data_size, data), EFI_NOT_FOUND);
}
TEST(StubRuntimeServicesTest, SomeVariablesSetAskForBiggerBuffer) {
StubRuntimeServices stub;
char16_t buf[] = u"";
size_t buf_size = sizeof(buf);
efi_guid vendor_guid = {};
uint32_t attr = 0;
uint8_t data[] = {0x00};
size_t data_size = sizeof(data);
std::u16string test_var_name = u"test";
fbl::Vector<uint8_t> test_var_val{0x00, 0x01};
stub.SetVariables({{{String(test_var_name), vendor_guid}, Copy(test_var_val)}});
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_BUFFER_TOO_SMALL);
EXPECT_EQ(buf_size, (test_var_name.size() + 1) * sizeof(test_var_name[0]));
EXPECT_EQ(
stub.GetVariable((char16_t*)test_var_name.c_str(), &vendor_guid, &attr, &data_size, data),
EFI_BUFFER_TOO_SMALL);
EXPECT_EQ(data_size, test_var_val.size());
}
TEST(StubRuntimeServicesTest, GetOneVariable) {
StubRuntimeServices stub;
efi_guid vendor_guid = {};
uint32_t attr = 0;
uint8_t data[2];
size_t data_size = sizeof(data);
std::u16string test_var_name(u"test");
char16_t buf[5] = {0x0000};
size_t buf_size = sizeof(buf);
VariableValue test_var_val{0x00, 0x01};
stub.SetVariables({{{String(test_var_name), vendor_guid}, Copy(test_var_val)}});
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_SUCCESS);
EXPECT_EQ(buf_size, (test_var_name.size() + 1) * sizeof(test_var_name[0]));
EXPECT_EQ(buf, test_var_name);
EXPECT_EQ(
stub.GetVariable((char16_t*)test_var_name.c_str(), &vendor_guid, &attr, &data_size, data),
EFI_SUCCESS);
EXPECT_EQ(data_size, test_var_val.size());
EXPECT_THAT(data, ElementsAreArray(test_var_val));
}
TEST(StubRuntimeServicesTest, GetOneVariableAfterSmallBuffer) {
StubRuntimeServices stub;
efi_guid vendor_guid = {};
uint32_t attr = 0;
uint8_t data[2];
size_t data_size = 0;
std::u16string test_var_name(u"test");
char16_t buf[5] = {0x0000};
size_t buf_size = sizeof(buf[0]);
VariableValue test_var_val{0x00, 0x01};
stub.SetVariables({{{String(test_var_name), vendor_guid}, Copy(test_var_val)}});
// Small buffer fails
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_BUFFER_TOO_SMALL);
// Big buffer succeeds
buf_size = sizeof(buf);
EXPECT_EQ(stub.GetNextVariableName(&buf_size, buf, &vendor_guid), EFI_SUCCESS);
// Small buffer fails
EXPECT_EQ(
stub.GetVariable((char16_t*)test_var_name.c_str(), &vendor_guid, &attr, &data_size, data),
EFI_BUFFER_TOO_SMALL);
// Big buffer succeeds
data_size = sizeof(data);
EXPECT_EQ(
stub.GetVariable((char16_t*)test_var_name.c_str(), &vendor_guid, &attr, &data_size, data),
EFI_SUCCESS);
EXPECT_THAT(data, ElementsAreArray(test_var_val));
}
TEST(StubRuntimeServicesTest, GetAllVariableNames) {
StubRuntimeServices stub;
char16_t buf[128] = {0x0000};
size_t buf_size = sizeof(buf);
efi_guid vendor_guid = {};
std::list<Variable> test_vars{
{{String(u"var_1"), vendor_guid}, {0x00}},
{{String(u"var_2"), vendor_guid}, {0x00, 0x01}},
{{String(u"abcDEF123!@#Δ☹☼"), vendor_guid}, {0x01, 0x02, 0x03}},
{{String(u"\xfeff"), vendor_guid}, {0xff, 0xf1, 0xf2, 0xf3}},
{{String(u"var_3"), vendor_guid}, {0x00}},
};
std::list<efi::VariableId> expected_var_names;
std::transform(test_vars.begin(), test_vars.end(), std::back_inserter(expected_var_names),
[](const auto& it) { return it.id; });
stub.SetVariables(test_vars);
std::list<VariableId> processed;
efi_status res;
do {
// Big buffer succeeds
buf_size = sizeof(buf);
res = stub.GetNextVariableName(&buf_size, buf, &vendor_guid);
if (EFI_ERROR(res))
break;
processed.emplace_back(VariableId{String(buf), vendor_guid});
} while (true);
EXPECT_THAT(processed, UnorderedElementsAreArray(expected_var_names));
}
TEST(StubRuntimeServicesTest, DifferentGuidSameVariableName) {
StubRuntimeServices stub;
char16_t buf[128] = {0x0000};
size_t buf_size = sizeof(buf);
efi_guid vendor_guid = {};
std::list<Variable> test_vars{
{{String(u"var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x01, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x01, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x02, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00}}},
{0x00}},
{{String("var_1"), {0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a}}},
{0x00}},
};
std::list<VariableId> expected_var_names;
std::transform(test_vars.begin(), test_vars.end(), std::back_inserter(expected_var_names),
[](const auto& it) { return it.id; });
stub.SetVariables(test_vars);
std::list<VariableId> processed;
efi_status res;
do {
// Big buffer succeeds
buf_size = sizeof(buf);
res = stub.GetNextVariableName(&buf_size, buf, &vendor_guid);
if (EFI_ERROR(res))
break;
processed.emplace_back(VariableId{String(buf), vendor_guid});
} while (true);
EXPECT_THAT(processed, UnorderedElementsAreArray(expected_var_names));
}
TEST(StubRuntimeServicesTest, GetCorrectVariableValue) {
StubRuntimeServices stub;
uint8_t buf[128] = {0x00};
size_t buf_size = sizeof(buf);
uint32_t attr = 0;
efi_guid vendor_guid = {};
std::list<Variable> test_vars{
{{String(u"var_1"), vendor_guid}, {0x00}},
{{String(u"var_2"), vendor_guid}, {0x00, 0x01}},
{{String(u"var_3"), vendor_guid}, {0xff, 0xff, 0xff}},
};
stub.SetVariables(test_vars);
for (auto& it : test_vars) {
buf_size = sizeof(buf);
EXPECT_EQ(stub.GetVariable(const_cast<char16_t*>(std::u16string_view(it.id.name).data()),
&it.id.vendor_guid, &attr, &buf_size, buf),
EFI_SUCCESS);
ASSERT_EQ(buf_size, it.value.size());
EXPECT_THAT(std::vector<uint8_t>(&buf[0], &buf[buf_size]), ElementsAreArray(it.value));
}
}
class EfiGuidFixture : public ::testing::TestWithParam<std::list<efi_guid>> {};
TEST_P(EfiGuidFixture, Eq) {
std::list<efi_guid> input = GetParam();
for (const auto& a : input) {
EXPECT_EQ(a, a);
}
}
TEST_P(EfiGuidFixture, Ne) {
std::list<efi_guid> input = GetParam();
for (auto a = input.begin(); a != input.end(); a++) {
for (auto b = std::next(a); b != input.end(); b++) {
EXPECT_NE(*a, *b);
}
}
}
TEST_P(EfiGuidFixture, Lt) {
std::list<efi_guid> input = GetParam();
for (auto a = input.begin(); a != input.end(); a++) {
for (auto b = std::next(a); b != input.end(); b++) {
EXPECT_LT(*a, *b);
}
}
}
INSTANTIATE_TEST_SUITE_P(
EfiGuidTest, EfiGuidFixture,
::testing::Values(std::list<efi_guid>{
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0100, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0001, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0100, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00010000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000100, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000001, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x01020304, 0x0506, 0x0708, {0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}},
{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xee}},
{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0xf1234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0x1fffffff, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0xffffffff, 0xffff, 0xffff, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
}));
TEST(EfiGuid, Equal) {
const std::vector<efi_guid> guids = {
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x01020304, 0x0506, 0x0708, {0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}},
{0xffffffff, 0xffff, 0xffff, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}},
};
for (auto& it : guids) {
EXPECT_EQ(it, it);
}
}
TEST(EfiGuid, NotEqual) {
const std::vector<std::pair<efi_guid, efi_guid>> guids = {
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00010000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000100, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000001, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0100, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0100, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0001, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}},
{{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xee}}},
{{0xf1234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}},
};
for (auto& it : guids) {
EXPECT_NE(it.first, it.second);
}
}
TEST(EfiGuid, LessThan) {
const std::vector<std::pair<efi_guid, efi_guid>> guids = {
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00010000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000100, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000001, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0100, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0100, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0001, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}}},
{{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}},
{{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xee}},
{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}},
{{0x01234567, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}},
{0x1fffffff, 0x89ab, 0xcdef, {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}},
};
for (auto& it : guids) {
EXPECT_LT(it.first, it.second);
}
}
TEST(VariableName, LessThan) {
const struct efi_guid some_guid = {
0x00010203, 0x0405, 0x0607, {0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}};
const std::vector<std::pair<VariableId, VariableId>> variable_names = {
{{String(u""),
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{String(u""),
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}},
{{String(u"a"),
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{String(u"a"),
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}},
{{String(u"a"),
{0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}},
{String(u"b"),
{0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}}},
{{String(u"a1"), some_guid}, {String(u"a2"), some_guid}},
{{String(u""), some_guid}, {String(u"a"), some_guid}},
{{String(u""), some_guid}, {String(u"a"), some_guid}},
{{String(u"abcDEF123!@#Δ☹☼1"), some_guid}, {String(u"abcDEF123!@#Δ☹☼2"), some_guid}},
{{String(u"abc"), some_guid}, {String(u"abcDEF123!@#Δ☹☼"), some_guid}},
{{String(u""), some_guid}, {String(u"abcDEF123!@#Δ☹☼"), some_guid}},
};
for (auto& it : variable_names) {
EXPECT_LT(it.first, it.second);
}
}
class VariableNameFixture : public ::testing::TestWithParam<std::list<VariableId>> {};
TEST_P(VariableNameFixture, Eq) {
std::list<VariableId> input = GetParam();
for (const auto& a : input) {
EXPECT_EQ(a, a);
}
}
TEST_P(VariableNameFixture, Ne) {
std::list<VariableId> input = GetParam();
for (auto a = input.begin(); a != input.end(); a++) {
for (auto b = std::next(a); b != input.end(); b++) {
EXPECT_NE(*a, *b);
}
}
}
constexpr efi_guid guid_zero = {
0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
constexpr efi_guid guid_nz = {
0x00010203, 0x0405, 0x0607, {0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}};
constexpr efi_guid guid_one = {
0x01000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
INSTANTIATE_TEST_SUITE_P(VariableNameTest, VariableNameFixture,
::testing::Values(std::list<VariableId>{
{String(u""), guid_zero},
{String(u""), guid_one},
{String(u"a"), guid_zero},
{String(u"a"), guid_one},
{String(u"a1"), guid_nz},
{String(u"a2"), guid_nz},
{String(u"b"), guid_zero},
{String(u"abcDEF123!@#Δ☹☼"), guid_nz},
{String(u"abcDEF123!@#Δ☹☼1"), guid_nz},
{String(u"abcDEF123!@#Δ☹☼2"), guid_nz},
}));
} // namespace
} // namespace efi