Skip to content

Commit

Permalink
Merge pull request #23 from CDOT-CV/addressing-usdot-pr-comments-2-1-…
Browse files Browse the repository at this point in the history
…2024

Modified dockerfiles, added data documentation & refactored code for clarity
  • Loading branch information
drewjj authored Feb 1, 2024
2 parents 0daa2b6 + f10bc08 commit 64489b2
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 38 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ USER root
WORKDIR /asn1_codec
VOLUME ["/asn1_codec_share"]

# update the package manager
RUN apk update

# add build dependencies
RUN apk add --upgrade --no-cache --virtual .build-deps \
cmake \
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ USER root
WORKDIR /asn1_codec
VOLUME ["/asn1_codec_share"]

# update the package manager
RUN apk update

# add build dependencies
RUN apk add --upgrade --no-cache --virtual .build-deps \
cmake \
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile.standalone
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ FROM alpine:3.12 as builder
USER root
WORKDIR /asn1_codec

# update the package manager
RUN apk update

# add build dependencies
RUN apk add --upgrade --no-cache --virtual .build-deps \
cmake \
Expand Down
20 changes: 16 additions & 4 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
- You can construct test data files by working with the BSM MessageFrame and working up.

j2735.MessageFrame.Bsm.xml : apply converter-example -ixer -oper -p MessageFrame
j2735.MessageFrame.Bsm.per : apply xxd -p
j2735.MessageFrame.Bsm.uper : apply xxd -p
j2735.MessageFrame.Bsm.hex : cut and paste into Ieee1609Dot2Data xml structure.

Ieee1609Dot2Data.unsecuredData.xml : apply converter-example -ixer -oper -p Ieee1609Dot2Data
Ieee1609Dot2Data.unsecuredData.per : apply xxd -p
Ieee1609Dot2Data.unsecuredData.uper : apply xxd -p
Ieee1609Dot2Data.unsecuredData.hex : cut and paste into the BAH packet that goes into the input Kafka stream.

BAH.Input.xml : the data that is received on the Kafka input stream.
Expand Down Expand Up @@ -35,5 +35,17 @@ BAH.Input.xml : the data that is received on the Kafka input stream.
encryptedData EncryptedData,
signedCertificateRequest Opaque,



# Data Files
The data files in this directory are referenced in the following files:
| Data File | File | Test Name / Context |
| --------- | --------- | --------- |
| InputData.encoding.tim.odetimpayload.xml | src/tests.cpp | Encode TIM with payload type 'OdeTimPayload' |
| InputData.encoding.tim.odeasdpayload.xml | src/tests.cpp | Encode TIM with payload type 'OdeAsdPayload' |
| InputData.decoding.bsm.xml | src/tests.cpp | Decode BSM |
| producer_test_xml.txt | do_kafka_test.sh | ./test-scripts/standalone.sh config/test/c1.properties data/producer_test_xml.txt encode 0 |
| InputData.Ieee1609Dot2Data.packed.xml | testing.md | Testing Documentation |
| j2735.MessageFrame.Bsm.xml | data/README.md | Building Test Data Files |
| j2735.MessageFrame.Bsm.uper | data/README.md | Building Test Data Files |
| j2735.MessageFrame.Bsm.hex | data/README.md | Building Test Data Files |

