tests: cram: add uci import testing on fuzzer corpus
authorPetr Štetiar <ynezz@true.cz>
Sat, 3 Oct 2020 07:18:17 +0000 (09:18 +0200)
committerPetr Štetiar <ynezz@true.cz>
Sat, 3 Oct 2020 07:46:18 +0000 (09:46 +0200)
Use valgrind and uci cli compiled with undefined, address and leak
sanitizers.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
tests/cram/CMakeLists.txt
tests/cram/test-san_uci_import.t [new file with mode: 0644]
tests/cram/test_uci_import.t [new file with mode: 0644]

index 06c7c9419c7e182a1a92ec1db37c20037ae2b3d4..175c0671a55846eefd1ae9120d7ed8c883a5b406 100644 (file)
@@ -1,6 +1,10 @@
 FIND_PACKAGE(PythonInterp 3 REQUIRED)
 FILE(GLOB test_cases "test_*.t")
 
+IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+  FILE(GLOB test_cases_san "test-san_*.t")
+ENDIF()
+
 SET(PYTHON_VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv")
 SET(PYTHON_VENV_PIP "${PYTHON_VENV_DIR}/bin/pip")
 SET(PYTHON_VENV_CRAM "${PYTHON_VENV_DIR}/bin/cram")
@@ -14,8 +18,9 @@ ADD_CUSTOM_TARGET(prepare-cram-venv ALL DEPENDS ${PYTHON_VENV_CRAM})
 
 ADD_TEST(
        NAME cram
-       COMMAND ${PYTHON_VENV_CRAM} ${test_cases}
+       COMMAND ${PYTHON_VENV_CRAM} ${test_cases} ${test_cases_san}
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
 SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "UCI_LUA=$<TARGET_FILE:uci_lua>")
+SET_PROPERTY(TEST cram APPEND PROPERTY ENVIRONMENT "BUILD_BIN_DIR=$<TARGET_FILE_DIR:uci>")
diff --git a/tests/cram/test-san_uci_import.t b/tests/cram/test-san_uci_import.t
new file mode 100644 (file)
index 0000000..7faed22
--- /dev/null
@@ -0,0 +1,15 @@
+check that uci import is producing expected results:
+
+  $ [ -n "$BUILD_BIN_DIR" ] && export PATH="$BUILD_BIN_DIR:$PATH"
+  $ export TEST_INPUTS="$TESTDIR/inputs"
+  $ export FUZZ_CORPUS="$TESTDIR/../fuzz/corpus"
+
+  $ for file in $(LC_ALL=C find $FUZZ_CORPUS -type f | sort ); do
+  >   uci-san import -f $file; \
+  > done
+  uci-san: I/O error
+  uci-san: Parse error (invalid command) at line 0, byte 0
+  uci-san: Parse error (invalid command) at line 1, byte 18
+  uci-san: I/O error
+  uci-san: I/O error
+  [1]
diff --git a/tests/cram/test_uci_import.t b/tests/cram/test_uci_import.t
new file mode 100644 (file)
index 0000000..8d5ab74
--- /dev/null
@@ -0,0 +1,15 @@
+check that uci import is producing expected results:
+
+  $ [ -n "$BUILD_BIN_DIR" ] && export PATH="$BUILD_BIN_DIR:$PATH"
+  $ export TEST_INPUTS="$TESTDIR/inputs"
+  $ export FUZZ_CORPUS="$TESTDIR/../fuzz/corpus"
+
+  $ for file in $(LC_ALL=C find $FUZZ_CORPUS -type f | sort ); do
+  >   valgrind --quiet --leak-check=full uci import -f $file; \
+  > done
+  uci: I/O error
+  uci: Parse error (invalid command) at line 0, byte 0
+  uci: Parse error (invalid command) at line 1, byte 18
+  uci: I/O error
+  uci: I/O error
+  [1]