Skip to content

Commit

Permalink
feat: add fuzz testing (#109)
Browse files Browse the repository at this point in the history
* Added infra::Join to OutputStream to concatenate infra::MemoryRange using a glue string

* Replaced auto parameter with explicit type to stay compatible with C++11

* Tracer: Make Trace() and Continue() as virtual

* Add PersistingBondStorage.

* infra/util/Observer: Add DelayedAttachDetach to Observer and SingleObserver

* infra/syntax/Json: Handle the {" case, where a string literal is opened but not closed

* feat: add fuzz testing of JsonObject

* fix: stop reviewdog from changing line-endings

* chore: normalize line-endings

* fix: run formatter

* fix: get rid of last gmtime

* fix: TracerWithTime

Co-authored-by: Timmer, Daan <daan.timmer@philips.com>
Co-authored-by: Arun Magi <Arun.Magi@philips.com>
Co-authored-by: Rob Ekelmans <rob.ekelmans@philips.com>
Co-authored-by: Richard Peters <richard.peters@philips.com>
  • Loading branch information
5 people committed Nov 8, 2022
1 parent 4a99744 commit 23061b9
Show file tree
Hide file tree
Showing 36 changed files with 1,371 additions and 1,009 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: false
DeriveLineEnding: true
DerivePointerAlignment: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
Expand Down Expand Up @@ -154,7 +154,7 @@ SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
TabWidth: 4
UseCRLF: true
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
Expand Down
50 changes: 25 additions & 25 deletions .github/formatters/gtest-to-generic-execution.xslt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<!-- Use Muenchian grouping to group by filename; https://en.wikipedia.org/wiki/XSLT/Muenchian_grouping -->
<xsl:key name="testcases-by-file" match="*/testsuite/testcase" use="@file" />

<xsl:template match="/">
<xsl:for-each select="*/testsuite/testcase[count(. | key('testcases-by-file', @file)[1]) = 1]">
<xsl:variable name="current-grouping-key" select="@file"/>
<xsl:variable name="current-group" select="key('testcases-by-file', $current-grouping-key)"/>

<file path="{$current-grouping-key}">
<xsl:for-each select="$current-group">
<testCase name="{@name}" duration="{1000 * number(@time)}">
<xsl:if test="contains(@status, 'notrun')">
<skipped message="Disabled">Skipped disabled test</skipped>
</xsl:if>
</testCase>
</xsl:for-each>
</file>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<!-- Use Muenchian grouping to group by filename; https://en.wikipedia.org/wiki/XSLT/Muenchian_grouping -->
<xsl:key name="testcases-by-file" match="*/testsuite/testcase" use="@file" />

<xsl:template match="/">
<xsl:for-each select="*/testsuite/testcase[count(. | key('testcases-by-file', @file)[1]) = 1]">
<xsl:variable name="current-grouping-key" select="@file"/>
<xsl:variable name="current-group" select="key('testcases-by-file', $current-grouping-key)"/>

<file path="{$current-grouping-key}">
<xsl:for-each select="$current-group">
<testCase name="{@name}" duration="{1000 * number(@time)}">
<xsl:if test="contains(@status, 'notrun')">
<skipped message="Disabled">Skipped disabled test</skipped>
</xsl:if>
</testCase>
</xsl:for-each>
</file>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
16 changes: 16 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
},
"generator": "Ninja"
},
{
"name": "Fuzzing",
"displayName": "Configuration for Fuzzing",
"inherits": "ContinuousIntegration",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-12",
"CMAKE_CXX_COMPILER": "clang++-12",
"EMIL_ENABLE_FUZZING": "On"
},
"generator": "Ninja"
},
{
"name": "Host",
"displayName": "Configuration for Host Tooling",
Expand Down Expand Up @@ -82,6 +93,11 @@
"configuration": "Debug",
"configurePreset": "MutationTesting"
},
{
"name": "Fuzzing",
"configuration": "Debug",
"configurePreset": "Fuzzing"
},
{
"name": "Host-Debug",
"configuration": "Debug",
Expand Down
18 changes: 18 additions & 0 deletions cmake/emil_test_helpers.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
option(EMIL_ENABLE_COVERAGE "Enable compiler flags for code coverage measurements" Off)
option(EMIL_ENABLE_FUZZING "Enable compiler flags for fuzzing" Off)
option(EMIL_ENABLE_MUTATION_TESTING "Enable compiler flags for mutation testing" Off)
set(EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS "" CACHE STRING "Additional arguments for the mutation testing runner")

Expand Down Expand Up @@ -42,6 +43,18 @@ function(emil_enable_testing)
message(FATAL_ERROR "Mutation testing is currently only supported for Clang/LLVM; not for ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()

if (EMIL_ENABLE_FUZZING)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
-g -O1 -fsanitize=fuzzer-no-link
)

add_link_options(-fsanitize=fuzzer-no-link)
else()
message(FATAL_ERROR "Fuzzing is currently only supported for Clang/LLVM; not for ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
endfunction()

function(emil_add_test target)
Expand All @@ -51,3 +64,8 @@ function(emil_add_test target)
add_test(NAME ${target} COMMAND ${target})
endif()
endfunction()

function(emil_add_fuzzing_executable target)
add_executable(${target})
target_link_options(${target} PRIVATE -fsanitize=fuzzer)
endfunction()
Loading

0 comments on commit 23061b9

Please sign in to comment.