Skip to content

Commit

Permalink
Merge pull request #616 from apache/feature/527-manifest-improvement
Browse files Browse the repository at this point in the history
Feature/527 manifest improvement
  • Loading branch information
PengZheng authored Aug 18, 2023
2 parents db99d91 + 779e73a commit 9647e66
Show file tree
Hide file tree
Showing 37 changed files with 1,145 additions and 362 deletions.
13 changes: 3 additions & 10 deletions bundles/logging/log_helper/src/celix_log_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,11 @@ void celix_logHelper_vlogDetails(celix_log_helper_t* logHelper, celix_log_level_
}

void celix_logHelper_logTssErrors(celix_log_helper_t* logHelper, celix_log_level_e level) {
if (celix_err_getErrorCount() == 0) {
char buf[CELIX_ERR_BUFFER_SIZE] = {0};
if (celix_err_dump(buf, sizeof(buf), "[TssErr] ", NULL) == 0) {
// nothing to output
return;
}
char buf[512] = {0};
int ret;
int bytes = 0;
for (const char *errMsg = celix_err_popLastError(); errMsg != NULL && bytes < sizeof(buf); errMsg = celix_err_popLastError()) {
ret = snprintf(buf + bytes, sizeof(buf) - bytes, "[TssErr] %s\n", errMsg);
if (ret > 0) {
bytes += ret;
}
}
celix_err_resetErrors();
celix_logHelper_logDetails(logHelper, level, NULL, NULL, 0, "Detected tss errors:\n%s", buf);
}
Expand Down
1 change: 1 addition & 0 deletions libs/error_injector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ add_subdirectory(malloc)
add_subdirectory(asprintf)
add_subdirectory(stdio)
add_subdirectory(stdlib)
add_subdirectory(string)
add_subdirectory(eventfd)
add_subdirectory(stat)
add_subdirectory(fts)
Expand Down
3 changes: 3 additions & 0 deletions libs/error_injector/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ target_link_options(stdio_ei INTERFACE
LINKER:--wrap,fwrite
LINKER:--wrap,remove
LINKER:--wrap,open_memstream
LINKER:--wrap,fseek
LINKER:--wrap,ftell
LINKER:--wrap,fread
)
add_library(Celix::stdio_ei ALIAS stdio_ei)
6 changes: 6 additions & 0 deletions libs/error_injector/stdio/include/stdio_ei.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ CELIX_EI_DECLARE(remove, int);

CELIX_EI_DECLARE(open_memstream, FILE *);

CELIX_EI_DECLARE(fseek, int);

CELIX_EI_DECLARE(ftell, long);

CELIX_EI_DECLARE(fread, size_t);

#ifdef __cplusplus
}
#endif
Expand Down
48 changes: 36 additions & 12 deletions libs/error_injector/stdio/src/stdio_ei.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,66 @@
#include "stdio_ei.h"

