├── .github ├── .cSpellWords.txt ├── CONTRIBUTING.md ├── memory_statistics_config.json ├── pull_request_template.md └── workflows │ ├── ci.yml │ ├── doxygen.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── CHANGELOG.md ├── LICENSE ├── MISRA.md ├── MigrationGuide.md ├── README.md ├── SECURITY.md ├── cspell.config.yaml ├── docs ├── doxygen │ ├── config.doxyfile │ ├── include │ │ └── size_table.md │ ├── layout.xml │ ├── pages.dox │ ├── porting.dox │ ├── style.css │ └── timeouts.dox └── plantuml │ ├── images │ ├── mqtt_connect_design.png │ ├── mqtt_processloop_design.png │ └── mqtt_receiveloop_design.png │ ├── mqtt_connect_design.pu │ ├── mqtt_processloop_design.pu │ └── mqtt_receiveloop_design.pu ├── manifest.yml ├── mqttFilePaths.cmake ├── source ├── core_mqtt.c ├── core_mqtt_serializer.c ├── core_mqtt_state.c ├── include │ ├── core_mqtt.h │ ├── core_mqtt_config_defaults.h │ ├── core_mqtt_serializer.h │ ├── core_mqtt_state.h │ ├── stdbool.readme │ └── stdint.readme └── interface │ └── transport_interface.h ├── test ├── CMakeLists.txt ├── cbmc │ ├── .gitignore │ ├── include │ │ ├── README.md │ │ ├── core_mqtt_config.h │ │ ├── event_callback_stub.h │ │ ├── get_time_stub.h │ │ ├── mqtt_cbmc_state.h │ │ └── network_interface_stubs.h │ ├── proofs │ │ ├── MQTT_Connect │ │ │ ├── MQTT_Connect_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_DeserializeAck │ │ │ ├── MQTT_DeserializeAck_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_DeserializePublish │ │ │ ├── MQTT_DeserializePublish_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Disconnect │ │ │ ├── MQTT_Disconnect_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_GetBytesInMQTTVec │ │ │ ├── MQTT_GetBytesInMQTTVec_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_GetIncomingPacketTypeAndLength │ │ │ ├── MQTT_GetIncomingPacketTypeAndLength_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_GetPacketId │ │ │ ├── MQTT_GetPacketId_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_GetSubAckStatusCodes │ │ │ ├── MQTT_GetSubAckStatusCodes_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Init │ │ │ ├── MQTT_Init_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_MatchTopic │ │ │ ├── MQTT_MatchTopic_harness.c │ │ │ ├── Makefile │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Ping │ │ │ ├── MQTT_Ping_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_ProcessLoop │ │ │ ├── MQTT_ProcessLoop_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Publish │ │ │ ├── MQTT_Publish_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_ReceiveLoop │ │ │ ├── MQTT_ReceiveLoop_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeAck │ │ │ ├── MQTT_SerializeAck_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeConnect │ │ │ ├── MQTT_SerializeConnect_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeDisconnect │ │ │ ├── MQTT_SerializeDisconnect_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeMQTTVec │ │ │ ├── MQTT_SerializeMQTTVec_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializePingreq │ │ │ ├── MQTT_SerializePingreq_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializePublish │ │ │ ├── MQTT_SerializePublish_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializePublishHeader │ │ │ ├── MQTT_SerializePublishHeader_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeSubscribe │ │ │ ├── MQTT_SerializeSubscribe_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_SerializeUnsubscribe │ │ │ ├── MQTT_SerializeUnsubscribe_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Subscribe │ │ │ ├── MQTT_Subscribe_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── MQTT_Unsubscribe │ │ │ ├── MQTT_Unsubscribe_harness.c │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── cbmc-proof.txt │ │ │ └── cbmc-viewer.json │ │ ├── Makefile-project-defines │ │ ├── Makefile-project-targets │ │ ├── Makefile-project-testing │ │ ├── Makefile-template-defines │ │ ├── Makefile.common │ │ ├── README.md │ │ ├── lib │ │ │ ├── __init__.py │ │ │ ├── print_tool_versions.py │ │ │ └── summarize.py │ │ └── run-cbmc-proofs.py │ ├── sources │ │ ├── README.md │ │ └── mqtt_cbmc_state.c │ └── stubs │ │ ├── README.md │ │ ├── event_callback_stub.c │ │ ├── get_time_stub.c │ │ ├── memmove.c │ │ └── network_interface_stubs.c └── unit-test │ ├── CMakeLists.txt │ ├── cmock_build.cmake │ ├── cmock_opaque_types.h │ ├── core_mqtt_config.h │ ├── core_mqtt_serializer_utest.c │ ├── core_mqtt_state_utest.c │ ├── core_mqtt_utest.c │ └── logging │ ├── logging_levels.h │ └── logging_stack.h └── tools ├── cmock ├── coverage.cmake ├── create_test.cmake └── project.yml └── coverity ├── README.md └── misra.config /.github/.cSpellWords.txt: -------------------------------------------------------------------------------- 1 | cbmc 2 | CBMC 3 | cbor 4 | CBOR 5 | cmock 6 | Cmock 7 | CMock 8 | CMOCK 9 | coremqtt 10 | coverity 11 | Coverity 12 | CSDK 13 | ctest 14 | DCMAKE 15 | DCMOCK 16 | decihours 17 | Decihours 18 | DECIHOURS 19 | DLIBRARY 20 | DNDEBUG 21 | DUNITTEST 22 | DUNITY 23 | getbytesinmqttvec 24 | getpacketid 25 | isystem 26 | lcov 27 | misra 28 | Misra 29 | MISRA 30 | MQTT 31 | mypy 32 | nondet 33 | Nondet 34 | NONDET 35 | pylint 36 | pytest 37 | pyyaml 38 | serializemqttvec 39 | sinclude 40 | UNACKED 41 | unpadded 42 | Unpadded 43 | UNPADDED 44 | UNSUB 45 | UNSUBACK 46 | unsubscriptions 47 | utest 48 | vect 49 | Vect 50 | VECT 51 | Werror 52 | Wextra 53 | Wsign 54 | Wunused 55 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/FreeRTOS/coreMQTT/issues), or [recently closed](https://github.com/FreeRTOS/coreMQTT/issues?q=is%3Aissue+is%3Aclosed), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 1. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 1. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 1. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 1. Ensure that your contributions conform to the [style guide](https://docs.aws.amazon.com/embedded-csdk/202011.00/lib-ref/docs/doxygen/output/html/guide_developer_styleguide.html). 35 | 1. Format your code with uncrustify, using the config available in [FreeRTOS/CI-CD-Github-Actions](https://github.com/FreeRTOS/CI-CD-Github-Actions/blob/main/formatting/uncrustify.cfg). 36 | 1. Ensure local tests pass. 37 | 1. Commit to your fork using clear commit messages. 38 | 1. Send us a pull request, answering any default questions in the pull request interface. 39 | 1. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 40 | 41 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 42 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 43 | 44 | 45 | ## Finding contributions to work on 46 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/FreeRTOS/coreMQTT/labels?q=help+wanted) issues is a great place to start. 47 | 48 | 49 | ## Code of Conduct 50 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 51 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 52 | opensource-codeofconduct@amazon.com with any additional questions or comments. 53 | 54 | 55 | ## Security issue notifications 56 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](https://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 57 | 58 | 59 | ## Licensing 60 | 61 | See the [LICENSE](../LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 62 | 63 | We may ask you to sign a [Contributor License Agreement (CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 64 | -------------------------------------------------------------------------------- /.github/memory_statistics_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "lib_name": "coreMQTT", 3 | "src": [ 4 | "source/core_mqtt.c", 5 | "source/core_mqtt_state.c", 6 | "source/core_mqtt_serializer.c" 7 | ], 8 | "include": [ 9 | "source/include", 10 | "source/interface" 11 | ], 12 | "compiler_flags": [ 13 | "MQTT_DO_NOT_USE_CUSTOM_CONFIG" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Description 4 | ----------- 5 | 6 | 7 | Test Steps 8 | ----------- 9 | 10 | 11 | Checklist: 12 | ---------- 13 | 14 | 15 | - [ ] I have tested my changes. No regression in existing tests. 16 | - [ ] I have modified and/or added unit-tests to cover the code changes in this Pull Request. 17 | 18 | Related Issue 19 | ----------- 20 | 21 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. 22 | -------------------------------------------------------------------------------- /.github/workflows/doxygen.yml: -------------------------------------------------------------------------------- 1 | name: Doxygen Generation 2 | on: 3 | push: 4 | branches: [main] 5 | workflow_dispatch: 6 | jobs: 7 | doxygen-generation: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Doxygen generation 11 | uses: FreeRTOS/CI-CD-Github-Actions/doxygen-generation@main 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore documentation output. 2 | **/docs/**/output/* 3 | 4 | # Ignore CMake build directory. 5 | build/ 6 | 7 | # Ignore build artifacts 8 | *.o 9 | 10 | # Ignore code coverage artifacts 11 | *.gcda 12 | *.gcno 13 | *.gcov 14 | 15 | # Ignore IDE setting folders 16 | .vscode/ 17 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "test/unit-test/CMock"] 2 | path = test/unit-test/CMock 3 | url = https://github.com/ThrowTheSwitch/CMock 4 | update = none 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /MISRA.md: -------------------------------------------------------------------------------- 1 | # MISRA Compliance 2 | 3 | The coreMQTT library files conform to the [MISRA C:2012](https://www.misra.org.uk/misra-c) 4 | guidelines, with the deviations listed below. Compliance is checked with Coverity static analysis. 5 | Since the coreMQTT library is designed for small-embedded devices, it needs to have a very small memory footprint and has to 6 | be efficient. To achieve that and to increase the performace of the library, it deviates from some MISRA rules. 7 | The specific deviations, suppressed inline, are listed below. 8 | 9 | Additionally, [MISRA configuration file](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/test/Coverity/coverity_misra.config) contains the project wide deviations. 10 | 11 | ### Suppressed with Coverity Comments 12 | To find the deviation references in the source files run grep on the source code 13 | with ( Assuming rule 18.2 violation; with justification in point 1 ): 14 | ``` 15 | grep 'MISRA Ref 18.2.1' . -rI 16 | ``` 17 | #### Rule 10.8 18 | 19 | _Ref 10.8.1_ 20 | 21 | - MISRA C-2012 Rule 10.8 states that value of composite expressions should not be cast 22 | to variables of different signedness. In this library, array of bytes are used to 23 | process data. Functions which fill the arrays with data update an index to an 24 | offset. To know the amount of data added to the array, the beginning address of the 25 | array has to be subtracted from the index. When the two pointers are subracted, it 26 | results in a signed value. It is verified however that the value will always be positive. 27 | And thus, can be casted and added to a size_t variable (which is unsigned). 28 | 29 | #### Rule 18.2 30 | 31 | _Ref 18.2.1_ 32 | 33 | - MISRA C-2012 Rule 18.2 states that two pointers may only be subtracted if they point 34 | to elements of the same array. In this library, array of bytes are used to process 35 | data. Functions which fill the arrays with data update an index to an offset. 36 | To know the amount of data added to the array, the beginning address of the array has 37 | to be subtracted from the index. It is manually verified that the index will always be 38 | within bounds of the array. However, Coverity is flagging this as a deviation. Thus, we 39 | are suppressing it. 40 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Reporting a Vulnerability 2 | 3 | If you discover a potential security issue in this project, we ask that you notify AWS/Amazon Security 4 | via our [vulnerability reporting page](https://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. 5 | Please do **not** create a public github issue. 6 | -------------------------------------------------------------------------------- /cspell.config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | $schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json 3 | version: '0.2' 4 | # Allows things like stringLength 5 | allowCompoundWords: true 6 | 7 | # Read files not to spell check from the git ignore 8 | useGitignore: true 9 | 10 | # Language settings for C 11 | languageSettings: 12 | - caseSensitive: false 13 | enabled: true 14 | languageId: c 15 | locale: "*" 16 | 17 | # Add a dictionary, and the path to the word list 18 | dictionaryDefinitions: 19 | - name: freertos-words 20 | path: '.github/.cSpellWords.txt' 21 | addWords: true 22 | 23 | dictionaries: 24 | - freertos-words 25 | 26 | # Paths and files to ignore 27 | ignorePaths: 28 | - 'dependency' 29 | - 'docs' 30 | - 'ThirdParty' 31 | - 'History.txt' 32 | -------------------------------------------------------------------------------- /docs/doxygen/include/size_table.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
Code Size of coreMQTT (example generated with GCC for ARM Cortex-M)
File
With -O1 Optimization
With -Os Optimization
core_mqtt.c
4.9K
4.2K
core_mqtt_state.c
1.7K
1.3K
core_mqtt_serializer.c
2.9K
2.3K
Total estimates
9.5K
7.8K
31 | -------------------------------------------------------------------------------- /docs/doxygen/porting.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @page mqtt_porting Porting Guide 3 | @brief Guide for porting MQTT to a new platform. 4 | 5 | A port to a new platform must provide the following components: 6 | 1. [Configuration Macros](@ref mqtt_porting_config) 7 | 2. [Transport Interface](@ref mqtt_porting_transport) 8 | 3. [Time Function](@ref mqtt_porting_time) 9 | 10 | @section mqtt_porting_config Configuration Macros 11 | @brief Settings that must be set as macros in the config header `core_mqtt_config.h`, or passed in as compiler options. 12 | 13 | @note If a custom configuration header `core_mqtt_config.h` is not provided, then the @ref MQTT_DO_NOT_USE_CUSTOM_CONFIG macro must be defined. 14 | 15 | @see [Configurations](@ref core_mqtt_config) 16 | 17 | The following macros can be configured for the managed MQTT library: 18 | - @ref MQTT_PINGRESP_TIMEOUT_MS
19 | - @ref MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT 20 | 21 | In addition, the following logging macros are used throughout the library: 22 | - @ref LogError 23 | - @ref LogWarn 24 | - @ref LogInfo 25 | - @ref LogDebug 26 | 27 | @section mqtt_porting_transport Transport Interface 28 | @brief The MQTT library relies on an underlying transport interface API that must be implemented 29 | in order to send and receive packets on a network. 30 | 31 | @see [Transport Interface](@ref mqtt_transport_interface) 32 | 33 | The transport interface API used by MQTT is defined in @ref transport_interface.h. 34 | A port must implement functions corresponding to the following functions pointers: 35 | - [Transport Receive](@ref TransportRecv_t): A function to receive bytes from a network. 36 | @code 37 | int32_t (* TransportRecv_t )( 38 | NetworkContext_t * pNetworkContext, void * pBuffer, size_t bytesToRecv 39 | ); 40 | @endcode 41 | - [Transport Send](@ref TransportSend_t): A function to send bytes over a network. 42 | @code 43 | int32_t (* TransportSend_t )( 44 | NetworkContext_t * pNetworkContext, const void * pBuffer, size_t bytesToSend 45 | ); 46 | @endcode 47 | 48 | The above two functions take in a pointer to a @ref NetworkContext_t, the typename of a 49 | `struct NetworkContext`. The NetworkContext struct must also be defined by the port, and 50 | ought to contain any information necessary to send and receive data with the @ref TransportSend_t 51 | and @ref TransportRecv_t implementations, respectively: 52 | @code 53 | struct NetworkContext { 54 | // Fields necessary for the transport implementations, e.g. a TCP socket descriptor. 55 | }; 56 | @endcode 57 | 58 | Please note that it is HIGHLY RECOMMENDED that the transport receive implementation does NOT block. 59 | 60 | @section mqtt_porting_time Time Function 61 | @brief The MQTT library relies on a function to generate millisecond timestamps, for the 62 | purpose of calculating durations and timeouts, as well as maintaining the keep-alive mechanism 63 | of the MQTT protocol. 64 | 65 | @see @ref MQTTGetCurrentTimeFunc_t 66 | 67 | Platforms must supply a function capable of generating 32 bit timestamps of millisecond resolution. 68 | These timestamps need not correspond with any real world clock; the only requirement is that the 69 | difference between two timestamps must be an accurate representation of the duration between them, 70 | in milliseconds. 71 | 72 | @note Should the platform be incapable of providing millisecond timestamps, the port may instead 73 | provide a function that always returns 0, or a strictly non-decreasing sequence. In this case, the 74 | timeout values in all library calls to @ref MQTT_Connect, @ref MQTT_ProcessLoop, or @ref MQTT_ReceiveLoop 75 | MUST be set to 0, resulting in loop functions running for a single iteration, and @ref MQTT_Connect 76 | relying on @ref MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT to receive the CONNACK packet. 77 | */ 78 | -------------------------------------------------------------------------------- /docs/doxygen/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Stylesheet for Doxygen HTML output. 3 | * 4 | * This file defines styles for custom elements in the header/footer and 5 | * overrides some of the default Doxygen styles. 6 | * 7 | * Styles in this file do not affect the treeview sidebar. 8 | */ 9 | 10 | /* Set the margins to place a small amount of whitespace on the left and right 11 | * side of the page. */ 12 | div.contents { 13 | margin-left:4em; 14 | margin-right:4em; 15 | } 16 | 17 | /* Justify text in paragraphs. */ 18 | p { 19 | text-align: justify; 20 | } 21 | 22 | /* Style of section headings. */ 23 | h1 { 24 | border-bottom: 1px solid #879ECB; 25 | color: #354C7B; 26 | font-size: 160%; 27 | font-weight: normal; 28 | padding-bottom: 4px; 29 | padding-top: 8px; 30 | } 31 | 32 | /* Style of subsection headings. */ 33 | h2:not(.memtitle):not(.groupheader) { 34 | font-size: 125%; 35 | margin-bottom: 0px; 36 | margin-top: 16px; 37 | padding: 0px; 38 | } 39 | 40 | /* Style of paragraphs immediately after subsection headings. */ 41 | h2 + p { 42 | margin: 0px; 43 | padding: 0px; 44 | } 45 | 46 | /* Style of subsection headings. */ 47 | h3 { 48 | font-size: 100%; 49 | margin-bottom: 0px; 50 | margin-left: 2em; 51 | margin-right: 2em; 52 | } 53 | 54 | /* Style of paragraphs immediately after subsubsection headings. */ 55 | h3 + p { 56 | margin-top: 0px; 57 | margin-left: 2em; 58 | margin-right: 2em; 59 | } 60 | 61 | /* Style of the prefix "AWS IoT Device SDK C" that appears in the header. */ 62 | #csdkprefix { 63 | color: #757575; 64 | } 65 | 66 | /* Style of the "Return to main page" link that appears in the header. */ 67 | #returntomain { 68 | padding: 0.5em; 69 | } 70 | 71 | /* Style of the dividers on Configuration Settings pages. */ 72 | div.configpagedivider { 73 | margin-left: 0px !important; 74 | margin-right: 0px !important; 75 | margin-top: 20px !important; 76 | } 77 | 78 | /* Style of configuration setting names. */ 79 | dl.section.user ~ h1 { 80 | border-bottom: none; 81 | color: #000000; 82 | font-family: monospace, fixed; 83 | font-size: 16px; 84 | margin-bottom: 0px; 85 | margin-left: 2em; 86 | margin-top: 1.5em; 87 | } 88 | 89 | /* Style of paragraphs on a configuration settings page. */ 90 | dl.section.user ~ * { 91 | margin-bottom: 10px; 92 | margin-left: 4em; 93 | margin-right: 4em; 94 | margin-top: 0px; 95 | } 96 | 97 | /* Hide the configuration setting marker. */ 98 | dl.section.user { 99 | display: none; 100 | } 101 | 102 | /* Overrides for code fragments and lines. */ 103 | div.fragment { 104 | background: #ffffff; 105 | border: none; 106 | padding: 5px; 107 | } 108 | 109 | div.line { 110 | color: #3a3a3a; 111 | } 112 | 113 | /* Overrides for code syntax highlighting colors. */ 114 | span.comment { 115 | color: #008000; 116 | } 117 | 118 | span.keyword, span.keywordtype, span.keywordflow { 119 | color: #0000ff; 120 | } 121 | 122 | span.preprocessor { 123 | color: #50015a; 124 | } 125 | 126 | span.stringliteral, span.charliteral { 127 | color: #800c0c; 128 | } 129 | 130 | a.code, a.code:visited, a.line, a.line:visited { 131 | color: #496194; 132 | } 133 | -------------------------------------------------------------------------------- /docs/plantuml/images/mqtt_connect_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/coreMQTT/42d843f40ef2abc752a419f45f7adb7dac67e591/docs/plantuml/images/mqtt_connect_design.png -------------------------------------------------------------------------------- /docs/plantuml/images/mqtt_processloop_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/coreMQTT/42d843f40ef2abc752a419f45f7adb7dac67e591/docs/plantuml/images/mqtt_processloop_design.png -------------------------------------------------------------------------------- /docs/plantuml/images/mqtt_receiveloop_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/coreMQTT/42d843f40ef2abc752a419f45f7adb7dac67e591/docs/plantuml/images/mqtt_receiveloop_design.png -------------------------------------------------------------------------------- /docs/plantuml/mqtt_connect_design.pu: -------------------------------------------------------------------------------- 1 | @startuml 2 | skinparam dpi 300 3 | skinparam ArrowFontSize 18 4 | 5 | start 6 | : Send CONNECT packet; 7 | : count = 0; 8 | 9 | repeat 10 | : Receive single byte; 11 | repeat while ( No network data available AND \n retry count < MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT) is (yes) 12 | -> no or timeout == 0; 13 | 14 | repeat 15 | : Get rest of CONNACK packet; 16 | note left: Retry zero byte reads for maximum period \nof **MQTT_RECV_POLLING_TIMEOUT_MS** 17 | repeat while( Received complete packet? ) is ( no ) 18 | : Deserialize CONNACK packet; 19 | stop 20 | 21 | @enduml 22 | -------------------------------------------------------------------------------- /docs/plantuml/mqtt_processloop_design.pu: -------------------------------------------------------------------------------- 1 | @startuml 2 | skinparam dpi 300 3 | skinparam ArrowFontSize 18 4 | 5 | start 6 | 7 | repeat 8 | : Receive single byte; 9 | if( read successful? ) then (yes) 10 | repeat 11 | : Get rest of packet; 12 | note left: Retry zero byte reads for maximum period \nof **MQTT_RECV_POLLING_TIMEOUT_MS** 13 | repeat while( Received complete packet? ) is ( no ) 14 | : Deserialize packet; 15 | if ( Need to send ACK response? ) then (yes) 16 | repeat 17 | : Send ACK packet; 18 | note left: Retry zero byte sends for maximum period \nof **MQTT_SEND_RETRY_TIMEOUT_MS** 19 | repeat while( Sent complete packet? ) is ( no ) 20 | else (no) 21 | endif 22 | : Invoke Application callback; 23 | else (no) 24 | : Manage Keep-Alive; 25 | endif 26 | 27 | repeat while (**timeout** reached) is (no) 28 | -> yes or timeout == 0; 29 | 30 | stop 31 | 32 | @enduml 33 | -------------------------------------------------------------------------------- /docs/plantuml/mqtt_receiveloop_design.pu: -------------------------------------------------------------------------------- 1 | @startuml 2 | skinparam dpi 300 3 | skinparam ArrowFontSize 18 4 | 5 | start 6 | 7 | repeat 8 | : Receive single byte; 9 | if( read successful? ) then (yes) 10 | repeat 11 | : Get rest of packet; 12 | note left: Retry zero byte reads for maximum period \nof **MQTT_RECV_POLLING_TIMEOUT_MS** 13 | repeat while( Received complete packet? ) is ( no ) 14 | : Deserialize packet; 15 | if ( Need to send ACK response? ) then (yes) 16 | repeat 17 | : Send ACK packet; 18 | note left: Retry zero byte sends for maximum period \nof **MQTT_SEND_RETRY_TIMEOUT_MS** 19 | repeat while( Sent complete packet? ) is ( no ) 20 | else (no) 21 | endif 22 | else (no) 23 | endif 24 | 25 | repeat while (**timeout** reached) is (no) 26 | -> yes or timeout == 0; 27 | 28 | stop 29 | 30 | @enduml 31 | -------------------------------------------------------------------------------- /manifest.yml: -------------------------------------------------------------------------------- 1 | name : "coreMQTT" 2 | version: "v2.3.1+" 3 | description: | 4 | "Client implementation of the MQTT 3.1.1 specification for embedded devices.\n" 5 | license: "MIT" 6 | -------------------------------------------------------------------------------- /mqttFilePaths.cmake: -------------------------------------------------------------------------------- 1 | # This file is to add source files and include directories 2 | # into variables so that it can be reused from different repositories 3 | # in their Cmake based build system by including this file. 4 | # 5 | # Files specific to the repository such as test runner, platform tests 6 | # are not added to the variables. 7 | 8 | # MQTT library source files. 9 | set( MQTT_SOURCES 10 | "${CMAKE_CURRENT_LIST_DIR}/source/core_mqtt.c" 11 | "${CMAKE_CURRENT_LIST_DIR}/source/core_mqtt_state.c" ) 12 | 13 | # MQTT Serializer library source files. 14 | set( MQTT_SERIALIZER_SOURCES 15 | "${CMAKE_CURRENT_LIST_DIR}/source/core_mqtt_serializer.c" ) 16 | 17 | # MQTT library Public Include directories. 18 | set( MQTT_INCLUDE_PUBLIC_DIRS 19 | "${CMAKE_CURRENT_LIST_DIR}/source/include" 20 | "${CMAKE_CURRENT_LIST_DIR}/source/interface" ) 21 | -------------------------------------------------------------------------------- /source/include/stdbool.readme: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | /******************************************************************************* 5 | * This file contains the definitions specified in stdbool.h. It is provided to 6 | * allow the library to be built using compilers that do not provide their own 7 | * stdbool.h defintion. 8 | * 9 | * To use this file: 10 | * 11 | * 1) Copy this file into a directory that is in your compiler's include path. 12 | * The directory must be part of the include path for system header files, 13 | * for example passed using gcc's "-I" or "-isystem" options. 14 | * 15 | * 2) Rename the copied file stdbool.h. 16 | * 17 | */ 18 | 19 | #ifndef __cplusplus 20 | 21 | /* _Bool was introduced in C99. */ 22 | #define bool int 23 | #define false 0 24 | #define true 1 25 | 26 | #endif 27 | 28 | #define __bool_true_false_are_defined 1 29 | 30 | #endif /* _STDBOOL_H */ 31 | -------------------------------------------------------------------------------- /source/include/stdint.readme: -------------------------------------------------------------------------------- 1 | #ifndef _STDINT_H 2 | #define _STDINT_H 3 | 4 | /******************************************************************************* 5 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 6 | * necessary to build the library code. It is provided to allow the library to 7 | * be built using compilers that do not provide their own stdint.h definition. 8 | * 9 | * To use this file: 10 | * 11 | * 1) Copy this file into a directory that is in your compiler's include path. 12 | * The directory must be part of the include path for system header file, 13 | * for example passed using gcc's "-I" or "-isystem" options. 14 | * 15 | * 2) Rename the copied file stdint.h. 16 | * 17 | */ 18 | 19 | typedef signed char int8_t; 20 | typedef unsigned char uint8_t; 21 | typedef short int16_t; 22 | typedef unsigned short uint16_t; 23 | typedef long int32_t; 24 | typedef unsigned long uint32_t; 25 | typedef long long int64_t; 26 | typedef unsigned long long uint64_t; 27 | 28 | #define INT8_MAX ( ( signed char ) 127 ) 29 | #define UINT8_MAX ( ( unsigned char ) 255 ) 30 | #define INT16_MAX ( ( short ) 32767 ) 31 | #define UINT16_MAX ( ( unsigned short ) 65535 ) 32 | #define INT32_MAX 2147483647L 33 | #define UINT32_MAX 4294967295UL 34 | #define INT64_MAX 9223372036854775807LL 35 | #define UINT64_MAX 18446744073709551615ULL 36 | 37 | #endif /* _STDINT_H */ 38 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required ( VERSION 3.22.0 ) 2 | project ( "CoreMQTT tests" 3 | VERSION 2.3.0 4 | LANGUAGES C ) 5 | 6 | # Allow the project to be organized into folders. 7 | set_property( GLOBAL PROPERTY USE_FOLDERS ON ) 8 | 9 | # Use C90 if not specified. 10 | if( NOT DEFINED CMAKE_C_STANDARD ) 11 | set( CMAKE_C_STANDARD 90 ) 12 | endif() 13 | if( NOT DEFINED CMAKE_C_STANDARD_REQUIRED ) 14 | set( CMAKE_C_STANDARD_REQUIRED ON ) 15 | endif() 16 | 17 | # If no configuration is defined, turn everything on. 18 | if( NOT DEFINED COV_ANALYSIS AND NOT DEFINED UNITTEST ) 19 | set( COV_ANALYSIS TRUE ) 20 | set( UNITTEST TRUE ) 21 | endif() 22 | 23 | # Do not allow in-source build. 24 | if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) 25 | message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) 26 | endif() 27 | 28 | # Set global path variables. 29 | get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) 30 | set(MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "coreMQTT repository root.") 31 | 32 | # Configure options to always show in CMake GUI. 33 | option( BUILD_CLONE_SUBMODULES 34 | "Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned." 35 | OFF ) 36 | 37 | # Set output directories. 38 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 39 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 40 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 41 | 42 | # ===================================== Coverity Analysis Configuration ================================================= 43 | 44 | if( COV_ANALYSIS ) 45 | # Include filepaths for source and include. 46 | include( ${MODULE_ROOT_DIR}/mqttFilePaths.cmake ) 47 | 48 | # Target for Coverity analysis that builds the library. 49 | add_library( coverity_analysis 50 | ${MQTT_SOURCES} 51 | ${MQTT_SERIALIZER_SOURCES} ) 52 | 53 | # Build MQTT library target without custom config dependency. 54 | target_compile_definitions( coverity_analysis PUBLIC MQTT_DO_NOT_USE_CUSTOM_CONFIG=1 ) 55 | 56 | # MQTT public include path. 57 | target_include_directories( coverity_analysis PUBLIC ${MQTT_INCLUDE_PUBLIC_DIRS} ) 58 | 59 | # Remove inclusion of assert. 60 | add_compile_definitions( NDEBUG=1 ) 61 | endif() 62 | 63 | # ==================================== Test Configuration ======================================== 64 | if( UNITTEST ) 65 | # Define a CMock resource path. 66 | set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." ) 67 | 68 | # Include CMock build configuration. 69 | include( unit-test/cmock_build.cmake ) 70 | 71 | # Check if the CMock source directory exists, and if not present, clone the submodule 72 | # if BUILD_CLONE_SUBMODULES configuration is enabled. 73 | if( NOT EXISTS ${CMOCK_DIR}/src ) 74 | # Attempt to clone CMock. 75 | if( ${BUILD_CLONE_SUBMODULES} ) 76 | clone_cmock() 77 | else() 78 | message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set\ 79 | BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." ) 80 | endif() 81 | endif() 82 | 83 | # Add unit test and coverage configuration. 84 | 85 | # Use CTest utility for managing test runs. This has to be added BEFORE 86 | # defining test targets with add_test() 87 | enable_testing() 88 | 89 | # Add build targets for CMock and Unit, required for unit testing. 90 | add_cmock_targets() 91 | 92 | # Add function to enable CMock based tests and coverage. 93 | include( ${MODULE_ROOT_DIR}/tools/cmock/create_test.cmake ) 94 | 95 | # Include build configuration for unit tests. 96 | add_subdirectory( unit-test ) 97 | 98 | # ==================================== Coverage Analysis configuration ======================================== 99 | 100 | # Add a target for running coverage on tests. 101 | add_custom_target( coverage 102 | COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR} 103 | -P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake 104 | DEPENDS cmock unity core_mqtt_utest core_mqtt_serializer_utest core_mqtt_state_utest 105 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 106 | ) 107 | endif() 108 | -------------------------------------------------------------------------------- /test/cbmc/.gitignore: -------------------------------------------------------------------------------- 1 | # Emitted when running CBMC proofs 2 | proofs/**/logs 3 | proofs/**/gotos 4 | proofs/**/report 5 | proofs/**/html 6 | proofs/output 7 | 8 | # Emitted by CBMC Viewer 9 | TAGS-* 10 | 11 | # Emitted by Arpa 12 | arpa_cmake/ 13 | arpa-validation-logs/ 14 | Makefile.arpa 15 | 16 | # Emitted by litani 17 | .ninja_deps 18 | .ninja_log 19 | .litani_cache_dir 20 | 21 | # These files should be overwritten whenever prepare.py runs 22 | cbmc-batch.yaml 23 | 24 | __pycache__/ 25 | -------------------------------------------------------------------------------- /test/cbmc/include/README.md: -------------------------------------------------------------------------------- 1 | CBMC proof include files 2 | ======================== 3 | 4 | This directory contains include files written for CBMC proof. It is 5 | common to write some code to model aspects of the system under test, 6 | and the header files for this code go here. 7 | -------------------------------------------------------------------------------- /test/cbmc/include/core_mqtt_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file core_mqtt_config.h 27 | * @brief This header sets configuration macros for the MQTT library. 28 | */ 29 | #ifndef CORE_MQTT_CONFIG_H_ 30 | #define CORE_MQTT_CONFIG_H_ 31 | 32 | /** 33 | * @brief Determines the maximum number of MQTT PUBLISH messages, pending 34 | * acknowledgement at a time, that are supported for incoming and outgoing 35 | * direction of messages, separately. 36 | * 37 | * QoS 1 and 2 MQTT PUBLISHes require acknowledgement from the server before 38 | * they can be completed. While they are awaiting the acknowledgement, the 39 | * client must maintain information about their state. The value of this 40 | * macro sets the limit on how many simultaneous PUBLISH states an MQTT 41 | * context maintains, separately, for both incoming and outgoing direction of 42 | * PUBLISHes. 43 | * 44 | * @note This definition must exist in order to compile. 10U is a typical value 45 | * used in the MQTT demos. 46 | */ 47 | #define MQTT_STATE_ARRAY_MAX_COUNT ( 10U ) 48 | 49 | /** 50 | * @brief Retry count for reading CONNACK from network. 51 | * 52 | * The MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT will be used only when the 53 | * timeoutMs parameter of #MQTT_Connect() is passed as 0 . The transport 54 | * receive for CONNACK will be retried MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT 55 | * times before timing out. A value of 0 for this config will cause the 56 | * transport receive for CONNACK to be invoked only once. 57 | */ 58 | #define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ( 2U ) 59 | 60 | /** 61 | * @brief Number of milliseconds to wait for a ping response to a ping 62 | * request as part of the keep-alive mechanism. 63 | * 64 | * If a ping response is not received before this timeout, then 65 | * #MQTT_ProcessLoop will return #MQTTKeepAliveTimeout. 66 | */ 67 | #define MQTT_PINGRESP_TIMEOUT_MS ( 5000U ) 68 | 69 | /** 70 | * @brief The maximum duration of receiving no data over network when 71 | * attempting to read an incoming MQTT packet by the #MQTT_ProcessLoop or 72 | * #MQTT_ReceiveLoop API functions. 73 | * 74 | * When an incoming MQTT packet is detected, the transport receive function 75 | * may be called multiple times until all the expected number of bytes for the 76 | * packet are received. This timeout represents the maximum duration of polling 77 | * for any data to be received over the network for the incoming. 78 | * If the timeout expires, the #MQTT_ProcessLoop or #MQTT_ReceiveLoop functions 79 | * return #MQTTRecvFailed. 80 | * 81 | * This is set to 1 to exit right away after a zero is received in the transport 82 | * receive stub. There is no added value, in proving memory safety, to repeat 83 | * the logic that checks if the polling timeout is reached. 84 | */ 85 | #define MQTT_RECV_POLLING_TIMEOUT_MS ( 1U ) 86 | 87 | #endif /* ifndef CORE_MQTT_CONFIG_H_ */ 88 | -------------------------------------------------------------------------------- /test/cbmc/include/event_callback_stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file event_callback_stub.h 27 | * @brief Stub definition for the application defined MQTT library incoming 28 | * event callback. 29 | */ 30 | #ifndef EVENT_CALLBACK_STUB_H_ 31 | #define EVENT_CALLBACK_STUB_H_ 32 | 33 | /* mqtt.h must precede including this header. */ 34 | 35 | /** 36 | * @brief User defined callback for receiving incoming publishes and incoming 37 | * acks. 38 | * 39 | * @param[in] pContext Initialized MQTT context. 40 | * @param[in] pPacketInfo Information on the type of incoming MQTT packet. 41 | * @param[in] pDeserializedInfo Deserialized information from incoming packet. 42 | */ 43 | void EventCallbackStub( MQTTContext_t * pContext, 44 | MQTTPacketInfo_t * pPacketInfo, 45 | MQTTDeserializedInfo_t * pDeserializedInfo ); 46 | 47 | #endif /* ifndef EVENT_CALLBACK_STUB_H_ */ 48 | -------------------------------------------------------------------------------- /test/cbmc/include/get_time_stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file get_time_stub.h 27 | * @brief Stub definition for the application defined callback to retrieve the 28 | * current time in milliseconds. 29 | */ 30 | #ifndef GET_TIME_STUB_H_ 31 | #define GET_TIME_STUB_H_ 32 | 33 | /** 34 | * Application defined callback to retrieve the current time in milliseconds. 35 | * 36 | * @return The current time in milliseconds. 37 | */ 38 | uint32_t GetCurrentTimeStub( void ); 39 | 40 | #endif /* ifndef GET_TIME_STUB_H_ */ 41 | -------------------------------------------------------------------------------- /test/cbmc/include/network_interface_stubs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file network_interface_stubs.h 27 | * @brief Stub definitions for the application defined transport interface send 28 | * and receive callback. 29 | */ 30 | #ifndef NETWORK_INTERFACE_STUBS_H_ 31 | #define NETWORK_INTERFACE_STUBS_H_ 32 | 33 | /* transport_interface.h must precede including this header. */ 34 | 35 | /** 36 | * @brief Application defined network interface receive function. 37 | * 38 | * @param[in] pNetworkContext Application defined network interface context. 39 | * @param[out] pBuffer MQTT network receive buffer. 40 | * @param[in] bytesToRecv MQTT requested bytes. 41 | * 42 | * @return Any value from INT32_MIN to INT32_MAX. 43 | */ 44 | int32_t NetworkInterfaceReceiveStub( NetworkContext_t * pNetworkContext, 45 | void * pBuffer, 46 | size_t bytesToRecv ); 47 | 48 | /** 49 | * @brief Application defined network interface send function. 50 | * 51 | * @param[in] pNetworkContext Application defined network interface context. 52 | * @param[out] pBuffer MQTT network send buffer. 53 | * @param[in] bytesToSend Number of bytes to send over the network. 54 | * 55 | * @return Any value from INT32_MIN to INT32_MAX. 56 | */ 57 | int32_t NetworkInterfaceSendStub( NetworkContext_t * pNetworkContext, 58 | const void * pBuffer, 59 | size_t bytesToSend ); 60 | 61 | #endif /* ifndef NETWORK_INTERFACE_STUBS_H_ */ 62 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Connect/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Connect proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Connect. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Connect/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Connect/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Connect", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializeAck/MQTT_DeserializeAck_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_DeserializeAck_harness.c 27 | * @brief Implements the proof harness for MQTT_DeserializeAck function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTPacketInfo_t * pIncomingPacket; 35 | uint16_t * pPacketId; 36 | bool * pSessionPresent; 37 | 38 | pIncomingPacket = allocateMqttPacketInfo( NULL ); 39 | __CPROVER_assume( isValidMqttPacketInfo( pIncomingPacket ) ); 40 | 41 | /* These are allocated for coverage of a NULL input. */ 42 | pPacketId = malloc( sizeof( uint16_t ) ); 43 | pSessionPresent = malloc( sizeof( bool ) ); 44 | 45 | MQTT_DeserializeAck( pIncomingPacket, 46 | pPacketId, 47 | pSessionPresent ); 48 | } 49 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializeAck/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_DeserializeAck_harness 24 | PROOF_UID=MQTT_DeserializeAck 25 | 26 | # The maximum remaining length is bounded for MQTT_DeserializeAck() in order to 27 | # place a limit on the number of iterations in deserializing a SUBACK. Please 28 | # see REMAINING_LENGTH_MAX in libraries\standard\mqtt\cbmc\sources\mqtt_cbmc_state.c. 29 | REMAINING_LENGTH_MAX=5 30 | DEFINES += -DREMAINING_LENGTH_MAX=$(REMAINING_LENGTH_MAX) 31 | INCLUDES += 32 | 33 | REMOVE_FUNCTION_BODY += 34 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_readSubackStatus.0:$(REMAINING_LENGTH_MAX) 35 | 36 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 37 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 38 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 39 | 40 | include ../Makefile.common 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializeAck/README.md: -------------------------------------------------------------------------------- 1 | MQTT_DeserializeAck proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_DeserializeAck. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializeAck/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializeAck/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_DeserializeAck", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializePublish/MQTT_DeserializePublish_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_DeserializePublish_harness.c 27 | * @brief Implements the proof harness for MQTT_DeserializePublish function. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | void harness() 34 | { 35 | MQTTPacketInfo_t * pIncomingPacket; 36 | MQTTPublishInfo_t * pPublishInfo; 37 | uint16_t * pPacketId; 38 | 39 | pIncomingPacket = allocateMqttPacketInfo( NULL ); 40 | __CPROVER_assume( isValidMqttPacketInfo( pIncomingPacket ) ); 41 | 42 | pPublishInfo = allocateMqttPublishInfo( NULL ); 43 | __CPROVER_assume( isValidMqttPublishInfo( pPublishInfo ) ); 44 | 45 | pPacketId = malloc( sizeof( uint16_t ) ); 46 | 47 | /* This function grabs the topic name, the topic name length, the 48 | * the payload, and the payload length. */ 49 | MQTT_DeserializePublish( pIncomingPacket, pPacketId, pPublishInfo ); 50 | } 51 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializePublish/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_DeserializePublish_harness 24 | PROOF_UID=MQTT_DeserializePublish 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializePublish/README.md: -------------------------------------------------------------------------------- 1 | MQTT_DeserializePublish proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_DeserializePublish. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializePublish/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_DeserializePublish/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_DeserializePublish", 6 | "proof-root": "test/cbmc" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Disconnect/MQTT_Disconnect_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Disconnect_harness.c 27 | * @brief Implements the proof harness for MQTT_Disconnect function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTContext_t * pContext; 35 | 36 | pContext = allocateMqttContext( NULL ); 37 | __CPROVER_assume( isValidMqttContext( pContext ) ); 38 | __CPROVER_assume( pContext != NULL ); 39 | __CPROVER_assume( pContext->networkBuffer.pBuffer != NULL ); 40 | 41 | MQTT_Disconnect( pContext ); 42 | } 43 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Disconnect/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Disconnect_harness 24 | PROOF_UID=MQTT_Disconnect 25 | 26 | # Please see test/cbmc/stubs/network_interface_subs.c for 27 | # more information on MAX_NETWORK_SEND_TRIES. 28 | MAX_NETWORK_SEND_TRIES=3 29 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 30 | INCLUDES += 31 | 32 | REMOVE_FUNCTION_BODY += 33 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 34 | # sendBuffer will continue until all the bytes are sent or a network error 35 | # occurs. Please see NetworkInterfaceReceiveStub in 36 | # libraries\standard\mqtt\cbmc\stubs\network_interface_stubs.c for more 37 | # information. 38 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 39 | 40 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 41 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 42 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 43 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 44 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 45 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 46 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 47 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 48 | 49 | include ../Makefile.common 50 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Disconnect/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Disconnect proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Disconnect. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Disconnect/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Disconnect/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Disconnect", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetBytesInMQTTVec/MQTT_GetBytesInMQTTVec_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Disconnect_harness.c 27 | * @brief Implements the proof harness for MQTT_Disconnect function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTVec_t * mqttVec; 35 | size_t memoryRequired; 36 | 37 | mqttVec = allocateMqttVec( NULL ); 38 | 39 | memoryRequired = MQTT_GetBytesInMQTTVec( mqttVec ); 40 | } 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetBytesInMQTTVec/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_GetBytesInMQTTVec_harness 24 | PROOF_UID=MQTT_GetBytesInMQTTVec 25 | 26 | PUBLISH_PACKET_VECTORS = 5 27 | 28 | DEFINES += 29 | INCLUDES += 30 | 31 | REMOVE_FUNCTION_BODY += 32 | UNWINDSET += MQTT_GetBytesInMQTTVec.0:${PUBLISH_PACKET_VECTORS} 33 | UNWINDSET += allocateMqttVec.0:${PUBLISH_PACKET_VECTORS} 34 | 35 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 36 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 37 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 38 | 39 | include ../Makefile.common 40 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetBytesInMQTTVec/README.md: -------------------------------------------------------------------------------- 1 | MQTT_GetBytesInMQTTVec proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_GetBytesInMQTTVec. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetBytesInMQTTVec/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetBytesInMQTTVec/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_GetBytesInMQTTVec", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/MQTT_GetIncomingPacketTypeAndLength_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_GetIncomingPacketTypeAndLength_harness.c 27 | * @brief Implements the proof harness for MQTT_GetIncomingPacketTypeAndLength function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "network_interface_stubs.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | struct NetworkContext 34 | { 35 | int NetworkContext; 36 | }; 37 | 38 | void harness() 39 | { 40 | /* NetworkContext_t is an application defined network interface context. It 41 | * is passed through to the readFunc parameter of 42 | * MQTT_GetIncomingPacketTypeAndLength(). */ 43 | NetworkContext_t networkContext; 44 | 45 | /* MQTT_GetIncomingPacketTypeAndLength() will set only the remainingLength 46 | * field in the input MQTTPacketInfo_t structure. */ 47 | MQTTPacketInfo_t * pIncomingPacket; 48 | 49 | pIncomingPacket = allocateMqttPacketInfo( NULL ); 50 | __CPROVER_assume( isValidMqttPacketInfo( pIncomingPacket ) ); 51 | 52 | MQTT_GetIncomingPacketTypeAndLength( NetworkInterfaceReceiveStub, 53 | &networkContext, 54 | pIncomingPacket ); 55 | } 56 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_GetIncomingPacketTypeAndLength_harness 24 | PROOF_UID=MQTT_GetIncomingPacketTypeAndLength 25 | 26 | DEFINES += 27 | INCLUDES += 28 | REMOVE_FUNCTION_BODY += 29 | 30 | # The getRemainingLength loop is unwound 5 times because getRemainingLength() 31 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 32 | # log128(SIZE_MAX) = 4.571... 33 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_getRemainingLength.0:5 34 | 35 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 36 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 37 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 38 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 39 | 40 | include ../Makefile.common 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/README.md: -------------------------------------------------------------------------------- 1 | MQTT_GetIncomingPacketTypeAndLength proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_GetIncomingPacketTypeAndLength. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetIncomingPacketTypeAndLength/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_GetIncomingPacketTypeAndLength", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetPacketId/MQTT_GetPacketId_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_GetPacketId_harness.c 27 | * @brief Implements the proof harness for MQTT_GetPacketId function. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | void harness() 34 | { 35 | /* The MQTTContext_t is allocated such that we can test a NULL input. 36 | * MQTT_GetPacketId() touches only the nextPacketId field in MQTTContext_t. 37 | * This nextPacketId is left unbounded to verify the function under harness. 38 | */ 39 | MQTTContext_t * pContext = malloc( sizeof( MQTTContext_t ) ); 40 | 41 | MQTT_GetPacketId( pContext ); 42 | } 43 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetPacketId/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_GetPacketId_harness 24 | PROOF_UID=MQTT_GetPacketId 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetPacketId/README.md: -------------------------------------------------------------------------------- 1 | MQTT_GetPacketId proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_GetPacketId. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetPacketId/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetPacketId/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_GetPacketId", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetSubAckStatusCodes/MQTT_GetSubAckStatusCodes_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_GetSubAckStatusCodes_harness.c 27 | * @brief Implements the proof harness for MQTT_GetSubAckStatusCodes function. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | void harness() 34 | { 35 | MQTTPacketInfo_t * pSubackPacket; 36 | uint8_t ** pPayloadStart; 37 | size_t * pPayloadSize; 38 | 39 | pSubackPacket = allocateMqttPacketInfo( NULL ); 40 | __CPROVER_assume( isValidMqttPacketInfo( pSubackPacket ) ); 41 | 42 | /* pPayloadStart and pPayloadSize are output parameters, and 43 | * thus, don't carry any assumptions. */ 44 | pPayloadStart = malloc( sizeof( uint8_t * ) ); 45 | pPayloadSize = malloc( sizeof( size_t ) ); 46 | 47 | MQTT_GetSubAckStatusCodes( pSubackPacket, 48 | pPayloadStart, 49 | pPayloadSize ); 50 | } 51 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetSubAckStatusCodes/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_GetSubAckStatusCodes_harness 24 | PROOF_UID=MQTT_GetSubAckStatusCodes 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetSubAckStatusCodes/README.md: -------------------------------------------------------------------------------- 1 | MQTT_GetSubAckStatusCodes proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_GetSubAckStatusCodes. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetSubAckStatusCodes/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_GetSubAckStatusCodes/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_GetSubAckStatusCodes", 6 | "proof-root": "../../../../.." 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Init/MQTT_Init_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Init_harness.c 27 | * @brief Implements the proof harness for MQTT_Init function. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | void harness() 34 | { 35 | MQTTContext_t * pContext; 36 | TransportInterface_t * pTransportInterface; 37 | MQTTGetCurrentTimeFunc_t getTimeFunction; 38 | MQTTEventCallback_t userCallback; 39 | MQTTFixedBuffer_t * pNetworkBuffer; 40 | 41 | pContext = malloc( sizeof( MQTTContext_t ) ); 42 | pTransportInterface = malloc( sizeof( TransportInterface_t ) ); 43 | getTimeFunction = malloc( sizeof( MQTTGetCurrentTimeFunc_t ) ); 44 | userCallback = malloc( sizeof( MQTTEventCallback_t ) ); 45 | pNetworkBuffer = malloc( sizeof( MQTTFixedBuffer_t ) ); 46 | 47 | MQTT_Init( pContext, 48 | pTransportInterface, 49 | getTimeFunction, 50 | userCallback, 51 | pNetworkBuffer ); 52 | } 53 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Init/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Init_harness 24 | PROOF_UID=MQTT_Init 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Init/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Init proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Init. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Init/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Init/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Init", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_MatchTopic/MQTT_MatchTopic_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_MatchTopic_harness.c 27 | * @brief Implements the proof harness for MQTT_MatchTopic function. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "mqtt_cbmc_state.h" 32 | 33 | void harness() 34 | { 35 | const char * pTopicName; 36 | uint16_t nameLength; 37 | const char * pTopicFilter; 38 | uint16_t filterLength; 39 | bool * pMatchResult; 40 | 41 | __CPROVER_assume( nameLength < MAX_TOPIC_NAME_FILTER_LENGTH ); 42 | pTopicName = malloc( ( sizeof( char ) * nameLength ) ); 43 | __CPROVER_assume( filterLength < MAX_TOPIC_NAME_FILTER_LENGTH ); 44 | pTopicFilter = malloc( ( sizeof( char ) * filterLength ) ); 45 | pMatchResult = malloc( sizeof( bool ) ); 46 | 47 | MQTT_MatchTopic( pTopicName, 48 | nameLength, 49 | pTopicFilter, 50 | filterLength, 51 | pMatchResult ); 52 | } 53 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_MatchTopic/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_MatchTopic_harness 24 | PROOF_UID=MQTT_MatchTopic 25 | 26 | # The topic name/filter length are bounded, so that the loops in topic matching algorithmic 27 | # functions called by MQTT_MatchTopic can be unwound to an expected 28 | # amount that won't make the proof run too long. 29 | MAX_TOPIC_NAME_FILTER_LENGTH=10 30 | 31 | DEFINES += -DMAX_TOPIC_NAME_FILTER_LENGTH=$(MAX_TOPIC_NAME_FILTER_LENGTH) 32 | INCLUDES += 33 | 34 | REMOVE_FUNCTION_BODY += 35 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_matchTopicFilter.0:$(MAX_TOPIC_NAME_FILTER_LENGTH) 36 | UNWINDSET += strncmp.0:$(MAX_TOPIC_NAME_FILTER_LENGTH) 37 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_matchWildcards.0:$(MAX_TOPIC_NAME_FILTER_LENGTH) 38 | 39 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 40 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 41 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 42 | 43 | include ../Makefile.common 44 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_MatchTopic/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_MatchTopic/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_MatchTopic", 6 | "proof-root": "standard/mqtt/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Ping/MQTT_Ping_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Ping_harness.c 27 | * @brief Implements the proof harness for MQTT_Ping function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTContext_t * pContext; 35 | 36 | pContext = allocateMqttContext( NULL ); 37 | __CPROVER_assume( isValidMqttContext( pContext ) ); 38 | 39 | MQTT_Ping( pContext ); 40 | } 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Ping/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Ping_harness 24 | PROOF_UID=MQTT_Ping 25 | 26 | # Please see test/cbmc/stubs/network_interface_subs.c for 27 | # more information on MAX_NETWORK_SEND_TRIES. 28 | MAX_NETWORK_SEND_TRIES=3 29 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 30 | INCLUDES += 31 | 32 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 33 | # sendBuffer will continue until all the bytes are sent or a network error 34 | # occurs. Please see NetworkInterfaceReceiveStub in 35 | # test/cbmc/stubs/network_interface_stubs.c for more 36 | # information. 37 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 38 | 39 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 40 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 41 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 42 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 43 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 44 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 45 | 46 | include ../Makefile.common 47 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Ping/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Ping proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Ping. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Ping/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Ping/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Ping", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ProcessLoop/MQTT_ProcessLoop_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_ProcessLoop_harness.c 27 | * @brief Implements the proof harness for MQTT_ProcessLoop function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | MQTTStatus_t MQTT_DeserializeAck( const MQTTPacketInfo_t * pIncomingPacket, 33 | uint16_t * pPacketId, 34 | bool * pSessionPresent ) 35 | { 36 | MQTTStatus_t result; 37 | 38 | return result; 39 | } 40 | 41 | void harness() 42 | { 43 | MQTTContext_t * pContext; 44 | 45 | pContext = allocateMqttContext( NULL ); 46 | __CPROVER_assume( isValidMqttContext( pContext ) ); 47 | 48 | MQTT_ProcessLoop( pContext ); 49 | } 50 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ProcessLoop/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_ProcessLoop_harness 24 | PROOF_UID=MQTT_ProcessLoop 25 | 26 | # Bound on the timeout in MQTT_ProcessLoop. This timeout is bounded because 27 | # memory saftey can be proven in a only a few iteration of the MQTT operations. 28 | # Each iteration will try to receive a single packet in its entirey. With a time 29 | # out of 2 we can get coverage of the entire function. Another iteration will 30 | # performed unnecessarily duplicating of the proof. 31 | MQTT_RECEIVE_TIMEOUT=3 32 | # Please see test/cbmc/stubs/network_interface_subs.c for 33 | # more information on MAX_NETWORK_SEND_TRIES. 34 | MAX_NETWORK_SEND_TRIES=3 35 | # The NetworkInterfaceReceiveStub is called once for getting the incoming packet 36 | # type with one byte of data, then it is called multiple times to reveive the 37 | # packet. 38 | MAX_NETWORK_RECV_TRIES=4 39 | # Please see test/cbmc/include/core_mqtt_config.h for more 40 | # information. 41 | MQTT_STATE_ARRAY_MAX_COUNT=11 42 | DEFINES += -DMQTT_RECEIVE_TIMEOUT=$(MQTT_RECEIVE_TIMEOUT) 43 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 44 | DEFINES += -DMAX_NETWORK_RECV_TRIES=$(MAX_NETWORK_RECV_TRIES) 45 | INCLUDES += 46 | 47 | # These functions have their memory saftey proven in other harnesses. 48 | REMOVE_FUNCTION_BODY += MQTT_Ping 49 | REMOVE_FUNCTION_BODY += MQTT_DeserializeAck 50 | REMOVE_FUNCTION_BODY += MQTT_SerializeAck 51 | REMOVE_FUNCTION_BODY += memmove # Use stub 52 | 53 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_discardStoredPacket.0:$(MAX_NETWORK_RECV_TRIES) 54 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_recvExact.0:$(MAX_NETWORK_RECV_TRIES) 55 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 56 | # sendBuffer will continue until all the bytes are sent or a network error 57 | # occurs. Please see NetworkInterfaceReceiveStub in 58 | # libraries\standard\mqtt\cbmc\stubs\network_interface_stubs.c for more 59 | # information. 60 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 61 | # The getRemainingLength loop is unwound 5 times because getRemainingLength() 62 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 63 | # log128(SIZE_MAX) = 4.571... 64 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_processRemainingLength.0:5 65 | # These loops will run for the maximum number of publishes pending 66 | # acknowledgements plus one. This value is set in 67 | # test/cbmc/include/core_mqtt_config.h. 68 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_addRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 69 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_findInRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 70 | 71 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 72 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 73 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 74 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 75 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 76 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/memmove.c 77 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 78 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 79 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 80 | 81 | EXPENSIVE = true 82 | 83 | include ../Makefile.common 84 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ProcessLoop/README.md: -------------------------------------------------------------------------------- 1 | MQTT_ProcessLoop proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_ProcessLoop. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ProcessLoop/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ProcessLoop/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | "MQTT_Ping", 4 | "MQTT_SerializeAck", 5 | "MQTT_DeserializeAck" 6 | ], 7 | "proof-name": "MQTT_ProcessLoop", 8 | "proof-root": "test/cbmc/proofs" 9 | } 10 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Publish/MQTT_Publish_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Publish_harness.c 27 | * @brief Implements the proof harness for MQTT_Publish function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | #include "core_mqtt_config_defaults.h" 32 | 33 | /** 34 | * @brief Implement a get time function to return timeout after certain 35 | * iterations have been made in the code. This ensures that we do not hit 36 | * unwinding error in CBMC. In real life scenarios, the send function will 37 | * not just keep accepting 1 byte at a time for a long time since it just 38 | * gets added to the TCP buffer. 39 | * 40 | * @return The global system time. 41 | */ 42 | static uint32_t ulGetTimeFunction( void ) 43 | { 44 | static uint32_t systemTime = 0; 45 | 46 | if( systemTime >= MAX_NETWORK_SEND_TRIES ) 47 | { 48 | systemTime = systemTime + MQTT_SEND_TIMEOUT_MS + 1; 49 | } 50 | else 51 | { 52 | systemTime = systemTime + 1; 53 | } 54 | 55 | return systemTime; 56 | } 57 | 58 | void harness() 59 | { 60 | MQTTContext_t * pContext; 61 | MQTTPublishInfo_t * pPublishInfo; 62 | uint16_t packetId; 63 | 64 | pContext = allocateMqttContext( NULL ); 65 | __CPROVER_assume( isValidMqttContext( pContext ) ); 66 | 67 | if( pContext != NULL ) 68 | { 69 | pContext->getTime = ulGetTimeFunction; 70 | } 71 | 72 | pPublishInfo = allocateMqttPublishInfo( NULL ); 73 | __CPROVER_assume( isValidMqttPublishInfo( pPublishInfo ) ); 74 | 75 | MQTT_Publish( pContext, pPublishInfo, packetId ); 76 | } 77 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Publish/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Publish_harness 24 | PROOF_UID=MQTT_Publish 25 | 26 | # Please see test/cbmc/stubs/network_interface_subs.c for 27 | # more information on MAX_NETWORK_SEND_TRIES. 28 | MAX_NETWORK_SEND_TRIES=3 29 | # Please see test/cbmc/include/core_mqtt_config.h for more 30 | # information. 31 | MQTT_STATE_ARRAY_MAX_COUNT=11 32 | PUBLISH_PACKET_VECTORS = 5 33 | 34 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 35 | INCLUDES += 36 | 37 | REMOVE_FUNCTION_BODY += 38 | REMOVE_FUNCTION_BODY += 39 | # These loops will run for the maximum number of publishes pending acknowledgement. 40 | # This is set in test/cbmc/include/core_mqtt_config.h. 41 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_addRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 42 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_findInRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 43 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 44 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 45 | # log128(SIZE_MAX) = 4.571... 46 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 47 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.0:${PUBLISH_PACKET_VECTORS} 48 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.1:${PUBLISH_PACKET_VECTORS} 49 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.2:${PUBLISH_PACKET_VECTORS} 50 | 51 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 52 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 53 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 54 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 55 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 56 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 57 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 58 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 59 | 60 | include ../Makefile.common 61 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Publish/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Publish proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Publish. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Publish/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Publish/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Publish", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ReceiveLoop/MQTT_ReceiveLoop_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_ReceiveLoop_harness.c 27 | * @brief Implements the proof harness for MQTT_ReceiveLoop function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | MQTTStatus_t MQTT_DeserializeAck( const MQTTPacketInfo_t * pIncomingPacket, 33 | uint16_t * pPacketId, 34 | bool * pSessionPresent ) 35 | { 36 | MQTTStatus_t result; 37 | 38 | return result; 39 | } 40 | 41 | void harness() 42 | { 43 | MQTTContext_t * pContext; 44 | 45 | pContext = allocateMqttContext( NULL ); 46 | __CPROVER_assume( isValidMqttContext( pContext ) ); 47 | 48 | MQTT_ReceiveLoop( pContext ); 49 | } 50 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ReceiveLoop/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: MIT-0 3 | 4 | HARNESS_ENTRY=harness 5 | HARNESS_FILE=MQTT_ReceiveLoop_harness 6 | PROOF_UID=MQTT_ReceiveLoop 7 | 8 | # Bound on the timeout in MQTT_ProcessLoop. This timeout is bounded because 9 | # memory saftey can be proven in a only a few iteration of the MQTT operations. 10 | # Each iteration will try to receive a single packet in its entirety. With a time 11 | # out of 2 we can get coverage of the entire function. Another iteration will 12 | # performed unnecessarily duplicating of the proof. 13 | MQTT_RECEIVE_TIMEOUT=3 14 | # The NetworkInterfaceReceiveStub is called once for getting the incoming packet 15 | # type with one byte of data, then it is called multiple times to reveive the 16 | # packet. 17 | MAX_NETWORK_RECV_TRIES=4 18 | # Please see test/cbmc/stubs/network_interface_subs.c for 19 | # more information on MAX_NETWORK_SEND_TRIES. 20 | MAX_NETWORK_SEND_TRIES=3 21 | # Please see test/cbmc/include/core_mqtt_config.h for more 22 | # information. 23 | MQTT_STATE_ARRAY_MAX_COUNT=11 24 | DEFINES += -DMQTT_RECEIVE_TIMEOUT=$(MQTT_RECEIVE_TIMEOUT) 25 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 26 | DEFINES += -DMAX_NETWORK_RECV_TRIES=$(MAX_NETWORK_RECV_TRIES) 27 | INCLUDES += 28 | 29 | # These functions have their memory saftey proven in other harnesses. 30 | REMOVE_FUNCTION_BODY += MQTT_DeserializeAck 31 | REMOVE_FUNCTION_BODY += MQTT_SerializeAck 32 | REMOVE_FUNCTION_BODY += memmove # Use stub 33 | 34 | # The loops below are unwound once more than the exclusive timeout bound. 35 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_discardStoredPacket.0:$(MAX_NETWORK_RECV_TRIES) 36 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_recvExact.0:$(MAX_NETWORK_RECV_TRIES) 37 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 38 | # sendBuffer will continue until all the bytes are sent or a network error 39 | # occurs. Please see NetworkInterfaceReceiveStub in 40 | # libraries\standard\mqtt\cbmc\stubs\network_interface_stubs.c for more 41 | # information. 42 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 43 | # The getRemainingLength loop is unwound 5 times because getRemainingLength() 44 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 45 | # log128(SIZE_MAX) = 4.571... 46 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_processRemainingLength.0:5 47 | # These loops will run for the maximum number of publishes pending acknowledgement. 48 | # This is set in test/cbmc/include/core_mqtt_config.h. 49 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_addRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 50 | UNWINDSET += __CPROVER_file_local_core_mqtt_state_c_findInRecord.0:$(MQTT_STATE_ARRAY_MAX_COUNT) 51 | 52 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 53 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 54 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 55 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 56 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 57 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/memmove.c 58 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 59 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 60 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 61 | 62 | EXPENSIVE = true 63 | 64 | include ../Makefile.common 65 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ReceiveLoop/README.md: -------------------------------------------------------------------------------- 1 | MQTT_ReceiveLoop proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_ReceiveLoop. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ReceiveLoop/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_ReceiveLoop/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | "MQTT_DeserializeAck", 4 | "MQTT_SerializeAck" 5 | ], 6 | "proof-name": "MQTT_ReceiveLoop", 7 | "proof-root": "test/cbmc/proofs" 8 | } 9 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeAck/MQTT_SerializeAck_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializeAck_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializeAck function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTFixedBuffer_t * pFixedBuffer; 35 | uint8_t packetType; 36 | uint16_t packetId; 37 | 38 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 39 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 40 | 41 | MQTT_SerializeAck( pFixedBuffer, packetType, packetId ); 42 | } 43 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeAck/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeAck_harness 24 | PROOF_UID=MQTT_SerializeAck 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeAck/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeAck proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeAck. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeAck/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeAck/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeAck", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeConnect/MQTT_SerializeConnect_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializeConnect_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializeConnect function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTConnectInfo_t * pConnectInfo; 35 | MQTTPublishInfo_t * pWillInfo; 36 | size_t remainingLength; 37 | MQTTFixedBuffer_t * pFixedBuffer; 38 | size_t packetSize; 39 | MQTTStatus_t status = MQTTSuccess; 40 | 41 | pConnectInfo = allocateMqttConnectInfo( NULL ); 42 | __CPROVER_assume( isValidMqttConnectInfo( pConnectInfo ) ); 43 | 44 | pWillInfo = allocateMqttPublishInfo( NULL ); 45 | __CPROVER_assume( isValidMqttPublishInfo( pWillInfo ) ); 46 | 47 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 48 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 49 | 50 | /* Before calling MQTT_SerializeConnect() it is up to the application to make 51 | * sure that the information in MQTTConnectInfo_t and MQTTPublishInfo_t can 52 | * fit into the MQTTFixedBuffer_t. It is a violation of the API to call 53 | * MQTT_SerializeConnect() without first calling MQTT_GetConnectPacketSize(). */ 54 | if( pConnectInfo != NULL ) 55 | { 56 | /* The output parameter pPacketSize of the function MQTT_GetConnectPacketSize() 57 | * must not be NULL. packetSize returned is not used in this proof, but 58 | * is used normally by the application to verify the size of its 59 | * MQTTFixedBuffer_t. MQTT_SerializeConnect() will use the remainingLength 60 | * to recalculate the packetSize. */ 61 | status = MQTT_GetConnectPacketSize( pConnectInfo, 62 | pWillInfo, 63 | &remainingLength, 64 | &packetSize ); 65 | } 66 | 67 | if( status == MQTTSuccess ) 68 | { 69 | /* For coverage, it is expected that a NULL pConnectInfo will reach this 70 | * function. */ 71 | MQTT_SerializeConnect( pConnectInfo, pWillInfo, remainingLength, pFixedBuffer ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeConnect/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeConnect_harness 24 | PROOF_UID=MQTT_SerializeConnect 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | # This function does not coincide with the call graph of MQTT_Serialize, but is 30 | # found by CBMC during processing in logs/MQTT_Connect_harness3.txt. We remove 31 | # the function body to improve coverage accuracy. 32 | REMOVE_FUNCTION_BODY += MQTT_GetIncomingPacketTypeAndLength 33 | 34 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 35 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 36 | # log128(SIZE_MAX) = 4.571... 37 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 38 | 39 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 40 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 41 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 42 | 43 | include ../Makefile.common 44 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeConnect/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeConnect proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeConnect. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeConnect/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeConnect/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeConnect", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeDisconnect/MQTT_SerializeDisconnect_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializeDisconnect_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializeDisconnect function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTFixedBuffer_t * pFixedBuffer; 35 | 36 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 37 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 38 | 39 | MQTT_SerializeDisconnect( pFixedBuffer ); 40 | } 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeDisconnect/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeDisconnect_harness 24 | PROOF_UID=MQTT_SerializeDisconnect 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeDisconnect/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeDisconnect proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeDisconnect. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeDisconnect/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeDisconnect/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeDisconnect", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeMQTTVec/MQTT_SerializeMQTTVec_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Disconnect_harness.c 27 | * @brief Implements the proof harness for MQTT_Disconnect function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTVec_t * mqttVec; 35 | size_t memoryRequired; 36 | uint8_t * memoryBuffer; 37 | 38 | mqttVec = allocateMqttVec( NULL ); 39 | 40 | memoryRequired = MQTT_GetBytesInMQTTVec( mqttVec ); 41 | 42 | /* It is a part of the API contract that #MQTT_SerializeMQTTVec will be called with 43 | * a memory buffer of size output by #MQTT_GetBytesInMQTTVec function and the 44 | * #MQTTVec_t pointer given by the library as an input to the user defined 45 | * #MQTTStorePacketForRetransmit callback function. Hence the memory buffer must 46 | * not be NULL. 47 | */ 48 | memoryBuffer = malloc( memoryRequired ); 49 | __CPROVER_assume( memoryBuffer != NULL ); 50 | 51 | MQTT_SerializeMQTTVec( memoryBuffer, mqttVec ); 52 | } 53 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeMQTTVec/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeMQTTVec_harness 24 | PROOF_UID=MQTT_SerializeMQTTVec 25 | 26 | PUBLISH_PACKET_VECTORS = 5 27 | 28 | DEFINES += 29 | INCLUDES += 30 | 31 | REMOVE_FUNCTION_BODY += 32 | UNWINDSET += MQTT_GetBytesInMQTTVec.0:${PUBLISH_PACKET_VECTORS} 33 | UNWINDSET += allocateMqttVec.0:${PUBLISH_PACKET_VECTORS} 34 | UNWINDSET += MQTT_SerializeMQTTVec.0:${PUBLISH_PACKET_VECTORS} 35 | 36 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 37 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 38 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 39 | 40 | include ../Makefile.common 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeMQTTVec/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeMQTTVec proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeMQTTVec. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeMQTTVec/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeMQTTVec/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeMQTTVec", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePingreq/MQTT_SerializePingreq_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializePingreq_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializePingreq function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTFixedBuffer_t * pFixedBuffer; 35 | 36 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 37 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 38 | 39 | MQTT_SerializePingreq( pFixedBuffer ); 40 | } 41 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePingreq/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializePingreq_harness 24 | PROOF_UID=MQTT_SerializePingreq 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | UNWINDSET += 31 | 32 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 33 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 34 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 35 | 36 | include ../Makefile.common 37 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePingreq/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializePingreq proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializePingreq. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePingreq/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePingreq/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializePingreq", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublish/MQTT_SerializePublish_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializePublish_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializePublish function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTPublishInfo_t * pPublishInfo; 35 | uint16_t packetId; 36 | size_t remainingLength; 37 | size_t packetSize; 38 | const MQTTFixedBuffer_t * pFixedBuffer; 39 | MQTTStatus_t status = MQTTSuccess; 40 | 41 | pPublishInfo = allocateMqttPublishInfo( NULL ); 42 | __CPROVER_assume( isValidMqttPublishInfo( pPublishInfo ) ); 43 | 44 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 45 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 46 | 47 | /* Before calling MQTT_SerializePublish() it is up to the application to 48 | * make sure that the information in MQTTPublishInfo_t can fit into the 49 | * MQTTFixedBuffer_t. It is a violation of the API to call 50 | * MQTT_SerializePublish() without first calling MQTT_GetPublishPacketSize(). */ 51 | if( pPublishInfo != NULL ) 52 | { 53 | /* The output parameter pPacketSize of the function MQTT_GetConnectPacketSize() 54 | * must not be NULL. packetSize returned is not used in this proof, but 55 | * is used normally by the application to verify the size of its 56 | * MQTTFixedBuffer_t. MQTT_SerializeConnect() will use the remainingLength 57 | * to recalculate the packetSize. */ 58 | status = MQTT_GetPublishPacketSize( pPublishInfo, &remainingLength, &packetSize ); 59 | } 60 | 61 | if( status == MQTTSuccess ) 62 | { 63 | /* For coverage it is expected that a NULL pPublishInfo could 64 | * reach this function. */ 65 | MQTT_SerializePublish( pPublishInfo, 66 | packetId, 67 | remainingLength, 68 | pFixedBuffer ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublish/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializePublish_harness 24 | PROOF_UID=MQTT_SerializePublish 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 31 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 32 | # log128(SIZE_MAX) = 4.571... 33 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 34 | 35 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 36 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 37 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 38 | 39 | include ../Makefile.common 40 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublish/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializePublish proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializePublish. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublish/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublish/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializePublish", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublishHeader/MQTT_SerializePublishHeader_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializePublishHeader_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializePublishHeader function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTPublishInfo_t * pPublishInfo; 35 | uint16_t packetId; 36 | size_t remainingLength; 37 | size_t packetSize; 38 | MQTTFixedBuffer_t * pFixedBuffer; 39 | size_t * pHeaderSize; 40 | MQTTStatus_t status = MQTTSuccess; 41 | 42 | pPublishInfo = allocateMqttPublishInfo( NULL ); 43 | __CPROVER_assume( isValidMqttPublishInfo( pPublishInfo ) ); 44 | 45 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 46 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 47 | 48 | /* Allocate space for a returned header size to get coverage of a possibly 49 | * NULL input. */ 50 | pHeaderSize = malloc( sizeof( size_t ) ); 51 | 52 | /* Before calling MQTT_SerializePublishHeader() it is up to the application 53 | * to verify that the information in MQTTPublishInfo_t can fit into the 54 | * MQTTFixedBuffer_t. It is a violation of the API to call 55 | * MQTT_SerializePublishHeader() without first calling MQTT_GetPublishPacketSize(). */ 56 | if( pPublishInfo != NULL ) 57 | { 58 | /* The output parameter pPacketSize of the function MQTT_GetConnectPacketSize() 59 | * must not be NULL. packetSize returned is not used in this proof, but 60 | * is used normally by the application to verify the size of its 61 | * MQTTFixedBuffer_t. MQTT_SerializeConnect() will use the remainingLength 62 | * to recalculate the packetSize. */ 63 | status = MQTT_GetPublishPacketSize( pPublishInfo, 64 | &remainingLength, 65 | &packetSize ); 66 | } 67 | 68 | if( status == MQTTSuccess ) 69 | { 70 | /* For coverage it is expected that a NULL pPublishInfo could 71 | * reach this function. */ 72 | MQTT_SerializePublishHeader( pPublishInfo, 73 | packetId, 74 | remainingLength, 75 | pFixedBuffer, 76 | pHeaderSize ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublishHeader/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializePublishHeader_harness 24 | PROOF_UID=MQTT_SerializePublishHeader 25 | 26 | DEFINES += 27 | INCLUDES += 28 | 29 | REMOVE_FUNCTION_BODY += 30 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 31 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 32 | # log128(SIZE_MAX) = 4.571... 33 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 34 | 35 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 36 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 37 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 38 | 39 | include ../Makefile.common 40 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublishHeader/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializePublishHeader proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializePublishHeader. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublishHeader/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializePublishHeader/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializePublishHeader", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeSubscribe/MQTT_SerializeSubscribe_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializeSubscribe_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializeSubscribe function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTSubscribeInfo_t * pSubscriptionList; 35 | size_t subscriptionCount; 36 | size_t remainingLength; 37 | uint16_t packetId; 38 | size_t packetSize; 39 | MQTTFixedBuffer_t * pFixedBuffer; 40 | MQTTStatus_t status = MQTTSuccess; 41 | 42 | /* Please see the default bound description on SUBSCRIPTION_COUNT_MAX in 43 | * mqtt_cbmc_state.c for more information. */ 44 | __CPROVER_assume( subscriptionCount < SUBSCRIPTION_COUNT_MAX ); 45 | 46 | pSubscriptionList = allocateMqttSubscriptionList( NULL, subscriptionCount ); 47 | __CPROVER_assume( isValidMqttSubscriptionList( pSubscriptionList, subscriptionCount ) ); 48 | 49 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 50 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 51 | 52 | /* Before calling MQTT_SerializeSubscribe() it is up to the application to 53 | * make sure that the information in the list of MQTTSubscribeInfo_t can fit 54 | * into the MQTTFixedBuffer_t. It is a violation of the API to call 55 | * MQTT_SerializeSubscribe() without first calling MQTT_GetSubscribePacketSize(). */ 56 | if( pSubscriptionList != NULL ) 57 | { 58 | /* The output parameter pPacketSize of the function MQTT_GetConnectPacketSize() 59 | * must not be NULL. packetSize returned is not used in this proof, but 60 | * is used normally by the application to verify the size of its 61 | * MQTTFixedBuffer_t. MQTT_SerializeConnect() will use the remainingLength 62 | * to recalculate the packetSize. */ 63 | status = MQTT_GetSubscribePacketSize( pSubscriptionList, 64 | subscriptionCount, 65 | &remainingLength, 66 | &packetSize ); 67 | } 68 | 69 | if( status == MQTTSuccess ) 70 | { 71 | /* For coverage it is expected that a NULL pSubscriptionList could 72 | * reach this function. */ 73 | MQTT_SerializeSubscribe( pSubscriptionList, 74 | subscriptionCount, 75 | packetId, 76 | remainingLength, 77 | pFixedBuffer ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeSubscribe/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeSubscribe_harness 24 | PROOF_UID=MQTT_SerializeSubscribe 25 | 26 | # Bound on the the subscription count. Please see the default value in 27 | # mqtt_cbmc_state.c for more information on this bound. This is set to 2 28 | # currently to have the proof run quickly. 29 | SUBSCRIPTION_COUNT_MAX=2 30 | DEFINES += -DSUBSCRIPTION_COUNT_MAX=$(SUBSCRIPTION_COUNT_MAX) 31 | INCLUDES += 32 | 33 | REMOVE_FUNCTION_BODY += 34 | UNWINDSET += allocateMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 35 | UNWINDSET += isValidMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 36 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_calculateSubscriptionPacketSize.0:$(SUBSCRIPTION_COUNT_MAX) 37 | UNWINDSET += MQTT_SerializeSubscribe.0:$(SUBSCRIPTION_COUNT_MAX) 38 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 39 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 40 | # log128(SIZE_MAX) = 4.571... 41 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 42 | 43 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 44 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 45 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 46 | 47 | include ../Makefile.common 48 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeSubscribe/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeSubscribe proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeSubscribe. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeSubscribe/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeSubscribe/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeSubscribe", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeUnsubscribe/MQTT_SerializeUnsubscribe_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_SerializeUnsubscribe_harness.c 27 | * @brief Implements the proof harness for MQTT_SerializeUnsubscribe function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | 32 | void harness() 33 | { 34 | MQTTSubscribeInfo_t * pSubscriptionList; 35 | size_t subscriptionCount; 36 | size_t remainingLength; 37 | uint16_t packetId; 38 | 39 | /* This variable is not used but is needed for MQTT_GetUnsubscribePacketSize() 40 | * to verify the pSubscriptionList. */ 41 | size_t packetSize; 42 | MQTTFixedBuffer_t * pFixedBuffer; 43 | MQTTStatus_t status = MQTTSuccess; 44 | 45 | /* Please see the default bound description on SUBSCRIPTION_COUNT_MAX in 46 | * mqtt_cbmc_state.c for more information. */ 47 | __CPROVER_assume( subscriptionCount < SUBSCRIPTION_COUNT_MAX ); 48 | 49 | pSubscriptionList = allocateMqttSubscriptionList( NULL, subscriptionCount ); 50 | __CPROVER_assume( isValidMqttSubscriptionList( pSubscriptionList, subscriptionCount ) ); 51 | 52 | pFixedBuffer = allocateMqttFixedBuffer( NULL ); 53 | __CPROVER_assume( isValidMqttFixedBuffer( pFixedBuffer ) ); 54 | 55 | /* Before calling MQTT_SerializeUnsubscribe() it is up to the application to 56 | * make sure that the information in the list of MQTTSubscribeInfo_t can fit 57 | * into the MQTTFixedBuffer_t. It is a violation of the API to call 58 | * MQTT_SerializeUnsubscribe() without first calling MQTT_GetUnsubscribePacketSize(). */ 59 | if( pSubscriptionList != NULL ) 60 | { 61 | /* The output parameter pPacketSize of the function MQTT_GetConnectPacketSize() 62 | * must not be NULL. packetSize returned is not used in this proof, but 63 | * is used normally by the application to verify the size of its 64 | * MQTTFixedBuffer_t. MQTT_SerializeConnect() will use the remainingLength 65 | * to recalculate the packetSize. */ 66 | status = MQTT_GetUnsubscribePacketSize( pSubscriptionList, 67 | subscriptionCount, 68 | &remainingLength, 69 | &packetSize ); 70 | } 71 | 72 | if( status == MQTTSuccess ) 73 | { 74 | /* For coverage it is expected that a NULL pSubscriptionList could 75 | * reach this function. */ 76 | MQTT_SerializeUnsubscribe( pSubscriptionList, 77 | subscriptionCount, 78 | packetId, 79 | remainingLength, 80 | pFixedBuffer ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeUnsubscribe/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_SerializeUnsubscribe_harness 24 | PROOF_UID=MQTT_SerializeUnsubscribe 25 | 26 | # Bound on the the subscription count. Please see the default value in 27 | # mqtt_cbmc_state.c for more information on this bound. This is set to 2 28 | # currently to have the proof run quickly. 29 | SUBSCRIPTION_COUNT_MAX=2 30 | DEFINES += -DSUBSCRIPTION_COUNT_MAX=$(SUBSCRIPTION_COUNT_MAX) 31 | INCLUDES += 32 | 33 | REMOVE_FUNCTION_BODY += 34 | UNWINDSET += allocateMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 35 | UNWINDSET += isValidMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 36 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_calculateSubscriptionPacketSize.0:$(SUBSCRIPTION_COUNT_MAX) 37 | UNWINDSET += MQTT_SerializeUnsubscribe.0:$(SUBSCRIPTION_COUNT_MAX) 38 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 39 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 40 | # log128(SIZE_MAX) = 4.571... 41 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 42 | 43 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 44 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 45 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 46 | 47 | include ../Makefile.common 48 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeUnsubscribe/README.md: -------------------------------------------------------------------------------- 1 | MQTT_SerializeUnsubscribe proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_SerializeUnsubscribe. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeUnsubscribe/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_SerializeUnsubscribe/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_SerializeUnsubscribe", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Subscribe/MQTT_Subscribe_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Subscribe_harness.c 27 | * @brief Implements the proof harness for MQTT_Subscribe function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | #include "core_mqtt_config_defaults.h" 32 | 33 | /** 34 | * @brief Implement a get time function to return timeout after certain 35 | * iterations have been made in the code. This ensures that we do not hit 36 | * unwinding error in CBMC. In real life scenarios, the send function will 37 | * not just keep accepting 1 byte at a time for a long time since it just 38 | * gets added to the TCP buffer. 39 | * 40 | * @return The global system time. 41 | */ 42 | static uint32_t ulGetTimeFunction( void ) 43 | { 44 | static uint32_t systemTime = 0; 45 | 46 | if( systemTime >= MAX_NETWORK_SEND_TRIES ) 47 | { 48 | systemTime = systemTime + MQTT_SEND_TIMEOUT_MS + 1; 49 | } 50 | else 51 | { 52 | systemTime = systemTime + 1; 53 | } 54 | 55 | return systemTime; 56 | } 57 | 58 | void harness() 59 | { 60 | MQTTContext_t * pContext; 61 | MQTTSubscribeInfo_t * pSubscriptionList; 62 | size_t subscriptionCount; 63 | uint16_t packetId; 64 | 65 | pContext = allocateMqttContext( NULL ); 66 | __CPROVER_assume( isValidMqttContext( pContext ) ); 67 | 68 | if( pContext != NULL ) 69 | { 70 | pContext->getTime = ulGetTimeFunction; 71 | } 72 | 73 | /* Please see the default bound description on SUBSCRIPTION_COUNT_MAX in 74 | * mqtt_cbmc_state.c for more information. */ 75 | __CPROVER_assume( subscriptionCount < SUBSCRIPTION_COUNT_MAX ); 76 | 77 | pSubscriptionList = allocateMqttSubscriptionList( NULL, 1U ); 78 | __CPROVER_assume( isValidMqttSubscriptionList( pSubscriptionList, 1U ) ); 79 | 80 | MQTT_Subscribe( pContext, pSubscriptionList, subscriptionCount, packetId ); 81 | } 82 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Subscribe/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Subscribe_harness 24 | PROOF_UID=MQTT_Subscribe 25 | 26 | # Please see test/cbmc/stubs/network_interface_subs.c for 27 | # more information on MAX_NETWORK_SEND_TRIES. 28 | MAX_NETWORK_SEND_TRIES=3 29 | # Bound on the the subscription count. Please see the default value in 30 | # mqtt_cbmc_state.c for more information on this bound. This is set to 2 31 | # currently to have the proof run quickly. 32 | SUBSCRIPTION_COUNT_MAX=2 33 | SUBSCRIBE_PACKET_VECTORS = 5 34 | 35 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 36 | DEFINES += -DSUBSCRIPTION_COUNT_MAX=$(SUBSCRIPTION_COUNT_MAX) 37 | INCLUDES += 38 | 39 | REMOVE_FUNCTION_BODY += 40 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 41 | # sendBuffer will continue until all the bytes are sent or a network error 42 | # occurs. Please see NetworkInterfaceReceiveStub in 43 | # libraries\standard\mqtt\cbmc\stubs\network_interface_stubs.c for more 44 | # information. 45 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 46 | UNWINDSET += allocateMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 47 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_calculateSubscriptionPacketSize.0:$(SUBSCRIPTION_COUNT_MAX) 48 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_validateSubscribeUnsubscribeParams.0:$(SUBSCRIPTION_COUNT_MAX) 49 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.0:${SUBSCRIBE_PACKET_VECTORS} 50 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.1:${SUBSCRIBE_PACKET_VECTORS} 51 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.2:${SUBSCRIBE_PACKET_VECTORS} 52 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 53 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 54 | # log128(SIZE_MAX) = 4.571... 55 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 56 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendSubscribeWithoutCopy.0:$(MAX_NETWORK_SEND_TRIES) 57 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendSubscribeWithoutCopy.1:$(MAX_NETWORK_SEND_TRIES) 58 | 59 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 60 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 61 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 62 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 63 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 64 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 65 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 66 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 67 | 68 | include ../Makefile.common 69 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Subscribe/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Subscribe proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Subscribe. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Subscribe/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Subscribe/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Subscribe", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Unsubscribe/MQTT_Unsubscribe_harness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file MQTT_Unsubscribe_harness.c 27 | * @brief Implements the proof harness for MQTT_Unsubscribe function. 28 | */ 29 | #include "core_mqtt.h" 30 | #include "mqtt_cbmc_state.h" 31 | #include "core_mqtt_config_defaults.h" 32 | 33 | /** 34 | * @brief Implement a get time function to return timeout after certain 35 | * iterations have been made in the code. This ensures that we do not hit 36 | * unwinding error in CBMC. In real life scenarios, the send function will 37 | * not just keep accepting 1 byte at a time for a long time since it just 38 | * gets added to the TCP buffer. 39 | * 40 | * @return The global system time. 41 | */ 42 | static uint32_t ulGetTimeFunction( void ) 43 | { 44 | static uint32_t systemTime = 0; 45 | 46 | if( systemTime >= MAX_NETWORK_SEND_TRIES ) 47 | { 48 | systemTime = systemTime + MQTT_SEND_TIMEOUT_MS + 1; 49 | } 50 | else 51 | { 52 | systemTime = systemTime + 1; 53 | } 54 | 55 | return systemTime; 56 | } 57 | 58 | void harness() 59 | { 60 | MQTTContext_t * pContext; 61 | MQTTSubscribeInfo_t * pSubscriptionList; 62 | size_t subscriptionCount; 63 | uint16_t packetId; 64 | 65 | pContext = allocateMqttContext( NULL ); 66 | __CPROVER_assume( isValidMqttContext( pContext ) ); 67 | 68 | if( pContext != NULL ) 69 | { 70 | pContext->getTime = ulGetTimeFunction; 71 | } 72 | 73 | /* Please see the default bound description on SUBSCRIPTION_COUNT_MAX in 74 | * mqtt_cbmc_state.c for more information. */ 75 | __CPROVER_assume( subscriptionCount < SUBSCRIPTION_COUNT_MAX ); 76 | 77 | pSubscriptionList = allocateMqttSubscriptionList( NULL, 1U ); 78 | __CPROVER_assume( isValidMqttSubscriptionList( pSubscriptionList, 1U ) ); 79 | 80 | MQTT_Unsubscribe( pContext, pSubscriptionList, subscriptionCount, packetId ); 81 | } 82 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Unsubscribe/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | 22 | HARNESS_ENTRY=harness 23 | HARNESS_FILE=MQTT_Unsubscribe_harness 24 | PROOF_UID=MQTT_Unsubscribe 25 | 26 | # Please see test/cbmc/stubs/network_interface_subs.c for 27 | # more information on MAX_NETWORK_SEND_TRIES. 28 | MAX_NETWORK_SEND_TRIES=3 29 | # Bound on the the subscription count. Please see the default value in 30 | # mqtt_cbmc_state.c for more information on this bound. This is set to 2 31 | # currently to have the proof run quickly. 32 | SUBSCRIPTION_COUNT_MAX=2 33 | UNSUBSCRIBE_PACKET_VECTORS = 5 34 | 35 | DEFINES += -DMAX_NETWORK_SEND_TRIES=$(MAX_NETWORK_SEND_TRIES) 36 | DEFINES += -DSUBSCRIPTION_COUNT_MAX=$(SUBSCRIPTION_COUNT_MAX) 37 | INCLUDES += 38 | 39 | REMOVE_FUNCTION_BODY += 40 | # Unlike recvExact, sendBuffer is not bounded by the timeout. The loop in 41 | # sendBuffer will continue until all the bytes are sent or a network error 42 | # occurs. Please see NetworkInterfaceReceiveStub in 43 | # libraries\standard\mqtt\cbmc\stubs\network_interface_stubs.c for more 44 | # information. 45 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendBuffer.0:$(MAX_NETWORK_SEND_TRIES) 46 | UNWINDSET += allocateMqttSubscriptionList.0:$(SUBSCRIPTION_COUNT_MAX) 47 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_validateSubscribeUnsubscribeParams.0:$(SUBSCRIPTION_COUNT_MAX) 48 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_calculateSubscriptionPacketSize.0:$(SUBSCRIPTION_COUNT_MAX) 49 | UNWINDSET += MQTT_SerializeUnsubscribe.0:$(SUBSCRIPTION_COUNT_MAX) 50 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.0:${UNSUBSCRIBE_PACKET_VECTORS} 51 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.1:${UNSUBSCRIBE_PACKET_VECTORS} 52 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendMessageVector.2:${UNSUBSCRIBE_PACKET_VECTORS} 53 | # The encodeRemainingLength loop is unwound 5 times because encodeRemainingLength() 54 | # divides a size_t variable by 128 until it reaches zero to stop the loop. 55 | # log128(SIZE_MAX) = 4.571... 56 | UNWINDSET += __CPROVER_file_local_core_mqtt_serializer_c_encodeRemainingLength.0:5 57 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendUnsubscribeWithoutCopy.0:$(MAX_NETWORK_SEND_TRIES) 58 | UNWINDSET += __CPROVER_file_local_core_mqtt_c_sendUnsubscribeWithoutCopy.1:$(MAX_NETWORK_SEND_TRIES) 59 | 60 | PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c 61 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/mqtt_cbmc_state.c 62 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/network_interface_stubs.c 63 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/get_time_stub.c 64 | PROOF_SOURCES += $(SRCDIR)/test/cbmc/stubs/event_callback_stub.c 65 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt.c 66 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_serializer.c 67 | PROJECT_SOURCES += $(SRCDIR)/source/core_mqtt_state.c 68 | 69 | include ../Makefile.common 70 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Unsubscribe/README.md: -------------------------------------------------------------------------------- 1 | MQTT_Unsubscribe proof 2 | ============== 3 | 4 | This directory contains a memory safety proof for MQTT_Unsubscribe. 5 | 6 | To run the proof. 7 | * Add cbmc, goto-cc, goto-instrument, goto-analyzer, and cbmc-viewer 8 | to your path. 9 | * Run "make". 10 | * Open html/index.html in a web browser. 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Unsubscribe/cbmc-proof.txt: -------------------------------------------------------------------------------- 1 | # This file marks this directory as containing a CBMC proof. 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/MQTT_Unsubscribe/cbmc-viewer.json: -------------------------------------------------------------------------------- 1 | { "expected-missing-functions": 2 | [ 3 | 4 | ], 5 | "proof-name": "MQTT_Unsubscribe", 6 | "proof-root": "test/cbmc/proofs" 7 | } 8 | -------------------------------------------------------------------------------- /test/cbmc/proofs/Makefile-project-defines: -------------------------------------------------------------------------------- 1 | # -*- mode: makefile -*- 2 | # The first line sets the emacs major mode to Makefile 3 | 4 | ################################################################ 5 | # Use this file to give project-specific definitions of the command 6 | # line arguments to pass to CBMC tools like goto-cc to build the goto 7 | # binaries and cbmc to do the property and coverage checking. 8 | # 9 | # Use this file to override most default definitions of variables in 10 | # Makefile.common. 11 | ################################################################ 12 | 13 | # Flags to pass to goto-cc for compilation (typically those passed to gcc -c) 14 | COMPILE_FLAGS += -fPIC 15 | COMPILE_FLAGS += -std=gnu90 16 | 17 | # Path to litani executable, used for running proofs and displaying report 18 | LITANI ?= litani 19 | PROJECT_NAME = "FreeRTOS coreMQTT" 20 | 21 | 22 | # Flags to pass to goto-cc for linking (typically those passed to gcc) 23 | LINK_FLAGS = 24 | 25 | # Preprocessor include paths -I... 26 | INCLUDES += -I$(SRCDIR)/test/cbmc/include 27 | INCLUDES += -I$(SRCDIR)/source/include 28 | INCLUDES += -I$(SRCDIR)/source/src 29 | INCLUDES += -I$(SRCDIR)/source/interface 30 | 31 | # Preprocessor definitions -D... 32 | DEFINES += -Dmqtt_EXPORTS 33 | 34 | # Use the external solver kissat for property checking if it is available, 35 | # because it is much faster than the default solver minisat on MQTT. 36 | ifneq ($(shell which kissat),) 37 | EXTERNAL_SAT_SOLVER ?= kissat 38 | endif 39 | -------------------------------------------------------------------------------- /test/cbmc/proofs/Makefile-project-targets: -------------------------------------------------------------------------------- 1 | # -*- mode: makefile -*- 2 | # The first line sets the emacs major mode to Makefile 3 | 4 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | # SPDX-License-Identifier: MIT-0 6 | 7 | ################################################################ 8 | # Use this file to give project-specific targets, including targets 9 | # that may depend on targets defined in Makefile.common. 10 | ################################################################ 11 | -------------------------------------------------------------------------------- /test/cbmc/proofs/Makefile-project-testing: -------------------------------------------------------------------------------- 1 | # -*- mode: makefile -*- 2 | # The first line sets the emacs major mode to Makefile 3 | 4 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | # SPDX-License-Identifier: MIT-0 6 | 7 | ################################################################ 8 | # Use this file to define project-specific targets and definitions for 9 | # unit testing or continuous integration that may depend on targets 10 | # defined in Makefile.common 11 | ################################################################ 12 | -------------------------------------------------------------------------------- /test/cbmc/proofs/Makefile-template-defines: -------------------------------------------------------------------------------- 1 | SRCDIR ?= $(abspath $(PROOF_ROOT)/../../..) 2 | -------------------------------------------------------------------------------- /test/cbmc/proofs/README.md: -------------------------------------------------------------------------------- 1 | CBMC proofs 2 | =========== 3 | 4 | This directory contains the CBMC proofs. Each proof is in its own 5 | directory. 6 | 7 | This directory includes four Makefiles. 8 | 9 | One Makefile describes the basic workflow for building and running proofs: 10 | 11 | * Makefile.common: 12 | * make: builds the goto binary, does the cbmc property checking 13 | and coverage checking, and builds the final report. 14 | * make goto: builds the goto binary 15 | * make result: does cbmc property checking 16 | * make coverage: does cbmc coverage checking 17 | * make report: builds the final report 18 | 19 | Three included Makefiles describe project-specific settings and can override 20 | definitions in Makefile.common: 21 | 22 | * Makefile-project-defines: definitions like compiler flags 23 | required to build the goto binaries, and definitions to override 24 | definitions in Makefile.common. 25 | * Makefile-project-targets: other make targets needed for the project 26 | * Makefile-project-testing: other definitions and targets needed for 27 | unit testing or continuous integration. 28 | -------------------------------------------------------------------------------- /test/cbmc/proofs/lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/coreMQTT/42d843f40ef2abc752a419f45f7adb7dac67e591/test/cbmc/proofs/lib/__init__.py -------------------------------------------------------------------------------- /test/cbmc/proofs/lib/print_tool_versions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | # SPDX-License-Identifier: MIT-0 5 | 6 | 7 | import logging 8 | import pathlib 9 | import shutil 10 | import subprocess 11 | 12 | 13 | _TOOLS = [ 14 | "cadical", 15 | "cbmc", 16 | "cbmc-viewer", 17 | "cbmc-starter-kit-update", 18 | "kissat", 19 | "litani", 20 | ] 21 | 22 | 23 | def _format_versions(table): 24 | lines = [ 25 | "", 26 | '', 27 | ] 28 | for tool, version in table.items(): 29 | if version: 30 | v_str = f'
{version}
' 31 | else: 32 | v_str = 'not found' 33 | lines.append( 34 | f'' 36 | f'') 37 | lines.append("
Tool Versions
{tool}:{v_str}
") 38 | return "\n".join(lines) 39 | 40 | 41 | def _get_tool_versions(): 42 | ret = {} 43 | for tool in _TOOLS: 44 | err = f"Could not determine version of {tool}: " 45 | ret[tool] = None 46 | if not shutil.which(tool): 47 | logging.error("%s'%s' not found on $PATH", err, tool) 48 | continue 49 | cmd = [tool, "--version"] 50 | proc = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE) 51 | try: 52 | out, _ = proc.communicate(timeout=10) 53 | except subprocess.TimeoutExpired: 54 | logging.error("%s'%s --version' timed out", err, tool) 55 | continue 56 | if proc.returncode: 57 | logging.error( 58 | "%s'%s --version' returned %s", err, tool, str(proc.returncode)) 59 | continue 60 | ret[tool] = out.strip() 61 | return ret 62 | 63 | 64 | def main(): 65 | exe_name = pathlib.Path(__file__).name 66 | logging.basicConfig(format=f"{exe_name}: %(message)s") 67 | 68 | table = _get_tool_versions() 69 | out = _format_versions(table) 70 | print(out) 71 | 72 | 73 | if __name__ == "__main__": 74 | main() 75 | -------------------------------------------------------------------------------- /test/cbmc/sources/README.md: -------------------------------------------------------------------------------- 1 | CBMC proof source code 2 | ====================== 3 | 4 | This directory contains source code written for CBMC proofs. It is 5 | common to write some code to model aspects of the system under test, 6 | and this code goes here. 7 | -------------------------------------------------------------------------------- /test/cbmc/stubs/README.md: -------------------------------------------------------------------------------- 1 | CBMC proof stubs 2 | ====================== 3 | 4 | This directory contains the stubs written for CBMC proofs. It is 5 | common to stub out functionality like network send and receive methods 6 | when writing a CBMC proof, and the code for these stubs goes here. 7 | -------------------------------------------------------------------------------- /test/cbmc/stubs/event_callback_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file event_callback_stub.c 27 | * @brief A stub for the event callback. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "event_callback_stub.h" 32 | 33 | void EventCallbackStub( MQTTContext_t * pContext, 34 | MQTTPacketInfo_t * pPacketInfo, 35 | MQTTDeserializedInfo_t * pDeserializedInfo ) 36 | { 37 | __CPROVER_assert( pContext != NULL, 38 | "EventCallbackStub pContext is not NULL" ); 39 | __CPROVER_assert( pPacketInfo != NULL, 40 | "EventCallbackStub pPacketInfo is not NULL" ); 41 | __CPROVER_assert( pDeserializedInfo != NULL, 42 | "EventCallbackStub pDeserializedInfo is not NULL" ); 43 | } 44 | -------------------------------------------------------------------------------- /test/cbmc/stubs/get_time_stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file get_time_stub.c 27 | * @brief A stub to mock the retrieval of current time. 28 | */ 29 | 30 | #include "core_mqtt.h" 31 | #include "get_time_stub.h" 32 | 33 | uint32_t GetCurrentTimeStub( void ) 34 | { 35 | /* There are loops in the MQTT library that rely on the timestamp being 36 | * reasonable in order to complete. Returning an unbounded timestamp does 37 | * not add value to the proofs as the MQTT library uses the timestamp for 38 | * only arithmetic operations. In C arithmetic operations on unsigned 39 | * integers are guaranteed to reliably wrap around with no adverse side 40 | * effects. If the time returned was unbounded, the loops could be unwound 41 | * a large number of times making the proof execution very long. */ 42 | static uint32_t globalEntryTime = 0; 43 | 44 | return ++globalEntryTime; 45 | } 46 | -------------------------------------------------------------------------------- /test/cbmc/stubs/memmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | void * memmove( void * destination, 28 | const void * source, 29 | size_t num ) 30 | { 31 | __CPROVER_assert( destination, "memmove destination is nonnull" ); 32 | __CPROVER_assert( source, "memmove source is nonnull" ); 33 | __CPROVER_havoc_object( destination ); 34 | return destination; 35 | } 36 | -------------------------------------------------------------------------------- /test/unit-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Include filepaths for source and include. 2 | include( ${MODULE_ROOT_DIR}/mqttFilePaths.cmake ) 3 | 4 | # ==================== Define your project name (edit) ======================== 5 | set(project_name "core_mqtt") 6 | 7 | # ===================== Create your mock here (edit) ======================== 8 | 9 | # list the files to mock here 10 | list(APPEND mock_list 11 | "${MODULE_ROOT_DIR}/source/include/core_mqtt_serializer.h" 12 | "${MODULE_ROOT_DIR}/source/include/core_mqtt_state.h" 13 | ) 14 | # list the directories your mocks need 15 | list(APPEND mock_include_list 16 | . 17 | ${CMAKE_CURRENT_LIST_DIR}/logging 18 | ${MQTT_INCLUDE_PUBLIC_DIRS} 19 | ) 20 | #list the definitions of your mocks to control what to be included 21 | list(APPEND mock_define_list 22 | "" 23 | ) 24 | 25 | # ================= Create the library under test here (edit) ================== 26 | 27 | # list the files you would like to test here 28 | list(APPEND real_source_files 29 | ${MQTT_SOURCES} 30 | ${MQTT_SERIALIZER_SOURCES} 31 | ) 32 | # list the directories the module under test includes 33 | list(APPEND real_include_directories 34 | . 35 | ${CMAKE_CURRENT_LIST_DIR}/logging 36 | ${MQTT_INCLUDE_PUBLIC_DIRS} 37 | ) 38 | 39 | # ===================== Create UnitTest Code here (edit) ===================== 40 | 41 | # list the directories your test needs to include 42 | list(APPEND test_include_directories 43 | . 44 | ${MQTT_INCLUDE_PUBLIC_DIRS} 45 | ) 46 | 47 | # ============================= (end edit) =================================== 48 | 49 | set(mock_name "${project_name}_mock") 50 | set(real_name "${project_name}_real") 51 | 52 | create_mock_list(${mock_name} 53 | "${mock_list}" 54 | "${MODULE_ROOT_DIR}/tools/cmock/project.yml" 55 | "${mock_include_list}" 56 | "${mock_define_list}" 57 | ) 58 | 59 | create_real_library(${real_name} 60 | "${real_source_files}" 61 | "${real_include_directories}" 62 | "${mock_name}" 63 | ) 64 | 65 | list(APPEND utest_link_list 66 | -l${mock_name} 67 | lib${real_name}.a 68 | ) 69 | 70 | list(APPEND utest_dep_list 71 | ${real_name} 72 | ) 73 | 74 | set(utest_name "${project_name}_utest") 75 | set(utest_source "${project_name}_utest.c") 76 | create_test(${utest_name} 77 | ${utest_source} 78 | "${utest_link_list}" 79 | "${utest_dep_list}" 80 | "${test_include_directories}" 81 | ) 82 | 83 | # need to redefine because the tests below don't use any mocks 84 | set(utest_link_list "") 85 | list(APPEND utest_link_list 86 | lib${real_name}.a 87 | ) 88 | 89 | # mqtt_state_utest 90 | set(utest_name "${project_name}_state_utest") 91 | set(utest_source "${project_name}_state_utest.c") 92 | 93 | create_test(${utest_name} 94 | ${utest_source} 95 | "${utest_link_list}" 96 | "${utest_dep_list}" 97 | "${test_include_directories}" 98 | ) 99 | 100 | # mqtt_serializer_utest 101 | set(utest_name "${project_name}_serializer_utest") 102 | set(utest_source "${project_name}_serializer_utest.c") 103 | 104 | set(utest_link_list "") 105 | list(APPEND utest_link_list 106 | lib${real_name}.a 107 | ) 108 | 109 | create_test(${utest_name} 110 | ${utest_source} 111 | "${utest_link_list}" 112 | "${utest_dep_list}" 113 | "${test_include_directories}" 114 | ) 115 | -------------------------------------------------------------------------------- /test/unit-test/cmock_build.cmake: -------------------------------------------------------------------------------- 1 | # Macro utility to clone the CMock submodule. 2 | macro( clone_cmock ) 3 | find_package( Git REQUIRED ) 4 | message( "Cloning submodule CMock." ) 5 | execute_process( COMMAND rm -rf ${CMOCK_DIR} 6 | COMMAND ${GIT_EXECUTABLE} submodule update --checkout --init --recursive ${CMOCK_DIR} 7 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 8 | RESULT_VARIABLE CMOCK_CLONE_RESULT ) 9 | 10 | if( NOT ${CMOCK_CLONE_RESULT} STREQUAL "0" ) 11 | message( FATAL_ERROR "Failed to clone CMock submodule." ) 12 | endif() 13 | endmacro() 14 | 15 | # Macro utility to add library targets for Unity and CMock to build configuration. 16 | macro( add_cmock_targets ) 17 | # Build Configuration for CMock and Unity libraries. 18 | list( APPEND CMOCK_INCLUDE_DIRS 19 | "${CMOCK_DIR}/vendor/unity/src/" 20 | "${CMOCK_DIR}/vendor/unity/extras/fixture/src" 21 | "${CMOCK_DIR}/vendor/unity/extras/memory/src" 22 | "${CMOCK_DIR}/src" 23 | ) 24 | 25 | add_library(cmock STATIC 26 | "${CMOCK_DIR}/src/cmock.c" 27 | ) 28 | 29 | set_target_properties(cmock PROPERTIES 30 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib 31 | POSITION_INDEPENDENT_CODE ON 32 | COMPILE_FLAGS "-Og" 33 | ) 34 | 35 | target_include_directories(cmock PUBLIC 36 | ${CMOCK_DIR}/src 37 | ${CMOCK_DIR}/vendor/unity/src/ 38 | ${CMOCK_DIR}/examples 39 | ${CMOCK_INCLUDE_DIRS} 40 | ) 41 | 42 | add_library(unity STATIC 43 | "${CMOCK_DIR}/vendor/unity/src/unity.c" 44 | "${CMOCK_DIR}/vendor/unity/extras/fixture/src/unity_fixture.c" 45 | "${CMOCK_DIR}/vendor/unity/extras/memory/src/unity_memory.c" 46 | ) 47 | 48 | set_target_properties(unity PROPERTIES 49 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib 50 | POSITION_INDEPENDENT_CODE ON 51 | ) 52 | 53 | target_include_directories(unity PUBLIC 54 | ${CMOCK_INCLUDE_DIRS} 55 | ) 56 | 57 | target_link_libraries(cmock unity) 58 | endmacro() 59 | -------------------------------------------------------------------------------- /test/unit-test/cmock_opaque_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef CMOCK_OPAQUE_TYPES_H_ 26 | #define CMOCK_OPAQUE_TYPES_H_ 27 | 28 | /* CMock does not support opaque types so needs concrete definitions for them. 29 | * This file is included in CMock .c files. */ 30 | 31 | struct NetworkContext 32 | { 33 | int a; 34 | }; 35 | 36 | #endif /* ifndef CMOCK_OPAQUE_TYPES_H_ */ 37 | -------------------------------------------------------------------------------- /test/unit-test/core_mqtt_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file core_mqtt_config.h 27 | * @brief This header sets configuration macros for the MQTT library. 28 | */ 29 | #ifndef CORE_MQTT_CONFIG_H_ 30 | #define CORE_MQTT_CONFIG_H_ 31 | 32 | /* Standard include. */ 33 | #include 34 | 35 | /**************************************************/ 36 | /******* DO NOT CHANGE the following order ********/ 37 | /**************************************************/ 38 | 39 | /* Include logging header files and define logging macros in the following order: 40 | * 1. Include the header file "logging_levels.h". 41 | * 2. Define the LIBRARY_LOG_NAME and LIBRARY_LOG_LEVEL macros depending on 42 | * the logging configuration for MQTT. 43 | * 3. Include the header file "logging_stack.h", if logging is enabled for MQTT. 44 | */ 45 | 46 | #include "logging_levels.h" 47 | 48 | /* Logging configuration for the MQTT library. */ 49 | #ifndef LIBRARY_LOG_NAME 50 | #define LIBRARY_LOG_NAME "MQTT" 51 | #endif 52 | 53 | #ifndef LIBRARY_LOG_LEVEL 54 | #define LIBRARY_LOG_LEVEL LOG_NONE 55 | #endif 56 | 57 | #include "logging_stack.h" 58 | 59 | /************ End of logging configuration ****************/ 60 | 61 | /** 62 | * @brief Retry count for reading CONNACK from network. 63 | * 64 | * #MQTT_Connect() can be using retries. If timeout passed as 0 to MQTT_Connect(), 65 | * retries are used to attempt to read from network. The maximum retry count is 66 | * specified by this config. 67 | * 68 | * These unit tests expect retrying only twice. 69 | */ 70 | #define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ( 2U ) 71 | 72 | #define MQTT_SUB_UNSUB_MAX_VECTORS ( 6U ) 73 | 74 | #define MQTT_SEND_TIMEOUT_MS ( 20U ) 75 | 76 | #endif /* ifndef CORE_MQTT_CONFIG_H_ */ 77 | -------------------------------------------------------------------------------- /test/unit-test/logging/logging_levels.h: -------------------------------------------------------------------------------- 1 | /* 2 | * coreMQTT 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * @file logging_levels.h 27 | * @brief Defines the logging level macros. 28 | */ 29 | 30 | #ifndef LOGGING_LEVELS_H_ 31 | #define LOGGING_LEVELS_H_ 32 | 33 | /** 34 | * @brief No log messages. 35 | * 36 | * When @ref LIBRARY_LOG_LEVEL is #LOG_NONE, logging is disabled and no 37 | * logging messages are printed. 38 | */ 39 | #define LOG_NONE 0 40 | 41 | /** 42 | * @brief Represents erroneous application state or event. 43 | * 44 | * These messages describe the situations when a library encounters an error from 45 | * which it cannot recover. 46 | * 47 | * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either 48 | * of #LOG_ERROR, #LOG_WARN, #LOG_INFO or #LOG_DEBUG. 49 | */ 50 | #define LOG_ERROR 1 51 | 52 | /** 53 | * @brief Message about an abnormal event. 54 | * 55 | * These messages describe the situations when a library encounters 56 | * abnormal event that may be indicative of an error. Libraries continue 57 | * execution after logging a warning. 58 | * 59 | * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either 60 | * of #LOG_WARN, #LOG_INFO or #LOG_DEBUG. 61 | */ 62 | #define LOG_WARN 2 63 | 64 | /** 65 | * @brief A helpful, informational message. 66 | * 67 | * These messages describe normal execution of a library. They provide 68 | * the progress of the program at a coarse-grained level. 69 | * 70 | * These messages are printed when @ref LIBRARY_LOG_LEVEL is defined as either 71 | * of #LOG_INFO or #LOG_DEBUG. 72 | */ 73 | #define LOG_INFO 3 74 | 75 | /** 76 | * @brief Detailed and excessive debug information. 77 | * 78 | * Debug log messages are used to provide the 79 | * progress of the program at a fine-grained level. These are mostly used 80 | * for debugging and may contain excessive information such as internal 81 | * variables, buffers, or other specific information. 82 | * 83 | * These messages are only printed when @ref LIBRARY_LOG_LEVEL is defined as 84 | * #LOG_DEBUG. 85 | */ 86 | #define LOG_DEBUG 4 87 | 88 | /* The macro definition for LIBRARY_LOG_LEVEL is for Doxygen 89 | * documentation only. This macro is typically defined in only the 90 | * _config.h file or the demo_config.h file. */ 91 | 92 | /** 93 | * @brief The logging level verbosity configuration of log messages from library. 94 | * 95 | * The logging verbosity levels are one of #LOG_DEBUG, #LOG_INFO, #LOG_WARN, 96 | * and #LOG_ERROR. 97 | * - With level #LOG_NONE, logging will be disabled. 98 | * - With level #LOG_DEBUG, all log messages will print. 99 | * - With level #LOG_INFO, all log messages, except level #LOG_DEBUG, will print. 100 | * - With level #LOG_WARN, only messages this level and #LOG_ERROR level will print. 101 | * - With level #LOG_ERROR, only messages at this level will print. 102 | */ 103 | #ifdef DOXYGEN 104 | #define LIBRARY_LOG_LEVEL LOG_ERROR 105 | #endif 106 | 107 | #endif /* ifndef LOGGING_LEVELS_H_ */ 108 | -------------------------------------------------------------------------------- /tools/cmock/coverage.cmake: -------------------------------------------------------------------------------- 1 | # Taken from amazon-freertos repository 2 | cmake_minimum_required(VERSION 3.13) 3 | set(BINARY_DIR ${CMAKE_BINARY_DIR}) 4 | # reset coverage counters 5 | execute_process( 6 | COMMAND lcov --directory ${CMAKE_BINARY_DIR} 7 | --base-directory ${CMAKE_BINARY_DIR} 8 | --zerocounters 9 | 10 | COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage 11 | ) 12 | # make the initial/baseline capture a zeroed out files 13 | execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR} 14 | --base-directory ${CMAKE_BINARY_DIR} 15 | --initial 16 | --capture 17 | --rc branch_coverage=1 18 | --output-file=${CMAKE_BINARY_DIR}/base_coverage.info 19 | --include "*source*" 20 | 21 | ) 22 | file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*") 23 | 24 | set(REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt) 25 | file(WRITE ${REPORT_FILE} "") 26 | # execute all files in bin directory, gathering the output to show it in CI 27 | foreach(testname ${files}) 28 | get_filename_component(test 29 | ${testname} 30 | NAME_WLE 31 | ) 32 | message("Running ${testname}") 33 | execute_process(COMMAND ${testname} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${test}_out.txt) 34 | 35 | file(READ ${CMAKE_BINARY_DIR}/${test}_out.txt CONTENTS) 36 | file(APPEND ${REPORT_FILE} "${CONTENTS}") 37 | endforeach() 38 | 39 | # generate Junit style xml output 40 | execute_process(COMMAND ruby 41 | ${CMOCK_DIR}/vendor/unity/auto/parse_output.rb 42 | -xml ${REPORT_FILE} 43 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 44 | ) 45 | 46 | # capture data after running the tests 47 | execute_process( 48 | COMMAND lcov --capture 49 | --rc branch_coverage=1 50 | --base-directory ${CMAKE_BINARY_DIR} 51 | --directory ${CMAKE_BINARY_DIR} 52 | --output-file ${CMAKE_BINARY_DIR}/second_coverage.info 53 | --include "*source*" 54 | ) 55 | 56 | # combile baseline results (zeros) with the one after running the tests 57 | execute_process( 58 | COMMAND lcov --base-directory ${CMAKE_BINARY_DIR} 59 | --directory ${CMAKE_BINARY_DIR} 60 | --add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info 61 | --add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info 62 | --output-file ${CMAKE_BINARY_DIR}/coverage.info 63 | --rc branch_coverage=1 64 | --include "*source*" 65 | ) 66 | execute_process( 67 | COMMAND genhtml --rc branch_coverage=1 68 | --branch-coverage 69 | --output-directory ${CMAKE_BINARY_DIR}/coverage 70 | ${CMAKE_BINARY_DIR}/coverage.info 71 | ) 72 | -------------------------------------------------------------------------------- /tools/cmock/project.yml: -------------------------------------------------------------------------------- 1 | # Taken from amazon-freertos repository 2 | :cmock: 3 | :mock_prefix: mock_ 4 | :when_no_prototypes: :warn 5 | :enforce_strict_ordering: TRUE 6 | :plugins: 7 | - :ignore 8 | - :ignore_arg 9 | - :expect_any_args 10 | - :array 11 | - :callback 12 | - :return_thru_ptr 13 | :callback_include_count: true # include a count arg when calling the callback 14 | :callback_after_arg_check: false # check arguments before calling the callback 15 | :treat_as: 16 | uint8: HEX8 17 | uint16: HEX16 18 | uint32: UINT32 19 | int8: INT8 20 | bool: UINT8 21 | :includes: # This will add these includes to each mock. 22 | - 23 | - 24 | :includes_c_post_header: 25 | - 26 | :treat_externs: :exclude # Now the extern-ed functions will be mocked. 27 | :treat_externs: :include 28 | -------------------------------------------------------------------------------- /tools/coverity/misra.config: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "standard" : "c2012", 4 | "title": "Coverity MISRA Configuration", 5 | "deviations" : [ 6 | { 7 | "deviation": "Directive 4.8", 8 | "reason": "Allow inclusion of unused types. Header files for a specific port, which are needed by all files, may define types that are not used by a specific file." 9 | }, 10 | { 11 | "deviation": "Directive 4.9", 12 | "reason": "Allow inclusion of function like macros. Logging is done using function like macros." 13 | }, 14 | { 15 | "deviation": "Rule 2.3", 16 | "reason": "Allow unused types. Library headers may define types intended for the application's use, but not used within the library files." 17 | }, 18 | { 19 | "deviation": "Rule 2.4", 20 | "reason": "Allow unused tags. Some compilers warn if types are not tagged." 21 | }, 22 | { 23 | "deviation": "Rule 2.5", 24 | "reason": "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file." 25 | }, 26 | { 27 | "deviation": "Rule 3.1", 28 | "reason": "Allow nested comments. Documentation blocks contain comments for example code." 29 | }, 30 | { 31 | "deviation": "Rule 8.7", 32 | "reason": "API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application." 33 | }, 34 | { 35 | "deviation": "Rule 11.5", 36 | "reason": "Allow casts from `void *`. The payload buffers are stored as `void *` and are cast to various types for use in functions." 37 | } 38 | ] 39 | } 40 | 41 | --------------------------------------------------------------------------------