Livt packages

Livt.Net

Version 1.4.1

Ethernet, IPv4, TCP, UDP, ARP, TFTP, and Telnet networking components for Livt hardware.

Published files (163)

tests/ScheduledWordSumTest.lvt

namespace Livt.Net.Tests

/**
 * Checks the independently expected unfolded sum of a fixed byte string.
 * The assertion verifies the value, not single-cycle or combinational timing.
 */
@Test
component ScheduledWordSumTest
{
	const INDEX_CONTENT : byte[] = "<!doctype html><html><body><h1>Livt FPGA Web</h1></body></html>\n".Encode()

	/**
	 * No mutable fixture state is required.
	 */
	new()
	{
	}

	/**
	 * Accumulates 32 network-order words inside an explicit state.
	 */
	public fn ComputeWordSumUsingSingleState() int
	{
		var sum: int = 0

		state {
			for (var i = 0; i < 32; i++) {
				var hi: int = INDEX_CONTENT[i * 2]
				var lo: int = INDEX_CONTENT[i * 2 + 1]
				sum = sum + hi * 256 + lo
			}
		}

		return sum
	}

	/**
	 * Accumulates the same 32 words using a scheduled loop.
	 */
	public fn ComputeWordSum() int
	{
		var sum: int = 0

		for (var i = 0; i < 32; i++) {
			var hi: int = INDEX_CONTENT[i * 2]
			var lo: int = INDEX_CONTENT[i * 2 + 1]
			sum = sum + hi * 256 + lo
		}

		return sum
	}

	/**
	 * Compares the fixed input against an independently calculated word sum.
	 */
	@Test
	fn MatchesIndependentWordSum()
	{
		var checksum = this.ComputeWordSum()

		Simulation.Report("Computed word sum: {checksum}")

		assert this.ComputeWordSum() == 717318
	}
}