-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathchain_output.cpp
66 lines (53 loc) · 1.53 KB
/
chain_output.cpp
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
#include <faasm/faasm.h>
#include <stdio.h>
#include <string>
int otherA()
{
std::string outputA = "expected A";
faasmSetOutput(outputA.c_str(), outputA.size());
return 0;
}
int otherB()
{
std::string outputB = "longer expected B";
faasmSetOutput(outputB.c_str(), outputB.size());
return 0;
}
/**
* Checks getting output from chained functions
*/
int main(int argc, char* argv[])
{
unsigned int callIdA = faasmChain(otherA, nullptr, 0);
unsigned int callIdB = faasmChain(otherB, nullptr, 0);
std::string expectedA = "expected A";
std::string expectedB = "longer expected B";
std::string actualA;
char* actualABuf;
int actualABufSize;
unsigned int resA =
faasmAwaitCallOutput(callIdA, &actualABuf, &actualABufSize);
actualA.assign(actualABuf, actualABuf + actualABufSize);
std::string actualB;
char* actualBBuf;
int actualBBufSize;
unsigned int resB =
faasmAwaitCallOutput(callIdB, &actualBBuf, &actualBBufSize);
actualB.assign(actualBBuf, actualBBuf + actualBBufSize);
if (resA != 0 || resB != 0) {
printf("One or more chained calls failed: %i %i\n", resA, resB);
return 1;
}
if (actualA != expectedA) {
printf(
"Output mismatch: %s != %s\n", actualA.c_str(), expectedA.c_str());
return 1;
}
if (actualB != expectedB) {
printf(
"Output mismatch: %s != %s\n", actualB.c_str(), expectedB.c_str());
return 1;
}
printf("Chained outputs as expected\n");
return 0;
}