Remove tests (for now)
This commit is contained in:
parent
32dec9b4d8
commit
7f405f4d49
10 changed files with 0 additions and 2217 deletions
|
@ -1,45 +0,0 @@
|
||||||
SRCDIR = ../src
|
|
||||||
TESTDIR = .
|
|
||||||
|
|
||||||
SRCOBJS := $(addprefix $(SRCDIR)/, net-utils.o net-arp.o net-ethernet.o)
|
|
||||||
TESTOBJS := $(addprefix $(TESTDIR)/, test.o net-arp.o net-utils.o)
|
|
||||||
OBJS := $(SRCOBJS) $(TESTOBJS)
|
|
||||||
|
|
||||||
INCLUDE = -I../uspi/include/ -I..
|
|
||||||
|
|
||||||
CC := clang
|
|
||||||
CXX := clang++
|
|
||||||
|
|
||||||
CFLAGS += $(ARCH) $(INCLUDE) -MMD -MP -Wall -Wno-psabi -fsigned-char -fno-builtin -g -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined -fno-omit-frame-pointer
|
|
||||||
CXXFLAGS := $(CFLAGS) $(CXXFLAGS) -std=c++11
|
|
||||||
CFLAGS += -fno-delete-null-pointer-checks -fdata-sections -ffunction-sections -u _printf_float -std=gnu99
|
|
||||||
|
|
||||||
TARGET ?= test
|
|
||||||
|
|
||||||
DEPENDS := $(patsubst %.o,%.d,$(OBJS))
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
coverage: $(TARGET)
|
|
||||||
LLVM_PROFILE_FILE="$(TARGET).profraw" ./$(TARGET)
|
|
||||||
llvm-profdata merge -sparse "$(TARGET).profraw" -o "$(TARGET).profdata"
|
|
||||||
llvm-cov show ./$(TARGET) -instr-profile="$(TARGET).profdata" ../src
|
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
|
||||||
@echo " LINK $@"
|
|
||||||
$(Q)$(CXX) $(CFLAGS) -o $(TARGET) $(OBJS)
|
|
||||||
|
|
||||||
generate-inputs: $(SRCOBJS) generate-inputs.o
|
|
||||||
@echo " LINK $@"
|
|
||||||
$(Q)$(CXX) $(CFLAGS) -o generate-inputs $(SRCOBJS) generate-inputs.o
|
|
||||||
./generate-inputs
|
|
||||||
|
|
||||||
afl: $(SRCOBJS) afl.o
|
|
||||||
@echo " LINK $@"
|
|
||||||
$(Q)afl-clang++ $(CFLAGS) -o afl $(SRCOBJS) afl.o
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(Q)$(RM) $(SRCDIR)/*.o $(TESTDIR)/*.o $(SRCDIR)/*.d $(TESTDIR)/*.d $(TARGET) kernel test afl generate-inputs *.profraw *.profdata
|
|
1794
tests/acutest.h
1794
tests/acutest.h
File diff suppressed because it is too large
Load diff
|
@ -1,49 +0,0 @@
|
||||||
#include <array>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include <src/types.h>
|
|
||||||
#include <uspi.h>
|
|
||||||
|
|
||||||
static uint8_t uspiBuffer[USPI_FRAME_BUFFER_SIZE];
|
|
||||||
static size_t uspiBufferLength;
|
|
||||||
|
|
||||||
extern "C" int USPiEthernetAvailable(void)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" int USPiReceiveFrame(void* pBuffer, unsigned* pResultLength)
|
|
||||||
{
|
|
||||||
memcpy(pBuffer, uspiBuffer, uspiBufferLength);
|
|
||||||
*pResultLength = uspiBufferLength;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" int USPiSendFrame(const void* pBuffer, unsigned nLength)
|
|
||||||
{
|
|
||||||
assert(nLength <= USPI_FRAME_BUFFER_SIZE);
|
|
||||||
memcpy(uspiBuffer, pBuffer, nLength);
|
|
||||||
uspiBufferLength = nLength;
|
|
||||||
return nLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void USPiGetMACAddress(unsigned char Buffer[6])
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < 6; i++)
|
|
||||||
Buffer[i] = i << 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void MsDelay(unsigned) {}
|
|
||||||
|
|
||||||
#include <src/net-arp.h>
|
|
||||||
|
|
||||||
int main(int, char**)
|
|
||||||
{
|
|
||||||
fread(uspiBuffer, 1, sizeof(uspiBuffer), stdin);
|
|
||||||
Net::Ethernet::Header ethernetHeader;
|
|
||||||
Net::Arp::HandlePacket(ethernetHeader, uspiBuffer, sizeof(uspiBuffer));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
#pragma once
|
|
||||||
extern uint8_t uspiBuffer[USPI_FRAME_BUFFER_SIZE];
|
|
|
@ -1,41 +0,0 @@
|
||||||
#include <algorithm>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <src/net-arp.h>
|
|
||||||
|
|
||||||
#include <src/types.h>
|
|
||||||
#include <uspi.h>
|
|
||||||
|
|
||||||
using namespace Net;
|
|
||||||
|
|
||||||
extern "C" int USPiSendFrame(const void* pBuffer, unsigned nLength)
|
|
||||||
{
|
|
||||||
return std::min(nLength, static_cast<unsigned>(USPI_FRAME_BUFFER_SIZE));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void USPiGetMACAddress(unsigned char Buffer[6]) {}
|
|
||||||
|
|
||||||
static void generateNetArpPacketValid()
|
|
||||||
{
|
|
||||||
std::array<uint8_t, Arp::Packet::SerializedLength()> buffer;
|
|
||||||
std::ofstream stream("inputs/net-arp-packet-valid.bin");
|
|
||||||
const Utils::MacAddress sourceMac{10, 11, 12, 13, 14, 15};
|
|
||||||
const Utils::MacAddress destMac{20, 21, 22, 23, 24, 25};
|
|
||||||
|
|
||||||
Arp::Packet packet(Arp::Operation::ARP_OPERATION_REQUEST);
|
|
||||||
packet.senderMac = sourceMac;
|
|
||||||
packet.senderIp = Utils::Ipv4Address;
|
|
||||||
packet.targetMac = destMac;
|
|
||||||
packet.targetIp = Utils::Ipv4Address;
|
|
||||||
packet.Serialize(buffer.data(), buffer.size());
|
|
||||||
stream.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
|
|
||||||
|
|
||||||
std::cerr << "Generated Net::Arp::Packet (valid)" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int, char**)
|
|
||||||
{
|
|
||||||
Utils::Ipv4Address = 0xC0FFEEEE;
|
|
||||||
generateNetArpPacketValid();
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,182 +0,0 @@
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#define TEST_NO_MAIN
|
|
||||||
#include "acutest.h"
|
|
||||||
|
|
||||||
#include <src/net-arp.h>
|
|
||||||
#include <src/types.h>
|
|
||||||
#include <uspi.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "net-arp.h"
|
|
||||||
|
|
||||||
using namespace Net;
|
|
||||||
|
|
||||||
static const auto targetMac = Utils::MacAddress{1, 2, 3, 4, 5, 6};
|
|
||||||
static const auto senderMac = Utils::MacAddress{11, 12, 13, 14, 15, 16};
|
|
||||||
static const uint32_t targetIp = 0xCAFE0000;
|
|
||||||
static const uint32_t senderIp = 0x00C0FFEE;
|
|
||||||
|
|
||||||
static void netArpCheckSentPacket(
|
|
||||||
const uint16_t operation, const Utils::MacAddress targetMac, const uint32_t targetIp)
|
|
||||||
{
|
|
||||||
// Check if SendPacket set the ethernet header correctly
|
|
||||||
Ethernet::Header ethernetHeader;
|
|
||||||
auto size = Ethernet::Header::Deserialize(ethernetHeader, uspiBuffer, USPI_FRAME_BUFFER_SIZE);
|
|
||||||
TEST_CHECK(size == Ethernet::Header::SerializedLength());
|
|
||||||
|
|
||||||
TEST_CHECK(ethernetHeader.macSource == senderMac);
|
|
||||||
TEST_CHECK(ethernetHeader.macDestination == targetMac);
|
|
||||||
|
|
||||||
// Check if the ARP packet fields were set correctly.
|
|
||||||
Arp::Packet packet;
|
|
||||||
size = packet.Deserialize(
|
|
||||||
uspiBuffer + Ethernet::Header::SerializedLength(), USPI_FRAME_BUFFER_SIZE - size);
|
|
||||||
TEST_CHECK(size == Arp::Packet::SerializedLength());
|
|
||||||
|
|
||||||
TEST_CHECK(packet.hardwareType == 1);
|
|
||||||
TEST_CHECK(packet.protocolType == Ethernet::EtherType::Ipv4);
|
|
||||||
TEST_CHECK(packet.hardwareAddressLength == 6);
|
|
||||||
TEST_CHECK(packet.protocolAddressLength == 4);
|
|
||||||
TEST_CHECK(packet.operation == operation);
|
|
||||||
TEST_CHECK(packet.senderMac == senderMac);
|
|
||||||
TEST_CHECK(packet.senderIp == senderIp);
|
|
||||||
TEST_CHECK(packet.targetMac == targetMac);
|
|
||||||
TEST_CHECK(packet.targetIp == targetIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpPacketSerializeDeserialize()
|
|
||||||
{
|
|
||||||
constexpr auto expectedSize = Arp::Packet::SerializedLength();
|
|
||||||
const Arp::Packet packet(Arp::ARP_OPERATION_REQUEST);
|
|
||||||
|
|
||||||
// Serialize
|
|
||||||
uint8_t buffer[expectedSize];
|
|
||||||
auto size = packet.Serialize(buffer, expectedSize);
|
|
||||||
TEST_CHECK(size == expectedSize);
|
|
||||||
|
|
||||||
// Deserialize
|
|
||||||
Arp::Packet deserialized;
|
|
||||||
size = deserialized.Deserialize(buffer, expectedSize);
|
|
||||||
TEST_CHECK(size == expectedSize);
|
|
||||||
|
|
||||||
// Check if the packet was deserialized correctly
|
|
||||||
TEST_CHECK(packet.hardwareType == deserialized.hardwareType);
|
|
||||||
TEST_CHECK(packet.protocolType == deserialized.protocolType);
|
|
||||||
TEST_CHECK(packet.hardwareAddressLength == deserialized.hardwareAddressLength);
|
|
||||||
TEST_CHECK(packet.protocolAddressLength == deserialized.protocolAddressLength);
|
|
||||||
TEST_CHECK(packet.operation == deserialized.operation);
|
|
||||||
TEST_CHECK(packet.senderMac == deserialized.senderMac);
|
|
||||||
TEST_CHECK(packet.senderIp == deserialized.senderIp);
|
|
||||||
TEST_CHECK(packet.targetMac == deserialized.targetMac);
|
|
||||||
TEST_CHECK(packet.targetIp == deserialized.targetIp);
|
|
||||||
|
|
||||||
// Check serialization and deserialization with a too small buffer
|
|
||||||
TEST_CHECK(packet.Serialize(buffer, expectedSize - 1) == 0);
|
|
||||||
TEST_CHECK(deserialized.Deserialize(buffer, expectedSize - 1) == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpSendPacket()
|
|
||||||
{
|
|
||||||
Arp::SendPacket(Arp::ARP_OPERATION_REQUEST, targetMac, senderMac, targetIp, senderIp);
|
|
||||||
netArpCheckSentPacket(Arp::ARP_OPERATION_REQUEST, targetMac, targetIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpSendRequest()
|
|
||||||
{
|
|
||||||
Arp::SendRequest(targetMac, senderMac, targetIp, senderIp);
|
|
||||||
netArpCheckSentPacket(Arp::ARP_OPERATION_REQUEST, targetMac, targetIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpSendReply()
|
|
||||||
{
|
|
||||||
Arp::SendReply(targetMac, senderMac, targetIp, senderIp);
|
|
||||||
netArpCheckSentPacket(Arp::ARP_OPERATION_REPLY, targetMac, targetIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpSendAnnouncement()
|
|
||||||
{
|
|
||||||
Arp::SendAnnouncement(senderMac, senderIp);
|
|
||||||
netArpCheckSentPacket(Arp::ARP_OPERATION_REPLY, Utils::MacBroadcast, senderIp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadFrame(const std::string path)
|
|
||||||
{
|
|
||||||
std::ifstream stream(path);
|
|
||||||
stream.read(reinterpret_cast<char*>(uspiBuffer), sizeof(uspiBuffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpHandlePacketInvalid()
|
|
||||||
{
|
|
||||||
Ethernet::Header ethernetHeader;
|
|
||||||
|
|
||||||
std::array<uint8_t, USPI_FRAME_BUFFER_SIZE> bufferRef = {};
|
|
||||||
auto buffer = bufferRef;
|
|
||||||
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), Arp::Packet::SerializedLength() - 1);
|
|
||||||
TEST_CHECK(buffer == bufferRef);
|
|
||||||
|
|
||||||
Arp::Packet reference(Arp::ARP_OPERATION_REQUEST);
|
|
||||||
reference.targetIp = Utils::Ipv4Address;
|
|
||||||
|
|
||||||
{
|
|
||||||
auto packet = reference;
|
|
||||||
packet.hardwareType = 2;
|
|
||||||
const auto size = packet.Serialize(bufferRef.data(), bufferRef.size());
|
|
||||||
|
|
||||||
buffer = bufferRef;
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), size);
|
|
||||||
TEST_CHECK(buffer == bufferRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto packet = reference;
|
|
||||||
packet.protocolType = static_cast<Ethernet::EtherType>(1337);
|
|
||||||
const auto size = packet.Serialize(bufferRef.data(), bufferRef.size());
|
|
||||||
|
|
||||||
buffer = bufferRef;
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), size);
|
|
||||||
TEST_CHECK(buffer == bufferRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto packet = reference;
|
|
||||||
packet.targetIp = 0xFEEDFEED;
|
|
||||||
const auto size = packet.Serialize(bufferRef.data(), bufferRef.size());
|
|
||||||
|
|
||||||
buffer = bufferRef;
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), size);
|
|
||||||
TEST_CHECK(buffer == bufferRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto packet = reference;
|
|
||||||
packet.operation = static_cast<Arp::Operation>(31337);
|
|
||||||
const auto size = packet.Serialize(bufferRef.data(), bufferRef.size());
|
|
||||||
|
|
||||||
buffer = bufferRef;
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), size);
|
|
||||||
TEST_CHECK(buffer == bufferRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetArpHandlePacketRequest()
|
|
||||||
{
|
|
||||||
Ethernet::Header ethernetHeader;
|
|
||||||
|
|
||||||
std::array<uint8_t, USPI_FRAME_BUFFER_SIZE> buffer;
|
|
||||||
Arp::Packet reference(Arp::ARP_OPERATION_REQUEST);
|
|
||||||
reference.targetIp = Utils::Ipv4Address;
|
|
||||||
|
|
||||||
{
|
|
||||||
auto packet = reference;
|
|
||||||
const auto size = packet.Serialize(buffer.data(), buffer.size());
|
|
||||||
const auto bufferRef = buffer;
|
|
||||||
|
|
||||||
Arp::HandlePacket(ethernetHeader, buffer.data(), size);
|
|
||||||
|
|
||||||
// Check if we've got a proper response
|
|
||||||
TEST_CHECK(buffer != bufferRef);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void TestNetArpPacketSerializeDeserialize();
|
|
||||||
void TestNetArpSendPacket();
|
|
||||||
void TestNetArpSendRequest();
|
|
||||||
void TestNetArpSendReply();
|
|
||||||
void TestNetArpSendAnnouncement();
|
|
||||||
void TestNetArpHandlePacketInvalid();
|
|
||||||
void TestNetArpHandlePacketRequest();
|
|
|
@ -1,49 +0,0 @@
|
||||||
#define TEST_NO_MAIN
|
|
||||||
#include "acutest.h"
|
|
||||||
|
|
||||||
#include <src/net-utils.h>
|
|
||||||
|
|
||||||
using namespace Net;
|
|
||||||
|
|
||||||
void TestNetUtilsInternetChecksum()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
const char buffer[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
|
||||||
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
|
||||||
TEST_CHECK(checksum == 61419);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const char buffer[] = {1, 2, 3, 4, 5, 6, 7};
|
|
||||||
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
|
||||||
TEST_CHECK(checksum == 61427);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const char buffer[] = {};
|
|
||||||
const auto checksum = Utils::InternetChecksum(buffer, sizeof(buffer));
|
|
||||||
TEST_CHECK(checksum == 65535);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetUtilsCrc32()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
const uint8_t buffer[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
|
||||||
const auto checksum = Utils::Crc32(buffer, sizeof(buffer));
|
|
||||||
TEST_CHECK(checksum == 1070237893);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const uint8_t buffer[] = {};
|
|
||||||
const auto checksum = Utils::Crc32(buffer, sizeof(buffer));
|
|
||||||
TEST_CHECK(checksum == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestNetUtilsGetMacAddress()
|
|
||||||
{
|
|
||||||
const auto mac = Utils::GetMacAddress();
|
|
||||||
const auto expected = Utils::MacAddress{0x00, 0x10, 0x20, 0x30, 0x40, 0x50};
|
|
||||||
TEST_CHECK(mac == expected);
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
#pragma once
|
|
||||||
void TestNetUtilsInternetChecksum();
|
|
||||||
void TestNetUtilsCrc32();
|
|
||||||
void TestNetUtilsGetMacAddress();
|
|
|
@ -1,42 +0,0 @@
|
||||||
#include "acutest.h"
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
|
||||||
#include <src/types.h>
|
|
||||||
#include <uspi.h>
|
|
||||||
|
|
||||||
#include <src/net-arp.h>
|
|
||||||
#include <src/net-ipv4.h>
|
|
||||||
|
|
||||||
uint8_t uspiBuffer[USPI_FRAME_BUFFER_SIZE];
|
|
||||||
|
|
||||||
extern "C" int USPiSendFrame(const void* pBuffer, unsigned nLength)
|
|
||||||
{
|
|
||||||
assert(nLength <= USPI_FRAME_BUFFER_SIZE);
|
|
||||||
memcpy(uspiBuffer, pBuffer, nLength);
|
|
||||||
return nLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void USPiGetMACAddress(unsigned char Buffer[6])
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
Buffer[i] = i << 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "net-arp.h"
|
|
||||||
#include "net-utils.h"
|
|
||||||
|
|
||||||
TEST_LIST = {
|
|
||||||
{"Net::Utils::InternetChecksum", TestNetUtilsInternetChecksum},
|
|
||||||
{"Net::Utils::Crc32", TestNetUtilsCrc32},
|
|
||||||
{"Net::Utils::GetMacAddress", TestNetUtilsGetMacAddress},
|
|
||||||
{"Net::Arp::PacketSerializeDeserialize", TestNetArpPacketSerializeDeserialize},
|
|
||||||
{"Net::Arp::SendPacket", TestNetArpSendPacket},
|
|
||||||
{"Net::Arp::SendRequest", TestNetArpSendRequest},
|
|
||||||
{"Net::Arp::SendReply", TestNetArpSendReply},
|
|
||||||
{"Net::Arp::SendAnnouncement", TestNetArpSendAnnouncement},
|
|
||||||
{"Net::Arp::HandlePacket Invalid", TestNetArpHandlePacketInvalid},
|
|
||||||
{"Net::Arp::HandlePacket Request", TestNetArpHandlePacketRequest},
|
|
||||||
{nullptr, nullptr},
|
|
||||||
};
|
|
Loading…
Reference in a new issue