Test: Add basic TBL fuzzing harness
Jeffrey Pfau jeffrey@endrift.com
Wed, 02 Nov 2016 16:25:53 -0700
2 files changed,
32 insertions(+),
1 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -730,7 +730,10 @@ if(BUILD_TEST)
add_executable(${BINARY_NAME}-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/fuzz-main.c) target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME}) set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") - install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test) + add_executable(tbl-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/tbl-fuzz-main.c) + target_link_libraries(tbl-fuzz ${BINARY_NAME}) + set_target_properties(tbl-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") + install(TARGETS ${BINARY_NAME}-fuzz tbl-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test) endif() if(NOT USE_CMOCKA)
A
src/platform/test/tbl-fuzz-main.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "util/text-codec.h" +#include "util/vfs.h" + +int main(int argc, char** argv) { + struct TextCodec codec; + struct VFile* vf = VFileOpen(argv[1], O_RDONLY); + TextCodecLoadTBL(&codec, vf, true); + vf->close(vf); + + vf = VFileOpen(argv[2], O_RDONLY); + struct TextCodecIterator iter; + TextCodecStartDecode(&codec, &iter); + uint8_t lineBuffer[128]; + uint8_t c; + while (vf->read(vf, &c, 1) > 0) { + TextCodecAdvance(&iter, c, lineBuffer, sizeof(lineBuffer)); + } + TextCodecFinish(&iter, lineBuffer, sizeof(lineBuffer)); + + TextCodecDeinit(&codec); + return 0; +} +