Add service load test.
authorDavin McCall <davmac@davmac.org>
Tue, 5 Jun 2018 09:12:43 +0000 (10:12 +0100)
committerDavin McCall <davmac@davmac.org>
Tue, 5 Jun 2018 09:33:36 +0000 (10:33 +0100)
src/includes/service.h
src/tests/Makefile
src/tests/loadtests.cc [new file with mode: 0644]
src/tests/test-services/t1 [new file with mode: 0644]

index 318deefd123766dbfb386b45c9baf1b096a0d6f1..d907b09ee2c88bc33e9cd9648884ed66d27b1d89 100644 (file)
@@ -881,6 +881,8 @@ class dirload_service_set : public service_set
         // nothing to do.
     }
 
+    dirload_service_set(const dirload_service_set &) = delete;
+
     // Construct a dirload_service_set which loads services from the specified directory. The
     // directory specified can be dynamically allocated via "new char[...]" (dyn_allocd == true)
     // or statically allocated.
index 09186486b97e49e6ee6a22bceb8ab40c3f91dc72..f713af7b9b56aeb92db96178b98c804672f6214a 100644 (file)
@@ -1,13 +1,14 @@
 -include ../../mconfig
 
-objects = tests.o test-dinit.o proctests.o test-run-child-proc.o test-bpsys.o
+objects = tests.o test-dinit.o proctests.o loadtests.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
 
 check: build-tests
        ./tests
        ./proctests
+       ./loadtests
 
-build-tests: tests proctests
+build-tests: tests proctests loadtests
 
 # Create an "includes" directory populated with a combination of real and mock headers:
 prepare-incdir:
@@ -21,6 +22,9 @@ tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o test-run-
 
 proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o
        $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(LDFLAGS)
+       
+loadtests: prepare-incdir $(parent_objs) loadtests.o test-dinit.o test-bpsys.o test-run-child-proc.o
+       $(CXX) $(SANITIZEOPTS) -o loadtests $(parent_objs) loadtests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(LDFLAGS)
 
 $(objects): %.o: %.cc
        $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -MMD -MP -Iincludes -I../dasynq -c $< -o $@
diff --git a/src/tests/loadtests.cc b/src/tests/loadtests.cc
new file mode 100644 (file)
index 0000000..3341002
--- /dev/null
@@ -0,0 +1,31 @@
+#include <string>
+#include <iostream>
+#include <cassert>
+
+#include "service.h"
+
+std::string test_service_dir;
+
+void init_test_service_dir()
+{
+    test_service_dir = "./test-services";
+}
+
+void test1()
+{
+    dirload_service_set sset(test_service_dir.c_str());
+    auto t1 = sset.load_service("t1");
+    assert(t1->get_name() == "t1");
+}
+
+#define RUN_TEST(name, spacing) \
+    std::cout << #name "..." spacing; \
+    name(); \
+    std::cout << "PASSED" << std::endl;
+
+int main(int argc, char **argv)
+{
+    init_test_service_dir();
+    RUN_TEST(test1, "    ");
+    return 0;
+}
diff --git a/src/tests/test-services/t1 b/src/tests/test-services/t1
new file mode 100644 (file)
index 0000000..9799080
--- /dev/null
@@ -0,0 +1,3 @@
+# A comment
+restart = yes # comment at end of setting
+type = internal