Skip to content

Commit a1ec017

Browse files
committed
Organizing
1 parent 5e74b7c commit a1ec017

16 files changed

Lines changed: 218 additions & 205 deletions

.github/actions/autotools/build/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ runs:
1010
run: ./configure
1111
shell: bash --noprofile --norc -euxo pipefail {0}
1212

13+
- name: Override default `MAPNIK_PLUGINS_DIR`
14+
run: echo "#define MAPNIK_PLUGINS_DIR \"$(find /usr -mindepth 1 -type d -name input | grep mapnik)\"" >> includes/config.h
15+
shell: bash --noprofile --norc -euxo pipefail {0}
16+
1317
- name: Run `make`
1418
run: make
1519
shell: bash --noprofile --norc -euxo pipefail {0}

Makefile.am

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ noinst_PROGRAMS = \
3131
render_list_test \
3232
render_old_test \
3333
render_speedtest_test \
34-
unit_test_renderd_config
34+
unit_tests
3535

3636
man_MANS = \
3737
docs/man/renderd.1 \
@@ -129,23 +129,23 @@ render_speedtest_test_SOURCES = \
129129
tests/render_speedtest_test.cpp
130130
render_speedtest_test_LDADD = $(GLIB_LIBS) catch_main.o catch_test_common.o
131131

132-
unit_test_renderd_config_SOURCES = \
133-
tests/unit_test_renderd_config.cpp
134-
unit_test_renderd_config_CXXFLAGS = -Isrc
135-
unit_test_renderd_config_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) catch_main.o catch_test_common.o
132+
unit_tests_SOURCES = \
133+
tests/unit_tests.cpp
134+
unit_tests_CXXFLAGS = -Isrc
135+
unit_tests_LDADD = $(GLIB_LIBS) $(INIPARSER_LDFLAGS) $(MAPNIK_LDFLAGS) $(PTHREAD_CFLAGS) catch_main.o catch_test_common.o
136136

