Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Apr 12, 2024
1 parent e8d6f22 commit 24c903f
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
3 changes: 2 additions & 1 deletion velox/expression/tests/ExpressionFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ int main(int argc, char** argv) {
// experience, and initialize glog and gflags.
folly::Init init(&argc, &argv);

size_t initialSeed = FLAGS_seed == 0 ? std::time(nullptr) : FLAGS_seed;

// TODO: List of the functions that at some point crash or fail and need to
// be fixed before we can enable.
// This list can include a mix of function names and function signatures.
Expand Down Expand Up @@ -81,6 +83,5 @@ int main(int argc, char** argv) {
{"floor", std::make_shared<FloorAndRoundArgGenerator>()},
{"round", std::make_shared<FloorAndRoundArgGenerator>()}};

size_t initialSeed = FLAGS_seed == 0 ? std::time(nullptr) : FLAGS_seed;
return FuzzerRunner::run(initialSeed, skipFunctions, {{}}, argGenerators);
}
15 changes: 14 additions & 1 deletion velox/expression/tests/SparkExpressionFuzzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

#include "velox/expression/tests/FuzzerRunner.h"
#include "velox/functions/sparksql/Register.h"
#include "velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h"
#include "velox/functions/sparksql/fuzzer/DivideArgGenerator.h"
#include "velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h"

using namespace facebook::velox::functions::sparksql::test;
using facebook::velox::test::ArgGenerator;

DEFINE_int64(
seed,
Expand Down Expand Up @@ -60,5 +66,12 @@ int main(int argc, char** argv) {
std::unordered_map<std::string, std::string> queryConfigs = {
{facebook::velox::core::QueryConfig::kSparkPartitionId, "123"}};

return FuzzerRunner::run(FLAGS_seed, skipFunctions, queryConfigs, {});
std::unordered_map<std::string, std::shared_ptr<ArgGenerator>> argGenerators =
{{"add", std::make_shared<AddSubtractArgGenerator>()},
{"subtract", std::make_shared<AddSubtractArgGenerator>()},
{"multiply", std::make_shared<MultiplyArgGenerator>()},
{"divide", std::make_shared<DivideArgGenerator>()}};

return FuzzerRunner::run(
FLAGS_seed, skipFunctions, queryConfigs, argGenerators);
}
47 changes: 47 additions & 0 deletions velox/functions/sparksql/fuzzer/AddSubtractArgGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*/
#pragma once

#include "velox/expression/tests/ArgGenerator.h"
#include "velox/functions/sparksql/DecimalUtil.h"

namespace facebook::velox::functions::sparksql::test {

class AddSubtractArgGenerator
: public facebook::velox::test::DecimalArgGeneratorBase {
public:
AddSubtractArgGenerator() {
initialize();
}

protected:
std::optional<std::pair<int, int>> toReturnType(int count, ...) override {
VELOX_CHECK_EQ(count, 4);
va_list args;
va_start(args, count);
const int p1 = va_arg(args, int);
const int s1 = va_arg(args, int);
const int p2 = va_arg(args, int);
const int s2 = va_arg(args, int);
va_end(args);

const auto precision = std::max(p1 - s1, p2 - s2) + std::max(s1, s2) + 1;
const auto scale = max(s1, s2);
return DecimalUtil::adjustPrecisionScale(precision, scale);
}
};

} // namespace facebook::velox::functions::sparksql::test
47 changes: 47 additions & 0 deletions velox/functions/sparksql/fuzzer/DivideArgGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*/
#pragma once

#include "velox/expression/tests/ArgGenerator.h"
#include "velox/functions/sparksql/DecimalUtil.h"

namespace facebook::velox::functions::sparksql::test {

class DivideArgGenerator
: public facebook::velox::test::DecimalArgGeneratorBase {
public:
DivideArgGenerator() {
initialize();
}

protected:
std::optional<std::pair<int, int>> toReturnType(int count, ...) override {
VELOX_CHECK_EQ(count, 4);
va_list args;
va_start(args, count);
const int p1 = va_arg(args, int);
const int s1 = va_arg(args, int);
const int p2 = va_arg(args, int);
const int s2 = va_arg(args, int);
va_end(args);

const auto scale = std::max(6, s1 + p2 + 1);
const auto precision = p1 - s1 + s2 + scale;
return DecimalUtil::adjustPrecisionScale(precision, scale);
}
};

} // namespace facebook::velox::functions::sparksql::test
45 changes: 45 additions & 0 deletions velox/functions/sparksql/fuzzer/MultiplyArgGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/
#pragma once

#include "velox/expression/tests/ArgGenerator.h"
#include "velox/functions/sparksql/DecimalUtil.h"

namespace facebook::velox::functions::sparksql::test {

class MultiplyArgGenerator
: public facebook::velox::test::DecimalArgGeneratorBase {
public:
MultiplyArgGenerator() {
initialize();
}

protected:
std::optional<std::pair<int, int>> toReturnType(int count, ...) override {
VELOX_CHECK_EQ(count, 4);
va_list args;
va_start(args, count);
const int p1 = va_arg(args, int);
const int s1 = va_arg(args, int);
const int p2 = va_arg(args, int);
const int s2 = va_arg(args, int);
va_end(args);

return DecimalUtil::adjustPrecisionScale(p1 + p2 + 1, s1 + s2);
}
};

} // namespace facebook::velox::functions::sparksql::test

0 comments on commit 24c903f

Please sign in to comment.