Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract fuzzer into expression/fuzzer directory #9651

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: presto
path: velox/_build/debug/velox/expression/tests/velox_expression_fuzzer_test
path: velox/_build/debug/velox/expression/fuzzer/velox_expression_fuzzer_test
retention-days: "${{ env.RETENTION }}"

- name: Upload spark expression fuzzer
uses: actions/upload-artifact@v4
with:
name: spark_expression_fuzzer
path: velox/_build/debug/velox/expression/tests/spark_expression_fuzzer_test
path: velox/_build/debug/velox/expression/fuzzer/spark_expression_fuzzer_test
retention-days: "${{ env.RETENTION }}"

- name: Upload spark aggregation fuzzer
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ unittest: debug #: Build with debugging and run unit tests
# Build with debugging and run expression fuzzer test. Use a fixed seed to
# ensure the tests are reproducible.
fuzzertest: debug
$(BUILD_BASE_DIR)/debug/velox/expression/tests/velox_expression_fuzzer_test \
$(BUILD_BASE_DIR)/debug/velox/expression/fuzzer/velox_expression_fuzzer_test \
--seed $(FUZZER_SEED) \
--duration_sec $(FUZZER_DURATION_SEC) \
--repro_persist_path $(FUZZER_REPRO_PERSIST_PATH) \
Expand Down
2 changes: 1 addition & 1 deletion velox/docs/develop/testing/fuzzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ When Fuzzer test fails, a seed number and the evaluated expression are
printed to the log. An example is given below. Developers can use ``--seed``
with this seed number to rerun the exact same expression with the same inputs,
and use a debugger to investigate the issue. For the example below, the command
to reproduce the error would be ``velox/expression/tests/velox_expression_fuzzer_test --seed 1188545576``.
to reproduce the error would be ``velox/expression/fuzzer/velox_expression_fuzzer_test --seed 1188545576``.

::

Expand Down
10 changes: 5 additions & 5 deletions velox/exec/fuzzer/AggregationFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "velox/exec/PartitionFunction.h"
#include "velox/exec/fuzzer/AggregationFuzzerBase.h"
#include "velox/expression/tests/utils/FuzzerToolkit.h"
#include "velox/expression/fuzzer/FuzzerToolkit.h"
#include "velox/vector/VectorSaver.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

Expand All @@ -39,8 +39,8 @@ DEFINE_bool(
false,
"When true, the results of the window aggregation are compared to reference DB results");

using facebook::velox::test::CallableSignature;
using facebook::velox::test::SignatureTemplate;
using facebook::velox::fuzzer::CallableSignature;
using facebook::velox::fuzzer::SignatureTemplate;

