-
Notifications
You must be signed in to change notification settings - Fork 105
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
update fuzztest #1112
base: master
Are you sure you want to change the base?
update fuzztest #1112
Changes from 6 commits
9e474a7
a66fe2d
b66990c
dc45b00
0359666
fec7d9b
ea188db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,3 +421,15 @@ TEST(Boolean, Precision2) { | |
cube2 = cube2.Translate(vec3(scale * kPrecision)); | ||
EXPECT_FALSE((cube ^ cube2).IsEmpty()); | ||
} | ||
|
||
TEST(Boolean, SimpleCubeRegression) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elalish it is now here. |
||
ManifoldParams().intermediateChecks = true; | ||
ManifoldParams().processOverlaps = false; | ||
Manifold result = | ||
Manifold::Cube().Rotate(-0.10000000000000001, 0.10000000000000001, -1.) + | ||
Manifold::Cube() - | ||
Manifold::Cube().Rotate(-0.10000000000000001, -0.10000000000066571, -1.); | ||
EXPECT_EQ(result.Status(), Manifold::Error::NoError); | ||
ManifoldParams().intermediateChecks = false; | ||
ManifoldParams().processOverlaps = true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2024 The Manifold Authors. | ||
// | ||
// 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. | ||
|
||
#include <atomic> | ||
#include <future> | ||
|
||
#include "fuzztest/fuzztest.h" | ||
#include "gtest/gtest.h" | ||
#include "manifold/manifold.h" | ||
|
||
using namespace fuzztest; | ||
using namespace manifold; | ||
|
||
enum class TransformType { Translate, Rotate, Scale }; | ||
struct Transform { | ||
TransformType ty; | ||
std::array<double, 3> vector; | ||
}; | ||
struct CubeOp { | ||
std::vector<Transform> transforms; | ||
bool isUnion; | ||
}; | ||
|
||
// larger numbers may cause precision issues, prefer to test them later | ||
auto GoodNumbers = OneOf(InRange(0.1, 10.0), InRange(-10.0, -0.1)); | ||
auto Vec3Domain = ArrayOf<3>(GoodNumbers); | ||
auto TransformDomain = StructOf<Transform>( | ||
ElementOf({TransformType::Translate, TransformType::Rotate, | ||
TransformType::Scale}), | ||
Vec3Domain); | ||
auto CsgDomain = | ||
VectorOf(StructOf<CubeOp>(VectorOf(TransformDomain).WithMaxSize(20), | ||
ElementOf({false, true}))) | ||
.WithMaxSize(100); | ||
|
||
void SimpleCube(const std::vector<CubeOp> &inputs) { | ||
ManifoldParams().intermediateChecks = true; | ||
ManifoldParams().processOverlaps = false; | ||
Manifold result; | ||
for (const auto &input : inputs) { | ||
auto cube = Manifold::Cube(); | ||
for (const auto &transform : input.transforms) { | ||
printf("transform: %d\n", static_cast<int>(transform.ty)); | ||
switch (transform.ty) { | ||
case TransformType::Translate: | ||
cube = cube.Translate({std::get<0>(transform.vector), | ||
std::get<1>(transform.vector), | ||
std::get<2>(transform.vector)}); | ||
break; | ||
case TransformType::Rotate: | ||
cube = cube.Rotate(std::get<0>(transform.vector), | ||
std::get<1>(transform.vector), | ||
std::get<2>(transform.vector)); | ||
break; | ||
case TransformType::Scale: | ||
cube = cube.Scale({std::get<0>(transform.vector), | ||
std::get<1>(transform.vector), | ||
std::get<2>(transform.vector)}); | ||
break; | ||
} | ||
} | ||
|
||
printf("isUnion: %d\n", input.isUnion); | ||
std::atomic<pid_t> tid; | ||
std::atomic<bool> faulted(true); | ||
auto asyncFuture = std::async( | ||
std::launch::async, [&result, &faulted, &tid, &cube, &input]() { | ||
tid.store(gettid()); | ||
if (input.isUnion) { | ||
result += cube; | ||
} else { | ||
result -= cube; | ||
} | ||
EXPECT_EQ(result.Status(), Manifold::Error::NoError); | ||
faulted.store(false); | ||
}); | ||
if (asyncFuture.wait_for(std::chrono::milliseconds(10000)) == | ||
std::future_status::timeout) { | ||
printf("timeout after %dms...\n", 10000); | ||
pthread_cancel(tid.load()); | ||
} | ||
|
||
EXPECT_FALSE(faulted.load()); | ||
if (faulted.load()) break; | ||
} | ||
} | ||
|
||
FUZZ_TEST(ManifoldFuzz, SimpleCube).WithDomains(CsgDomain); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this use the same random seed every time or different? If it fails, will it spit out all the info we need to create a deterministic test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is different every time, but we can override that to replay the fuzzing process. It will spit out the info needed for the test when using the minimizer script, I will document it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to enable
MANIFOLD_FUZZ
on the CI?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is something that runs indefinitely, and non-deterministically. So this is probably something we want to run in our own machines.