137137
CLEANFILES=*.slo mod_tile.la stderr.out src/*.slo src/*.lo src/.libs/* src/*.la
138138

139139
COMMA=,
140140

141-
test: gen_tile_test renderd_test render_expired_test render_list_test render_old_test render_speedtest_test unit_test_renderd_config
141+
test: gen_tile_test renderd_test render_expired_test render_list_test render_old_test render_speedtest_test unit_tests
142142
./gen_tile_test
143143
./renderd_test
144144
./render_expired_test
145145
./render_list_test
146146
./render_old_test
147147
./render_speedtest_test
148-
./unit_test_renderd_config
148+
./unit_tests
149149

150150
all-local:
151151
$(APXS) -c $(DEF_LDLIBS) $(AM_CFLAGS) \

docker/debian/Dockerfile.autotools

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ RUN --mount=type=cache,sharing=locked,id=debian:${debian_version}-/var/cache/apt
4646
## Build, Test & Install `mod_tile`
4747
COPY . /tmp/mod_tile_src
4848
WORKDIR /tmp/mod_tile_src
49+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4950
RUN export DESTDIR=/tmp/mod_tile && \
5051
./autogen.sh && \
5152
./configure && \
53+
echo "#define MAPNIK_PLUGINS_DIR \"$(find /usr -mindepth 1 -type d -name input | grep mapnik)\"" >> includes/config.h && \
5254
make DESTDIR=${DESTDIR} install install-mod_tile
5355
RUN make test
5456

docker/ubuntu/Dockerfile.autotools

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ RUN --mount=type=cache,sharing=locked,id=ubuntu:${ubuntu_version}-/var/cache/apt
4545
## Build, Test & Install `mod_tile`
4646
COPY . /tmp/mod_tile_src
4747
WORKDIR /tmp/mod_tile_src
48+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
4849
RUN export DESTDIR=/tmp/mod_tile && \
4950
./autogen.sh && \
5051
./configure && \
52+
echo "#define MAPNIK_PLUGINS_DIR \"$(find /usr -mindepth 1 -type d -name input | grep mapnik)\"" >> includes/config.h && \
5153
make DESTDIR=${DESTDIR} install install-mod_tile
5254
RUN make test
5355

includes/render_submit_queue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
extern "C" {
2222
#endif
2323

24+
int make_connection(const char *spath);
2425
void enqueue(const char *xmlname, int x, int y, int z);
2526
void spawn_workers(int num, const char *socketpath, int maxLoad);
2627
void wait_for_empty_queue(void);

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ set(unit_tests_SRCS
232232
${PROJECT_SOURCE_DIR}/tests/unit_tests.cpp
233233
)
234234
set(unit_tests_LIBS
235-
${GLIB_LIBRARIES}
235+
${COMMON_LIBRARIES}
236236
${INIPARSER_LIBRARIES}
237237
${LIBMAPNIK_LIBRARIES}
238238
)

tests/catch_test_common.cpp

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,10 @@
3535
#include "catch_test_common.hpp"
3636
#include "pstreams/pstream.hpp"
3737

38+
#include "protocol.h"
39+
3840
extern int foreground;
3941

40-
int exit_status = 0;
41-
int mock_errno = 0;
42-
43-
bool fail_next_asprintf = false;
44-
bool fail_next_connect = false;
45-
bool fail_next_getaddrinfo = false;
46-
bool fail_next_getaddrinfo_empty_res = false;
47-
bool fail_next_getloadavg = false;
48-
bool fail_next_malloc = false;
49-
bool fail_next_mkdir = false;
50-
bool fail_next_open = false;
51-
bool fail_next_socket = false;
52-
bool fail_next_strndup = false;
53-
bool fail_next_strtok = false;
54-
bool fail_next_write = false;
55-
56-
jmp_buf exit_jump;
5742
std::string err_log_lines, out_log_lines;
5843

5944
captured_stdio captured_stderr;
@@ -280,6 +265,29 @@ int delete_tile_dir(const std::string &tile_dir)
280265
}
281266

282267
extern "C" {
268+
int exit_status = 0;
269+
int mock_errno = 0;
270+
271+
bool fail_next_asprintf = false;
272+
bool fail_next_connect = false;
273+
bool fail_next_getaddrinfo = false;
274+
bool fail_next_getaddrinfo_empty_res = false;
275+
bool fail_next_getloadavg = false;
276+
bool fail_next_malloc = false;
277+
bool fail_next_mkdir = false;
278+
bool fail_next_open = false;
279+
bool fail_next_recv = false;
280+
bool fail_next_socket = false;
281+
bool fail_next_strndup = false;
282+
bool fail_next_strtok = false;
283+
bool fail_next_write = false;
284+
int fail_next_next_recv_reponse_size = -1;
285+
int fail_next_next_recv_reponse_version = -1;
286+
int fail_next_recv_reponse_size = -1;
287+
int fail_next_recv_reponse_version = -1;
288+
289+
jmp_buf exit_jump;
290+
283291
void mocked_exit(int status)
284292
{
285293
exit_status = status;
@@ -389,6 +397,35 @@ extern "C" {
389397
return result;
390398
}
391399

400+
ssize_t mocked_recv(int fd, void *buf, size_t n, int flags)
401+
{
402+
if (fail_next_recv) {
403+
fail_next_recv = false;
404+
return -1;
405+
}
406+
407+
if (fail_next_recv_reponse_size != -1) {
408+
int reponse_size = fail_next_recv_reponse_size;
409+
fail_next_recv_reponse_size = (fail_next_next_recv_reponse_size != -1) ? fail_next_next_recv_reponse_size : -1;
410+
fail_next_next_recv_reponse_size = -1;
411+
412+
if (fail_next_recv_reponse_version != -1) {
413+
struct protocol *cmd = (struct protocol *)malloc(sizeof(struct protocol));
414+
cmd->ver = fail_next_recv_reponse_version;
415+
fail_next_recv_reponse_version = (fail_next_next_recv_reponse_version != -1) ? fail_next_next_recv_reponse_version : -1;
416+
fail_next_next_recv_reponse_version = -1;
417+
418+
memcpy(buf, cmd, reponse_size);
419+
420+
free(cmd);
421+
}
422+
423+
return reponse_size;
424+
}
425+
426+
return recv(fd, buf, n, flags);
427+
}
428+
392429
int mocked_socket(int domain, int type, int protocol) noexcept
393430
{
394431
if (fail_next_socket) {

tests/catch_test_common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern "C" {
5959
void *mocked_malloc(size_t size);
6060
int mocked_mkdir(const char *path, mode_t mode);
6161
int mocked_open(const char *pathname, int flags, ...);
62+
ssize_t mocked_recv(int fd, void *buf, size_t n, int flags);
6263
int mocked_socket(int domain, int type, int protocol) noexcept;
6364
char *mocked_strndup(const char *s, size_t n);
6465
char *mocked_strtok(char *s, const char *delim);

tests/unit_test_cache_expire.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "catch/catch.hpp"
22
#include "catch_test_common.hpp"
33

4+
#include "cache_expire.h"
5+
6+
extern bool fail_next_connect;
7+
extern bool fail_next_getaddrinfo;
8+
extern bool fail_next_getaddrinfo_empty_res;
9+
extern bool fail_next_malloc;
10+
extern bool fail_next_socket;
11+
extern std::string err_log_lines;
12+
413
TEST_CASE("cache_expire.c", "[cache_expire]")
514
{
615
int x = 0;
@@ -9,8 +18,7 @@ TEST_CASE("cache_expire.c", "[cache_expire]")
918
std::string host("host");
1019
std::string uri("/uri/");
1120

12-
SECTION("cache_expire_url function")
13-
{
21+
SECTION("cache_expire_url function") {
1422
std::string url("http://" + host + uri + std::to_string(z) + "/" + std::to_string(x) + "/" + std::to_string(y) + ".png");
1523

1624
err_log_lines.clear();
@@ -39,8 +47,7 @@ TEST_CASE("cache_expire.c", "[cache_expire]")
3947
}
4048
}
4149

42-
SECTION("cache_expire function")
43-
{
50+
SECTION("cache_expire function") {
4451
err_log_lines.clear();
4552

4653
SECTION("cache_expire", "should return") {
@@ -65,8 +72,7 @@ TEST_CASE("cache_expire.c", "[cache_expire]")
6572
}
6673
}
6774

68-
SECTION("init_cache_expire functiong")
69-
{
75+
SECTION("init_cache_expire function") {
7076
err_log_lines.clear();
7177

7278
SECTION("init_cache_expire", "should return") {
@@ -79,14 +85,14 @@ TEST_CASE("cache_expire.c", "[cache_expire]")
7985
std::string htcphost("nonexistenthost");
8086
init_cache_expire((char *)htcphost.c_str());
8187
REQUIRE_THAT(err_log_lines,
82-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Address family for hostname not supported")
83-
||
84-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Name or service not known")
85-
||
86-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Temporary failure in name resolution")
87-
||
88-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: nodename nor servname provided, or not known")
89-
);
88+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Address family for hostname not supported")
89+
||
90+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Name or service not known")
91+
||
92+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Temporary failure in name resolution")
93+
||
94+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: nodename nor servname provided, or not known")
95+
);
9096
}
9197

9298
SECTION("init_cache_expire with failed socket", "should return") {
@@ -105,10 +111,10 @@ TEST_CASE("cache_expire.c", "[cache_expire]")
105111

106112
init_cache_expire((char *)htcphost.c_str());
107113
REQUIRE_THAT(err_log_lines,
108-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Bad value for ai_flags")
109-
||
110-
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Unknown error")
111-
);
114+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Bad value for ai_flags")
115+
||
116+
Catch::Matchers::Contains("Failed to lookup HTCP cache host: Unknown error")
117+
);
112118
}
113119

114120
SECTION("init_cache_expire with empty getaddrinfo response", "should return") {

tests/unit_test_metatile.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "catch/catch.hpp"
22
#include "catch_test_common.hpp"
33

4+
#include "metatile.h"
5+
#include "store.h"
6+
7+
extern bool fail_next_malloc;
8+
extern bool fail_next_mkdir;
9+
extern bool fail_next_open;
10+
extern bool fail_next_write;
11+
extern std::string err_log_lines;
12+
413
TEST_CASE("metatile.cpp", "[metatile]")
514
{
615
int x = 1024;
@@ -16,8 +25,7 @@ TEST_CASE("metatile.cpp", "[metatile]")
1625

1726
metaTile tiles(xmlconfig.c_str(), "", x, y, z);
1827

19-
SECTION("metaTile::save function")
20-
{
28+
SECTION("metaTile::save function") {
2129
tile_dir = create_tile_dir("mod_tile.unit_test_metatile");
2230
store = init_storage_backend(tile_dir.c_str());
2331

@@ -71,8 +79,7 @@ TEST_CASE("metatile.cpp", "[metatile]")
7179
}
7280

7381

74-
SECTION("metaTile::set function")
75-
{
82+
SECTION("metaTile::set function") {
7683
err_log_lines.clear();
7784

7885
SECTION("metaTile::set", "then metaTile::get, then metaTile::clear, then metaTile::get") {
@@ -98,8 +105,7 @@ TEST_CASE("metatile.cpp", "[metatile]")
98105
}
99106

100107

101-
SECTION("metaTile::expire_tiles function")
102-
{
108+
SECTION("metaTile::expire_tiles function") {
103109
err_log_lines.clear();
104110

105111
SECTION("metaTile::expire_tile", "should return") {
@@ -119,8 +125,7 @@ TEST_CASE("metatile.cpp", "[metatile]")
119125
}
120126

121127

122-
SECTION("metaTile::xyz_to_meta_offset function")
123-
{
128+
SECTION("metaTile::xyz_to_meta_offset function") {
124129
err_log_lines.clear();
125130

126131
SECTION("metaTile::xyz_to_meta_offset", "should return") {

0 commit comments

Comments
 (0)