diff options
Diffstat (limited to '')
-rw-r--r-- | utils/libtest/CMakeLists.txt | 9 | ||||
-rw-r--r-- | utils/libtest/README.md | 37 | ||||
-rw-r--r-- | utils/libtest/include/libtest/all.hpp | 11 | ||||
-rw-r--r-- | utils/libtest/include/libtest/device.hpp | 22 | ||||
-rw-r--r-- | utils/libtest/src/device.cpp | 40 | ||||
-rw-r--r-- | utils/libtest/utils/CMakeLists.txt | 2 | ||||
-rw-r--r-- | utils/libtest/utils/exchange_ints.cpp | 47 |
7 files changed, 168 insertions, 0 deletions
diff --git a/utils/libtest/CMakeLists.txt b/utils/libtest/CMakeLists.txt new file mode 100644 index 0000000..8c64ba1 --- /dev/null +++ b/utils/libtest/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB_RECURSE libtest_headers "include/*.hpp") +file(GLOB libtest_sources "src/*.cpp") +add_library(libtest + ${libtest_sources} + ${libtest_headers}) +target_link_libraries(libtest libservice) +target_include_directories(libtest PUBLIC include/) + +add_subdirectory(utils) diff --git a/utils/libtest/README.md b/utils/libtest/README.md new file mode 100644 index 0000000..dae0cfe --- /dev/null +++ b/utils/libtest/README.md @@ -0,0 +1,37 @@ +# libtest + +[test](../../src/test) usage examples. + +## Usage + +### libtest.lib + +Wraps `test`'s virtual device interface using [libservice](../libservice). +Include the headers by `#include`ing `libtest/all.hpp`, which includes all the +other header files. + +### exchange_ints.exe + + Usage: exchange_ints.exe N + +Parses a given `unsigned int` and exchanges it with the value stored in +driver's memory. +Usage example (assuming `test` is already loaded): + + > exchange_ints.exe 1 + 42 + + > exchange_ints.exe 32 + 1 + + > exchange_ints.exe 100500 + 32 + +## Building + +See [Building](../README.md#building). + +## Licensing + +This project is licensed under the terms of the MIT License. +See [Licensing](../../README.md#licensing) for details. diff --git a/utils/libtest/include/libtest/all.hpp b/utils/libtest/include/libtest/all.hpp new file mode 100644 index 0000000..899fc3d --- /dev/null +++ b/utils/libtest/include/libtest/all.hpp @@ -0,0 +1,11 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include "device.hpp" diff --git a/utils/libtest/include/libtest/device.hpp b/utils/libtest/include/libtest/device.hpp new file mode 100644 index 0000000..365088d --- /dev/null +++ b/utils/libtest/include/libtest/device.hpp @@ -0,0 +1,22 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include "libservice/all.hpp" + +namespace libtest +{ + class Device : libservice::Device + { + public: + Device(); + + unsigned int exchange_ints(unsigned int) const; + }; +} diff --git a/utils/libtest/src/device.cpp b/utils/libtest/src/device.cpp new file mode 100644 index 0000000..4093c04 --- /dev/null +++ b/utils/libtest/src/device.cpp @@ -0,0 +1,40 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#include "libtest/all.hpp" + +#include "libservice/all.hpp" + +#include <Windows.h> + +namespace libtest +{ + namespace + { + const char* const device_path = "\\\\.\\test_device1"; + const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + } + + Device::Device() + : libservice::Device(libservice::Device::open(device_path)) + { } + + unsigned int Device::exchange_ints(unsigned int src) const + { + unsigned int dest; + + send_control_code( + exchange_ints_ctl_code, + &src, + sizeof(src), + &dest, + sizeof(dest)); + + return dest; + } +} diff --git a/utils/libtest/utils/CMakeLists.txt b/utils/libtest/utils/CMakeLists.txt new file mode 100644 index 0000000..9b22ab2 --- /dev/null +++ b/utils/libtest/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(exchange_ints exchange_ints.cpp) +target_link_libraries(exchange_ints libtest) diff --git a/utils/libtest/utils/exchange_ints.cpp b/utils/libtest/utils/exchange_ints.cpp new file mode 100644 index 0000000..0f54879 --- /dev/null +++ b/utils/libtest/utils/exchange_ints.cpp @@ -0,0 +1,47 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#include "libtest/all.hpp" + +#include <exception> +#include <iostream> +#include <sstream> +#include <string> + +namespace +{ + bool parse_int(unsigned int& dest, const std::string& src) + { + std::istringstream iss(src); + char c; + return iss >> dest && !iss.get(c); + } +} + +int main(int argc, char* argv[]) +{ + try + { + unsigned int src; + + if (argc != 2 || !parse_int(src, argv[1])) + { + std::cout << "Usage: " << argv[0] << " N\n"; + return 1; + } + + std::cout << libtest::Device().exchange_ints(src) << "\n"; + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + + return 0; +} |