blob: 7c35c111913fad7b39ceed2c7cca5c1eb340d3e4 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT
#include <lib/acpi_lite.h>
#include <lib/acpi_lite/apic.h>
#include <lib/acpi_lite/testing/test_util.h>
#include <vector>
#include <fuzzer/FuzzedDataProvider.h>
namespace acpi_lite::testing {
namespace {
void TestOneInput(FuzzedDataProvider& provider) {
// Get the test data.
std::vector<uint8_t> data = provider.ConsumeRemainingBytes<uint8_t>();
// Ensure we have at least enough bytes for a valid header.
if (data.size() < sizeof(AcpiSdtHeader)) {
return;
}
// Update |length| to match the actual data length.
auto* table = reinterpret_cast<AcpiSdtHeader*>(data.data());
table->length = static_cast<uint32_t>(data.size());
// Try and enumerate the entries.
EnumerateIoApics(FakeAcpiParser({table}), [](const AcpiMadtIoApicEntry& entry) { return ZX_OK; });
}
} // namespace
} // namespace acpi_lite::testing
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider provider(data, size);
acpi_lite::testing::TestOneInput(provider);
return 0;
}