namespace facebook::velox::exec::test {

Expand Down Expand Up @@ -153,7 +153,7 @@ class AggregationFuzzer : public AggregationFuzzerBase {
const std::vector<PlanWithSplits>& plans,
bool customVerification,
const std::vector<std::shared_ptr<ResultVerifier>>& customVerifiers,
const velox::test::ResultOrError& expected,
const velox::fuzzer::ResultOrError& expected,
int32_t maxDrivers = 2,
bool testWithSpilling = true) {
for (auto i = 0; i < plans.size(); ++i) {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ bool AggregationFuzzer::compareEquivalentPlanResults(
stats_.updateReferenceQueryStats(referenceResult.second);

if (referenceResult.first) {
velox::test::ResultOrError expected;
velox::fuzzer::ResultOrError expected;
expected.result =
mergeRowVectors(referenceResult.first.value(), pool_.get());

Expand Down
17 changes: 9 additions & 8 deletions velox/exec/fuzzer/AggregationFuzzerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "velox/exec/fuzzer/PrestoQueryRunner.h"
#include "velox/exec/tests/utils/TempDirectoryPath.h"
#include "velox/expression/SignatureBinder.h"
#include "velox/expression/tests/utils/ArgumentTypeFuzzer.h"
#include "velox/expression/fuzzer/ArgumentTypeFuzzer.h"
#include "velox/vector/VectorSaver.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

Expand Down Expand Up @@ -198,7 +198,7 @@ AggregationFuzzerBase::pickSignature() {
const auto& signatureTemplate =
signatureTemplates_[idx - signatures_.size()];
signature.name = signatureTemplate.name;
velox::test::ArgumentTypeFuzzer typeFuzzer(
velox::fuzzer::ArgumentTypeFuzzer typeFuzzer(
*signatureTemplate.signature, rng_);
VELOX_CHECK(typeFuzzer.fuzzArgumentTypes(FLAGS_max_num_varargs));
signature.args = typeFuzzer.argumentTypes();
Expand Down Expand Up @@ -386,7 +386,7 @@ void AggregationFuzzerBase::printSignatureStats() {
}
}

velox::test::ResultOrError AggregationFuzzerBase::execute(
velox::fuzzer::ResultOrError AggregationFuzzerBase::execute(
const core::PlanNodePtr& plan,
const std::vector<exec::Split>& splits,
bool injectSpill,
Expand All @@ -395,7 +395,7 @@ velox::test::ResultOrError AggregationFuzzerBase::execute(
LOG(INFO) << "Executing query plan: " << std::endl
<< plan->toString(true, true);

velox::test::ResultOrError resultOrError;
velox::fuzzer::ResultOrError resultOrError;
try {
std::shared_ptr<TempDirectoryPath> spillDirectory;
AssertQueryBuilder builder(plan);
Expand Down Expand Up @@ -511,7 +511,7 @@ void AggregationFuzzerBase::testPlan(
bool abandonPartial,
bool customVerification,
const std::vector<std::shared_ptr<ResultVerifier>>& customVerifiers,
const velox::test::ResultOrError& expected,
const velox::fuzzer::ResultOrError& expected,
int32_t maxDrivers) {
auto actual = execute(
planWithSplits.plan,
Expand All @@ -523,10 +523,10 @@ void AggregationFuzzerBase::testPlan(
}

void AggregationFuzzerBase::compare(
const velox::test::ResultOrError& actual,
const velox::fuzzer::ResultOrError& actual,
bool customVerification,
const std::vector<std::shared_ptr<ResultVerifier>>& customVerifiers,
const velox::test::ResultOrError& expected) {
const velox::fuzzer::ResultOrError& expected) {
// Compare results or exceptions (if any). Fail is anything is different.
if (FLAGS_enable_oom_injection) {
// If OOM injection is enabled and we've made it this far and the test
Expand All @@ -537,7 +537,8 @@ void AggregationFuzzerBase::compare(
// Compare results or exceptions (if any). Fail if anything is different.
if (expected.exceptionPtr || actual.exceptionPtr) {
// Throws in case exceptions are not compatible.
velox::test::compareExceptions(expected.exceptionPtr, actual.exceptionPtr);
velox::fuzzer::compareExceptions(
expected.exceptionPtr, actual.exceptionPtr);
return;
}

Expand Down
14 changes: 7 additions & 7 deletions velox/exec/fuzzer/AggregationFuzzerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "velox/exec/fuzzer/ReferenceQueryRunner.h"
#include "velox/exec/fuzzer/ResultVerifier.h"
#include "velox/exec/tests/utils/AssertQueryBuilder.h"
#include "velox/expression/tests/utils/FuzzerToolkit.h"
#include "velox/expression/fuzzer/FuzzerToolkit.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"
#include "velox/vector/tests/utils/VectorMaker.h"

Expand All @@ -47,8 +47,8 @@ DECLARE_bool(log_signature_stats);

namespace facebook::velox::exec::test {

using facebook::velox::test::CallableSignature;
using facebook::velox::test::SignatureTemplate;
using facebook::velox::fuzzer::CallableSignature;
using facebook::velox::fuzzer::SignatureTemplate;

constexpr const std::string_view kPlanNodeFileName = "plan_nodes";

Expand Down Expand Up @@ -219,7 +219,7 @@ class AggregationFuzzerBase {
const core::PlanNodePtr& plan,
const std::vector<RowVectorPtr>& input);

velox::test::ResultOrError execute(
velox::fuzzer::ResultOrError execute(
const core::PlanNodePtr& plan,
const std::vector<exec::Split>& splits = {},
bool injectSpill = false,
Expand All @@ -236,10 +236,10 @@ class AggregationFuzzerBase {
const std::vector<RowVectorPtr>& input);

void compare(
const velox::test::ResultOrError& actual,
const velox::fuzzer::ResultOrError& actual,
bool customVerification,
const std::vector<std::shared_ptr<ResultVerifier>>& customVerifiers,
const velox::test::ResultOrError& expected);
const velox::fuzzer::ResultOrError& expected);

/// Returns false if the type or its children are unsupported.
/// Currently returns false if type is Date,IntervalDayTime or Unknown.
Expand All @@ -258,7 +258,7 @@ class AggregationFuzzerBase {
bool abandonPartial,
bool customVerification,
const std::vector<std::shared_ptr<ResultVerifier>>& customVerifiers,
const velox::test::ResultOrError& expected,
const velox::fuzzer::ResultOrError& expected,
int32_t maxDrivers = 2);

void printSignatureStats();
Expand Down
2 changes: 1 addition & 1 deletion velox/exec/fuzzer/AggregationFuzzerRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AggregationFuzzerRunner {
exit(1);
}

auto filteredSignatures = velox::test::filterSignatures(
auto filteredSignatures = velox::fuzzer::filterSignatures(
signatures, options.onlyFunctions, options.skipFunctions);
if (filteredSignatures.empty()) {
LOG(ERROR)
Expand Down
4 changes: 2 additions & 2 deletions velox/exec/fuzzer/WindowFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void WindowFuzzer::testAlternativePlans(
const std::vector<RowVectorPtr>& input,
bool customVerification,
const std::shared_ptr<ResultVerifier>& customVerifier,
const velox::test::ResultOrError& expected) {
const velox::fuzzer::ResultOrError& expected) {
std::vector<AggregationFuzzerBase::PlanWithSplits> plans;

std::vector<std::string> allKeys;
Expand Down Expand Up @@ -393,7 +393,7 @@ bool WindowFuzzer::verifyWindow(
persistReproInfo({{plan, {}}}, reproPersistPath_);
}

velox::test::ResultOrError resultOrError;
velox::fuzzer::ResultOrError resultOrError;
try {
resultOrError = execute(plan);
if (resultOrError.exceptionPtr) {
Expand Down
2 changes: 1 addition & 1 deletion velox/exec/fuzzer/WindowFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class WindowFuzzer : public AggregationFuzzerBase {
const std::vector<RowVectorPtr>& input,
bool customVerification,
const std::shared_ptr<ResultVerifier>& customVerifier,
const velox::test::ResultOrError& expected);
const velox::fuzzer::ResultOrError& expected);

const std::unordered_set<std::string> orderDependentFunctions_;

Expand Down
6 changes: 3 additions & 3 deletions velox/exec/fuzzer/WindowFuzzerRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "velox/exec/Aggregate.h"
#include "velox/exec/fuzzer/AggregationFuzzerOptions.h"
#include "velox/exec/fuzzer/WindowFuzzer.h"
#include "velox/expression/tests/utils/FuzzerToolkit.h"
#include "velox/expression/fuzzer/FuzzerToolkit.h"
#include "velox/parse/TypeResolver.h"
#include "velox/serializers/PrestoSerializer.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"
Expand Down Expand Up @@ -63,9 +63,9 @@ class WindowFuzzerRunner {
exit(1);
}

auto filteredAggregationSignatures = velox::test::filterSignatures(
auto filteredAggregationSignatures = velox::fuzzer::filterSignatures(
aggregationSignatures, options.onlyFunctions, options.skipFunctions);
auto filteredWindowSignatures = velox::test::filterSignatures(
auto filteredWindowSignatures = velox::fuzzer::filterSignatures(
windowSignatures, options.onlyFunctions, options.skipFunctions);
if (filteredAggregationSignatures.empty() &&
filteredWindowSignatures.empty()) {
Expand Down
3 changes: 1 addition & 2 deletions velox/expression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ add_subdirectory(signature_parser)

if(${VELOX_BUILD_TESTING})
add_subdirectory(tests)
elseif(${VELOX_BUILD_TEST_UTILS})
add_subdirectory(tests/utils)
add_subdirectory(fuzzer)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "velox/expression/tests/utils/ArgumentTypeFuzzer.h"
#include "velox/expression/fuzzer/ArgumentTypeFuzzer.h"

#include <boost/algorithm/string.hpp>
#include <boost/random/uniform_int_distribution.hpp>
Expand All @@ -24,7 +24,7 @@
#include "velox/type/Type.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"

namespace facebook::velox::test {
namespace facebook::velox::fuzzer {

std::string typeToBaseName(const TypePtr& type) {
if (type->isDecimal()) {
Expand Down Expand Up @@ -226,4 +226,4 @@ int32_t ArgumentTypeFuzzer::rand32(int32_t min, int32_t max) {
return boost::random::uniform_int_distribution<uint32_t>(min, max)(rng_);
}

} // namespace facebook::velox::test
} // namespace facebook::velox::fuzzer
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "velox/expression/SignatureBinder.h"
#include "velox/type/Type.h"

namespace facebook::velox::test {
namespace facebook::velox::fuzzer {

/// For function signatures using type variables, generates a list of
/// arguments types. Optionally, allows to specify a desired return type. If
Expand Down Expand Up @@ -104,4 +104,4 @@ std::string typeToBaseName(const TypePtr& type);
/// Return the TypeKind that corresponds to typeName.
std::optional<TypeKind> baseNameToTypeKind(const std::string& typeName);

} // namespace facebook::velox::test
} // namespace facebook::velox::fuzzer
46 changes: 46 additions & 0 deletions velox/expression/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_library(velox_expression_test_utility ArgumentTypeFuzzer.cpp
FuzzerToolkit.cpp)

target_link_libraries(velox_expression_test_utility velox_type
velox_expression_functions gtest)

add_library(
velox_expression_fuzzer ArgumentTypeFuzzer.cpp ExpressionFuzzer.cpp
FuzzerRunner.cpp ExpressionFuzzerVerifier.cpp)

target_link_libraries(
velox_expression_fuzzer
velox_expression_verifier
velox_type
velox_vector_fuzzer
velox_vector_test_lib
velox_function_registry
velox_expression_test_utility)

add_executable(velox_expression_fuzzer_test ExpressionFuzzerTest.cpp)

target_link_libraries(velox_expression_fuzzer_test velox_expression_fuzzer
velox_functions_prestosql gtest gtest_main)

add_executable(spark_expression_fuzzer_test SparkExpressionFuzzerTest.cpp)

target_link_libraries(spark_expression_fuzzer_test velox_expression_fuzzer
velox_functions_spark gtest gtest_main)

if(${VELOX_BUILD_TESTING})
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include "velox/expression/FunctionSignature.h"
#include "velox/expression/ReverseSignatureBinder.h"
#include "velox/expression/SimpleFunctionRegistry.h"
#include "velox/expression/tests/ExpressionFuzzer.h"
#include "velox/expression/tests/utils/ArgumentTypeFuzzer.h"
#include "velox/expression/fuzzer/ArgumentTypeFuzzer.h"
#include "velox/expression/fuzzer/ExpressionFuzzer.h"

namespace facebook::velox::test {
namespace facebook::velox::fuzzer {

namespace {
using exec::SignatureBinder;
Expand Down Expand Up @@ -1384,4 +1384,4 @@ RowTypePtr ExpressionFuzzer::fuzzRowReturnType(size_t size, char prefix) {
return ROW(std::move(names), std::move(children));
}

} // namespace facebook::velox::test
} // namespace facebook::velox::fuzzer
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include "velox/core/ITypedExpr.h"
#include "velox/core/QueryCtx.h"
#include "velox/expression/Expr.h"
#include "velox/expression/fuzzer/FuzzerToolkit.h"
#include "velox/expression/tests/ExpressionVerifier.h"
#include "velox/expression/tests/utils/FuzzerToolkit.h"
#include "velox/functions/FunctionRegistry.h"
#include "velox/vector/fuzzer/VectorFuzzer.h"
#include "velox/vector/tests/utils/VectorMaker.h"

namespace facebook::velox::test {
namespace facebook::velox::fuzzer {

// A tool that can be used to generate random expressions.
class ExpressionFuzzer {
Expand Down Expand Up @@ -418,4 +418,4 @@ class ExpressionFuzzer {
friend class ExpressionFuzzerUnitTest;
};

} // namespace facebook::velox::test
} // namespace facebook::velox::fuzzer
Loading
Loading