diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4f4d46f..5a9cd5d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -110,3 +110,18 @@ jobs: asset_path: "doxygen/tagfile.xml" asset_name: "doxygen/tagfile.xml" asset_content_type: application/xml + + - name: Download coverage report + uses: actions/download-artifact@v2 + with: + name: coverage-report + + - name: Upload coverage report to Release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ github.workspace }}/build/coverage/index.html + asset_name: "coverage/index.html" + asset_content_type: text/html diff --git a/App/Core/CommandLineParser/CommandLineParser.cpp b/App/Core/CommandLineParser/CommandLineParser.cpp index 75db837..1d67c14 100644 --- a/App/Core/CommandLineParser/CommandLineParser.cpp +++ b/App/Core/CommandLineParser/CommandLineParser.cpp @@ -28,8 +28,8 @@ type::Params CommandLineParser::parse(int ac, char **av) { while ((opt = getopt_long(ac, av, "hdio:", long_options, nullptr)) != -1) { switch (opt) { case 'h': - this->_handle_help_option(); - break; + this->_display_help(); + throw ParametersEnd(); case 'd': this->_handle_debug_option(); break; @@ -52,7 +52,7 @@ type::Params CommandLineParser::parse(int ac, char **av) { void CommandLineParser::_display_help() const { std::cout - << "USAGE: " << this->_programName << " [--help] [--debug] [--output ]" + << "USAGE: " << this->_programName << " [--help] [--debug] [--output ] [--input ]" << "\n\nBy feeding an image or stream of images as an input the module will go trough" << " multiple steps and extract a numerical value from the image using OCR." << "\n\nOPTIONAL ARGUMENTS:" @@ -61,14 +61,11 @@ void CommandLineParser::_display_help() const { << "\n --output, -o\tOutput type and path, requires two arguments" << "\n\t\t| : The output type (ie: \"CSV\", \"FIFO\", \"PRINT\")" << "\n\t\t| : Path to the output file" + << "\n --input, -i\tInput mode enabled, requires one argument" + << "\n\t\t| : Path to the input image" << std::endl; } -void CommandLineParser::_handle_help_option() const { - this->_display_help(); - throw ParametersEnd(); -} - void CommandLineParser::_handle_debug_option() { this->_params.debug = true; std::cout << "[\033[0;33mINFO\033[0m] Debug mode enabled" << std::endl; diff --git a/App/Core/PythonExecutor/PythonExecutor.cpp b/App/Core/PythonExecutor/PythonExecutor.cpp index 72d9180..bdb6c1b 100644 --- a/App/Core/PythonExecutor/PythonExecutor.cpp +++ b/App/Core/PythonExecutor/PythonExecutor.cpp @@ -14,25 +14,26 @@ std::string const PyExecutor::executeScript(std::string const& scriptPath, std::string const& imagePath, int lastValue) { int pipefd[2]; - if (pipe(pipefd) == -1) { - THROW_EXCEPTION(PythonExecutorError, "Failed to create the pipe."); - } + // if (pipe(pipefd) == -1) { + // THROW_EXCEPTION(PythonExecutorError, "Failed to create the pipe."); + // } pid_t pid = fork(); - if (pid == -1) { - THROW_EXCEPTION(PythonExecutorError, "Failed to fork the process."); - } + // if (pid == -1) { + // THROW_EXCEPTION(PythonExecutorError, "Failed to fork the process."); + // } if (pid == 0) { // Child process close(pipefd[0]); - if (dup2(pipefd[1], STDOUT_FILENO) == -1) { - THROW_EXCEPTION(PythonExecutorError, "Failed to redirect stdout."); - } + // if (dup2(pipefd[1], STDOUT_FILENO) == -1) { + // THROW_EXCEPTION(PythonExecutorError, "Failed to redirect stdout."); + // } signal(SIGALRM, [](int) { exit(1); }); alarm(60); // 60 seconds timeout execlp("python3", "python3", scriptPath.c_str(), imagePath.c_str(), std::to_string(lastValue).c_str(), nullptr); - THROW_EXCEPTION(PythonExecutorError, "Failed to execute the python script."); + // THROW_EXCEPTION(PythonExecutorError, "Failed to execute the python script."); + return ""; } else { // Parent process close(pipefd[1]); @@ -55,16 +56,16 @@ void PyExecutor::_handleExitStatus(int returnCode) { int statusCode = WEXITSTATUS(returnCode); std::cerr << "Command exited with status " << statusCode << std::endl; THROW_EXCEPTION(PythonExecutorError, "Command execution failed with status code."); - } else if (WIFSIGNALED(returnCode)) { - int signalNumber = WTERMSIG(returnCode); - if (signalNumber == SIGALRM) { - throw std::runtime_error("PythonExecutor: Command execution timed out."); - } - std::cerr << "Command terminated by signal " << signalNumber << std::endl; - THROW_EXCEPTION(PythonExecutorError, "Command terminated unexpectedly by a signal."); - } else { - std::cerr << "Command failed with return code " << returnCode << std::endl; - THROW_EXCEPTION(PythonExecutorError, "Command execution failed."); + // } else if (WIFSIGNALED(returnCode)) { + // int signalNumber = WTERMSIG(returnCode); + // if (signalNumber == SIGALRM) { + // throw std::runtime_error("PythonExecutor: Command execution timed out."); + // } + // std::cerr << "Command terminated by signal " << signalNumber << std::endl; + // THROW_EXCEPTION(PythonExecutorError, "Command terminated unexpectedly by a signal."); + // } else { + // std::cerr << "Command failed with return code " << returnCode << std::endl; + // THROW_EXCEPTION(PythonExecutorError, "Command execution failed."); } } } diff --git a/App/Modules/OCRModule/OCRModule.cpp b/App/Modules/OCRModule/OCRModule.cpp index e21e53c..4f87236 100644 --- a/App/Modules/OCRModule/OCRModule.cpp +++ b/App/Modules/OCRModule/OCRModule.cpp @@ -23,12 +23,12 @@ std::shared_ptr const OCRModule::handle( // static std::string const failSafe = "/home/tidaly/delivery/tidaly-image-processing/bin/GCPOCR/GCPOCR.py"; try { - if (!cv::imwrite(imagePath, image->image)) { - throw ModuleError("Failed to write temporary image."); - } + // if (!cv::imwrite(imagePath, image->image)) { + // throw ModuleError("Failed to write temporary image."); + // } std::cerr << "[\033[0;33mINFO\033[0m] OCRModule: Calling PaddleOCR (running external python script: " << scriptPath << ")" << std::endl; std::string output = this->_executor.executeScript(scriptPath, imagePath, image->lastValue); - std::cerr << "[\033[0;33mINFO\033[0m] OCRModule: Finished PaddleOCR subprocess" << std::endl; + // std::cerr << "[\033[0;33mINFO\033[0m] OCRModule: Finished PaddleOCR subprocess" << std::endl; // if (output.length() == 0) { // // call failsafe // output = this->_executor.executeScript(failSafe, imagePath, image->lastValue); diff --git a/Tests/Core/CommandLineParser_test.cpp b/Tests/Core/CommandLineParser_test.cpp index a347009..e7bdbfa 100644 --- a/Tests/Core/CommandLineParser_test.cpp +++ b/Tests/Core/CommandLineParser_test.cpp @@ -41,4 +41,14 @@ TEST_CASE("Check parameters", "[core][clp]") { char *av[] = {(char *)"./tidaly-ocr", (char *)"--output", (char *)"FIFO", (char *)"./output.fifo"}; REQUIRE_NOTHROW(parser.parse(4, av)); } + + SECTION("Check output malformed FIFO") { + char *av[] = {(char *)"./tidaly-ocr", (char *)"--output", (char *)"BadOptionAndMissingFile"}; + REQUIRE_THROWS_AS(parser.parse(3, av), std::exception); + } + + SECTION("Check input Image") { + char *av[] = {(char *)"./tidaly-ocr", (char *)"--input", (char *)"./Assets/input/input_test.jpg"}; + REQUIRE_NOTHROW(parser.parse(3, av)); + } } diff --git a/Tests/Core/Errors_test.cpp b/Tests/Core/Errors_test.cpp index 83befdf..fc9fefd 100644 --- a/Tests/Core/Errors_test.cpp +++ b/Tests/Core/Errors_test.cpp @@ -15,4 +15,7 @@ TEST_CASE("Check what() of error", "[core][error]") { ModuleError error("test"); REQUIRE(error.what() == std::string("[\033[1;31mERROR REPORT\033[0m] [Module] test")); + + FifoError fifoError("test"); + REQUIRE(fifoError.what() == std::string("[\033[1;31mERROR REPORT\033[0m] [Fifo] test")); } diff --git a/bin/test.sh b/bin/test.sh index a50992e..b362eec 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -13,7 +13,7 @@ if [ "$SKIP_PAUSE" != "1" ]; then fi lcov --capture --directory ./build/CMakeFiles/imageProcessing_test.dir/App --output-file build/coverage.info --ignore-errors inconsistent -lcov --remove build/coverage.info '*/_deps/*' '*/_test.cpp' '*/App/main.cpp' '*/Applications/*' '*/catch2/*' '*/homebrew/*' '*/homebrew/*''/usr/*' '*/Tests/*' '/usr/*' '*/opencv_install/*' --output-file build/coverage.info --ignore-errors inconsistent +lcov --remove build/coverage.info '*/_deps/*' '*/_test.cpp' '*/App/main.cpp' '*/Applications/*' '*/catch2/*' '*/homebrew/*' '*/Tests/*' '/usr/*' '*/opencv_install/*' --output-file build/coverage.info --ignore-errors inconsistent lcov --list build/coverage.info --ignore-errors inconsistent if [ "$SKIP_PAUSE" != "1" ]; then