From 5d1a9398be78f938f06bfab0d81dacd6b460912c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 10 Jul 2024 19:20:05 -0500 Subject: [PATCH] Add unit test for nanors wrapper --- tests/unit/test_rswrapper.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/unit/test_rswrapper.cpp diff --git a/tests/unit/test_rswrapper.cpp b/tests/unit/test_rswrapper.cpp new file mode 100644 index 00000000000..a74a558bfad --- /dev/null +++ b/tests/unit/test_rswrapper.cpp @@ -0,0 +1,37 @@ +/** + * @file tests/unit/test_rswrapper.cpp + * @brief Test src/rswrapper.* + */ + +extern "C" { +#include +} + +#include + +TEST(ReedSolomonWrapperTests, InitTest) { + reed_solomon_init(); + + // Ensure all function pointers were populated + ASSERT_NE(reed_solomon_new, nullptr); + ASSERT_NE(reed_solomon_release, nullptr); + ASSERT_NE(reed_solomon_encode, nullptr); + ASSERT_NE(reed_solomon_decode, nullptr); +} + +TEST(ReedSolomonWrapperTests, EncodeTest) { + reed_solomon_init(); + + auto rs = reed_solomon_new(1, 1); + ASSERT_NE(rs, nullptr); + + uint8_t dataShard[16] = {}; + uint8_t fecShard[16] = {}; + + // If we picked the incorrect ISA in our wrapper, we should crash here + uint8_t *shardPtrs[2] = { dataShard, fecShard }; + auto ret = reed_solomon_encode(rs, shardPtrs, 2, sizeof(dataShard)); + ASSERT_EQ(ret, 0); + + reed_solomon_release(rs); +}