Commit 758d023c authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Added tests. ForwardPacketTable seems to work.

parent af625951
......@@ -20,7 +20,7 @@ typedef struct {
uint32_t payload_len;
} PrrtPacket;
#define SEQNO_SPACE 66536 // 2**16 as seqno is uint16_t
#define SEQNO_SPACE 65536 // 2**16 as seqno is uint16_t
#define PRRT_PACKET_DATA_HEADER_SIZE 12
typedef struct {
......
......@@ -29,24 +29,19 @@ int PrrtForwardPacketTable_destroy(PrrtForwardPacketTable* fpt_prt) {
int PrrtForwardPacketTable_test_set_is_number_relevant(PrrtForwardPacketTable *fpt_ptr, uint16_t seqno) {
uint16_t stop = (uint16_t) (SEQNO_SPACE / 2 + fpt_ptr->start);
if (fpt_ptr->start < stop && !(fpt_ptr->start <= seqno && seqno <= stop)) {
return FALSE;
} else if (!(seqno < stop)) {
return FALSE;
} else {
printf("SEQ: %d, START:%d\n", seqno, fpt_ptr->start);
uint16_t which_byte = (uint16_t) (seqno / 32);
uint16_t which_bit = (uint16_t) (seqno % 32);
int res = ((fpt_ptr->data[which_byte] >> which_bit) & 0x01) == 0;
fpt_ptr->data[which_byte] |= 1 << which_bit;
printf("D: %d\n", fpt_ptr->data[which_byte]);
if(seqno == fpt_ptr->start) {
move_start(fpt_ptr);
}
printf("START:%d\n", fpt_ptr->start);
return res;
}
......
......@@ -9,7 +9,6 @@
#define FORWARD_PACKET_TABLE_LENGTH 2048 // sequence number space is 2**16 and we have 32 bit so: 2048
#define MAX_FORWARD_ENTRY_VALUE 4294967296 // 2**32
typedef struct {
uint32_t data[FORWARD_PACKET_TABLE_LENGTH];
......
#include <gtest/gtest.h>
#include <cmath>
extern "C" {
#include "prrt/stores/forward_packet_table.h"
......@@ -13,20 +14,44 @@ protected:
PrrtForwardPacketTable* forwardPacketTable;
};
TEST_F(ForwardPacketTableTest, Destroy) {
PrrtForwardPacketTable* forwardPacketTable = (PrrtForwardPacketTable *) malloc(sizeof(PrrtForwardPacketTable));
PrrtForwardPacketTable_create(forwardPacketTable);
PrrtForwardPacketTable_destroy(forwardPacketTable);
TEST_F(ForwardPacketTableTest, CreateDestroy) {
ASSERT_EQ(forwardPacketTable->start, 1);
PrrtForwardPacketTable_destroy(forwardPacketTable);
}
TEST_F(ForwardPacketTableTest, SimpleTestAndSet) {
int seqno = 1;
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, seqno));
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, seqno));
for (int i = 1; i < 10; ++i) {
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
}
}
TEST_F(ForwardPacketTableTest, SimpleMoveStart) {
ASSERT_EQ(forwardPacketTable->start, 1);
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 1));
ASSERT_EQ(forwardPacketTable->start, 2);
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 5));
ASSERT_EQ(forwardPacketTable->start, 2);
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 4));
ASSERT_EQ(forwardPacketTable->start, 2);
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 3));
ASSERT_EQ(forwardPacketTable->start, 2);
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 2));
ASSERT_EQ(forwardPacketTable->start, 6);
for (int i = 1; i < 6; ++i) {
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
}
}
TEST_F(ForwardPacketTableTest, ProperStop) {
uint16_t seqno = (uint16_t) (pow(2, 15) + 1);
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, seqno));
for (int i = 1; i < seqno / 2; ++i) {
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, i));
}
ASSERT_TRUE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, seqno));
ASSERT_FALSE(PrrtForwardPacketTable_test_set_is_number_relevant(forwardPacketTable, 5));
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment