Skip to content

Commit 58bdca9

Browse files
authored
Merge pull request #154 from baranyaib90/fixes-12
Fixes 12
2 parents a61074d + 468bdbf commit 58bdca9

File tree

8 files changed

+78
-30
lines changed

8 files changed

+78
-30
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

CMakeLists.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu-zero-variadic-macro-arguments -Wno-
3535
endif()
3636

3737
# VERSION
38+
# It is possible to define external default value like: cmake -DSW_VERSION=1.2-custom
3839

3940
find_package(Git)
4041
if(Git_FOUND)
@@ -43,15 +44,23 @@ if(Git_FOUND)
4344
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
4445
OUTPUT_VARIABLE GIT_VERSION
4546
OUTPUT_STRIP_TRAILING_WHITESPACE)
46-
message(STATUS "Version: ${GIT_VERSION}")
47+
48+
if(GIT_VERSION)
49+
set(SW_VERSION "${GIT_VERSION}")
50+
else()
51+
message(WARNING "Could not find out version from git command!")
52+
endif()
4753

4854
# May not update version in some cases (example: git commit --amend)
4955
set_property(GLOBAL APPEND
5056
PROPERTY CMAKE_CONFIGURE_DEPENDS
5157
"${CMAKE_SOURCE_DIR}/.git/index")
5258
else()
53-
set(GIT_VERSION "UNKNOWN")
54-
message(WARNING "Could not find git command! Version is set to: ${GIT_VERSION}")
59+
message(WARNING "Could not find git command!")
60+
endif()
61+
62+
if(NOT SW_VERSION)
63+
message(WARNING "Version unset, using hardcoded!")
5564
endif()
5665

5766
# LIBRARY DEPENDENCIES
@@ -99,9 +108,12 @@ set_property(TARGET ${TARGET_NAME} PROPERTY C_STANDARD 11)
99108

100109
define_file_basename_for_sources("https_dns_proxy")
101110

102-
set_source_files_properties(
103-
src/main.c src/options.c
104-
PROPERTIES COMPILE_FLAGS "-DGIT_VERSION='\"${GIT_VERSION}\"'")
111+
112+
if(SW_VERSION)
113+
set_source_files_properties(
114+
src/options.c
115+
PROPERTIES COMPILE_FLAGS "-DSW_VERSION='\"${SW_VERSION}\"'")
116+
endif()
105117

106118
if(CLANG_TIDY_EXE)
107119
set_target_properties(

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

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ int main(int argc, char *argv[]) {
216216

217217
logging_init(opt.logfd, opt.loglevel);
218218

219-
ILOG("Version " GIT_VERSION);
220-
ILOG("Built "__DATE__" "__TIME__".");
219+
ILOG("Version: %s", options_sw_version());
220+
ILOG("Built: " __DATE__ " " __TIME__);
221221
ILOG("System c-ares: %s", ares_version(NULL));
222222
ILOG("System libcurl: %s", curl_version());
223223

src/options.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
#define DEFAULT_HTTP_VERSION 2
1919

20+
21+
const char * options_sw_version() {
22+
#ifdef SW_VERSION
23+
return SW_VERSION;
24+
#else
25+
return "2023.01.01-atLeast"; // update date sometimes, like 1-2 times a year
26+
#endif
27+
}
28+
2029
void options_init(struct Options *opt) {
2130
opt->listen_addr = "127.0.0.1";
2231
opt->listen_port = 5053;
@@ -107,7 +116,7 @@ int options_parse_args(struct Options *opt, int argc, char **argv) {
107116
case 'h':
108117
return -1;
109118
case 'V': // version
110-
printf("%s\n", GIT_VERSION);
119+
printf("%s\n", options_sw_version());
111120
exit(0);
112121
default:
113122
printf("Unknown state!");

src/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct Options options_t;
5757
#ifdef __cplusplus
5858
extern "C" {
5959
#endif
60+
const char * options_sw_version();
6061
void options_init(struct Options *opt);
6162
int options_parse_args(struct Options *opt, int argc, char **argv);
6263
void options_show_usage(int argc, char **argv);

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)