Skip to content

Commit 468bdbf

Browse files
committed
Run test with valgrind
Avoid memory and file descriptor leak.
1 parent 7a89ad5 commit 468bdbf

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

.github/workflows/cmake.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: sudo apt-get update
2222

2323
- name: Setup Dependencies
24-
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }} dnsutils python3-pip
24+
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }} dnsutils python3-pip valgrind
2525

2626
- name: Setup Robot Framework
2727
run: sudo pip3 install robotframework
@@ -47,4 +47,6 @@ jobs:
4747
if: ${{ success() || failure() }}
4848
with:
4949
name: robot-logs-${{ matrix.compiler }}
50-
path: ${{github.workspace}}/tests/robot/*.html
50+
path: |
51+
${{github.workspace}}/tests/robot/*.html
52+
${{github.workspace}}/tests/robot/valgrind-*.log

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ log.html
1717
output.xml
1818
report.html
1919
custom_curl/
20+
valgrind-*.log

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Usage: ./https_dns_proxy [-a <listen_addr>] [-p <listen_port>]
201201

202202
Functional tests can be executed using [Robot Framework](https://robotframework.org/).
203203

204-
dig command is expected to be available.
204+
dig and valgrind commands are expected to be available.
205205

206206
```
207207
pip3 install robotframework

tests/robot/functional_tests.robot

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,40 @@ ${PORT} 55353
1111

1212

1313
*** Settings ***
14-
Test Setup Start Proxy
1514
Test Teardown Stop Proxy
1615

1716

1817
*** Keywords ***
18+
Common Test Setup
19+
Set Test Variable &{expected_logs} loop destroyed=1 # last log line
20+
Set Test Variable @{error_logs} [F] # any fatal error
21+
1922
Start Proxy
2023
[Arguments] @{args}
2124
@{default_args} = Create List -v -v -v -4 -p ${PORT}
2225
@{proces_args} = Combine Lists ${default_args} ${args}
2326
${proxy} = Start Process ${BINARY_PATH} @{proces_args}
24-
# ... stdout=${TEMPDIR}/https_dns_proxy_robot_test_stdout.txt
2527
... stderr=STDOUT alias=proxy
2628
Set Test Variable ${proxy}
27-
Set Test Variable &{expected_logs} loop destroyed=1 # last log line
28-
Set Test Variable @{error_logs} [F] # any fatal error
29+
Set Test Variable ${dig_timeout} 2
30+
Set Test Variable ${dig_retry} 0
2931
Sleep 0.5
32+
Common Test Setup
33+
34+
Start Proxy With Valgrind
35+
[Arguments] @{args}
36+
@{default_args} = Create List --track-fds=yes --time-stamp=yes --log-file=valgrind-%p.log
37+
... --gen-suppressions=all --tool=memcheck --leak-check=full --leak-resolution=high
38+
... --show-leak-kinds=all --track-origins=yes --keep-stacktraces=alloc-and-free
39+
... ${BINARY_PATH} -v -v -v -4 -p ${PORT}
40+
@{proces_args} = Combine Lists ${default_args} ${args}
41+
${proxy} = Start Process valgrind @{proces_args}
42+
... stderr=STDOUT alias=proxy
43+
Set Test Variable ${proxy}
44+
Set Test Variable ${dig_timeout} 4
45+
Set Test Variable ${dig_retry} 2
46+
Sleep 3 # wait for valgrind to fire up the proxy
47+
Common Test Setup
3048

3149
Stop Proxy
3250
Send Signal To Process SIGINT ${proxy}
@@ -44,7 +62,7 @@ Stop Proxy
4462

4563
Start Dig
4664
[Arguments] ${domain}=google.com
47-
${handle} = Start Process dig +timeout\=2 +retry\=0 @127.0.0.1 -p ${PORT} ${domain}
65+
${handle} = Start Process dig +timeout\=${dig_timeout} +retry\=${dig_retry} @127.0.0.1 -p ${PORT} ${domain}
4866
... stderr=STDOUT alias=dig
4967
[Return] ${handle}
5068

@@ -60,26 +78,31 @@ Run Dig
6078
${handle} = Start Dig ${domain}
6179
Stop Dig ${handle}
6280

81+
Run Dig Parallel
82+
${dig_handles} = Create List
83+
FOR ${domain} IN facebook.com microsoft.com youtube.com maps.google.com wikipedia.org amazon.com
84+
${handle} = Start Dig ${domain}
85+
Append To List ${dig_handles} ${handle}
86+
END
87+
FOR ${handle} IN @{dig_handles}
88+
Stop Dig ${handle}
89+
END
6390

64-
*** Test Cases ***
65-
Simple smoke test
66-
Run Dig
6791

92+
*** Test Cases ***
6893
Handle Unbound Server Does Not Support HTTP/1.1
69-
[Setup] NONE
7094
Start Proxy -x -r https://doh.mullvad.net/dns-query # resolver uses Unbound
7195
Run Keyword And Expect Error 9 != 0 # timeout exit code
7296
... Run Dig
7397

7498
Reuse HTTP/2 Connection
7599
[Documentation] After first successful request, further requests should not open new connections
76-
Run Dig # opens first connection
77-
${dig_handles} = Create List
78-
FOR ${domain} IN facebook.com microsoft.com youtube.com maps.google.com wikipedia.org amazon.com
79-
${handle} = Start Dig ${domain}
80-
Append To List ${dig_handles} ${handle}
81-
END
82-
FOR ${handle} IN @{dig_handles}
83-
Stop Dig ${handle}
84-
END
100+
Start Proxy
101+
Run Dig # Simple smoke test and opens first connection
102+
Run Dig Parallel
85103
Set To Dictionary ${expected_logs} curl opened socket=1 # curl must not open more sockets then 1
104+
105+
Valgrind Resource Leak Check
106+
Start Proxy With Valgrind
107+
Run Dig Parallel
108+

0 commit comments

Comments
 (0)