"docs/vscode:/vscode.git/clone" did not exist on "d965808e561d3146a7109d5424c345e0f7bdd3d4"
Commit d4c02429 authored by Tijana Vukovic's avatar Tijana Vukovic
Browse files

Added simple process test

parent 767133d2
#include <iostream>
#include <string>
#include <vector>
#include <Windows.h>
#include <migraphx/errors.hpp>
int main()
{
std::vector<char> result;
HANDLE std_in = GetStdHandle(STD_INPUT_HANDLE);
HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE);
if(std_in == INVALID_HANDLE_VALUE)
MIGRAPHX_THROW("STDIN invalid handle (" + std::to_string(GetLastError()) + ")");
constexpr std::size_t BUFFER_SIZE = 1024;
DWORD bytes_read;
TCHAR buffer[BUFFER_SIZE];
for(;;)
{
BOOL status = ReadFile(std_in, buffer, BUFFER_SIZE, &bytes_read, nullptr);
if(status == FALSE or bytes_read == 0)
break;
DWORD written;
if(WriteFile(std_out, buffer, bytes_read, &written, nullptr) == FALSE)
break;
// result.insert(result.end(), buffer, buffer + bytes_read);
}
// std::cout << result.data();
return 0;
}
\ No newline at end of file
#include <Windows.h>
#include <iostream>
#include <string>
#include "test.hpp"
#include <migraphx/msgpack.hpp>
#include <migraphx/process.hpp>
#include <migraphx/filesystem.hpp>
#include <migraphx/errors.hpp>
TEST_CASE(string_data)
{
auto child_path = migraphx::fs::path{"C:/develop/AMDMIGraphX/build/bin"};
std::string string_data = "Parent string \0";
// write string data to child process
migraphx::process{"test_child.exe"}.cwd(child_path).write([&](auto writer) {
migraphx::to_msgpack(string_data, writer);
});
//// parent process read from child stdout
// std::vector<char> result;
// HANDLE std_in = GetStdHandle(STD_INPUT_HANDLE);
// if(std_in == INVALID_HANDLE_VALUE)
// MIGRAPHX_THROW("STDIN invalid handle (" + std::to_string(GetLastError()) + ")");
// constexpr std::size_t BUFFER_SIZE = 4096;
// DWORD bytes_read;
// TCHAR buffer[BUFFER_SIZE];
// for(;;)
//{
// BOOL status = ReadFile(std_in, buffer, BUFFER_SIZE, &bytes_read, nullptr);
// if(status == FALSE or bytes_read == 0)
// break;
// result.insert(result.end(), buffer, buffer + bytes_read);
//}
// EXPECT(result.data() == string_data);
}
TEST_CASE(binary_data)
{
// binary data
std::vector<char> binary_data = {'B', 'i', 'n', 'a', 'r', 'y'};
auto child_path = migraphx::fs::path{"C:/develop/AMDMIGraphX/build/bin"};
// write string data to child process
migraphx::process{"test_child.exe"}.cwd(child_path).write([&](auto writer) {
migraphx::to_msgpack(binary_data, writer);
});
//// parent process read from child stdout
// std::vector<char> result;
// HANDLE std_in = GetStdHandle(STD_INPUT_HANDLE);
// if(std_in == INVALID_HANDLE_VALUE)
// MIGRAPHX_THROW("STDIN invalid handle (" + std::to_string(GetLastError()) + ")");
// constexpr std::size_t BUFFER_SIZE = 4096;
// DWORD bytes_read;
// TCHAR buffer[BUFFER_SIZE];
// for(;;)
//{
// BOOL status = ReadFile(std_in, buffer, BUFFER_SIZE, &bytes_read, nullptr);
// if(status == FALSE or bytes_read == 0)
// break;
// result.insert(result.end(), buffer, buffer + bytes_read);
//}
// EXPECT(result.data() == string_data);
}
int main(int argc, const char* argv[]) { test::run(argc, argv); }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment