Skip to content

Commit

Permalink
Merge pull request #55 from nasa/code_coverage
Browse files Browse the repository at this point in the history
Code coverage
  • Loading branch information
rjbrown2 authored Jan 12, 2022
2 parents f42a742 + 07ad4e5 commit a8a6ec2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
47 changes: 43 additions & 4 deletions util/src_util/ut_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "sadb_routine.h"
#include "utest.h"

/**
* @brief Unit Test: Crypto Calc/Verify CRC16
**/
UTEST(CRYPTO_C, CALC_CRC16)
{
char *data_h = "2003002000ff000100001880d2c9000e197f0b001b0004000400003040d95e";
Expand All @@ -43,7 +46,10 @@ UTEST(CRYPTO_C, CALC_CRC16)
ASSERT_EQ(crc, validated_crc);
}

UTEST(CRYPTO_C, HAPPY_BAD_CC)
/**
* @brief Unit Test: Crypto Bad CC Flag
**/
UTEST(CRYPTO_C, BAD_CC_FLAG)
{
// Setup & Initialize CryptoLib
Crypto_Config_CryptoLib(SADB_TYPE_INMEMORY, CRYPTOGRAPHY_TYPE_LIBGCRYPT, CRYPTO_TC_CREATE_FECF_TRUE, TC_PROCESS_SDLS_PDUS_TRUE, TC_HAS_PUS_HDR,
Expand Down Expand Up @@ -71,7 +77,10 @@ UTEST(CRYPTO_C, HAPPY_BAD_CC)
ASSERT_EQ(CRYPTO_LIB_ERR_INVALID_CC_FLAG, return_val);
}

//TODO: This needs to be reworked to actually better test.
/**
* @brief Unit Test: PDU Switch testing
* @note: TODO: This needs to be reworked to actually better test.
**/
UTEST(CRYPTO_C, PDU_SWITCH)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand Down Expand Up @@ -114,7 +123,7 @@ UTEST(CRYPTO_C, PDU_SWITCH)
sdls_frame.pdu.pid = PID_KEY_INVENTORY;
status = Crypto_PDU(ingest, tc_frame);
ASSERT_EQ(status, CRYPTOGRAPHY_UNSUPPORTED_OPERATION_FOR_KEY_RING);

sdls_frame.pdu.pid = SG_KEY_MGMT;
status = Crypto_PDU(ingest, tc_frame);
ASSERT_EQ(status, CRYPTO_LIB_SUCCESS);
Expand Down Expand Up @@ -237,6 +246,9 @@ UTEST(CRYPTO_C, PDU_SWITCH)
ASSERT_EQ(status, CRYPTO_LIB_SUCCESS);
}

/**
* @brief Unit Test: Crypto Extended Procedures PDU Test
**/
UTEST(CRYPTO_C, EXT_PROC_PDU)
{
uint8_t *ingest = NULL;
Expand All @@ -254,7 +266,10 @@ UTEST(CRYPTO_C, EXT_PROC_PDU)

//TODO: Move these to their own unit test files.

//TODO: This test will need to be reworked when this functionality exists.
/**
* @brief Unit Test: Crypto Init with invalid SADB
* @note: TODO: This test will need to be reworked when this functionality exists.
**/
UTEST(CRYPTO_AOS, APPLY_SECURITY)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -266,6 +281,9 @@ UTEST(CRYPTO_AOS, APPLY_SECURITY)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);
}

/**
* @brief Unit Test: Crypto AOS Process Security
**/
UTEST(CRYPTO_AOS, PROCESS_SECURITY)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -277,6 +295,9 @@ UTEST(CRYPTO_AOS, PROCESS_SECURITY)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);
}

/**
* @brief Unit Test: Crypto MC Status test
**/
UTEST(CRYPTO_MC, STATUS)
{
int count = 0;
Expand All @@ -286,6 +307,9 @@ UTEST(CRYPTO_MC, STATUS)
ASSERT_EQ(11, count);
}

/**
* @brief Unit Test: Crypto MC Dump test
**/
UTEST(CRYPTO_MC, DUMP)
{
int count = 0;
Expand All @@ -295,6 +319,9 @@ UTEST(CRYPTO_MC, DUMP)
ASSERT_EQ(((log_count * 4) + (log_count * 2) + 9), count);
}

/**
* @brief Unit Test: Crypto MC Erase Test
**/
UTEST(CRYPTO_MC, ERASE)
{
int count = 0;
Expand All @@ -304,6 +331,9 @@ UTEST(CRYPTO_MC, ERASE)
ASSERT_EQ(11, count);
}

