Skip to content

Commit

Permalink
Clean up unit tests
Browse files Browse the repository at this point in the history
Don't use the symlinked-header trick that we previously used to include
application headers in the tests; instead change from using:

> #include "..."

to

> #include <...>

... generally, so it is possible to override included headers via the
include path; use this in the tests to override various headers, instead
of duplicating the entire "includes" directory via symlinks to a
combination of the original headers plus mock headers.
  • Loading branch information
davmac314 committed Aug 27, 2023
1 parent 48dac91 commit 6548689
Show file tree
Hide file tree
Showing 57 changed files with 49 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/includes/baseproc-sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <cstdlib> // getenv

#include "dasynq.h" // for pipe2
#include <dasynq.h> // for pipe2

#include <sys/uio.h> // writev
#include <unistd.h>
Expand Down
10 changes: 5 additions & 5 deletions src/includes/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#include <unistd.h>

#include "dinit.h"
#include "dinit-log.h"
#include "control-cmds.h"
#include "service-listener.h"
#include "cpbuffer.h"
#include <dinit.h>
#include <dinit-log.h>
#include <control-cmds.h>
#include <service-listener.h>
#include <cpbuffer.h>

// Control connection for dinit

Expand Down
2 changes: 1 addition & 1 deletion src/includes/cpbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <cstring>
#include <algorithm>

#include "baseproc-sys.h"
#include <baseproc-sys.h>

// control protocol buffer, a circular buffer with fixed capacity.
template <unsigned SIZE> class cpbuffer
Expand Down
6 changes: 3 additions & 3 deletions src/includes/dinit-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <sys/types.h>
#include <pwd.h>

#include "mconfig.h"
#include "cpbuffer.h"
#include "control-cmds.h"
#include <mconfig.h>
#include <cpbuffer.h>
#include <control-cmds.h>

// Client library for Dinit clients

Expand Down
4 changes: 2 additions & 2 deletions src/includes/dinit-env.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <unordered_map>
#include <string>

#include "dinit-util.h"
#include "baseproc-sys.h"
#include <dinit-util.h>
#include <baseproc-sys.h>

class environment;
extern environment main_env;
Expand Down
2 changes: 1 addition & 1 deletion src/includes/dinit-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sys/types.h>
#include <unistd.h>

#include "baseproc-sys.h"
#include <baseproc-sys.h>

// Check if a value is one of several possible values.
// Use like: value(x).is_in(1,2,3)
Expand Down
2 changes: 1 addition & 1 deletion src/includes/dinit-utmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef DINIT_UTMP_H_INCLUDED
#define DINIT_UTMP_H_INCLUDED

#include "mconfig.h" // pull in any explicit configuration
#include <mconfig.h> // pull in any explicit configuration

// Configuration:
// USE_UTMPX - whether to update the utmp[x] database. If 0, no-op stubs are defined.
Expand Down
10 changes: 5 additions & 5 deletions src/includes/load-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <grp.h>
#include <pwd.h>

#include "dinit-env.h"
#include "dinit-utmp.h"
#include "dinit-util.h"
#include "service-constants.h"
#include "mconfig.h"
#include <dinit-env.h>
#include <dinit-utmp.h>
#include <dinit-util.h>
#include <service-constants.h>
#include <mconfig.h>

struct service_flags_t
{
Expand Down
2 changes: 1 addition & 1 deletion src/includes/options-processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <vector>

#include "service-dir.h"
#include <service-dir.h>

class service_dir_opt
{
Expand Down
6 changes: 3 additions & 3 deletions src/includes/proc-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <sys/types.h>
#include <sys/resource.h>

#include "baseproc-sys.h"
#include "service.h"
#include "dinit-utmp.h"
#include <baseproc-sys.h>
#include <service.h>
#include <dinit-utmp.h>

// This header defines base_proc_service (base process service) and several derivatives, as well as some
// utility functions and classes. See service.h for full details of services.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/service-constants.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SERVICE_CONSTANTS_H
#define SERVICE_CONSTANTS_H

#include "mconfig.h"
#include <mconfig.h>

/* Service states */
enum class service_state_t {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/service-listener.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SERVICE_LISTENER_H
#define SERVICE_LISTENER_H

#include "service-constants.h"
#include <service-constants.h>

class service_record;

Expand Down
22 changes: 11 additions & 11 deletions src/includes/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#include <unordered_set>
#include <algorithm>

#include "dasynq.h"

#include "dinit.h"
#include "control.h"
#include "service-listener.h"
#include "service-constants.h"
#include "load-service.h"
#include "dinit-ll.h"
#include "dinit-log.h"
#include "service-dir.h"
#include "dinit-env.h"
#include <dasynq.h>

#include <dinit.h>
#include <control.h>
#include <service-listener.h>
#include <service-constants.h>
#include <load-service.h>
#include <dinit-ll.h>
#include <dinit-log.h>
#include <service-dir.h>
#include <dinit-env.h>

/*
* This header defines service_record, a data record maintaining information about a service,
Expand Down
6 changes: 3 additions & 3 deletions src/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ALL_TEST_CXXFLAGS=$(CPPFLAGS) $(TEST_CXXFLAGS) $(TEST_CXXFLAGS_EXTRA)
ALL_TEST_LDFLAGS=$(TEST_LDFLAGS) $(TEST_LDFLAGS_EXTRA)

objects = tests.o test-dinit.o proctests.o loadtests.o envtests.o test-run-child-proc.o test-bpsys.o
parent_objs = service.o proc-service.o dinit-log.o load-service.o baseproc-service.o dinit-env.o
parent_objs = service.o proc-service.o dinit-log.o load-service.o baseproc-service.o dinit-env.o control.o

check: build-tests run-tests

Expand All @@ -31,10 +31,10 @@ envtests: $(parent_objs) envtests.o test-dinit.o test-bpsys.o test-run-child-pro
$(CXX) -o envtests $(parent_objs) envtests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(ALL_TEST_LDFLAGS)

$(objects): %.o: %.cc
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Iincludes -I../../dasynq/include -I../../build/includes -c $< -o $@
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Itest-includes -I../../dasynq/include -I../../build/includes -I../includes -c $< -o $@

$(parent_objs): %.o: ../%.cc
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Iincludes -I../../dasynq/include -I../../build/includes -c $< -o $@
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Itest-includes -I../../dasynq/include -I../../build/includes -I../includes -c $< -o $@

clean:
$(MAKE) -C cptests clean
Expand Down
10 changes: 5 additions & 5 deletions src/tests/cptests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ cptests: cptests.o $(parent_objs) $(parent_test_objs)
$(CXX) -o cptests cptests.o $(parent_test_objects) $(parent_objs) $(ALL_TEST_LDFLAGS)

$(objects): %.o: %.cc
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Iincludes -I../../../dasynq/include -I../../../build/includes -c $< -o $@
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -I../test-includes -I../../../dasynq/include -I../../../build/includes -I../../includes -c $< -o $@

$(parent_objs): %.o: ../../%.cc
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -Iincludes -I../../../dasynq/include -I../../../build/includes -c $< -o $@
$(CXX) $(ALL_TEST_CXXFLAGS) -MMD -MP -I../test-includes -I../../../dasynq/include -I../../../build/includes -I../../includes -c $< -o $@

clean:
rm -f *.o *.d cptests
Expand All @@ -41,13 +41,13 @@ fuzz_objects = $(foreach obj,$(parent_objs),fuzz-$(obj))
$(MAKE) -C ../../../build all

fuzz: ../../../build/includes/mconfig.h fuzz.cc $(fuzz_parent_test_objects) $(fuzz_objects)
clang++ -std=c++11 -g -O1 -Iincludes -I../../../dasynq/include -I../../../build/includes/ -fsanitize=fuzzer,address,undefined,leak fuzz.cc $(fuzz_parent_test_objects) $(fuzz_objects) -o fuzz
clang++ -std=c++11 -g -O1 -I../test-includes -I../../../dasynq/include -I../../../build/includes/ -I../../includes -fsanitize=fuzzer,address,undefined,leak fuzz.cc $(fuzz_parent_test_objects) $(fuzz_objects) -o fuzz

$(fuzz_parent_test_objects): fuzz-%.o: ../%.cc
clang -O1 -fsanitize=address,undefined,fuzzer-no-link,leak -MMD -MP -Iincludes -I../../../dasynq/include -I../../../build/includes/ -c $< -o $@
clang -O1 -fsanitize=address,undefined,fuzzer-no-link,leak -MMD -MP -I../test-includes -I../../../dasynq/include -I../../../build/includes/ -I../../includes -c $< -o $@

$(fuzz_objects): fuzz-%.o: ../../%.cc
clang -O1 -fsanitize=address,undefined,fuzzer-no-link,leak -MMD -MP -Iincludes -I../../../dasynq/include -I../../../build/includes/ -c $< -o $@
clang -O1 -fsanitize=address,undefined,fuzzer-no-link,leak -MMD -MP -I../test-includes -I../../../dasynq/include -I../../../build/includes/ -I../../includes -c $< -o $@


-include $(objects:.o=.d)
Expand Down
10 changes: 5 additions & 5 deletions src/tests/cptests/cptests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <string>
#include <set>

#include "dinit.h"
#include "service.h"
#include "baseproc-sys.h"
#include "proc-service.h"
#include "control.h"
#include <dinit.h>
#include <service.h>
#include <baseproc-sys.h>
#include <proc-service.h>
#include <control.h>

#include "../test_service.h"
#include "../test_procservice.h"
Expand Down
1 change: 0 additions & 1 deletion src/tests/cptests/includes/baseproc-sys.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/control-cmds.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/control.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/cpbuffer.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-client.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-env.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-ll.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-log.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-socket.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-util.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit-utmp.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/dinit.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/load-service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/options-processing.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/proc-service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/service-constants.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/service-dir.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/service-listener.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/cptests/includes/static-string.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/baseproc-sys.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/control-cmds.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/control.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/cpbuffer.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-client.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-env.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-ll.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-log.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-socket.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-util.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit-utmp.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/dinit.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/load-service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/options-processing.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/proc-service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/service-constants.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/service-dir.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/service-listener.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/service.h

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/includes/static-string.h

This file was deleted.

14 changes: 0 additions & 14 deletions src/tests/test-includes/control.h

This file was deleted.

0 comments on commit 6548689

Please sign in to comment.