
5 changed files with 197 additions and 1 deletions
@ -0,0 +1,30 @@ |
|||
|
|||
LDLIBS=-lstdc++ -lpEpAdapter |
|||
LDFLAGS=-L../../src/ |
|||
CXXFLAGS=-std=c++11 -g |
|||
CXXFLAGS+=-I./src |
|||
TEST_EXTRA_OBJS=../framework/utils.o |
|||
|
|||
# Src
|
|||
SRC=$(wildcard src/*.cc) |
|||
OBJ=$(subst .cc,.o,$(SRC)) |
|||
|
|||
# Tests
|
|||
TEST_SRC=$(wildcard test/*.cc) |
|||
TEST_OBJ=$(subst .cc,,$(TEST_SRC)) |
|||
|
|||
|
|||
.PHONY: all clean rmtestdata |
|||
.DEFAULT_GOAL := all |
|||
|
|||
all: $(TEST_OBJ) |
|||
|
|||
$(TEST_OBJ): $(OBJ) $(TEST_EXTRA_OBJS) |
|||
|
|||
|
|||
clean: |
|||
rm -f $(OBJ) |
|||
rm -f $(TEST_OBJ) |
|||
rm -rf src/*.dSYM |
|||
rm -rf test/*.dSYM |
|||
|
@ -0,0 +1,80 @@ |
|||
#include "fw_dist_test.hh" |
|||
#include "../../../src/std_utils.hh" |
|||
#include "../../framework/utils.hh" |
|||
#include <iostream> |
|||
#include <unistd.h> |
|||
#include <stdlib.h> |
|||
#include <sys/stat.h> |
|||
|
|||
using namespace std; |
|||
namespace pEp { |
|||
namespace Test { |
|||
string dummy; |
|||
|
|||
DistTest::DistTest() : mode(TestMode::ALICE) |
|||
{ |
|||
alice_home = data_dir + "/" + "alice/"; |
|||
bob_home = data_dir + "/" + "bob/"; |
|||
data_dir_recreate(); |
|||
} |
|||
|
|||
void DistTest::run() |
|||
{ |
|||
if (mode == TestMode::ALICE) { |
|||
alice_main(); |
|||
} else if (mode == TestMode::ALICE_BOB) { |
|||
pid_t pid; |
|||
pid = fork(); |
|||
|
|||
if (pid == pid_t(0)) { |
|||
cout << "Child PID:" << pid << endl; |
|||
run_alice_main(); |
|||
} else if (pid > pid_t(0)) { |
|||
cout << "Parent PID:" << pid << endl; |
|||
run_bob_main(); |
|||
} else { |
|||
cerr << "error forking" << endl; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void DistTest::run_alice_main() |
|||
{ |
|||
cout << "New process for Alice" << endl; |
|||
setenv("HOME", alice_home.c_str(), 1); |
|||
mkdir(alice_home.c_str(), 0770); |
|||
cout << "HOME: " << getenv("HOME") << endl; |
|||
alice_main(); |
|||
} |
|||
|
|||
void DistTest::run_bob_main() |
|||
{ |
|||
cout << "New process for bob" << endl; |
|||
setenv("HOME", bob_home.c_str(), 1); |
|||
mkdir(bob_home.c_str(), 0770); |
|||
cout << "HOME: " << getenv("HOME") << endl; |
|||
bob_main(); |
|||
} |
|||
|
|||
|
|||
void DistTest::data_dir_delete() |
|||
{ |
|||
try { |
|||
Utils::path_delete_all(data_dir); |
|||
} catch (const exception& e) { |
|||
TESTLOG("DistTest: - could not delete data dir: " + data_dir); |
|||
} |
|||
} |
|||
|
|||
void DistTest::data_dir_create() |
|||
{ |
|||
Utils::dir_create(data_dir); |
|||
} |
|||
|
|||
void DistTest::data_dir_recreate() { |
|||
data_dir_delete(); |
|||
data_dir_create(); |
|||
}; |
|||
|
|||
} // namespace Test
|
|||
} // namespace pEp
|
@ -0,0 +1,43 @@ |
|||
// This file is under GNU General Public License 3.0
|
|||
// see LICENSE.txt
|
|||
|
|||
#ifndef LIBPEPADAPTER_FW_DIST_TEST_HH |
|||
#define LIBPEPADAPTER_FW_DIST_TEST_HH |
|||
|
|||
#include <string> |
|||
#include <functional> |
|||
|
|||
namespace pEp { |
|||
namespace Test { |
|||
|
|||
class DistTest { |
|||
public: |
|||
DistTest(); |
|||
|
|||
enum class TestMode |
|||
{ |
|||
ALICE, |
|||
ALICE_BOB |
|||
}; |
|||
TestMode mode; |
|||
|
|||
std::string data_dir = "./data"; |
|||
std::string alice_home; |
|||
std::string bob_home; |
|||
|
|||
std::function<void(void)> alice_main{}; |
|||
std::function<void(void)> bob_main{}; |
|||
void run(); |
|||
|
|||
private: |
|||
void run_alice_main(); |
|||
void run_bob_main(); |
|||
|
|||
void data_dir_delete(); |
|||
void data_dir_create(); |
|||
void data_dir_recreate(); |
|||
}; |
|||
}; // namespace Test
|
|||
}; // namespace pEp
|
|||
|
|||
#endif // LIBPEPADAPTER_FW_DIST_TEST_HH
|
@ -0,0 +1,40 @@ |
|||
#include "fw_dist_test.hh" |
|||
#include "../../framework/utils.hh" |
|||
|
|||
#include <iostream> |
|||
|
|||
using namespace std; |
|||
using namespace pEp; |
|||
|
|||
Test::DistTest test_fw; |
|||
|
|||
|
|||
void alice_main() |
|||
{ |
|||
cout << "HYA FROM ALICE" << endl; |
|||
while (true) { |
|||
cout << "1" << endl; |
|||
sleep_millis(1000); |
|||
} |
|||
} |
|||
|
|||
void bob_main() |
|||
{ |
|||
cout << "HYA FROM BOB" << endl; |
|||
while (true) { |
|||
cout << "2" << endl; |
|||
sleep_millis(1000); |
|||
} |
|||
} |
|||
|
|||
|
|||
int main(int argc, char* argv[]) |
|||
{ |
|||
test_fw.mode = Test::DistTest::TestMode::ALICE_BOB; |
|||
test_fw.alice_main = &::alice_main; |
|||
test_fw.bob_main = &::bob_main; |
|||
test_fw.run(); |
|||
|
|||
|
|||
cout << "HDUFGD" << endl; |
|||
} |
Loading…
Reference in new issue