-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_emulator.cpp
More file actions
83 lines (66 loc) · 2.15 KB
/
Copy pathtest_emulator.cpp
File metadata and controls
83 lines (66 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "utils.h"
#include <catch2/catch.hpp>
extern "C"
{
#include <faasm/emulator_api.h>
#include <faasm/host_interface.h>
}
#include <faabric/util/func.h>
#include <faabric/util/json.h>
#include <faabric/util/state.h>
#include <faasm/core.h>
#include <faasm/emulator.h>
namespace tests {
TEST_CASE("Test emulation", "[emulator]")
{
cleanCppTests();
std::vector<uint8_t> dummyBytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
long dummyLen = dummyBytes.size();
faabric::Message call = faabric::util::messageFactory("demo", "echo");
SECTION("Output data")
{
setEmulatedMessage(call);
faasmSetOutput(dummyBytes.data(), dummyLen);
const std::vector<uint8_t> actual = getEmulatorOutputData();
REQUIRE(actual == dummyBytes);
}
SECTION("Input data")
{
call.set_inputdata(dummyBytes.data(), dummyBytes.size());
setEmulatedMessage(call);
long actual = faasmGetInputSize();
REQUIRE(actual == dummyLen);
std::vector<uint8_t> actualBytes(dummyLen);
faasmGetInput(actualBytes.data(), dummyLen);
REQUIRE(actualBytes == dummyBytes);
}
SECTION("Read/ write state")
{
setEmulatedMessage(call);
std::string key = "foobar";
faasmWriteState(key.c_str(), dummyBytes.data(), dummyLen);
faasmPushState(key.c_str());
// Check reading from state
std::vector<uint8_t> actual(dummyLen);
faasmReadState(key.c_str(), actual.data(), dummyLen);
REQUIRE(actual == dummyBytes);
}
SECTION("Read/ write state offset")
{
setEmulatedMessage(call);
std::string key = "foobar_off";
std::vector<uint8_t> offsetData = { 7, 6, 5 };
long offset = 2;
long dataLen = 3;
faasmWriteStateOffset(
key.c_str(), dummyLen, offset, offsetData.data(), dataLen);
faasmPushState(key.c_str());
// Check reading from state
std::vector<uint8_t> actual(dataLen);
faasmPullState(key.c_str(), dummyLen);
faasmReadStateOffset(
key.c_str(), dummyLen, offset, actual.data(), dataLen);
REQUIRE(actual == offsetData);
}
}
}