Skip to content

Commit 4da5eee

Browse files
authored
Merge pull request #779 from apache/feature/685-remove-bundle-revision
Feature/685 remove bundle revision
2 parents 5e18244 + 98ec868 commit 4da5eee

25 files changed

+383
-709
lines changed

libs/error_injector/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_subdirectory(sys_shm)
3737
add_subdirectory(socket)
3838
add_subdirectory(pthread)
3939
add_subdirectory(unistd)
40+
add_subdirectory(dirent)
4041

4142
celix_subproject(ERROR_INJECTOR_MDNSRESPONDER "Option to enable building the mdnsresponder error injector" OFF)
4243
if (ERROR_INJECTOR_MDNSRESPONDER)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
add_library(dirent_ei STATIC src/dirent_ei.cc)
19+
20+
target_include_directories(dirent_ei PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
21+
target_link_libraries(dirent_ei PUBLIC Celix::error_injector)
22+
target_link_options(dirent_ei INTERFACE
23+
LINKER:--wrap,opendir
24+
)
25+
add_library(Celix::dirent_ei ALIAS dirent_ei)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#ifndef CELIX_DIRENT_EI_H
21+
#define CELIX_DIRENT_EI_H
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
#include "celix_error_injector.h"
27+
#include <dirent.h>
28+
29+
CELIX_EI_DECLARE(opendir, DIR*);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
#endif //CELIX_DIRENT_EI_H
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#include <errno.h>
21+
#include "dirent_ei.h"
22+
23+
extern "C" {
24+
25+
DIR* __real_opendir(const char* __name);
26+
CELIX_EI_DEFINE(opendir, DIR*)
27+
DIR* __wrap_opendir(const char* __name) {
28+
errno = EMFILE;
29+
CELIX_EI_IMPL(opendir);
30+
errno = 0;
31+
return __real_opendir(__name);
32+
}
33+
34+
}

libs/framework/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if (FRAMEWORK)
2323
find_package(CURL REQUIRED)
2424
endif ()
2525
set(FRAMEWORK_SRC
26-
src/bundle.c src/bundle_archive.c src/celix_bundle_cache.c
27-
src/bundle_context.c src/bundle_revision.c
26+
src/bundle.c src/celix_bundle_archive.c src/celix_bundle_cache.c
27+
src/bundle_context.c
2828
src/framework.c
2929
src/module.c
3030
src/service_reference.c src/service_registration.c

libs/framework/gtest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ if (EI_TESTS)
173173
Celix::hmap_ei
174174
Celix::stdio_ei
175175
Celix::string_ei
176+
Celix::dirent_ei
176177
GTest::gtest GTest::gtest_main
177178
)
178179

libs/framework/gtest/src/BundleArchiveTestSuite.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#include "celix_file_utils.h"
2525
#include "celix_framework_utils.h"
2626
#include "framework.h"
27-
#include "bundle_archive.h"
2827

2928
//including private headers, which should only be used for testing
30-
#include "bundle_archive_private.h"
29+
#include "celix_bundle_archive.h"
3130
#include "celix_bundle_private.h"
3231

3332
class CxxBundleArchiveTestSuite : public ::testing::Test {

libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
#include "celix/FrameworkFactory.h"
3333

3434
#include "asprintf_ei.h"
35-
#include "bundle_archive_private.h"
36-
#include "bundle_revision_private.h"
35+
#include "celix_bundle_archive.h"
3736
#include "framework_private.h"
3837
#include "malloc_ei.h"
3938
#include "celix_bundle_manifest.h"
@@ -113,19 +112,6 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreatedFailedTest)
113112
// Given a mocked malloc which returns NULL from a call from manifest_create
114113
celix_ei_expect_calloc((void*)celix_bundleManifest_create, 0, nullptr);
115114
installBundleAndExpectFailure();
116-
117-
teardownErrorInjectors();
118-
// Given a mocked calloc which returns NULL from a call from bundleRevision_create
119-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
120-
installBundleAndExpectFailure();
121-
122-
teardownErrorInjectors();
123-
// Given a mocked celix_utils_strdup which returns NULL from a call from bundleRevision_create
124-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr);
125-
installBundleAndExpectFailure();
126-
127-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleRevision_create, 0, nullptr, 2);
128-
installBundleAndExpectFailure();
129115
}
130116

131117
TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirectoryFailedTest) {
@@ -142,13 +128,13 @@ TEST_F(BundleArchiveWithErrorInjectionTestSuite, BundleArchiveCreateCacheDirecto
142128
installBundleAndExpectFailure();
143129

144130
teardownErrorInjectors();
145-
// Given a mocked celix_utils_strdup which returns NULL from a (indirect) call from bundleArchive_create
146-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr);
131+
// Given a mocked celix_utils_strdup which returns NULL from a call from bundleArchive_create
132+
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr);
147133
installBundleAndExpectFailure();
148134

149135
teardownErrorInjectors();
150-
// Given a mocked celix_utils_strdup which returns NULL from a second (indirect) call from bundleArchive_create
151-
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 1, nullptr, 2);
136+
// Given a mocked celix_utils_strdup which returns NULL from a second call from bundleArchive_create
137+
celix_ei_expect_celix_utils_strdup((void*)celix_bundleArchive_create, 0, nullptr, 2);
152138
installBundleAndExpectFailure();
153139
}
154140

@@ -189,7 +175,7 @@ class CelixBundleArchiveErrorInjectionTestSuite : public ::testing::Test {
189175
TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
190176
celix_bundle_cache_t* cache = nullptr;
191177
createCache(&cache);
192-
bundle_archive_t* archive = nullptr;
178+
celix_bundle_archive_t* archive = nullptr;
193179

194180
// archive directory creation failures not covered by other tests
195181
celix_ei_expect_celix_utils_getLastModified((void*)celix_bundleArchive_create, 2, CELIX_FILE_IO_EXCEPTION);
@@ -241,22 +227,6 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveCreateErrorTest) {
241227
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
242228
teardownErrorInjectors();
243229

244-
// revision creation failure
245-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
246-
EXPECT_EQ(CELIX_ENOMEM,
247-
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
248-
EXPECT_EQ(nullptr, archive);
249-
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
250-
teardownErrorInjectors();
251-
252-
// bundle state persistence failure
253-
celix_ei_expect_celix_properties_create((void*)celix_bundleArchive_create, 1, nullptr);
254-
EXPECT_EQ(CELIX_ENOMEM,
255-
celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
256-
EXPECT_EQ(nullptr, archive);
257-
EXPECT_FALSE(celix_utils_directoryExists(TEST_ARCHIVE_ROOT));
258-
teardownErrorInjectors();
259-
260230
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache));
261231
}
262232

libs/framework/gtest/src/CelixBundleCacheErrorInjectionTestSuite.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
#include "celix_properties_ei.h"
3333

3434
#include "asprintf_ei.h"
35-
#include "bundle_archive_private.h"
36-
#include "bundle_revision_private.h"
35+
#include "celix_bundle_archive.h"
3736
#include "framework_private.h"
3837
#include "malloc_ei.h"
3938
#include "celix_bundle_manifest.h"
4039
#include "unistd_ei.h"
40+
#include "dirent_ei.h"
4141

4242
class CelixBundleCacheErrorInjectionTestSuite : public ::testing::Test {
4343
public:
@@ -56,15 +56,18 @@ class CelixBundleCacheErrorInjectionTestSuite : public ::testing::Test {
5656
celix_ei_expect_celix_stringHashMap_create(nullptr, 0, nullptr);
5757
celix_ei_expect_malloc(nullptr, 0, nullptr);
5858
celix_ei_expect_calloc(nullptr, 0, nullptr);
59+
celix_ei_expect_opendir(nullptr, 0, nullptr);
5960
celix_ei_expect_celix_properties_load(nullptr, 0, CELIX_SUCCESS);
6061
celix_frameworkLogger_destroy(fw.logger);
6162
celix_properties_destroy(fw.configurationMap);
6263
}
64+
6365
void createCache(celix_bundle_cache_t** cache) {
6466
celix_properties_setBool(fw.configurationMap, CELIX_FRAMEWORK_CACHE_USE_TMP_DIR, true);
6567
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_create(&fw, &fw.cache));
6668
*cache = fw.cache;
6769
}
70+
6871
struct celix_framework fw {};
6972
};
7073

@@ -104,13 +107,19 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, CacheDeleteErrorTest) {
104107

105108
TEST_F(CelixBundleCacheErrorInjectionTestSuite, ArchiveCreateErrorTest) {
106109
celix_bundle_cache_t* cache = nullptr;
110+
long bndId;
107111
createCache(&cache);
108112

109-
bundle_archive_t* archive = nullptr;
113+
//note needs to be the first ei test, to ensure that the lookup bundle id map is not yet loaded.
114+
celix_ei_expect_opendir((void*)celix_bundleCache_findBundleIdForLocation, 1, nullptr);
115+
EXPECT_EQ(celix_bundleCache_findBundleIdForLocation(cache, SIMPLE_TEST_BUNDLE1_LOCATION, &bndId),
116+
CELIX_FILE_IO_EXCEPTION);
117+
118+
celix_bundle_archive_t* archive = nullptr;
110119
celix_ei_expect_celix_utils_writeOrCreateString((void*)celix_bundleCache_createArchive, 0, nullptr);
111120
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createArchive(cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
112121
EXPECT_EQ(nullptr, archive);
113-
long bndId;
122+
114123
auto status = celix_bundleCache_findBundleIdForLocation(cache, SIMPLE_TEST_BUNDLE1_LOCATION, &bndId);
115124
EXPECT_EQ(CELIX_SUCCESS, status);
116125
EXPECT_EQ(-1, bndId);
@@ -131,7 +140,7 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) {
131140
celix_bundle_cache_t* cache = nullptr;
132141
createCache(&cache);
133142

134-
bundle_archive_t* archive = nullptr;
143+
celix_bundle_archive_t* archive = nullptr;
135144
celix_ei_expect_calloc((void*)celix_bundleArchive_create, 0, nullptr);
136145
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
137146
EXPECT_EQ(nullptr, archive);
@@ -148,10 +157,6 @@ TEST_F(CelixBundleCacheErrorInjectionTestSuite, SystemArchiveCreateErrorTest) {
148157
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
149158
EXPECT_EQ(nullptr, archive);
150159

151-
celix_ei_expect_calloc((void*)celix_bundleRevision_create, 0, nullptr);
152-
EXPECT_EQ(CELIX_ENOMEM, celix_bundleCache_createSystemArchive(&fw, &archive));
153-
EXPECT_EQ(nullptr, archive);
154-
155160
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache));
156161
}
157162

libs/framework/gtest/src/CelixBundleCacheTestSuite.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
under the License.
1818
*/
1919

20-
#include "bundle_archive_private.h"
20+
#include "celix_bundle_archive.h"
2121
#include "celix_bundle_cache.h"
2222
#include "celix_constants.h"
2323
#include "celix_file_utils.h"
@@ -48,12 +48,11 @@ class CelixBundleCacheTestSuite : public ::testing::Test {
4848
};
4949

5050
TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) {
51-
bundle_archive_t* archive = nullptr;
51+
celix_bundle_archive_t* archive = nullptr;
5252
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
5353
EXPECT_NE(nullptr, archive);
5454
auto location = celix_bundleArchive_getLocation(archive);
5555
EXPECT_STREQ(SIMPLE_TEST_BUNDLE1_LOCATION, location);
56-
free(location);
5756
long bndId;
5857
auto status = celix_bundleCache_findBundleIdForLocation(fw.cache, SIMPLE_TEST_BUNDLE1_LOCATION, &bndId);
5958
EXPECT_EQ(CELIX_SUCCESS, status);
@@ -71,7 +70,7 @@ TEST_F(CelixBundleCacheTestSuite, ArchiveCreateDestroyTest) {
7170
}
7271

7372
TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) {
74-
bundle_archive_t* archive = nullptr;
73+
celix_bundle_archive_t* archive = nullptr;
7574
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createArchive(fw.cache, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive));
7675
EXPECT_NE(nullptr, archive);
7776
std::string loc = celix_bundleArchive_getPersistentStoreRoot(archive);
@@ -86,13 +85,11 @@ TEST_F(CelixBundleCacheTestSuite, NonPermanentDestroyTest) {
8685
}
8786

8887
TEST_F(CelixBundleCacheTestSuite, SystemArchiveCreateDestroyTest) {
89-
bundle_archive_t* archive = nullptr;
90-
const char* archiveRoot = nullptr;
88+
celix_bundle_archive_t* archive = nullptr;
9189
EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_createSystemArchive(&fw, &archive));
9290
EXPECT_NE(nullptr, archive);
9391
EXPECT_EQ(0, celix_bundleArchive_getId(archive));
94-
EXPECT_EQ(CELIX_SUCCESS, bundleArchive_getArchiveRoot(archive, &archiveRoot));
95-
EXPECT_EQ(nullptr, archiveRoot);
92+
EXPECT_EQ(nullptr, celix_bundleArchive_getArchiveRoot(archive));
9693
EXPECT_EQ(nullptr, celix_bundleArchive_getLocation(archive));
9794
celix_bundleArchive_invalidate(archive);
9895
celix_bundleCache_destroyArchive(fw.cache, archive);

0 commit comments

Comments
 (0)