From bd404769cc3cc1a9744a7d437c9ab771668b282e Mon Sep 17 00:00:00 2001 From: Samir Halilcevic Date: Fri, 29 Dec 2023 11:33:30 +0100 Subject: [PATCH] Add robot tests for length-prefix framing Also create and upload artifacts for all Robot test runs on Cirrus on GitHub CI. --- .cirrus.yml | 6 +++ .github/workflows/check-windows.yml | 8 +++- robot/CMakeLists.txt | 11 ++++- robot/lp/communication.robot | 70 +++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 robot/lp/communication.robot diff --git a/.cirrus.yml b/.cirrus.yml index 5f2df51dab..b5972022cf 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -18,6 +18,9 @@ freebsd13_task: prepare_script: .ci/freebsd-13/prepare.sh build_script: .ci/run.sh build .ci/debug-flags.cmake . build test_script: .ci/run.sh test build net.udp_datagram_socket + always: + robot_artifacts: + path: "build/robot-output/**" << : *BRANCH_FILTER # FreeBSD 14 EOL: November 2028 @@ -28,5 +31,8 @@ freebsd14_task: prepare_script: .ci/freebsd-14/prepare.sh build_script: .ci/run.sh build .ci/debug-flags.cmake . build test_script: .ci/run.sh test build net.udp_datagram_socket + always: + robot_artifacts: + path: "build/robot-output/**" << : *BRANCH_FILTER diff --git a/.github/workflows/check-windows.yml b/.github/workflows/check-windows.yml index 5127504f77..10d88a2948 100644 --- a/.github/workflows/check-windows.yml +++ b/.github/workflows/check-windows.yml @@ -2,7 +2,7 @@ name: build-caf on: pull_request: push: - branches: + branches: - master jobs: Windows: @@ -20,3 +20,9 @@ jobs: run: .ci/windows/build.cmd - name: Test run: .ci/windows/test.cmd + - name: Archive Robot logs + uses: actions/upload-artifact@v4 + if: always() + with: + name: robot-logs + path: build/robot-output/ diff --git a/robot/CMakeLists.txt b/robot/CMakeLists.txt index 6443b83fb4..178cbbe49a 100644 --- a/robot/CMakeLists.txt +++ b/robot/CMakeLists.txt @@ -8,13 +8,16 @@ find_package(Python COMPONENTS Interpreter) function(add_robot_test dir name) set(test_name caf-robot-${dir}-${name}) + set(test_wdir "${CMAKE_BINARY_DIR}/robot-output/${dir}/${name}") + file(MAKE_DIRECTORY "${test_wdir}") add_test( NAME ${test_name} COMMAND ${Python_EXECUTABLE} -m robot ${ARGN} - "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.robot") + "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.robot" + WORKING_DIRECTORY "${test_wdir}") set_tests_properties(${test_name} PROPERTIES TIMEOUT 300) endfunction() @@ -127,4 +130,10 @@ if(TARGET CAF::net AND CAF_ENABLE_EXAMPLES) client --variable BINARY_PATH:$) + add_robot_test( + lp + communication + --variable SERVER_PATH:$ + --variable CLIENT_PATH:$) + endif() diff --git a/robot/lp/communication.robot b/robot/lp/communication.robot new file mode 100644 index 0000000000..f861b4937f --- /dev/null +++ b/robot/lp/communication.robot @@ -0,0 +1,70 @@ +*** Settings *** +Documentation A test suite for the length previx framing communication + +Library Process +Library String +Library OperatingSystem + +Test Setup Start Chat Server +Test Teardown Terminate All Processes + + +*** Variables *** +${SERVER_HOST} localhost +${SERVER_PORT} 55519 +${SERVER_PATH} /path/to/the/server +${CLIENT_PATH} /path/to/the/client + +${INPUT} Hello\nToday is a wonderful day!\n +${BASELINE} bob: Hello\nbob: Today is a wonderful day! + + +*** Test Cases *** +Send Some message + Start Chat Client alice PIPE + Wait For Client ${1} + Start Chat Client bob ${INPUT} + Wait For Client ${2} + Wait Until Contains Baseline alice.out + + +*** Keywords *** +Start Chat Server + Start Process + ... ${SERVER_PATH} + ... -p ${SERVER_PORT} + ... --caf.logger.file.verbosity trace + ... --caf.logger.file.path server.log + ... stdout=server.out + ... stderr=server.err + +Start Chat Client + [Arguments] ${name} ${stdin} + Start Process + ... ${CLIENT_PATH} + ... -p ${SERVER_PORT} + ... -n ${name} + ... --caf.logger.file.verbosity trace + ... --caf.logger.file.path ${name}.log + ... stdin=${stdin} + ... stdout=${name}.out + ... stderr=${name}.err + +Has Baseline + [Arguments] ${file_path} + ${output} Get File ${file_path} + Should Contain ${output} ${BASELINE} + +Wait Until Contains Baseline + [Arguments] ${file_path} + Wait Until Keyword Succeeds 5s 125ms Has Baseline ${file_path} + +Count Connected Clients + [Arguments] ${client_count} + ${output}= Grep File server.out accepted new connection + ${lc}= Get Line Count ${output} + Should Be True ${lc} >= ${client_count} + +Wait For Client + [Arguments] ${client_count} + Wait Until Keyword Succeeds 5s 125ms Count Connected Clients ${client_count}