The rest of the files in this directory (and subdirectories) are provided as examples and are not referenced anywhere.
10 changes: 7 additions & 3 deletions include/acm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class ASN1_Codec : public tool::Tool {
const char* getEnvironmentVariable(const char* variableName);

/**
* @brief Create and setup the two loggers used for the ASN1_Codec. The locations and filenames for the logs can be specified
* @brief Create and setup the logger used for the ASN1_Codec. The locations and filenames for the logs can be specified
* using command line parameters. The CANNOT be set via the configuration file, since these loggers are setup
* prior to the configuration file being read.
*
Expand All @@ -231,8 +231,12 @@ class ASN1_Codec : public tool::Tool {
*
* @return true upon success; false if some failure occurred during logger setup.
*/
bool make_loggers( bool remove_files );
bool make_loggers_testing();
bool setup_logger( bool remove_files );

/**
* @brief Set up the logger for testing
*/
bool setup_logger_for_testing();

private:

Expand Down
2 changes: 1 addition & 1 deletion include/acm_blob_producer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ACMBlobProducer : public tool::Tool {
*
* @return true upon success; false if some failure occurred during logger setup.
*/
bool make_loggers( bool remove_files );
bool setup_logger( bool remove_files );

private:

Expand Down
10 changes: 9 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ ACM_LOG_TO_FILE=

# The log level to use.
# Valid values are: "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "OFF"
ACM_LOG_LEVEL=
ACM_LOG_LEVEL=

# If unset, a local kafka broker will be targeted.
# If set to "CONFLUENT", the application will target a Confluent Cloud cluster.
KAFKA_TYPE=

# Confluent Cloud Integration (if KAFKA_TYPE is set to "CONFLUENT")
CONFLUENT_KEY=
CONFLUENT_SECRET=
19 changes: 11 additions & 8 deletions src/acm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ bool ASN1_Codec::configure() {

// confluent cloud integration
std::string kafkaType = getEnvironmentVariable("KAFKA_TYPE");
if (kafkaType == "") {
logger->warn(fnname + ": KAFKA_TYPE environment variable not set. A local kafka broker will be targeted.");
}

if (kafkaType == "CONFLUENT") {
// get username and password
std::string username = getEnvironmentVariable("CONFLUENT_KEY");
Expand All @@ -507,6 +503,9 @@ bool ASN1_Codec::configure() {
conf->set("api.version.fallback.ms", "0", error_string);
conf->set("broker.version.fallback", "0.10.0.0", error_string);
}
else {
logger->warn(fnname + ": KAFKA_TYPE environment variable not set to 'CONFLUENT'. A local kafka broker will be targeted.");
}
// end of confluent cloud integration

if ( getOption('g').isSet() && conf->set("group.id", optString('g'), error_string) != RdKafka::Conf::CONF_OK) {
Expand Down Expand Up @@ -655,7 +654,7 @@ bool ASN1_Codec::launch_consumer(){
return true;
}

bool ASN1_Codec::make_loggers( bool remove_files ) {
bool ASN1_Codec::setup_logger( bool remove_files ) {
// defaults.
std::string path{ "logs/" };
std::string logname{ "log.info" };
Expand Down Expand Up @@ -703,8 +702,12 @@ bool ASN1_Codec::make_loggers( bool remove_files ) {
return true;
}

bool ASN1_Codec::make_loggers_testing() {
logger = std::make_shared<AcmLogger>("testlog");
/**
* @brief This method is used to setup the logger for testing purposes.
*/
bool ASN1_Codec::setup_logger_for_testing() {
std::string TEST_LOGGER_FILE_NAME = "test_logger_file.log";
logger = std::make_shared<AcmLogger>(TEST_LOGGER_FILE_NAME);
return true;
}

Expand Down Expand Up @@ -1971,7 +1974,7 @@ int main( int argc, char* argv[] )
}

// can set levels if needed here.
if ( !asn1_codec.make_loggers( asn1_codec.optIsSet('R') )) {
if ( !asn1_codec.setup_logger( asn1_codec.optIsSet('R') )) {
std::exit( EXIT_FAILURE );
}

Expand Down
4 changes: 2 additions & 2 deletions src/acm_blob_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bool ACMBlobProducer::launch_producer()
return true;
}

bool ACMBlobProducer::make_loggers( bool remove_files )
bool ACMBlobProducer::setup_logger( bool remove_files )
{
// defaults.
std::string path{ "logs/" };
Expand Down Expand Up @@ -533,7 +533,7 @@ int main(int argc, char* argv[])
}

// can set levels if needed here.
if (!acm_blob_producer.make_loggers((acm_blob_producer.optIsSet('R')))) {
if (!acm_blob_producer.setup_logger((acm_blob_producer.optIsSet('R')))) {
std::exit(EXIT_FAILURE);
}

Expand Down
20 changes: 10 additions & 10 deletions src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const char *ASD_ONE609_HEX = "44400000000084782786283B90A7148D2B0A89C49F8A85A776
*/
// TEST_CASE("Encode BSM", "[encoding]" ) { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out1;
// CHECK(asn1_codec.file_test("unit-test-data/BSM.xml", out1) == EXIT_SUCCESS);
Expand All @@ -60,7 +60,7 @@ TEST_CASE("Encode ASD", "[encoding]" ) {
std::cout << "=== Encode ASD ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out2;
CHECK(asn1_codec.file_test("unit-test-data/ASD.xml", out2) == EXIT_SUCCESS);
Expand All @@ -79,7 +79,7 @@ TEST_CASE("Encode ASD", "[encoding]" ) {
*/
// TEST_CASE("Encode ASD_BSM", "[encoding]" ) { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();
// std::stringstream out3;
// CHECK(asn1_codec.file_test("unit-test-data/ASD_BSM.xml", out3) == EXIT_SUCCESS);
// parse_result = output_doc.load(out3, pugi::parse_default | pugi::parse_declaration | pugi::parse_doctype | pugi::parse_trim_pcdata);
Expand All @@ -98,7 +98,7 @@ TEST_CASE("Encode 1609", "[encoding]" ) {
std::cout << "=== Encode 1609 ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out4;
CHECK(asn1_codec.file_test("unit-test-data/1609.xml", out4) == EXIT_SUCCESS);
Expand All @@ -115,7 +115,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
std::cout << "=== Encode ASD_1609 ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out5;
CHECK(asn1_codec.file_test("unit-test-data/ASD_1609.xml", out5) == EXIT_SUCCESS);
Expand All @@ -137,7 +137,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
*/
// TEST_CASE("Encode 1609_BSM", "[encoding]") { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out6;
// CHECK(asn1_codec.file_test("unit-test-data/1609_BSM.xml", out6) == EXIT_SUCCESS);
Expand All @@ -159,7 +159,7 @@ TEST_CASE("Encode ASD_1609", "[encoding]" ) {
*/
// TEST_CASE("Encode ASD_1609_BSM", "[encoding]") { // TODO: fix test case failing
// // prepare
// asn1_codec.make_loggers_testing();
// asn1_codec.setup_logger_for_testing();

// std::stringstream out7;
// CHECK(asn1_codec.file_test("unit-test-data/ASD_1609_BSM.xml", out7) == EXIT_SUCCESS);
Expand All @@ -182,7 +182,7 @@ TEST_CASE("Encode TIM with payload type 'OdeTimPayload'", "[encoding][odetimpayl
std::cout << "=== Encode TIM with payload type 'OdeTimPayload' ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out8;
CHECK(asn1_codec.file_test("data/InputData.encoding.tim.odetimpayload.xml", out8) == EXIT_SUCCESS);
Expand All @@ -196,7 +196,7 @@ TEST_CASE("Encode TIM with payload type 'OdeAsdPayload'", "[encoding][odeasdpayl
std::cout << "=== Encode TIM with payload type 'OdeAsdPayload' ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out8;
CHECK(asn1_codec.file_test("data/InputData.encoding.tim.odeasdpayload.xml", out8) == EXIT_SUCCESS);
Expand All @@ -212,7 +212,7 @@ TEST_CASE("Decode BSM", "[decoding]") {
std::cout << "=== Decode BSM ===" << std::endl;

// prepare
asn1_codec.make_loggers_testing();
asn1_codec.setup_logger_for_testing();

std::stringstream out9;
CHECK(asn1_codec.file_test("data/InputData.decoding.bsm.xml", out9, false) == EXIT_SUCCESS);
Expand Down
12 changes: 12 additions & 0 deletions unit-test-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Data Usage
The data files in this directory are used in the following tests:
| Data File | Test File | Test Name |
| --------- | --------- | --------- |
| 1609_BSM.xml | src/tests.cpp | Encode 1609_BSM |
| 1609.xml | src/tests.cpp | Encode 1609 |
| ASD_1609_BSM.xml | src/tests.cpp | Encode ASD_1609_BSM |
| ASD_1609.xml | src/tests.cpp | Encode ASD_1609 |
| ASD_BSM.xml | src/tests.cpp | Encode ASD_BSM |
| ASD.xml | src/tests.cpp | Encode ASD_BSM |
| BSM.xml | src/tests.cpp | Encode BSM |
| empty.xml | N/A | N/A |

0 comments on commit 64489b2

Please sign in to comment.