From 7ebd03fab000eb0288bbd932a75135d381dd8178 Mon Sep 17 00:00:00 2001 From: gueckmooh Date: Wed, 22 Feb 2023 22:07:00 +0100 Subject: [PATCH 1/3] Make -D- option for compiled datalog behave same as if interpreted --- src/include/souffle/CompiledOptions.h | 9 ++++++++- src/synthesiser/Synthesiser.cpp | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/souffle/CompiledOptions.h b/src/include/souffle/CompiledOptions.h index 256f7e8709a..9de6c865008 100644 --- a/src/include/souffle/CompiledOptions.h +++ b/src/include/souffle/CompiledOptions.h @@ -151,7 +151,7 @@ class CmdOptions { break; /* Output directory for resulting .csv files */ case 'D': - if (*optarg && !existDir(optarg)) { + if (*optarg && !existDir(optarg) && !dirIsStdout(optarg)) { printf("Output directory %s does not exists!\n", optarg); ok = false; } @@ -258,6 +258,13 @@ class CmdOptions { } return false; } + + /** + * Check whether the output is "-", for which the output should be stdout + */ + bool dirIsStdout(const std::string& name) const { + return name == "-"; + } }; } // end of namespace souffle diff --git a/src/synthesiser/Synthesiser.cpp b/src/synthesiser/Synthesiser.cpp index f251a03124d..03eb81785ab 100644 --- a/src/synthesiser/Synthesiser.cpp +++ b/src/synthesiser/Synthesiser.cpp @@ -376,7 +376,10 @@ void Synthesiser::emitCode(std::ostream& out, const Statement& stmt) { out << "std::map directiveMap("; printDirectives(directives); out << ");\n"; - out << R"_(if (!outputDirectory.empty()) {)_"; + out << R"_(if (outputDirectory == "-"){)_"; + out << R"_(directiveMap["IO"] = "stdout"; directiveMap["headers"] = "true";)_"; + out << "}\n"; + out << R"_(else if (!outputDirectory.empty()) {)_"; out << R"_(directiveMap["output-dir"] = outputDirectory;)_"; out << "}\n"; out << "IOSystem::getInstance().getWriter("; From db6c30ed80edc96f16f10249b1d7dcd03bfdb321 Mon Sep 17 00:00:00 2001 From: gueckmooh Date: Fri, 24 Feb 2023 20:54:23 +0100 Subject: [PATCH 2/3] Add unit test --- cmake/SouffleTests.cmake | 8 ++++++-- tests/CMakeLists.txt | 1 + tests/behavior/CMakeLists.txt | 14 ++++++++++++++ tests/behavior/output_stdout/output_stdout.dl | 9 +++++++++ tests/behavior/output_stdout/output_stdout.err | 0 tests/behavior/output_stdout/output_stdout.out | 6 ++++++ 6 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/behavior/CMakeLists.txt create mode 100644 tests/behavior/output_stdout/output_stdout.dl create mode 100644 tests/behavior/output_stdout/output_stdout.err create mode 100644 tests/behavior/output_stdout/output_stdout.out diff --git a/cmake/SouffleTests.cmake b/cmake/SouffleTests.cmake index 9b320179b87..2782ed2c6ce 100644 --- a/cmake/SouffleTests.cmake +++ b/cmake/SouffleTests.cmake @@ -144,7 +144,7 @@ function(SOUFFLE_RUN_TEST_HELPER) #Usually just "facts" but can be different when running multi - tests cmake_parse_arguments( PARAM - "COMPILED;COMPILED_SPLITTED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR" # Options + "COMPILED;COMPILED_SPLITTED;FUNCTORS;NEGATIVE;MULTI_TEST;NO_PREPROCESSOR;OUTPUT_STDOUT" # Options "TEST_NAME;CATEGORY;FACTS_DIR_NAME;EXTRA_DATA" #Single valued options "INCLUDE_DIRS" # Multi-valued options ${ARGV} @@ -226,7 +226,11 @@ function(SOUFFLE_RUN_TEST_HELPER) FIXTURE_NAME ${FIXTURE_NAME} TEST_LABELS ${TEST_LABELS}) - set(SOUFFLE_PARAMS "-D" "." "-F" "${FACTS_DIR}") + if(PARAM_OUTPUT_STDOUT) + set(SOUFFLE_PARAMS "-D-" "-F" "${FACTS_DIR}") + else() + set(SOUFFLE_PARAMS "-D" "." "-F" "${FACTS_DIR}") + endif() list(PREPEND SOUFFLE_PARAMS ${EXTRA_FLAGS}) if (OPENMP_FOUND) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 41ee14a57be..6426f442e52 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,3 +19,4 @@ add_subdirectory(profile) add_subdirectory(scheduler) add_subdirectory(link) add_subdirectory(libsouffle_interface) +add_subdirectory(behavior) diff --git a/tests/behavior/CMakeLists.txt b/tests/behavior/CMakeLists.txt new file mode 100644 index 00000000000..85c651e231d --- /dev/null +++ b/tests/behavior/CMakeLists.txt @@ -0,0 +1,14 @@ +# Souffle - A Datalog Compiler +# Copyright (c) 2023 The Souffle Developers. All rights reserved +# Licensed under the Universal Permissive License v 1.0 as shown at: +# - https://opensource.org/licenses/UPL +# - /licenses/SOUFFLE-UPL.txt + +include(SouffleTests) + +function(POSITIVE_TEST NAME) + souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY behavior ${ARGV}) + souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY behavior ${ARGV} COMPILED) +endfunction() + +positive_test(output_stdout OUTPUT_STDOUT) diff --git a/tests/behavior/output_stdout/output_stdout.dl b/tests/behavior/output_stdout/output_stdout.dl new file mode 100644 index 00000000000..4ac5933e697 --- /dev/null +++ b/tests/behavior/output_stdout/output_stdout.dl @@ -0,0 +1,9 @@ +// Souffle - A Datalog Compiler +// Copyright (c) 2023, The Souffle Developers. All rights reserved +// Licensed under the Universal Permissive License v 1.0 as shown at: +// - https://opensource.org/licenses/UPL +// - /licenses/SOUFFLE-UPL.txt + +.decl foo(a: symbol) +.output foo +foo("bar"). diff --git a/tests/behavior/output_stdout/output_stdout.err b/tests/behavior/output_stdout/output_stdout.err new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/behavior/output_stdout/output_stdout.out b/tests/behavior/output_stdout/output_stdout.out new file mode 100644 index 00000000000..b7b7a7ec402 --- /dev/null +++ b/tests/behavior/output_stdout/output_stdout.out @@ -0,0 +1,6 @@ +--------------- +foo +a +=============== +bar +=============== From 519c438637b395b905310760376252621e23b9c7 Mon Sep 17 00:00:00 2001 From: Enzo Brignon Date: Mon, 27 Feb 2023 10:14:18 +0100 Subject: [PATCH 3/3] Move the tests from behavior to semantic --- tests/CMakeLists.txt | 1 - tests/behavior/CMakeLists.txt | 14 -------------- tests/semantic/CMakeLists.txt | 8 +++++++- .../output_stdout/output_stdout.dl | 0 .../output_stdout/output_stdout.err | 0 .../output_stdout/output_stdout.out | 0 6 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 tests/behavior/CMakeLists.txt rename tests/{behavior => semantic}/output_stdout/output_stdout.dl (100%) rename tests/{behavior => semantic}/output_stdout/output_stdout.err (100%) rename tests/{behavior => semantic}/output_stdout/output_stdout.out (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6426f442e52..41ee14a57be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,4 +19,3 @@ add_subdirectory(profile) add_subdirectory(scheduler) add_subdirectory(link) add_subdirectory(libsouffle_interface) -add_subdirectory(behavior) diff --git a/tests/behavior/CMakeLists.txt b/tests/behavior/CMakeLists.txt deleted file mode 100644 index 85c651e231d..00000000000 --- a/tests/behavior/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Souffle - A Datalog Compiler -# Copyright (c) 2023 The Souffle Developers. All rights reserved -# Licensed under the Universal Permissive License v 1.0 as shown at: -# - https://opensource.org/licenses/UPL -# - /licenses/SOUFFLE-UPL.txt - -include(SouffleTests) - -function(POSITIVE_TEST NAME) - souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY behavior ${ARGV}) - souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY behavior ${ARGV} COMPILED) -endfunction() - -positive_test(output_stdout OUTPUT_STDOUT) diff --git a/tests/semantic/CMakeLists.txt b/tests/semantic/CMakeLists.txt index eecadb55ecf..1d929b09189 100644 --- a/tests/semantic/CMakeLists.txt +++ b/tests/semantic/CMakeLists.txt @@ -18,6 +18,11 @@ function(positive_test NAME) souffle_positive_test(${NAME} semantic ${ARGN}) endfunction() +function(positive_output_stdout_test NAME) + souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY semantic OUTPUT_STDOUT ${ARGV}) + souffle_run_test_helper(TEST_NAME ${NAME} CATEGORY semantic OUTPUT_STDOUT ${ARGV} COMPILED) +endfunction() + function(negative_test NAME) souffle_negative_test(${NAME} semantic) endfunction() @@ -259,4 +264,5 @@ positive_test(underscore5) negative_test(mutually_dependent_aggregate) positive_test(independent_aggregate) positive_test(independent_aggregate2) -souffle_positive_functor_test(issue2373 CATEGORY semantic) \ No newline at end of file +souffle_positive_functor_test(issue2373 CATEGORY semantic) +positive_output_stdout_test(output_stdout) diff --git a/tests/behavior/output_stdout/output_stdout.dl b/tests/semantic/output_stdout/output_stdout.dl similarity index 100% rename from tests/behavior/output_stdout/output_stdout.dl rename to tests/semantic/output_stdout/output_stdout.dl diff --git a/tests/behavior/output_stdout/output_stdout.err b/tests/semantic/output_stdout/output_stdout.err similarity index 100% rename from tests/behavior/output_stdout/output_stdout.err rename to tests/semantic/output_stdout/output_stdout.err diff --git a/tests/behavior/output_stdout/output_stdout.out b/tests/semantic/output_stdout/output_stdout.out similarity index 100% rename from tests/behavior/output_stdout/output_stdout.out rename to tests/semantic/output_stdout/output_stdout.out