@@ -14,22 +14,37 @@ namespace Extensions {
14
14
namespace DynamicModules {
15
15
16
16
// This loads a shared object file from the test_data directory.
17
- std::string testSharedObjectPath (std::string name) {
17
+ std::string testSharedObjectPath (std::string name, std::string language ) {
18
18
return TestEnvironment::substitute (
19
19
" {{ test_rundir }}/test/extensions/dynamic_modules/test_data/" ) +
20
- " lib" + name + " .so" ;
20
+ language + " / lib" + name + " .so" ;
21
21
}
22
22
23
- TEST (DynamicModuleTest , InvalidPath) {
23
+ TEST (DynamicModuleTestGeneral , InvalidPath) {
24
24
absl::StatusOr<DynamicModuleSharedPtr> result = newDynamicModule (" invalid_name" , false );
25
25
EXPECT_FALSE (result.ok ());
26
26
EXPECT_EQ (result.status ().code (), absl::StatusCode::kInvalidArgument );
27
27
}
28
28
29
- TEST (DynamicModuleTest, LoadNoOp) {
29
+ /* *
30
+ * Class to test the identical behavior of the dynamic module in different languages.
31
+ */
32
+ class DynamicModuleTestLanguages : public ::testing::TestWithParam<std::string> {
33
+ public:
34
+ static std::string languageParamToTestName (const ::testing::TestParamInfo<std::string>& info) {
35
+ return info.param ;
36
+ };
37
+ };
38
+
39
+ INSTANTIATE_TEST_SUITE_P (LanguageTests, DynamicModuleTestLanguages,
40
+ testing::Values (" c" ), // TODO: Other languages.
41
+ DynamicModuleTestLanguages::languageParamToTestName);
42
+
43
+ TEST_P (DynamicModuleTestLanguages, DoNotClose) {
44
+ std::string language = GetParam ();
30
45
using GetSomeVariableFuncType = int (*)();
31
46
absl::StatusOr<DynamicModuleSharedPtr> module =
32
- newDynamicModule (testSharedObjectPath (" no_op" ), false );
47
+ newDynamicModule (testSharedObjectPath (" no_op" , language ), false );
33
48
EXPECT_TRUE (module.ok ());
34
49
const auto getSomeVariable =
35
50
module->get ()->getFunctionPointer <GetSomeVariableFuncType>(" getSomeVariable" );
@@ -39,8 +54,8 @@ TEST(DynamicModuleTest, LoadNoOp) {
39
54
40
55
// Release the module, and reload it.
41
56
module->reset ();
42
- module =
43
- newDynamicModule ( testSharedObjectPath ( " no_op " ), true ); // This time, do not close the module.
57
+ module = newDynamicModule ( testSharedObjectPath ( " no_op " , language),
58
+ true ); // This time, do not close the module.
44
59
EXPECT_TRUE (module.ok ());
45
60
46
61
// This module must be reloaded and the variable must be reset.
@@ -53,7 +68,7 @@ TEST(DynamicModuleTest, LoadNoOp) {
53
68
54
69
// Release the module, and reload it.
55
70
module->reset ();
56
- module = newDynamicModule (testSharedObjectPath (" no_op" ), false );
71
+ module = newDynamicModule (testSharedObjectPath (" no_op" , language ), false );
57
72
EXPECT_TRUE (module.ok ());
58
73
59
74
// This module must be the already loaded one, and the variable must be kept.
@@ -63,6 +78,43 @@ TEST(DynamicModuleTest, LoadNoOp) {
63
78
EXPECT_EQ (getSomeVariable3 (), 4 ); // Start from 4.
64
79
}
65
80
81
+ TEST_P (DynamicModuleTestLanguages, LoadNoOp) {
82
+ std::string language = GetParam ();
83
+ absl::StatusOr<DynamicModuleSharedPtr> module =
84
+ newDynamicModule (testSharedObjectPath (" no_op" , language), false );
85
+ EXPECT_TRUE (module.ok ());
86
+ }
87
+
88
+ TEST_P (DynamicModuleTestLanguages, NoProgramInit) {
89
+ std::string language = GetParam ();
90
+ absl::StatusOr<DynamicModuleSharedPtr> result =
91
+ newDynamicModule (testSharedObjectPath (" no_program_init" , language), false );
92
+ EXPECT_FALSE (result.ok ());
93
+ EXPECT_EQ (result.status ().code (), absl::StatusCode::kInvalidArgument );
94
+ EXPECT_THAT (result.status ().message (),
95
+ testing::HasSubstr (" undefined symbol: envoy_dynamic_module_on_program_init" ));
96
+ }
97
+
98
+ TEST_P (DynamicModuleTestLanguages, ProgramInitFail) {
99
+ std::string language = GetParam ();
100
+ absl::StatusOr<DynamicModuleSharedPtr> result =
101
+ newDynamicModule (testSharedObjectPath (" program_init_fail" , language), false );
102
+ EXPECT_FALSE (result.ok ());
103
+ EXPECT_EQ (result.status ().code (), absl::StatusCode::kInvalidArgument );
104
+ EXPECT_THAT (result.status ().message (),
105
+ testing::HasSubstr (" Failed to initialize dynamic module:" ));
106
+ }
107
+
108
+ TEST_P (DynamicModuleTestLanguages, ABIVersionMismatch) {
109
+ std::string language = GetParam ();
110
+ absl::StatusOr<DynamicModuleSharedPtr> result =
111
+ newDynamicModule (testSharedObjectPath (" abi_version_mismatch" , language), false );
112
+ EXPECT_FALSE (result.ok ());
113
+ EXPECT_EQ (result.status ().code (), absl::StatusCode::kInvalidArgument );
114
+ EXPECT_THAT (result.status ().message (),
115
+ testing::HasSubstr (" ABI version mismatch: got invalid-version-hash, but expected" ));
116
+ }
117
+
66
118
} // namespace DynamicModules
67
119
} // namespace Extensions
68
120
} // namespace Envoy
0 commit comments