Debian Codegraph @

tests/scripts/test-fd-receive

raw
1 #!/bin/bash
2 # GDBus++ - glib2 GDBus C++ wrapper
3 #
4 # SPDX-License-Identifier: AGPL-3.0-only
5 #
6 # Copyright (C) OpenVPN Inc <[email protected]>
7 # Copyright (C) David Sommerseth <[email protected]>
8 #
9
10 set -eu
11
12 ##
13 # @file tests/scripts/test-fd-passing.sh
14 #
15 # @brief Runs a test using tests/fd-receive-read.cpp
16 #
17 # This calls a D-Bus method with a file name which the
18 # tests/simple-service.cpp will call open() to and return the
19 # related file descriptor back to the test program. That program
20 # will then write the content of that file to a local file.
21 #
22 # This test script will then run sha256sum on both the requested
23 # file and the copied file, to verify the content is the same.
24 #
25 # This tests requires the tests/simple-service.cpp test service
26 # to be running
27 #
28
29 FAIL=0
30
31 run_receive_read()
32 {
33 echo ">> Running fd-receive-read command: ${BUILD_DIR:-.}/test_fd-receive-read $@"
34 ${BUILD_DIR:-.}/test_fd-receive-read -q "$@"
35 if [ $? -ne 0 ]; then
36 echo ">> ## FAIL: receiving file descriptor"
37 FAIL=1
38 else
39 echo ">> Success: file descriptor received, file copied"
40 fi
41 }
42
43 rm -f check.bin
44 run_receive_read -f ${BUILD_DIR:-.}/test_fd-receive-read -o check.bin
45 if [ $FAIL -eq 1 ]; then
46 echo "** ERROR ** Could not receive a file descriptor to read from D-Bus service"
47 exit 1
48 fi
49
50 orig_file="$(sha256sum ${BUILD_DIR:-.}/test_fd-receive-read | awk '{print $1}')"
51 copied_file="$(sha256sum check.bin | awk '{print $1}')"
52
53 if [ "${orig_file}" != "${copied_file}" ]; then
54 echo "** ERROR ** Copied file from file descriptor does not match the original file"
55 exit 1
56 fi
57 rm -f check.bin
58
59 echo "Test result: -- SUCCESS --"
60 exit 0