File: test-fd-receive

package info (click to toggle)
gdbuspp 3-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,116 kB
  • sloc: cpp: 9,462; python: 477; sh: 215; makefile: 5
file content (60 lines) | stat: -rwxr-xr-x 1,740 bytes parent folder | download | duplicates (2)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#  GDBus++ - glib2 GDBus C++ wrapper
#
#  SPDX-License-Identifier: AGPL-3.0-only
#
#  Copyright (C)  OpenVPN Inc <sales@openvpn.net>
#  Copyright (C)  David Sommerseth <davids@openvpn.net>
#

set -eu

##
# @file tests/scripts/test-fd-passing.sh
#
# @brief Runs a test using tests/fd-receive-read.cpp
#
#        This calls a D-Bus method with a file name which the
#        tests/simple-service.cpp will call open() to and return the
#        related file descriptor back to the test program.  That program
#        will then write the content of that file to a local file.
#
#        This test script will then run sha256sum on both the requested
#        file and the copied file, to verify the content is the same.
#
#        This tests requires the tests/simple-service.cpp test service
#        to be running
#

FAIL=0

run_receive_read()
{
    echo ">> Running fd-receive-read command: ${BUILD_DIR:-.}/test_fd-receive-read $@"
    ${BUILD_DIR:-.}/test_fd-receive-read -q "$@"
    if [ $? -ne 0 ]; then
        echo ">>     ## FAIL: receiving file descriptor"
        FAIL=1
    else
        echo ">>     Success: file descriptor received, file copied"
    fi
}

rm -f check.bin
run_receive_read -f ${BUILD_DIR:-.}/test_fd-receive-read -o check.bin
if [ $FAIL -eq 1 ]; then
    echo "** ERROR **  Could not receive a file descriptor to read from D-Bus service"
    exit 1
fi

orig_file="$(sha256sum ${BUILD_DIR:-.}/test_fd-receive-read | awk '{print $1}')"
copied_file="$(sha256sum check.bin | awk '{print $1}')"

if [ "${orig_file}" != "${copied_file}" ]; then
    echo "** ERROR ** Copied file from file descriptor does not match the original file"
    exit 1
fi
rm -f check.bin

echo "Test result:  -- SUCCESS --"
exit 0