/**
* @brief Unit Test: Crypto MC SelfTest Test
**/
UTEST(CRYPTO_MC, SELFTEST)
{
int count = 0;
Expand All @@ -313,6 +343,9 @@ UTEST(CRYPTO_MC, SELFTEST)
ASSERT_EQ(10, count);
}

/**
* @brief Unit Test: Crypto MC ReadARSN Test
**/
UTEST(CRYPTO_MC, READARSN)
{
int count = 0;
Expand All @@ -322,6 +355,9 @@ UTEST(CRYPTO_MC, READARSN)
ASSERT_EQ(11, count);
}

/**
* @brief Unit Test: Crypto MC Process Security Test
**/
UTEST(CRYPTO_MC, PROCESS)
{
uint8_t ingest[1024] = {0};
Expand All @@ -332,6 +368,9 @@ UTEST(CRYPTO_MC, PROCESS)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);
}

/**
* @brief Unit Test: Crypto Get TM Length Test
**/
UTEST(CRYPTO_MC, TMLENGTH)
{
int length = 0;
Expand Down
27 changes: 25 additions & 2 deletions util/src_util/ut_crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include "sadb_routine.h"
#include "utest.h"


/**
* @brief Unit Test: Crypto Init with incomplete configuration
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_WITH_INCOMPLETE_CONFIG)
{
// Make use of Crypto_Init_With_Configs
Expand All @@ -39,6 +41,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_WITH_INCOMPLETE_CONFIG)
ASSERT_EQ(CRYPTO_CONFIGURATION_NOT_COMPLETE, status);
}

/**
* @brief Unit Test: Crypto Init with no managed parameters configuration
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_NO_MANAGED_PARAM_CONFIG)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -51,6 +56,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_NO_MANAGED_PARAM_CONFIG)
ASSERT_EQ(CRYPTO_MANAGED_PARAM_CONFIGURATION_NOT_COMPLETE, status);
}

/**
* @brief Unit Test: Crypto Init with NULL Maria DB
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_MARIADB_NULL)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -68,6 +76,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_MARIADB_NULL)
ASSERT_EQ(CRYPTO_MARIADB_CONFIGURATION_NOT_COMPLETE, status);
}

/**
* @brief Unit Test: Crypto Init with NULL KMC Crypto configuration
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_KMCCRYPTO_NULL)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -87,6 +98,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_KMCCRYPTO_NULL)
ASSERT_EQ(CRYPTOGRAPHY_KMC_CRYPTO_SERVICE_CONFIGURATION_NOT_COMPLETE, status);
}

/**
* @brief Unit Test: Crypto Init with Invalid Interface
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_INVALID_INTERFACE)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -106,6 +120,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_INVALID_INTERFACE)
ASSERT_EQ(CRYPTOGRAPHY_INVALID_CRYPTO_INTERFACE_TYPE, status);
}

/**
* @brief Unit Test: Crypto Init with invalid SADB
**/
UTEST(CRYPTO_CONFIG, CRYPTO_INIT_INVALID_SADB)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -125,7 +142,10 @@ UTEST(CRYPTO_CONFIG, CRYPTO_INIT_INVALID_SADB)
ASSERT_EQ(SADB_INVALID_SADB_TYPE, status);
}

// TODO: Not able to force the Crypto_Lib_Error ATM
/**
* @brief Unit Test: Crypto Init with incomplete configuration
* @note TODO: Not able to force the Crypto_Lib_Error ATM
**/
UTEST(CRYPTO_CONFIG, CRYPTO_CONFIG_MDB)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand All @@ -143,6 +163,9 @@ UTEST(CRYPTO_CONFIG, CRYPTO_CONFIG_MDB)
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);
}

/**
* @brief Unit Test: Crypto KMC Configuration
**/
UTEST(CRYPTO_CONFIG, CRYPTO_CONFIG_KMC)
{
int32_t status = CRYPTO_LIB_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions util/src_util/ut_tc_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ UTEST(TC_APPLY_SECURITY, NO_CRYPTO_INIT)
Crypto_Shutdown();
}

/**
* @brief Unit Test: No Set Configuration
**/
UTEST(TC_APPLY_SECURITY, NO_CONFIG)
{
// No Crypto_Init(), but we still Configure It;
Expand Down

0 comments on commit a8a6ec2

Please sign in to comment.