Skip to content

Commit 3222ea6

Browse files
authored
Add test of NullVm. (proxy-wasm#5)
* Add test of NullVm. Signed-off-by: John Plevyak <[email protected]>
1 parent 463603d commit 3222ea6

File tree

18 files changed

+495
-64
lines changed

18 files changed

+495
-64
lines changed

BUILD

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,48 @@ package(default_visibility = ["//visibility:public"])
44

55
cc_library(
66
name = "include",
7-
hdrs = [
8-
"include/proxy-wasm/compat.h",
9-
"include/proxy-wasm/context.h",
10-
"include/proxy-wasm/wasm_vm.h",
11-
"include/proxy-wasm/word.h",
12-
],
7+
hdrs = glob(["include/proxy-wasm/**/*.h"]),
138
deps = [
149
"@proxy_wasm_cpp_sdk//:common_lib",
1510
],
1611
)
1712

13+
cc_library(
14+
name = "lib",
15+
srcs = glob(
16+
["src/**/*.cc"],
17+
exclude = [
18+
"src/**/wavm*",
19+
"src/**/v8*",
20+
],
21+
) + glob(["src/**/*.h"]),
22+
copts = ["-DWITHOUT_ZLIB=1"],
23+
deps = [
24+
":include",
25+
"@proxy_wasm_cpp_sdk//:api_lib",
26+
],
27+
)
28+
1829
# TODO: remove when dependent projects have been upgraded.
1930
cc_library(
20-
name = "include14",
21-
hdrs = [
22-
"include/proxy-wasm/compat.h",
23-
"include/proxy-wasm/context.h",
24-
"include/proxy-wasm/wasm_vm.h",
25-
"include/proxy-wasm/word.h",
31+
name = "lib14",
32+
srcs = glob(
33+
["src/**/*.cc"],
34+
exclude = [
35+
"src/**/wavm*",
36+
"src/**/v8*",
37+
],
38+
) + glob(["src/**/*.h"]),
39+
copts = [
40+
"-std=c++14",
41+
"-DWITHOUT_ZLIB=1",
2642
],
2743
deps = [
28-
"@proxy_wasm_cpp_sdk//:common_lib",
44+
":include",
45+
"@com_google_absl//absl/base",
46+
"@com_google_absl//absl/strings",
47+
"@com_google_absl//absl/types:optional",
48+
"@proxy_wasm_cpp_sdk//:api_lib",
2949
],
3050
)
3151

@@ -34,7 +54,7 @@ cc_test(
3454
srcs = ["wasm_vm_test.cc"],
3555
copts = ["-std=c++17"],
3656
deps = [
37-
":include",
57+
":lib",
3858
"@com_google_googletest//:gtest",
3959
"@com_google_googletest//:gtest_main",
4060
],
@@ -43,6 +63,7 @@ cc_test(
4363
cc_test(
4464
name = "context_test",
4565
srcs = ["context_test.cc"],
66+
copts = ["-std=c++17"],
4667
deps = [
4768
":include",
4869
"@com_google_googletest//:gtest",
@@ -51,26 +72,12 @@ cc_test(
5172
)
5273

5374
# TODO: remove when dependent projects have been upgraded.
54-
cc_test(
55-
name = "wasm_vm_14_test",
56-
srcs = ["wasm_vm_test.cc"],
57-
copts = ["-std=c++14"],
58-
deps = [
59-
":include14",
60-
"@com_google_absl//absl/base",
61-
"@com_google_absl//absl/strings",
62-
"@com_google_absl//absl/types:optional",
63-
"@com_google_googletest//:gtest",
64-
"@com_google_googletest//:gtest_main",
65-
],
66-
)
67-
6875
cc_test(
6976
name = "context_14_test",
7077
srcs = ["context_test.cc"],
7178
copts = ["-std=c++14"],
7279
deps = [
73-
":include14",
80+
":include",
7481
"@com_google_absl//absl/base",
7582
"@com_google_absl//absl/strings",
7683
"@com_google_absl//absl/types:optional",

WORKSPACE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
workspace(name = "proxy_wasm_cpp_host")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
45

56
http_archive(
67
name = "proxy_wasm_cpp_sdk",
78
sha256 = "14f66f67e8f37ec81d28d7f5307be4407d206ac5f0daaf6d22fa5536797bcac1",
89
strip_prefix = "proxy-wasm-cpp-sdk-31f1fc5b7e09f231fa532d2d296e479a113c3e10",
910
urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/archive/31f1fc5b7e09f231fa532d2d296e479a113c3e10.tar.gz"],
11+
patch_cmds = ["rm BUILD"],
12+
build_file = '//bazel/external:proxy-wasm-cpp-sdk.BUILD',
1013
)
1114

1215
http_archive(
@@ -17,6 +20,25 @@ http_archive(
1720
urls = ["https://github.com/abseil/abseil-cpp/archive/37dd2562ec830d547a1524bb306be313ac3f2556.tar.gz"],
1821
)
1922

23+
24+
# required by com_google_protobuf
25+
http_archive(
26+
name = "bazel_skylib",
27+
urls = [
28+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
29+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
30+
],
31+
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
32+
)
33+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
34+
bazel_skylib_workspace()
35+
36+
git_repository(
37+
name = "com_google_protobuf",
38+
remote = "https://github.com/protocolbuffers/protobuf",
39+
commit = "655310ca192a6e3a050e0ca0b7084a2968072260",
40+
)
41+
2042
http_archive(
2143
name = "com_google_googletest",
2244
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",

bazel/external/BUILD

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "api_lib",
7+
hdrs = ["proxy_wasm_api.h"],
8+
)
9+
10+
cc_library(
11+
name = "common_lib",
12+
hdrs = [
13+
"proxy_wasm_common.h",
14+
"proxy_wasm_enums.h",
15+
],
16+
deps = [
17+
"@com_google_protobuf//:protobuf_lite",
18+
],
19+
)

include/proxy-wasm/null_plugin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "include/proxy-wasm/null_vm_plugin.h"
2121
#include "include/proxy-wasm/wasm.h"
2222

23-
#include <google/protobuf/message.h>
23+
#include "google/protobuf/message.h"
2424

2525
namespace proxy_wasm {
2626
namespace null_plugin {
@@ -66,7 +66,7 @@ class NullPlugin : public NullVmPlugin {
6666
explicit NullPlugin(NullPluginRegistry *registry) : registry_(registry) {}
6767
NullPlugin(const NullPlugin &other) : registry_(other.registry_) {}
6868

69-
#define _DECLARE_OVERRIDE(_t) void getFunction(absl::string_view function_name, _t *f) override;
69+
#define _DECLARE_OVERRIDE(_t) void getFunction(string_view function_name, _t *f) override;
7070
FOR_ALL_WASM_VM_EXPORTS(_DECLARE_OVERRIDE)
7171
#undef _DECLARE_OVERRIDE
7272

@@ -107,7 +107,7 @@ class NullPlugin : public NullVmPlugin {
107107
uint64_t onDone(uint64_t context_id);
108108
void onDelete(uint64_t context_id);
109109

110-
null_plugin::RootContext *getRoot(absl::string_view root_id);
110+
null_plugin::RootContext *getRoot(string_view root_id);
111111

112112
void error(string_view message) { wasm_vm_->error(message); }
113113

include/proxy-wasm/null_vm.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ struct NullVm : public WasmVm {
3232
NullVm(const NullVm &other) : plugin_name_(other.plugin_name_) {}
3333

3434
// WasmVm
35-
absl::string_view runtime() override { return "null"; }
35+
string_view runtime() override { return "null"; }
3636
Cloneable cloneable() override { return Cloneable::InstantiatedModule; };
3737
std::unique_ptr<WasmVm> clone() override;
3838
bool load(const std::string &code, bool allow_precompiled) override;
39-
void link(absl::string_view debug_name) override;
39+
void link(string_view debug_name) override;
4040
uint64_t getMemorySize() override;
41-
absl::optional<absl::string_view> getMemory(uint64_t pointer, uint64_t size) override;
41+
optional<string_view> getMemory(uint64_t pointer, uint64_t size) override;
4242
bool setMemory(uint64_t pointer, uint64_t size, const void *data) override;
4343
bool setWord(uint64_t pointer, Word data) override;
4444
bool getWord(uint64_t pointer, Word *data) override;
45-
string_view getCustomSection(absl::string_view name) override;
45+
string_view getCustomSection(string_view name) override;
4646
string_view getPrecompiledSectionName() override;
4747

4848
#define _FORWARD_GET_FUNCTION(_T) \
49-
void getFunction(absl::string_view function_name, _T *f) override { \
49+
void getFunction(string_view function_name, _T *f) override { \
5050
plugin_->getFunction(function_name, f); \
5151
}
5252
FOR_ALL_WASM_VM_EXPORTS(_FORWARD_GET_FUNCTION)
5353
#undef _FORWARD_GET_FUNCTION
5454

5555
// These are not needed for NullVm which invokes the handlers directly.
5656
#define _REGISTER_CALLBACK(_T) \
57-
void registerCallback(absl::string_view, absl::string_view, _T, \
57+
void registerCallback(string_view, string_view, _T, \
5858
typename ConvertFunctionTypeWordToUint32<_T>::type) override{};
5959
FOR_ALL_WASM_VM_IMPORTS(_REGISTER_CALLBACK)
6060
#undef _REGISTER_CALLBACK

include/proxy-wasm/null_vm_plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class NullVmPlugin {
2828
// NB: These are defined rather than declared PURE because gmock uses __LINE__ internally for
2929
// uniqueness, making it impossible to use FOR_ALL_WASM_VM_EXPORTS with MOCK_METHOD.
3030
#define _DEFINE_GET_FUNCTION(_T) \
31-
virtual void getFunction(absl::string_view, _T *f) { *f = nullptr; }
31+
virtual void getFunction(string_view, _T *f) { *f = nullptr; }
3232
FOR_ALL_WASM_VM_EXPORTS(_DEFINE_GET_FUNCTION)
3333
#undef _DEFIN_GET_FUNCTIONE
3434

include/proxy-wasm/wasm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#pragma once
1717

18+
#include <string.h>
19+
1820
#include <atomic>
1921
#include <deque>
2022
#include <map>
@@ -252,8 +254,7 @@ class WasmHandle : public std::enable_shared_from_this<WasmHandle> {
252254
std::shared_ptr<WasmBase> wasm_;
253255
};
254256

255-
std::string makeVmKey(absl::string_view vm_id, absl::string_view configuration,
256-
absl::string_view code);
257+
std::string makeVmKey(string_view vm_id, string_view configuration, string_view code);
257258

258259
using WasmHandleFactory = std::function<std::shared_ptr<WasmHandle>(string_view vm_id)>;
259260
using WasmHandleCloneFactory =

include/proxy-wasm/wasm_api_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
#pragma once
1717

18+
#include "include/proxy-wasm/compat.h"
19+
1820
namespace proxy_wasm {
1921
namespace null_plugin {
2022
class RootContext;
2123
} // namespace null_plugin
2224

23-
null_plugin::RootContext *nullVmGetRoot(absl::string_view root_id);
25+
null_plugin::RootContext *nullVmGetRoot(string_view root_id);
2426

2527
namespace null_plugin {
2628

include/proxy-wasm/wasm_vm.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,4 @@ struct SaveRestoreContext {
267267
uint32_t saved_effective_context_id_;
268268
};
269269

270-
// Create a new low-level WASM VM using runtime of the given type (e.g. "v8").
271-
std::unique_ptr<WasmVm> createWasmVm(string_view runtime);
272-
273270
} // namespace proxy_wasm

0 commit comments

Comments
 (0)