1# 2# Copyright (c) 2021 Nordic Semiconductor ASA 3# 4# SPDX-License-Identifier: Apache-2.0 5# 6 7cmake_minimum_required(VERSION 3.13.1) 8 9project(zcbor_fuzz) 10 11add_executable(fuzz_target main_entry.c) 12 13target_compile_options(fuzz_target PUBLIC -Werror) 14 15file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/fuzz_input) 16 17set(TEST_CASE "pet" CACHE STRING "Test case (pet or manifest12)") 18 19if (${TEST_CASE} STREQUAL pet) 20 execute_process( 21 COMMAND zcbor 22 code 23 -c ${CMAKE_CURRENT_LIST_DIR}/../cases/pet.cddl 24 --output-cmake ${PROJECT_BINARY_DIR}/pet.cmake 25 -t Pet 26 -d 27 ) 28 29 execute_process( 30 COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../zcbor/zcbor.py 31 convert 32 --cddl ${CMAKE_CURRENT_LIST_DIR}/../cases/pet.cddl 33 --input ${CMAKE_CURRENT_LIST_DIR}/../cases/pet0.yaml 34 -t Pet 35 --yaml-compatibility 36 --output ${PROJECT_BINARY_DIR}/fuzz_input/input0.cbor 37 --output-as cbor 38 ) 39 40 target_sources(fuzz_target PRIVATE ${CMAKE_CURRENT_LIST_DIR}/fuzz_pet.c) 41 include(${PROJECT_BINARY_DIR}/pet.cmake) 42 target_link_libraries(fuzz_target PRIVATE pet) 43 44elseif (${TEST_CASE} STREQUAL manifest12) 45 execute_process( 46 COMMAND zcbor 47 code 48 -c ${CMAKE_CURRENT_LIST_DIR}/../cases/manifest12.cddl 49 --output-cmake ${PROJECT_BINARY_DIR}/manifest12.cmake 50 -t SUIT_Envelope_Tagged SUIT_Command_Sequence SUIT_Envelope 51 -d 52 ) 53 54 foreach(n RANGE 0 5) 55 execute_process( 56 COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../zcbor/zcbor.py 57 convert 58 --cddl ${CMAKE_CURRENT_LIST_DIR}/../cases/manifest12.cddl 59 --default-max-qty 16 60 --input ${CMAKE_CURRENT_LIST_DIR}/../cases/manifest12_example${n}.cborhex 61 -t SUIT_Envelope_Tagged 62 --output ${PROJECT_BINARY_DIR}/fuzz_input/input${n}.cbor 63 --output-as cbor 64 ) 65 endforeach() 66 67 target_sources(fuzz_target PRIVATE fuzz_manifest12.c) 68 include(${PROJECT_BINARY_DIR}/manifest12.cmake) 69 target_link_libraries(fuzz_target PRIVATE manifest12) 70 71elseif (${TEST_CASE} STREQUAL everything) 72 execute_process( 73 COMMAND zcbor 74 code 75 -c ${CMAKE_CURRENT_LIST_DIR}/../cases/everything.cddl 76 --output-cmake ${PROJECT_BINARY_DIR}/everything.cmake 77 -t EverythingUnion 78 -d 79 ) 80 81 foreach(n RANGE 0 1) 82 execute_process( 83 COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../../zcbor/zcbor.py 84 convert 85 --cddl ${CMAKE_CURRENT_LIST_DIR}/../cases/everything.cddl 86 --input ${CMAKE_CURRENT_LIST_DIR}/../cases/everything_example${n}.yaml 87 --yaml-compatibility 88 -t EverythingUnion 89 --output ${PROJECT_BINARY_DIR}/fuzz_input/input${n}.cbor 90 --output-as cbor 91 ) 92 endforeach() 93 94 target_sources(fuzz_target PRIVATE fuzz_everything.c) 95 include(${PROJECT_BINARY_DIR}/everything.cmake) 96 target_link_libraries(fuzz_target PRIVATE everything) 97 98else() 99 message(FATAL_ERROR "Invalid test case") 100endif() 101