Commit 0c72b1a9 authored by Sydney Hauke's avatar Sydney Hauke

Merge branch 'add-test-framework' into 'master'

Add test framework and first tests

See merge request she-reds/sdr_makerspace!3
parents c1047331 70551d59
......@@ -76,6 +76,15 @@ NMS decoder (factor = 29/32)
> ./main.icc -fixed -avx -NMS 29 -min 0.5 -max 4.0 -iter 20
> ./main.icc -fixed -avx -OMS 1 -min 0.5 -max 4.0 -iter 20
How to compile/run tests
#######################
You need googletest sources on your machine and set its path in the GTEST_DIR variable.
For instance:
> export GTEST_DIR=/usr/src/googletest/googletest
Then, you can compile and run tests:
> make test-run
Air throughput measure:
#######################
......
......@@ -59,8 +59,35 @@ main.icc: $(OBJ)
clean:
find ../src/ -name "*.o" -exec rm {} \;
find ../tests/ -name "*.o" -exec rm {} \;
find ../tests/ -name "*.a" -exec rm {} \;
find . -name "*.ic*" -exec rm {} \;
mrproper: clean
rm $(EXEC)
## Tests ##
TEST_LDFLAGS=-lpthread
SRC_DECODER_FLOODED= \
../tests/unit/test_decoder_flooded.cpp \
../src/CDecoder/MS/CDecoder_MS_fixed_flooded.cpp \
../src/CDecoder/template/CDecoder.cpp \
../src/CDecoder/template/CDecoder_fixed.cpp \
../src/CDecoder/template/CDecoder_fixed_flooded.cpp
OBJ_TEST_DECODER_FLOODED= $(SRC_DECODER_FLOODED:.cpp=.o)
test-run: test
./test_decoder_flooded.icc
test: test_decoder_flooded.icc
test_decoder_flooded.icc: $(OBJ_TEST_DECODER_FLOODED) libgtest.a
@echo "[LINKING] $@"
@$(CC) -o $@ $^ $(LDFLAGS) $(TEST_LDFLAGS)
libgtest.a:
@echo "[BUILDING] $@"
@$(CC) -isystem ${GTEST_DIR}/include -I${GTEST_DIR} -pthread -c ${GTEST_DIR}/src/gtest-all.cc
@ar -rv $@ gtest-all.o
#include <gtest/gtest.h>
#include "./Constantes/constantes_sse.h"
#include "CDecoder/MS/CDecoder_MS_fixed_flooded.h"
#define ITERATION_MIN 1
#define ITERATION_MAX 20
#define NB_BITS_VARIABLES 8
#define NB_BITS_MESSAGES 6
#define SAT_POS_VAR ( (0x0001<<(NB_BITS_VARIABLES-1))-1)
#define SAT_NEG_VAR (-(0x0001<<(NB_BITS_VARIABLES-1))+1)
#define SAT_POS_MSG ( (0x0001<<(NB_BITS_MESSAGES -1))-1)
#define SAT_NEG_MSG (-(0x0001<<(NB_BITS_MESSAGES -1))+1)
TEST(DecoderFloodedTest, ZeroedInput)
{
char i_llr[_N];
char o_llr[_N];
CDecoder_MS_fixed_flooded dec;
dec.setVarRange (SAT_NEG_VAR, SAT_POS_VAR);
dec.setMsgRange (SAT_NEG_MSG, SAT_POS_MSG);
for (int iter = ITERATION_MIN ; iter < ITERATION_MAX ; iter++)
{
std::fill_n(i_llr, _N, SAT_NEG_MSG);
dec.decode(i_llr, o_llr, iter);
for (int i = 0; i < _N ; i++)
{
ASSERT_EQ(o_llr[i], 0);
}
}
}
TEST(DecoderFloodedTest, ZeroedInputWithFirstFlippedBit)
{
char i_llr[_N];
char o_llr[_N];
CDecoder_MS_fixed_flooded dec;
dec.setVarRange (SAT_NEG_VAR, SAT_POS_VAR);
dec.setMsgRange (SAT_NEG_MSG, SAT_POS_MSG);
for (int iter = ITERATION_MIN ; iter < ITERATION_MAX ; iter++)
{
std::fill_n(i_llr, _N, SAT_NEG_MSG);
i_llr[0] = SAT_POS_MSG;
dec.decode(i_llr, o_llr, iter);
for (int i = 0; i < _N ; i++)
{
ASSERT_EQ(o_llr[i], 0);
}
}
}
TEST(DecoderFloodedTest, ZeroedInputWithLastFlippedBit)
{
char i_llr[_N];
char o_llr[_N];
CDecoder_MS_fixed_flooded dec;
dec.setVarRange (SAT_NEG_VAR, SAT_POS_VAR);
dec.setMsgRange (SAT_NEG_MSG, SAT_POS_MSG);
for (int iter = ITERATION_MIN ; iter < ITERATION_MAX ; iter++)
{
std::fill_n(i_llr, _N, SAT_NEG_MSG);
i_llr[_N-1] = SAT_POS_MSG;
dec.decode(i_llr, o_llr, iter);
for (int i = 0; i < _N ; i++)
{
ASSERT_EQ(o_llr[i], 0);
}
}
}
TEST(DecoderFloodedTest, ZeroedInputWithRandomFlippedBit)
{
char i_llr[_N];
char o_llr[_N];
CDecoder_MS_fixed_flooded dec;
dec.setVarRange (SAT_NEG_VAR, SAT_POS_VAR);
dec.setMsgRange (SAT_NEG_MSG, SAT_POS_MSG);
for (int iter = ITERATION_MIN ; iter < ITERATION_MAX ; iter++)
{
std::fill_n(i_llr, _N, SAT_NEG_MSG);
i_llr[_N/4] = SAT_POS_MSG;
dec.decode(i_llr, o_llr, iter);
for (int i = 0; i < _N ; i++)
{
ASSERT_EQ(o_llr[i], 0);
}
}
}
int main(int argc, char* argv[])
{
srand(0);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Markdown is supported
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