-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstate_file.cpp
44 lines (37 loc) · 1.16 KB
/
state_file.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
#include <faasm/faasm.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
const char* filePath = "/tmp/state_file_test";
const char* key = "state_file_test";
const char* dummyContent = "blah blah foo foo";
size_t contentLen = strlen(dummyContent);
// Write something to the file
FILE* f = fopen(filePath, "w");
if (f == NULL) {
printf("Error opening file at %s\n", filePath);
return 1;
}
fprintf(f, "%s", dummyContent);
fclose(f);
// Ask for the file to be written to state
size_t nBytesWritten = faasmWriteStateFromFile(key, filePath);
if (nBytesWritten != contentLen) {
printf("Expected %li bytes to be written but got %li\n",
contentLen,
nBytesWritten);
return 1;
}
// Read in the state
auto buffer = new uint8_t[contentLen];
faasmReadState(key, buffer, contentLen);
char* actual = reinterpret_cast<char*>(buffer);
if (strcmp(actual, dummyContent) != 0) {
printf("State not as expected (expected %s but got %s)\n",
dummyContent,
actual);
return 1;
}
return 0;
}