You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2023/07/14 14:02:13 UTC
[celix] 16/17: Update test_package to use celix API.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/579-automatic-dependency-deduction
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 2451c522d27134e653bebaacf77ffad05c5045af
Author: PengZheng <ho...@gmail.com>
AuthorDate: Fri Jul 14 16:42:19 2023 +0800
Update test_package to use celix API.
---
conanfile.py | 10 +++++----
examples/conan_test_package/CMakeLists.txt | 26 +++++++++-------------
examples/conan_test_package/conanfile.py | 5 ++++-
examples/conan_test_package/hello_bundle.c | 11 +++++----
.../conan_test_package/my_log_writer_activator.c | 9 +++++---
examples/conan_test_package/my_psa_activator.c | 6 ++---
examples/conan_test_package/my_rsa_activator.c | 4 ++--
examples/conan_test_package/test_cxx_shell.cpp | 14 +++++++-----
examples/conan_test_package/test_framework.c | 15 ++++++++-----
.../conan_test_package/test_http_admin_activator.c | 22 ++++++++++--------
examples/conan_test_package/test_shell.c | 17 ++++++++------
11 files changed, 76 insertions(+), 63 deletions(-)
diff --git a/conanfile.py b/conanfile.py
index d96eabbe..c40a87e1 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -202,10 +202,11 @@ class CelixConan(ConanFile):
for opt, val in self.options.values.items():
if opt.startswith('build_'):
setattr(self.options, opt, True)
- if self.settings.os != "Linux":
- self.options.build_rsa_remote_service_admin_shm_v2 = False
- self.options.build_rsa_discovery_zeroconf = False
- self.options.build_shell_bonjour = False
+
+ if self.settings.os != "Linux":
+ self.options.build_rsa_remote_service_admin_shm_v2 = False
+ self.options.build_rsa_discovery_zeroconf = False
+ self.options.build_shell_bonjour = False
if not self.options.enable_testing:
self.options.build_pubsub_integration = False
@@ -328,6 +329,7 @@ class CelixConan(ConanFile):
self.options.build_log_service_api = True
self.options.build_shell_api = True
self.options.build_framework = True
+ self.options.build_log_helper = True
if self.options.build_shell_api:
self.options.build_utils = True
diff --git a/examples/conan_test_package/CMakeLists.txt b/examples/conan_test_package/CMakeLists.txt
index 051dbbb4..09323552 100644
--- a/examples/conan_test_package/CMakeLists.txt
+++ b/examples/conan_test_package/CMakeLists.txt
@@ -21,14 +21,16 @@ set(CMAKE_CXX_STANDARD 17)
find_package(Celix REQUIRED)
-add_celix_bundle(hello VERSION 1.0.0 SOURCES hello_bundle.c)
-target_link_libraries(hello PRIVATE Celix::log_helper)
-celix_get_bundle_file(hello HELLO_TEST_BUNDLE)
+option(TEST_FRAMEWORK "Test Celix framework" OFF)
+if (TEST_FRAMEWORK)
+ add_celix_bundle(hello VERSION 1.0.0 SOURCES hello_bundle.c)
+ celix_get_bundle_file(hello HELLO_TEST_BUNDLE)
-add_executable(use_framework test_framework.c)
-target_link_libraries(use_framework Celix::framework)
-add_celix_bundle_dependencies(use_framework hello)
-target_compile_definitions(use_framework PRIVATE HELLO_TEST_BUNDLE_LOCATION="${HELLO_TEST_BUNDLE}")
+ add_executable(use_framework test_framework.c)
+ target_link_libraries(use_framework Celix::framework)
+ add_celix_bundle_dependencies(use_framework hello)
+ target_compile_definitions(use_framework PRIVATE HELLO_TEST_BUNDLE_LOCATION="${HELLO_TEST_BUNDLE}")
+endif ()
option(TEST_HTTP_ADMIN "Test http_admin" OFF)
if (TEST_HTTP_ADMIN)
@@ -52,7 +54,7 @@ if (TEST_LOG_SERVICE)
my_log_writer_activator.c
VERSION 1.0.0
)
- target_link_libraries(my_log_writer PRIVATE Celix::log_helper Celix::log_service_api)
+ target_link_libraries(my_log_writer PRIVATE Celix::log_service_api)
add_celix_container(use_log_writer COPY)
celix_container_bundles(use_log_writer LEVEL 0 Celix::log_admin)
celix_container_bundles(use_log_writer LEVEL 1 my_log_writer)
@@ -77,8 +79,6 @@ if (TEST_PUBSUB)
target_link_libraries(my_pubsub_admin PRIVATE Celix::pubsub_spi Celix::pubsub_utils )
add_celix_container(use_my_psa
BUNDLES
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_serializer_avrobin
Celix::celix_pubsub_topology_manager
my_pubsub_admin
hello
@@ -91,8 +91,6 @@ option(TEST_PSA_ZMQ "Test ZeroMQ PubSub Admin" OFF)
if (TEST_PSA_ZMQ)
add_celix_container(use_psa_zmq
BUNDLES
- Celix::celix_pubsub_serializer_json
- Celix::celix_pubsub_serializer_avrobin
Celix::celix_pubsub_topology_manager
Celix::celix_pubsub_admin_zmq
hello
@@ -105,7 +103,6 @@ option(TEST_PSA_TCP "Test TCP PubSub Admin" OFF)
if (TEST_PSA_TCP)
add_celix_container(use_psa_tcp
BUNDLES
- Celix::celix_pubsub_serializer_json
Celix::celix_pubsub_topology_manager
Celix::celix_pubsub_admin_tcp
hello
@@ -119,7 +116,6 @@ option(TEST_PSA_UDP_MC "Test UDP MC PubSub Admin" OFF)
if (TEST_PSA_UDP_MC)
add_celix_container(use_psa_udp_mc
BUNDLES
- Celix::celix_pubsub_serializer_json
Celix::celix_pubsub_topology_manager
Celix::celix_pubsub_admin_udp_multicast
hello
@@ -134,7 +130,6 @@ if (TEST_PSA_WS)
add_celix_container(use_psa_ws
BUNDLES
Celix::http_admin
- Celix::celix_pubsub_serializer_json
Celix::celix_pubsub_topology_manager
Celix::celix_pubsub_admin_websocket
hello
@@ -147,7 +142,6 @@ option(TEST_PSA_DISCOVERY_ETCD "Test the PubSub Discovery (ETCD) bundle" OFF)
if (TEST_PSA_DISCOVERY_ETCD)
add_celix_container(use_psa_discovery_etcd
BUNDLES
- Celix::celix_pubsub_serializer_json
Celix::celix_pubsub_topology_manager
Celix::celix_pubsub_discovery_etcd
my_pubsub_admin
diff --git a/examples/conan_test_package/conanfile.py b/examples/conan_test_package/conanfile.py
index 327a61a7..79d73626 100644
--- a/examples/conan_test_package/conanfile.py
+++ b/examples/conan_test_package/conanfile.py
@@ -22,9 +22,11 @@ import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake_paths", "cmake_find_package"
+ # requires = "celix/2.3.0@docker/test"
def build(self):
cmake = CMake(self)
+ cmake.definitions["TEST_FRAMEWORK"] = self.options["celix"].build_framework
cmake.definitions["TEST_HTTP_ADMIN"] = self.options["celix"].build_http_admin
cmake.definitions["TEST_LOG_SERVICE"] = self.options["celix"].build_log_service
cmake.definitions["TEST_SYSLOG_WRITER"] = self.options["celix"].build_syslog_writer
@@ -62,7 +64,8 @@ class TestPackageConan(ConanFile):
def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
- self.run("./use_framework", run_environment=True)
+ if self.options["celix"].build_framework:
+ self.run("./use_framework", run_environment=True)
if self.options["celix"].build_http_admin:
self.run("./use_http_admin", cwd=os.path.join("deploy", "use_http_admin"), run_environment=True)
if self.options["celix"].build_log_service:
diff --git a/examples/conan_test_package/hello_bundle.c b/examples/conan_test_package/hello_bundle.c
index 6e2afe67..d8452b72 100644
--- a/examples/conan_test_package/hello_bundle.c
+++ b/examples/conan_test_package/hello_bundle.c
@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include <celix_api.h>
-#include <celix_log_helper.h>
+#include <celix_bundle_activator.h>
+#include <celix_bundle_context.h>
+#include <celix_framework.h>
#include <stdio.h>
typedef struct activator_data {
- celix_log_helper_t *logger;
+ void* data;
} activator_data_t;
static celix_status_t activator_start(activator_data_t *data, celix_bundle_context_t *ctx) {
const char *key = NULL;
- data->logger = celix_logHelper_create(ctx, "test");
printf("\nHello world from C bundle with id %li\n", celix_bundle_getId(celix_bundleContext_getBundle(ctx)));
celix_array_list_t *bundles = celix_bundleContext_listInstalledBundles(ctx);
for (int i = 0; i < celix_arrayList_size(bundles); i++) {
@@ -40,8 +40,7 @@ static celix_status_t activator_start(activator_data_t *data, celix_bundle_conte
}
static celix_status_t activator_stop(activator_data_t *data, celix_bundle_context_t *ctx) {
- celix_logHelper_info(data->logger, "Goodbye world from C bundle with id %li\n", celix_bundle_getId(celix_bundleContext_getBundle(ctx)));
- celix_logHelper_destroy(data->logger);
+ printf("Goodbye world from C bundle with id %li\n", celix_bundle_getId(celix_bundleContext_getBundle(ctx)));
return CELIX_SUCCESS;
}
diff --git a/examples/conan_test_package/my_log_writer_activator.c b/examples/conan_test_package/my_log_writer_activator.c
index 4d11f35e..8bf40a72 100644
--- a/examples/conan_test_package/my_log_writer_activator.c
+++ b/examples/conan_test_package/my_log_writer_activator.c
@@ -18,9 +18,9 @@
*/
#define _GNU_SOURCE
-#include <stdio.h>
-#include <celix_api.h>
+#include <celix_bundle_activator.h>
#include <celix_log_sink.h>
+#include <stdio.h>
typedef struct my_log_writer_activator {
celix_log_sink_t logSinkSvc;
@@ -42,7 +42,10 @@ static void myLogWriter_sinkLog(void *handle __attribute__((unused)), celix_log_
va_end(argCopy);
if (needed > 1024) {
char *allocatedBuffer = NULL;
- vasprintf(&allocatedBuffer, format, formatArgs);
+ if(vasprintf(&allocatedBuffer, format, formatArgs) == -1) {
+ fprintf(stderr, "Error allocating memory for log message\n");
+ return;
+ }
printf("my [%s]: %s", logServiceName, allocatedBuffer);
free(allocatedBuffer);
} else {
diff --git a/examples/conan_test_package/my_psa_activator.c b/examples/conan_test_package/my_psa_activator.c
index 32a3b536..6c32125d 100644
--- a/examples/conan_test_package/my_psa_activator.c
+++ b/examples/conan_test_package/my_psa_activator.c
@@ -17,12 +17,12 @@
under the License.
*/
-#include <celix_api.h>
-#include <pubsub_serializer.h>
+#include <celix_bundle_activator.h>
+#include <celix_constants.h>
#include <celix_log_helper.h>
#include <pubsub_admin.h>
#include <pubsub_constants.h>
-#include <celix_constants.h>
+#include <pubsub_serializer.h>
#include <stdlib.h>
typedef struct my_psa_activator {
diff --git a/examples/conan_test_package/my_rsa_activator.c b/examples/conan_test_package/my_rsa_activator.c
index 24e6188d..e8f81714 100644
--- a/examples/conan_test_package/my_rsa_activator.c
+++ b/examples/conan_test_package/my_rsa_activator.c
@@ -17,10 +17,10 @@
under the License.
*/
-#include <celix_api.h>
+#include <celix_bundle_activator.h>
+#include <celix_log_helper.h>
#include <remote_service_admin.h>
#include <remote_constants.h>
-#include <celix_log_helper.h>
struct remote_service_admin {
diff --git a/examples/conan_test_package/test_cxx_shell.cpp b/examples/conan_test_package/test_cxx_shell.cpp
index e5f26908..da028ffa 100644
--- a/examples/conan_test_package/test_cxx_shell.cpp
+++ b/examples/conan_test_package/test_cxx_shell.cpp
@@ -19,8 +19,10 @@
#include <celix/BundleContext.h>
#include <celix/IShellCommand.h>
+#include <celix_framework.h>
+#include <celix_framework_factory.h>
#include <celix_shell.h>
-#include <celix_api.h>
+#include <celix_properties.h>
#include <iostream>
#include <atomic>
#include <assert.h>
@@ -39,13 +41,13 @@ int main() {
celix_bundle_context_t *ctx = NULL;
celix_properties_t *properties = NULL;
- properties = properties_create();
- properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
- properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
- properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
+ properties = celix_properties_create();
+ celix_properties_setBool(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", true);
+ celix_properties_setBool(properties, "org.osgi.framework.storage.clean", true);
+ celix_properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
fw = celix_frameworkFactory_createFramework(properties);
- ctx = framework_getContext(fw);
+ ctx = celix_framework_getFrameworkContext(fw);
long bndId = celix_bundleContext_installBundle(ctx, CXX_SHELL_BUNDLE_LOCATION, true);
assert(bndId >= 0);
diff --git a/examples/conan_test_package/test_framework.c b/examples/conan_test_package/test_framework.c
index 416a046a..ae9531ed 100644
--- a/examples/conan_test_package/test_framework.c
+++ b/examples/conan_test_package/test_framework.c
@@ -16,8 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include <celix_api.h>
#include <assert.h>
+#include <celix_bundle_context.h>
+#include <celix_framework.h>
+#include <celix_framework_factory.h>
+#include <celix_properties.h>
#include <stddef.h>
int main() {
@@ -25,13 +28,13 @@ int main() {
celix_bundle_context_t *ctx = NULL;
celix_properties_t *properties = NULL;
- properties = properties_create();
- properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
- properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
- properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
+ properties = celix_properties_create();
+ celix_properties_setBool(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", true);
+ celix_properties_setBool(properties, "org.osgi.framework.storage.clean", true);
+ celix_properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
fw = celix_frameworkFactory_createFramework(properties);
- ctx = framework_getContext(fw);
+ ctx = celix_framework_getFrameworkContext(fw);
long bndId = celix_bundleContext_installBundle(ctx, HELLO_TEST_BUNDLE_LOCATION, true);
assert(bndId >= 0);
celix_framework_waitForStop(fw);
diff --git a/examples/conan_test_package/test_http_admin_activator.c b/examples/conan_test_package/test_http_admin_activator.c
index 73a74d84..14931da3 100644
--- a/examples/conan_test_package/test_http_admin_activator.c
+++ b/examples/conan_test_package/test_http_admin_activator.c
@@ -16,13 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
+#include <celix_bundle_activator.h>
+#include <celix_framework.h>
+#include <civetweb.h>
+#include <http_admin/api.h>
#include <stdlib.h>
-#include "celix_api.h"
-#include "http_admin/api.h"
-
-#include "civetweb.h"
-
struct activator {
celix_http_service_t httpSvc;
celix_http_service_t httpSvc2;
@@ -37,6 +36,7 @@ struct activator {
//Local function prototypes
int alias_test_put(void *handle, struct mg_connection *connection, const char *path, const char *data, size_t length);
+
int websocket_data_echo(struct mg_connection *connection, int op_code, char *data, size_t length, void *handle);
celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
@@ -61,7 +61,8 @@ celix_status_t bnd_start(struct activator *act, celix_bundle_context_t *ctx) {
act->sockSvc.handle = act;
act->sockSvc.data = websocket_data_echo;
act->sockSvcId = celix_bundleContext_registerService(ctx, &act->sockSvc, WEBSOCKET_ADMIN_SERVICE_NAME, props4);
- celix_framework_stopBundleAsync(celix_bundleContext_getFramework(ctx), CELIX_FRAMEWORK_BUNDLE_ID); // make to container quit immediately
+ celix_framework_stopBundleAsync(celix_bundleContext_getFramework(ctx),
+ CELIX_FRAMEWORK_BUNDLE_ID); // make to container quit immediately
return CELIX_SUCCESS;
}
@@ -76,9 +77,10 @@ celix_status_t bnd_stop(struct activator *act, celix_bundle_context_t *ctx) {
CELIX_GEN_BUNDLE_ACTIVATOR(struct activator, bnd_start, bnd_stop);
-int alias_test_put(void *handle __attribute__((unused)), struct mg_connection *connection, const char *path __attribute__((unused)), const char *data, size_t length) {
+int alias_test_put(void *handle __attribute__((unused)), struct mg_connection *connection,
+ const char *path __attribute__((unused)), const char *data, size_t length) {
//If data received, echo the data for the test case
- if(length > 0 && data != NULL) {
+ if (length > 0 && data != NULL) {
const char *mime_type = mg_get_header(connection, "Content-Type");
mg_printf(connection,
"HTTP/1.1 200 OK\r\nContent-Type: %s\r\nConnection: close\r\n\r\n%s", mime_type, data);
@@ -88,7 +90,9 @@ int alias_test_put(void *handle __attribute__((unused)), struct mg_connection *c
return 200;
}
-int websocket_data_echo(struct mg_connection *connection, int op_code __attribute__((unused)), char *data, size_t length, void *handle __attribute__((unused))) {
+int
+websocket_data_echo(struct mg_connection *connection, int op_code __attribute__((unused)), char *data, size_t length,
+ void *handle __attribute__((unused))) {
mg_websocket_write(connection, MG_WEBSOCKET_OPCODE_PONG, data, length);
return 0; //Close socket after echoing.
diff --git a/examples/conan_test_package/test_shell.c b/examples/conan_test_package/test_shell.c
index e4c3421f..67f44a00 100644
--- a/examples/conan_test_package/test_shell.c
+++ b/examples/conan_test_package/test_shell.c
@@ -16,10 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+#include <assert.h>
+#include <celix_bundle_context.h>
+#include <celix_framework.h>
+#include <celix_framework_factory.h>
+#include <celix_properties.h>
#include <celix_shell_command.h>
#include <celix_shell.h>
-#include <celix_api.h>
-#include <assert.h>
static void use(void *handle, void *svc) {
celix_shell_t *shell = svc;
@@ -39,13 +42,13 @@ int main() {
celix_bundle_context_t *ctx = NULL;
celix_properties_t *properties = NULL;
- properties = properties_create();
- properties_set(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", "true");
- properties_set(properties, "org.osgi.framework.storage.clean", "onFirstInit");
- properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
+ properties = celix_properties_create();
+ celix_properties_setBool(properties, "LOGHELPER_ENABLE_STDOUT_FALLBACK", true);
+ celix_properties_setBool(properties, "org.osgi.framework.storage.clean", true);
+ celix_properties_set(properties, "org.osgi.framework.storage", ".cacheBundleContextTestFramework");
fw = celix_frameworkFactory_createFramework(properties);
- ctx = framework_getContext(fw);
+ ctx = celix_framework_getFrameworkContext(fw);
long bndId = celix_bundleContext_installBundle(ctx, SHELL_BUNDLE_LOCATION, true);
assert(bndId >= 0);