extern "C" {
FILE *__real_fopen (const char *__filename, const char *__modes);
CELIX_EI_DEFINE(fopen, FILE *)
FILE *__wrap_fopen (const char *__filename, const char *__modes) {
FILE* __real_fopen(const char* __filename, const char* __modes);
CELIX_EI_DEFINE(fopen, FILE*)
FILE* __wrap_fopen(const char* __filename, const char* __modes) {
errno = EMFILE;
CELIX_EI_IMPL(fopen);
errno = 0;
return __real_fopen(__filename, __modes);
}


size_t __real_fwrite (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s);
size_t __real_fwrite(const void* __restrict __ptr, size_t __size, size_t __n, FILE* __restrict __s);
CELIX_EI_DEFINE(fwrite, size_t)
size_t __wrap_fwrite (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s) {
size_t __wrap_fwrite(const void* __restrict __ptr, size_t __size, size_t __n, FILE* __restrict __s) {
errno = ENOSPC;
CELIX_EI_IMPL(fwrite);
errno = 0;
return __real_fwrite(__ptr, __size, __n, __s);
}


int __real_remove (const char *__filename);
int __real_remove(const char* __filename);
CELIX_EI_DEFINE(remove, int)
int __wrap_remove (const char *__filename) {
int __wrap_remove(const char* __filename) {
errno = EACCES;
CELIX_EI_IMPL(remove);
errno = 0;
return __real_remove(__filename);
}

FILE *__real_open_memstream (char **__bufloc, size_t *__sizeloc);
CELIX_EI_DEFINE(open_memstream, FILE *)
FILE *__wrap_open_memstream (char **__bufloc, size_t *__sizeloc) {
FILE* __real_open_memstream(char** __bufloc, size_t* __sizeloc);
CELIX_EI_DEFINE(open_memstream, FILE*)
FILE* __wrap_open_memstream(char** __bufloc, size_t* __sizeloc) {
errno = ENOMEM;
CELIX_EI_IMPL(open_memstream);
errno = 0;
return __real_open_memstream(__bufloc, __sizeloc);
}

int __real_fseek(FILE* __stream, long int __off, int __whence);
CELIX_EI_DEFINE(fseek, int)
int __wrap_fseek(FILE* __stream, long int __off, int __whence) {
errno = EACCES;
CELIX_EI_IMPL(fseek);
errno = 0;
return __real_fseek(__stream, __off, __whence);
}

long __real_ftell(FILE* __stream);
CELIX_EI_DEFINE(ftell, long)
long __wrap_ftell(FILE* __stream) {
if (ftell_ret == -1) {
errno = EACCES;
}
CELIX_EI_IMPL(ftell);
errno = 0;
return __real_ftell(__stream);
}

size_t __real_fread(void* __restrict __ptr, size_t __size, size_t __n, FILE* __restrict __s);
CELIX_EI_DEFINE(fread, size_t)
size_t __wrap_fread(void* __restrict __ptr, size_t __size, size_t __n, FILE* __restrict __s) {
CELIX_EI_IMPL(fread);
return __real_fread(__ptr, __size, __n, __s);
}
}
26 changes: 26 additions & 0 deletions libs/error_injector/string/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

add_library(string_ei STATIC src/string_ei.cc)

target_include_directories(string_ei PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(string_ei PUBLIC Celix::error_injector)

target_link_options(string_ei INTERFACE
LINKER:--wrap,strndup
)
add_library(Celix::string_ei ALIAS string_ei)
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,24 @@
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* attribute.h
*
* \date Jul 27, 2010
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/

#ifndef ATTRIBUTE_H_
#define ATTRIBUTE_H_

#include "celix_errno.h"

typedef struct attribute *attribute_pt;
#ifndef CELIX_STRING_EI_H
#define CELIX_STRING_EI_H
#ifdef __cplusplus
extern "C" {
#endif

celix_status_t attribute_create(char * key, char * value, attribute_pt *attribute);
celix_status_t attribute_destroy(attribute_pt attribute);
#include <string.h>
#include "celix_error_injector.h"

celix_status_t attribute_getKey(attribute_pt attribute, char **key);
celix_status_t attribute_getValue(attribute_pt attribute, char **value);
CELIX_EI_DECLARE(strndup, char *);

#endif /* ATTRIBUTE_H_ */
#ifdef __cplusplus
}
#endif
#endif // CELIX_STRING_EI_H
33 changes: 33 additions & 0 deletions libs/error_injector/string/src/string_ei.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

#include "string_ei.h"
#include <errno.h>

extern "C" {
char* __real_strndup(const char* s, size_t n);
CELIX_EI_DEFINE(strndup, char*)
char* __wrap_strndup(const char* s, size_t n) {
errno = ENOMEM;
CELIX_EI_IMPL(strndup);
errno = 0;
return __real_strndup(s, n);
}
}
2 changes: 1 addition & 1 deletion libs/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (FRAMEWORK)
find_package(CURL REQUIRED)
endif ()
set(FRAMEWORK_SRC
src/attribute.c src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c
src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c
src/bundle_context.c src/bundle_revision.c
src/framework.c src/manifest.c
src/manifest_parser.c src/module.c
Expand Down
5 changes: 5 additions & 0 deletions libs/framework/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(CELIX_FRAMEWORK_TEST_SOURCES
src/CelixBundleCacheTestSuite.cc
src/ScheduledEventTestSuite.cc
src/FrameworkBundleTestSuite.cc
src/ManifestTestSuite.cc
)

add_executable(test_framework ${CELIX_FRAMEWORK_TEST_SOURCES})
Expand Down Expand Up @@ -139,6 +140,7 @@ if (LINKER_WRAP_SUPPORTED)
src/ScheduledEventWithErrorInjectionTestSuite.cc
src/FrameworkBundleWithErrorInjectionTestSuite.cc
src/FrameworkFactoryWithErrorInjectionTestSuite.cc
src/ManifestErrorInjectionTestSuite.cc
)
target_compile_definitions(test_framework_with_ei PRIVATE
SIMPLE_TEST_BUNDLE1_LOCATION="${SIMPLE_TEST_BUNDLE1}"
Expand All @@ -159,6 +161,9 @@ if (LINKER_WRAP_SUPPORTED)
Celix::stdlib_ei
Celix::stat_ei
Celix::threads_ei
Celix::hmap_ei
Celix::stdio_ei
Celix::string_ei
GTest::gtest GTest::gtest_main
)

Expand Down
7 changes: 7 additions & 0 deletions libs/framework/gtest/src/CxxBundleContextTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "service_tracker.h"
#include "celix/BundleContext.h"
#include "celix_err.h"
#include "celix_framework_factory.h"
#include "celix_framework.h"
#include "service_tracker_customizer.h"
Expand Down Expand Up @@ -416,6 +417,12 @@ TEST_F(CxxBundleContextTestSuite, LoggingUsingContext) {
ctx->logFatal("fatal");
}

TEST_F(CxxBundleContextTestSuite, LoggingTssErrorsTest) {
ctx->logTssErrors(CELIX_LOG_LEVEL_FATAL);
celix_err_push("Hello ERR");
ctx->logTssErrors(CELIX_LOG_LEVEL_FATAL);
}

TEST_F(CxxBundleContextTestSuite, GetFramework) {
EXPECT_FALSE(ctx->getFramework()->getUUID().empty());
EXPECT_EQ(ctx->getFramework()->getFrameworkBundleContext()->getBundle().getId(), 0);
Expand Down
Loading

0 comments on commit 9647e66

Please sign in to comment.