mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Windows pipe for soltest
This commit is contained in:
parent
a10b6f92f9
commit
5925ae0c6a
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx
|
||||||
*/
|
*/
|
||||||
/** @file RPCSession.cpp
|
/** @file RPCSession.cpp
|
||||||
* @author Dimtiry Khokhlov <dimitry@ethdev.com>
|
* @author Dimtiry Khokhlov <dimitry@ethdev.com>
|
||||||
@ -32,6 +34,19 @@ using namespace dev;
|
|||||||
|
|
||||||
IPCSocket::IPCSocket(string const& _path): m_path(_path)
|
IPCSocket::IPCSocket(string const& _path): m_path(_path)
|
||||||
{
|
{
|
||||||
|
m_socket = CreateFile(
|
||||||
|
m_path.c_str(), // pipe name
|
||||||
|
GENERIC_READ | // read and write access
|
||||||
|
GENERIC_WRITE,
|
||||||
|
0, // no sharing
|
||||||
|
NULL, // default security attribute
|
||||||
|
OPEN_EXISTING, // opens existing pipe
|
||||||
|
0, // default attributes
|
||||||
|
NULL); // no template file
|
||||||
|
|
||||||
|
if (m_socket == INVALID_HANDLE_VALUE)
|
||||||
|
BOOST_FAIL("Error creating IPC socket object");
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#else
|
#else
|
||||||
if (_path.length() >= sizeof(sockaddr_un::sun_path))
|
if (_path.length() >= sizeof(sockaddr_un::sun_path))
|
||||||
@ -66,7 +81,36 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path)
|
|||||||
string IPCSocket::sendRequest(string const& _req)
|
string IPCSocket::sendRequest(string const& _req)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return "";
|
string returnStr;
|
||||||
|
DWORD cbWritten;
|
||||||
|
BOOL fSuccess = WriteFile(
|
||||||
|
m_socket, // pipe handle
|
||||||
|
_req.c_str(), // message
|
||||||
|
_req.size(), // message length
|
||||||
|
&cbWritten, // bytes written
|
||||||
|
NULL); // not overlapped
|
||||||
|
|
||||||
|
if (!fSuccess)
|
||||||
|
BOOST_FAIL("WriteFile to pipe failed");
|
||||||
|
|
||||||
|
DWORD cbRead;
|
||||||
|
TCHAR chBuf[c_buffsize];
|
||||||
|
|
||||||
|
// Read from the pipe.
|
||||||
|
fSuccess = ReadFile(
|
||||||
|
m_socket, // pipe handle
|
||||||
|
chBuf, // buffer to receive reply
|
||||||
|
c_buffsize,// size of buffer
|
||||||
|
&cbRead, // number of bytes read
|
||||||
|
NULL); // not overlapped
|
||||||
|
|
||||||
|
returnStr += chBuf;
|
||||||
|
|
||||||
|
if (!fSuccess)
|
||||||
|
BOOST_FAIL("ReadFile from pipe failed");
|
||||||
|
|
||||||
|
cerr << "."; //Output for log activity
|
||||||
|
return returnStr;
|
||||||
#else
|
#else
|
||||||
send(m_socket, _req.c_str(), _req.length(), 0);
|
send(m_socket, _req.c_str(), _req.length(), 0);
|
||||||
|
|
||||||
|
@ -19,33 +19,35 @@
|
|||||||
* @date 2016
|
* @date 2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <map>
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#include "libdevcore/UndefMacros.h"
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <map>
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
const int c_buffsize = 5120000; //because windows pipe is broken and wont work as in examples. use larger buffer limit to receive whole package in one call
|
||||||
class IPCSocket : public boost::noncopyable
|
class IPCSocket : public boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IPCSocket(std::string const& _path);
|
IPCSocket(std::string const& _path);
|
||||||
std::string sendRequest(std::string const& _req);
|
std::string sendRequest(std::string const& _req);
|
||||||
~IPCSocket() { fclose(m_fp); }
|
~IPCSocket() { CloseHandle(m_socket); }
|
||||||
|
|
||||||
std::string const& path() const { return m_path; }
|
std::string const& path() const { return m_path; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE *m_fp;
|
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
int m_socket;
|
HANDLE m_socket;
|
||||||
|
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
class IPCSocket: public boost::noncopyable
|
class IPCSocket: public boost::noncopyable
|
||||||
@ -61,7 +63,6 @@ private:
|
|||||||
FILE *m_fp;
|
FILE *m_fp;
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
int m_socket;
|
int m_socket;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
51
test/TestHelper.cpp
Normal file
51
test/TestHelper.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
This file is part of cpp-ethereum.
|
||||||
|
|
||||||
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
cpp-ethereum is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/** @file TestHelper.h
|
||||||
|
* @author Marko Simovic <markobarko@gmail.com>
|
||||||
|
* @date 2014
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <boost/test/framework.hpp>
|
||||||
|
#include "TestHelper.h"
|
||||||
|
using namespace std;
|
||||||
|
using namespace dev::test;
|
||||||
|
|
||||||
|
Options::Options(int argc, char** argv)
|
||||||
|
{
|
||||||
|
tArgc = 0;
|
||||||
|
tArgv = new char*[argc];
|
||||||
|
for (size_t i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
string arg = argv[i];
|
||||||
|
if (arg == "--ipc" && i + 1 < argc)
|
||||||
|
{
|
||||||
|
ipcPath = argv[i + 1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tArgv[i] = argv[i];
|
||||||
|
tArgc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Options const& Options::get(int argc, char** argv)
|
||||||
|
{
|
||||||
|
static Options instance(argc, argv);
|
||||||
|
return instance;
|
||||||
|
}
|
@ -102,5 +102,20 @@ namespace test
|
|||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
|
||||||
|
|
||||||
|
class Options
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string ipcPath;
|
||||||
|
int tArgc;
|
||||||
|
char **tArgv;
|
||||||
|
/// Get reference to options
|
||||||
|
/// The first time used, options are parsed with argc, argv
|
||||||
|
static Options const& get(int argc = 0, char** argv = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Options(int argc, char** argv = 0);
|
||||||
|
Options(Options const&) = delete;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,49 @@
|
|||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
|
|
||||||
|
|
||||||
|
#define BOOST_TEST_NO_MAIN
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
|
||||||
|
#endif
|
||||||
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <boost/version.hpp>
|
||||||
|
#include "TestHelper.h"
|
||||||
|
|
||||||
|
using namespace boost::unit_test;
|
||||||
|
|
||||||
|
std::vector<char*> parameters;
|
||||||
|
static std::ostringstream strCout;
|
||||||
|
std::streambuf* oldCoutStreamBuf;
|
||||||
|
std::streambuf* oldCerrStreamBuf;
|
||||||
|
|
||||||
|
//Custom Boost Initialization
|
||||||
|
test_suite* fake_init_func(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
//Required for boost. -nowarning
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Custom Boost Unit Test Main
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
//Initialize options before boost reads it
|
||||||
|
dev::test::Options const& opt = dev::test::Options::get(argc, argv);
|
||||||
|
return unit_test_main(fake_init_func, opt.tArgc, opt.tArgv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#else
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
|
#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
|
||||||
@ -38,4 +81,4 @@
|
|||||||
|
|
||||||
#include <test/TestHelper.h>
|
#include <test/TestHelper.h>
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
#endif*/
|
@ -25,8 +25,6 @@
|
|||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <test/libsolidity/SolidityExecutionFramework.h>
|
#include <test/libsolidity/SolidityExecutionFramework.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
@ -39,24 +37,13 @@ namespace // anonymous
|
|||||||
|
|
||||||
string getIPCSocketPath()
|
string getIPCSocketPath()
|
||||||
{
|
{
|
||||||
string ipcPath;
|
string ipcPath = dev::test::Options::get().ipcPath;
|
||||||
|
|
||||||
size_t argc = boost::unit_test::framework::master_test_suite().argc;
|
|
||||||
char** argv = boost::unit_test::framework::master_test_suite().argv;
|
|
||||||
for (size_t i = 0; i < argc; i++)
|
|
||||||
{
|
|
||||||
string arg = argv[i];
|
|
||||||
if (arg == "--ipc" && i + 1 < argc)
|
|
||||||
{
|
|
||||||
ipcPath = argv[i + 1];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ipcPath.empty())
|
if (ipcPath.empty())
|
||||||
if (auto path = getenv("ETH_TEST_IPC"))
|
if (auto path = getenv("ETH_TEST_IPC"))
|
||||||
ipcPath = path;
|
ipcPath = path;
|
||||||
if (ipcPath.empty())
|
if (ipcPath.empty())
|
||||||
BOOST_FAIL("ERROR: ipcPath not set! (use --ipc <path> or the environment variable ETH_TEST_IPC)");
|
BOOST_FAIL("ERROR: ipcPath not set! (use --ipc <path> or the environment variable ETH_TEST_IPC)");
|
||||||
|
|
||||||
return ipcPath;
|
return ipcPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user