Commit ad53f807 authored by Kenton Varda's avatar Kenton Varda

Improve fuzz-test-skipping check to work in automake build.

The previous approach worked only for ekam builds, where fuzz-test was its own binary.
parent f44ac96a
...@@ -38,15 +38,14 @@ namespace capnp { ...@@ -38,15 +38,14 @@ namespace capnp {
namespace _ { // private namespace _ { // private
namespace { namespace {
struct SkipTestHack { bool skipFuzzTest() {
SkipTestHack() {
if (getenv("CAPNP_SKIP_FUZZ_TEST") != nullptr) { if (getenv("CAPNP_SKIP_FUZZ_TEST") != nullptr) {
char message[] = "Skipping test because CAPNP_SKIP_FUZZ_TEST is set in environment.\n"; KJ_LOG(WARNING, "Skipping test because CAPNP_SKIP_FUZZ_TEST is set in environment.");
KJ_SYSCALL(write(STDOUT_FILENO, message, sizeof(message))); return true;
_exit(0); } else {
} return false;
} }
} skipTestHack; }
uint64_t traverse(AnyPointer::Reader reader); uint64_t traverse(AnyPointer::Reader reader);
uint64_t traverse(AnyStruct::Reader reader); uint64_t traverse(AnyStruct::Reader reader);
...@@ -163,6 +162,8 @@ struct StructChecker { ...@@ -163,6 +162,8 @@ struct StructChecker {
}; };
KJ_TEST("fuzz-test struct pointer") { KJ_TEST("fuzz-test struct pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder; MallocMessageBuilder builder;
builder.getRoot<TestAllTypes>().setTextField("foo"); builder.getRoot<TestAllTypes>().setTextField("foo");
KJ_ASSERT(builder.getSegmentsForOutput().size() == 1); KJ_ASSERT(builder.getSegmentsForOutput().size() == 1);
...@@ -181,6 +182,8 @@ struct ListChecker { ...@@ -181,6 +182,8 @@ struct ListChecker {
}; };
KJ_TEST("fuzz-test list pointer") { KJ_TEST("fuzz-test list pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder; MallocMessageBuilder builder;
auto list = builder.getRoot<AnyPointer>().initAs<List<uint32_t>>(2); auto list = builder.getRoot<AnyPointer>().initAs<List<uint32_t>>(2);
list.set(0, 12345); list.set(0, 12345);
...@@ -203,6 +206,8 @@ struct StructListChecker { ...@@ -203,6 +206,8 @@ struct StructListChecker {
}; };
KJ_TEST("fuzz-test struct list pointer") { KJ_TEST("fuzz-test struct list pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder; MallocMessageBuilder builder;
auto list = builder.getRoot<AnyPointer>().initAs<List<test::TestAllTypes>>(2); auto list = builder.getRoot<AnyPointer>().initAs<List<test::TestAllTypes>>(2);
list[0].setTextField("foo"); list[0].setTextField("foo");
...@@ -224,12 +229,16 @@ struct TextChecker { ...@@ -224,12 +229,16 @@ struct TextChecker {
}; };
KJ_TEST("fuzz-test text pointer") { KJ_TEST("fuzz-test text pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder; MallocMessageBuilder builder;
builder.template getRoot<AnyPointer>().setAs<Text>("foo"); builder.template getRoot<AnyPointer>().setAs<Text>("foo");
fuzz<TextChecker>(messageToFlatArray(builder), 2, 64, 192); fuzz<TextChecker>(messageToFlatArray(builder), 2, 64, 192);
} }
KJ_TEST("fuzz-test far pointer") { KJ_TEST("fuzz-test far pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder(1, AllocationStrategy::FIXED_SIZE); MallocMessageBuilder builder(1, AllocationStrategy::FIXED_SIZE);
initTestMessage(builder.getRoot<TestAllTypes>()); initTestMessage(builder.getRoot<TestAllTypes>());
...@@ -241,6 +250,8 @@ KJ_TEST("fuzz-test far pointer") { ...@@ -241,6 +250,8 @@ KJ_TEST("fuzz-test far pointer") {
} }
KJ_TEST("fuzz-test double-far pointer") { KJ_TEST("fuzz-test double-far pointer") {
if (skipFuzzTest()) return;
MallocMessageBuilder builder(1, AllocationStrategy::FIXED_SIZE); MallocMessageBuilder builder(1, AllocationStrategy::FIXED_SIZE);
// Carefully arrange for a double-far pointer to be created. // Carefully arrange for a double-far pointer to be created.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment