-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dynFunction_parse and dynFunction_parseWithStr.
- Loading branch information
Showing
8 changed files
with
205 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(ffi_ei STATIC src/ffi_ei.cc) | ||
|
||
target_include_directories(ffi_ei PUBLIC include) | ||
target_link_libraries(ffi_ei PUBLIC Celix::error_injector libffi::libffi) | ||
|
||
target_link_options(ffi_ei INTERFACE | ||
LINKER:--wrap,ffi_prep_cif | ||
) | ||
add_library(Celix::ffi_ei ALIAS ffi_ei) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
#ifndef CELIX_FFI_EI_H | ||
#define CELIX_FFI_EI_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "celix_error_injector.h" | ||
#include <ffi.h> | ||
|
||
CELIX_EI_DECLARE(ffi_prep_cif, ffi_status); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif //CELIX_FFI_EI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 "ffi_ei.h" | ||
|
||
extern "C" { | ||
ffi_status __real_ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes); | ||
CELIX_EI_DEFINE(ffi_prep_cif, ffi_status) | ||
ffi_status __wrap_ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes) { | ||
CELIX_EI_IMPL(ffi_prep_cif); | ||
return __real_ffi_prep_cif(cif, abi, nargs, rtype, atypes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 "dyn_function.h" | ||
#include "dyn_example_functions.h" | ||
|
||
#include "celix_err.h" | ||
#include "ffi_ei.h" | ||
#include "malloc_ei.h" | ||
#include "stdio_ei.h" | ||
|
||
#include <errno.h> | ||
#include <gtest/gtest.h> | ||
#include <string> | ||
#include <string.h> | ||
|
||
class DynFunctionErrorInjectionTestSuite : public ::testing::Test { | ||
public: | ||
DynFunctionErrorInjectionTestSuite() = default; | ||
~DynFunctionErrorInjectionTestSuite() override { | ||
celix_ei_expect_fmemopen(nullptr, 0, nullptr); | ||
celix_ei_expect_ffi_prep_cif(nullptr, 0, FFI_OK); | ||
celix_ei_expect_calloc(nullptr, 0, nullptr); | ||
celix_err_resetErrors(); | ||
} | ||
}; | ||
|
||
TEST_F(DynFunctionErrorInjectionTestSuite, ParseError) { | ||
dyn_function_type *dynFunc = nullptr; | ||
int rc; | ||
celix_ei_expect_calloc((void*)dynFunction_parse, 0, nullptr); | ||
rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, nullptr, &dynFunc); | ||
EXPECT_NE(0, rc); | ||
EXPECT_STREQ("Error allocating memory for dyn function", celix_err_popLastError()); | ||
|
||
celix_ei_expect_ffi_prep_cif((void*)dynFunction_parse, 1, FFI_BAD_TYPEDEF); | ||
rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, nullptr, &dynFunc); | ||
EXPECT_NE(0, rc); | ||
EXPECT_STREQ("Error initializing cif 1", celix_err_popLastError()); | ||
|
||
celix_ei_expect_fmemopen((void*)dynFunction_parseWithStr, 0, nullptr); | ||
rc = dynFunction_parseWithStr(EXAMPLE1_DESCRIPTOR, nullptr, &dynFunc); | ||
EXPECT_NE(0, rc); | ||
std::string result = "Error creating mem stream for descriptor string. "; | ||
result += strerror(ENOMEM); | ||
EXPECT_STREQ(result.c_str(), celix_err_popLastError()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters