From 11a96da4bb6468df30347580ac01315810a6a343 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 26 Mar 2014 11:57:33 +0900 Subject: [PATCH] add std:: for types --- libs/net/CMakeLists.txt | 2 +- libs/net/test/CMakeLists.txt | 6 +- libs/net/test/endian.cpp | 97 +++++----- sprout/net.hpp | 34 ++-- sprout/net/endian.hpp | 350 +++++++++++++++++------------------ testspr/header_all.hpp | 1 + testspr/sprout.cpp | 2 + tools/darkroom/darkcult.py | 242 ++++++++++++------------ tools/testspr/test.py | 146 +++++++-------- 9 files changed, 442 insertions(+), 438 deletions(-) diff --git a/libs/net/CMakeLists.txt b/libs/net/CMakeLists.txt index a32dcf20..cd727de1 100644 --- a/libs/net/CMakeLists.txt +++ b/libs/net/CMakeLists.txt @@ -1 +1 @@ -subdirs( test ) +subdirs( test ) diff --git a/libs/net/test/CMakeLists.txt b/libs/net/test/CMakeLists.txt index e072a131..a87a042f 100644 --- a/libs/net/test/CMakeLists.txt +++ b/libs/net/test/CMakeLists.txt @@ -1,3 +1,3 @@ -add_executable( libs_net_test_endian endian.cpp ) -set_target_properties( libs_net_test_endian PROPERTIES OUTPUT_NAME "endian" ) -add_test( libs_net_test_endian endian ) +add_executable( libs_net_test_endian endian.cpp ) +set_target_properties( libs_net_test_endian PROPERTIES OUTPUT_NAME "endian" ) +add_test( libs_net_test_endian endian ) diff --git a/libs/net/test/endian.cpp b/libs/net/test/endian.cpp index b73df5f6..1d23151f 100644 --- a/libs/net/test/endian.cpp +++ b/libs/net/test/endian.cpp @@ -1,49 +1,50 @@ -/*============================================================================= - Copyright (c) 2011-2014 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Copyright (c) 2014 Chris KAY - https://github.com/cjkay-cpp-utils/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP -#define SPROUT_LIBS_NET_TEST_ENDIAN_CPP - -#include -#include - -namespace testspr { - static void endian_test() { - using namespace sprout; - - { // 16 - TESTSPR_ASSERT(sprout::net::detail::reverse(uint16_t(0x0A1B)) == uint16_t(0x1B0A)); - TESTSPR_ASSERT(sprout::net::detail::reverse(uint16_t(0x1B0A)) == uint16_t(0x0A1B)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint16_t(0x0A1B)) == uint16_t(0x1B0A)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint16_t(0x1B0A)) == uint16_t(0x0A1B)); - } - - { // 32 - TESTSPR_ASSERT(sprout::net::detail::reverse(uint32_t(0x0A1B2C3D)) == uint32_t(0x3D2C1B0A)); - TESTSPR_ASSERT(sprout::net::detail::reverse(uint32_t(0x3D2C1B0A)) == uint32_t(0x0A1B2C3D)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint32_t(0x0A1B2C3D)) == uint32_t(0x1B0A3D2C)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint32_t(0x1B0A3D2C)) == uint32_t(0x0A1B2C3D)); - } - - { // 64 - TESTSPR_ASSERT(sprout::net::detail::reverse(uint64_t(0x0A1B2C3D4E5F6A7B)) == uint64_t(0x7B6A5F4E3D2C1B0A)); - TESTSPR_ASSERT(sprout::net::detail::reverse(uint64_t(0x7B6A5F4E3D2C1B0A)) == uint64_t(0x0A1B2C3D4E5F6A7B)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint64_t(0x0A1B2C3D4E5F6A7B)) == uint64_t(0x1B0A3D2C5F4E7B6A)); - TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint64_t(0x1B0A3D2C5F4E7B6A)) == uint64_t(0x0A1B2C3D4E5F6A7B)); - } - } -} // namespace testspr - -#ifndef TESTSPR_CPP_INCLUDE -# define TESTSPR_TEST_FUNCTION testspr::endian_test -# include -#endif - +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Copyright (c) 2014 Chris KAY + https://github.com/cjkay-cpp-utils/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP +#define SPROUT_LIBS_NET_TEST_ENDIAN_CPP + +#include +#include +#include + +namespace testspr { + static void endian_test() { + using namespace sprout; + + { // 16 + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A)); + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B)); + } + + { // 32 + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x3D2C1B0A)); + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x3D2C1B0A)) == std::uint32_t(0x0A1B2C3D)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x1B0A3D2C)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x1B0A3D2C)) == std::uint32_t(0x0A1B2C3D)); + } + + { // 64 + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x7B6A5F4E3D2C1B0A)); + TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x7B6A5F4E3D2C1B0A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x1B0A3D2C5F4E7B6A)); + TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x1B0A3D2C5F4E7B6A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B)); + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::endian_test +# include +#endif + #endif // #ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP \ No newline at end of file diff --git a/sprout/net.hpp b/sprout/net.hpp index 8775d032..115b6c15 100644 --- a/sprout/net.hpp +++ b/sprout/net.hpp @@ -1,17 +1,17 @@ -/*============================================================================= - Copyright (c) 2011-2014 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Copyright (c) 2014 Chris KAY - https://github.com/cjkay-cpp-utils/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_NET_HPP -#define SPROUT_NET_HPP - -#include -#include - -#endif // #ifndef SPROUT_NET_HPP +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Copyright (c) 2014 Chris KAY + https://github.com/cjkay-cpp-utils/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NET_HPP +#define SPROUT_NET_HPP + +#include +#include + +#endif // #ifndef SPROUT_NET_HPP diff --git a/sprout/net/endian.hpp b/sprout/net/endian.hpp index 5e1d1e6f..f5158d0a 100644 --- a/sprout/net/endian.hpp +++ b/sprout/net/endian.hpp @@ -1,175 +1,175 @@ -/*============================================================================= - Copyright (c) 2011-2014 Bolero MURAKAMI - https://github.com/bolero-MURAKAMI/Sprout - - Copyright (c) 2014 Chris KAY - https://github.com/cjkay-cpp-utils/Sprout - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ -#ifndef SPROUT_NET_NET_HPP -#define SPROUT_NET_NET_HPP - -#include -#include -#include - -namespace sprout { - namespace net { - namespace detail { - /* - * lshift_by - * Left shift 'val' by 'n' bytes - */ - template - SPROUT_CONSTEXPR T lshift_by(T val, uint_fast8_t n) { - return val << (n * 8); - } - - /* - * rshift_by - * Right shift 'val' by 'n' bytes - */ - template - SPROUT_CONSTEXPR T rshift_by(T val, uint_fast8_t n) { - return val >> (n * 8); - } - - /* - * mask_t - * Mask 'n'th byte - */ - template - SPROUT_CONSTEXPR T mask_at(uint_fast8_t n) { - return lshift_by(T(0xFF), n); - } - - /* - * byte_at - * Get 'n'th byte from 'val' - */ - template - SPROUT_CONSTEXPR T byte_at(T val, uint_fast8_t n) { - return rshift_by((val & mask_at(n)), n); - } - - /* - * replace_at - * Replace, in 'val', 'n'th byte with 'byte_val' - */ - template - SPROUT_CONSTEXPR T replace_at(T val, uint8_t byte_val, uint_fast8_t n) { - return (val & ~mask_at(n)) | lshift_by(T(byte_val), n); - } - - /* - * copy - * Copy, in 'val', byte at index 'from' to byte at index 'to' - */ - template - SPROUT_CONSTEXPR T copy(T val, uint_fast8_t from, uint_fast8_t to) { - return replace_at(val, byte_at(val, from), to); - } - - /* - * swap - * Swap, in 'val', byte at index 'n1' with byte at index 'n2' - */ - template - SPROUT_CONSTEXPR T swap(T val, uint_fast8_t n1, uint_fast8_t n2) { - return replace_at(copy(val, n1, n2), byte_at(val, n2), n1); - } - - /* - * reverse_impl - * Swap, in 'val', byte at index 'n1' with byte at index 'n2' in 'val', increment n1, decrement n2 until n1 > n2 - */ - template - SPROUT_CONSTEXPR T reverse_impl(T val, uint_fast8_t n1, uint_fast8_t n2) { - return n1 > n2 ? val : reverse_impl(swap(val, n1, n2), n1 + 1, n2 - 1); - } - - /* - * reverse - * Reverse 'val' - */ - template - SPROUT_CONSTEXPR T reverse(T val) { - return reverse_impl(val, 0, sizeof(T) - 1); - } - - /* - * reverse_words_impl - * Swap, in 'val', byte at index 'n' - 1 with byte at index 'n' - 2, decrement n by 2 until n == 0 - */ - template - SPROUT_CONSTEXPR T reverse_words_impl(T val, uint_fast8_t n) { - return n == 0 ? val : reverse_words_impl(swap(val, n - 1, n - 2), n - 2); - } - - /* - * reverse_words - * Reverse each word in 'val' - */ - template - SPROUT_CONSTEXPR T reverse_words(T val) { - return reverse_words_impl(val, sizeof(T)); - } - } // namespace detail - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // template<> - // constexpr unsigned-integral hton(unsigned-integral host) - template - SPROUT_CONSTEXPR T hton(T host) { -#if defined(BOOST_BIG_ENDIAN) - return host; -#elif defined(BOOST_LITTLE_ENDIAN) - return detail::reverse(host); -#elif defined(BOOST_PDP_ENDIAN) - return detail::reverse_words(host); -#endif - } - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // template<> - // constexpr unsigned-integral ntoh(unsigned-integral net) - template - SPROUT_CONSTEXPR T ntoh(T net) { -#if defined(BOOST_BIG_ENDIAN) - return net; -#elif defined(BOOST_LITTLE_ENDIAN) - return detail::reverse(net); -#elif defined(BOOST_PDP_ENDIAN) - return detail::reverse_words(host); -#endif - } - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // uint32_t htonl(uint32_t host32) - SPROUT_CONSTEXPR uint32_t htonl(uint32_t host32) { - return hton(host32); - } - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // uint16_t htons(uint16_t host16) - SPROUT_CONSTEXPR uint16_t htons(uint16_t host16) { - return hton(host16); - } - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // uint32_t ntohl(uint32_t net32) - SPROUT_CONSTEXPR uint32_t ntohl(uint32_t net32) { - return ntoh(net32); - } - - // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf - // uint16_t ntohs(uint32_t net16) - SPROUT_CONSTEXPR uint16_t ntohs(uint16_t net16) { - return ntoh(net16); - } - } //namespace net -} // namespace sprout - -#endif // #ifndef SPROUT_NET_NET_HPP +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Copyright (c) 2014 Chris KAY + https://github.com/cjkay-cpp-utils/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_NET_ENDIAN_HPP +#define SPROUT_NET_ENDIAN_HPP + +#include +#include +#include + +namespace sprout { + namespace net { + namespace detail { + /* + * lshift_by + * Left shift 'val' by 'n' bytes + */ + template + SPROUT_CONSTEXPR T lshift_by(T val, std::uint_fast8_t n) { + return val << (n * 8); + } + + /* + * rshift_by + * Right shift 'val' by 'n' bytes + */ + template + SPROUT_CONSTEXPR T rshift_by(T val, std::uint_fast8_t n) { + return val >> (n * 8); + } + + /* + * mask_t + * Mask 'n'th byte + */ + template + SPROUT_CONSTEXPR T mask_at(std::uint_fast8_t n) { + return lshift_by(T(0xFF), n); + } + + /* + * byte_at + * Get 'n'th byte from 'val' + */ + template + SPROUT_CONSTEXPR T byte_at(T val, std::uint_fast8_t n) { + return rshift_by((val & mask_at(n)), n); + } + + /* + * replace_at + * Replace, in 'val', 'n'th byte with 'byte_val' + */ + template + SPROUT_CONSTEXPR T replace_at(T val, std::uint8_t byte_val, std::uint_fast8_t n) { + return (val & ~mask_at(n)) | lshift_by(T(byte_val), n); + } + + /* + * copy + * Copy, in 'val', byte at index 'from' to byte at index 'to' + */ + template + SPROUT_CONSTEXPR T copy(T val, std::uint_fast8_t from, std::uint_fast8_t to) { + return replace_at(val, byte_at(val, from), to); + } + + /* + * swap + * Swap, in 'val', byte at index 'n1' with byte at index 'n2' + */ + template + SPROUT_CONSTEXPR T swap(T val, std::uint_fast8_t n1, std::uint_fast8_t n2) { + return replace_at(copy(val, n1, n2), byte_at(val, n2), n1); + } + + /* + * reverse_impl + * Swap, in 'val', byte at index 'n1' with byte at index 'n2' in 'val', increment n1, decrement n2 until n1 > n2 + */ + template + SPROUT_CONSTEXPR T reverse_impl(T val, std::uint_fast8_t n1, std::uint_fast8_t n2) { + return n1 > n2 ? val : reverse_impl(swap(val, n1, n2), n1 + 1, n2 - 1); + } + + /* + * reverse + * Reverse 'val' + */ + template + SPROUT_CONSTEXPR T reverse(T val) { + return reverse_impl(val, 0, sizeof(T) - 1); + } + + /* + * reverse_words_impl + * Swap, in 'val', byte at index 'n' - 1 with byte at index 'n' - 2, decrement n by 2 until n == 0 + */ + template + SPROUT_CONSTEXPR T reverse_words_impl(T val, std::uint_fast8_t n) { + return n == 0 ? val : reverse_words_impl(swap(val, n - 1, n - 2), n - 2); + } + + /* + * reverse_words + * Reverse each word in 'val' + */ + template + SPROUT_CONSTEXPR T reverse_words(T val) { + return reverse_words_impl(val, sizeof(T)); + } + } // namespace detail + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // template<> + // constexpr unsigned-integral hton(unsigned-integral host) + template + SPROUT_CONSTEXPR T hton(T host) { +#if defined(BOOST_BIG_ENDIAN) + return host; +#elif defined(BOOST_LITTLE_ENDIAN) + return detail::reverse(host); +#elif defined(BOOST_PDP_ENDIAN) + return detail::reverse_words(host); +#endif + } + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // template<> + // constexpr unsigned-integral ntoh(unsigned-integral net) + template + SPROUT_CONSTEXPR T ntoh(T net) { +#if defined(BOOST_BIG_ENDIAN) + return net; +#elif defined(BOOST_LITTLE_ENDIAN) + return detail::reverse(net); +#elif defined(BOOST_PDP_ENDIAN) + return detail::reverse_words(host); +#endif + } + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // uint32_t htonl(uint32_t host32) + SPROUT_CONSTEXPR std::uint32_t htonl(std::uint32_t host32) { + return hton(host32); + } + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // uint16_t htons(uint16_t host16) + SPROUT_CONSTEXPR std::uint16_t htons(std::uint16_t host16) { + return hton(host16); + } + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // uint32_t ntohl(uint32_t net32) + SPROUT_CONSTEXPR std::uint32_t ntohl(std::uint32_t net32) { + return ntoh(net32); + } + + // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf + // uint16_t ntohs(uint32_t net16) + SPROUT_CONSTEXPR std::uint16_t ntohs(std::uint16_t net16) { + return ntoh(net16); + } + } //namespace net +} // namespace sprout + +#endif // #ifndef SPROUT_NET_ENDIAN_HPP diff --git a/testspr/header_all.hpp b/testspr/header_all.hpp index 29cfd635..c8881083 100644 --- a/testspr/header_all.hpp +++ b/testspr/header_all.hpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp index 1ca307e8..eb38bc49 100644 --- a/testspr/sprout.cpp +++ b/testspr/sprout.cpp @@ -23,6 +23,7 @@ #include "../libs/random/test/random.cpp" #include "../libs/utility/string_ref/test/string_ref.cpp" #include "../libs/cstring/test/cstring.cpp" +#include "../libs/net/test/endian.cpp" #ifdef TESTSPR_CPP_INCLUDE_DISABLE_TESTSPR_SPROUT_HPP # undef TESTSPR_CPP_INCLUDE @@ -40,6 +41,7 @@ namespace testspr { testspr::random_test(); testspr::string_ref_test(); testspr::cstring_test(); + testspr::endian_test(); } } // namespace testspr diff --git a/tools/darkroom/darkcult.py b/tools/darkroom/darkcult.py index 6d57c852..100a02e9 100755 --- a/tools/darkroom/darkcult.py +++ b/tools/darkroom/darkcult.py @@ -1,121 +1,121 @@ -#!/usr/bin/env python -# ============================================================================= -# Copyright (c) 2011-2014 Bolero MURAKAMI -# https://github.com/bolero-MURAKAMI/Sprout -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# ============================================================================= -import sys -import optparse -import subprocess -import multiprocessing -import logging -import tty - -def build(command): - sys.stdout.write(".") - sys.stdout.flush() - return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - -def continue_build(command): - if command[2]: - sys.stdout.write("*") - sys.stdout.flush() - return 0 - sys.stdout.write(".") - sys.stdout.flush() - result = subprocess.call(command[0], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - if not result: - logging.critical(command[1]) - return result - -def main(): - parser = optparse.OptionParser(description='darkcult.py') - parser.add_option('--source', type='string', default='../../example/darkroom/two_spheres.hpp') - parser.add_option('--stagedir', type='string', default='darkroom') - parser.add_option('--output', type='string', default='out.ppm') - parser.add_option('--compiler', type='string', default='g++') - parser.add_option('--width', type='int', default=16) - parser.add_option('--height', type='int', default=16) - parser.add_option('--tile_width', type='int', default=16) - parser.add_option('--tile_height', type='int', default=16) - parser.add_option('--left', type='int', default=0) - parser.add_option('--top', type='int', default=0) - parser.add_option('--right', type='int') - parser.add_option('--bottom', type='int') - parser.add_option('--compile_options', type='string', default='') - parser.add_option('--darkcult_cpp', type='string') - parser.add_option('--continuable', type='int', default=0) - parser.add_option('--continue_file', type='string', default='continue.log') - parser.add_option('--max_procs', type='int', default=0) - (opts, args) = parser.parse_args() - - def format_command(x, y): - bin = "%s/%d/%d.out" % (opts.stagedir, y, x) - out = "%s/%d/%d.ppm" % (opts.stagedir, y, x) - return "%s -o %s" \ - " %s" \ - " -DDARKROOM_SOURCE=\'\"%s\"\'" \ - " -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \ - " -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \ - " -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \ - " %s" \ - " && %s > %s" \ - % (opts.compiler, bin, - opts.compile_options, - opts.source, - opts.width, opts.height, - opts.tile_width, opts.tile_height, - x, y, - opts.darkcult_cpp, - bin, out - ) - - if opts.continuable: - logging.basicConfig( - filename=opts.continue_file, - format="%(message)s" - ) - completed = [line.strip() for line in open(opts.continue_file)] - - fd = sys.stdin.fileno() - tc_old = tty.tcgetattr(fd) - tty.setcbreak(fd) - - def format_continue_command(x, y): - key = "%d %d" % (x, y) - return (format_command(x, y), key, key in completed) - - pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) - try: - results = pool.map_async( - continue_build, - [format_continue_command(x, y) - for y in range(opts.top, opts.bottom, opts.tile_height) - for x in range(opts.left, opts.right, opts.tile_width) - ] - ) - while True: - code = sys.stdin.read(1) - if results.ready(): - break - if code == 'q': - pool.terminate() - return 2 - return any(results.get()) - finally: - tty.tcsetattr(fd, tty.TCSADRAIN, tc_old) - logging.shutdown() - else: - pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) - return any(pool.map( - build, - [format_command(x, y) - for y in range(opts.top, opts.bottom, opts.tile_height) - for x in range(opts.left, opts.right, opts.tile_width) - ] - )) - -if __name__ == "__main__": - sys.exit(main()) +#!/usr/bin/env python +# ============================================================================= +# Copyright (c) 2011-2014 Bolero MURAKAMI +# https://github.com/bolero-MURAKAMI/Sprout +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# ============================================================================= +import sys +import optparse +import subprocess +import multiprocessing +import logging +import tty + +def build(command): + sys.stdout.write(".") + sys.stdout.flush() + return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + +def continue_build(command): + if command[2]: + sys.stdout.write("*") + sys.stdout.flush() + return 0 + sys.stdout.write(".") + sys.stdout.flush() + result = subprocess.call(command[0], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + if not result: + logging.critical(command[1]) + return result + +def main(): + parser = optparse.OptionParser(description='darkcult.py') + parser.add_option('--source', type='string', default='../../example/darkroom/two_spheres.hpp') + parser.add_option('--stagedir', type='string', default='darkroom') + parser.add_option('--output', type='string', default='out.ppm') + parser.add_option('--compiler', type='string', default='g++') + parser.add_option('--width', type='int', default=16) + parser.add_option('--height', type='int', default=16) + parser.add_option('--tile_width', type='int', default=16) + parser.add_option('--tile_height', type='int', default=16) + parser.add_option('--left', type='int', default=0) + parser.add_option('--top', type='int', default=0) + parser.add_option('--right', type='int') + parser.add_option('--bottom', type='int') + parser.add_option('--compile_options', type='string', default='') + parser.add_option('--darkcult_cpp', type='string') + parser.add_option('--continuable', type='int', default=0) + parser.add_option('--continue_file', type='string', default='continue.log') + parser.add_option('--max_procs', type='int', default=0) + (opts, args) = parser.parse_args() + + def format_command(x, y): + bin = "%s/%d/%d.out" % (opts.stagedir, y, x) + out = "%s/%d/%d.ppm" % (opts.stagedir, y, x) + return "%s -o %s" \ + " %s" \ + " -DDARKROOM_SOURCE=\'\"%s\"\'" \ + " -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \ + " -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \ + " -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \ + " %s" \ + " && %s > %s" \ + % (opts.compiler, bin, + opts.compile_options, + opts.source, + opts.width, opts.height, + opts.tile_width, opts.tile_height, + x, y, + opts.darkcult_cpp, + bin, out + ) + + if opts.continuable: + logging.basicConfig( + filename=opts.continue_file, + format="%(message)s" + ) + completed = [line.strip() for line in open(opts.continue_file)] + + fd = sys.stdin.fileno() + tc_old = tty.tcgetattr(fd) + tty.setcbreak(fd) + + def format_continue_command(x, y): + key = "%d %d" % (x, y) + return (format_command(x, y), key, key in completed) + + pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) + try: + results = pool.map_async( + continue_build, + [format_continue_command(x, y) + for y in range(opts.top, opts.bottom, opts.tile_height) + for x in range(opts.left, opts.right, opts.tile_width) + ] + ) + while True: + code = sys.stdin.read(1) + if results.ready(): + break + if code == 'q': + pool.terminate() + return 2 + return any(results.get()) + finally: + tty.tcsetattr(fd, tty.TCSADRAIN, tc_old) + logging.shutdown() + else: + pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) + return any(pool.map( + build, + [format_command(x, y) + for y in range(opts.top, opts.bottom, opts.tile_height) + for x in range(opts.left, opts.right, opts.tile_width) + ] + )) + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/testspr/test.py b/tools/testspr/test.py index 47fd4160..67c69909 100644 --- a/tools/testspr/test.py +++ b/tools/testspr/test.py @@ -1,73 +1,73 @@ -#!/usr/bin/env python -# ============================================================================= -# Copyright (c) 2011-2014 Bolero MURAKAMI -# https://github.com/bolero-MURAKAMI/Sprout -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# ============================================================================= -import sys -import optparse -import subprocess -import multiprocessing - -def build(command): - sys.stdout.write(".") - sys.stdout.flush() - return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - -def main(): - parser = optparse.OptionParser(description='test.py') - parser.add_option('--stagedir', type='string', default='testspr') - parser.add_option('--gcc_version', type='string', default='.') - parser.add_option('--clang_version', type='string', default='.') - parser.add_option('--gcc_root', type='string', default='/usr/local') - parser.add_option('--clang_root', type='string', default='/usr/local') - parser.add_option('--all_options', type='string', default='') - parser.add_option('--test_cpp', type='string') - parser.add_option('--serialized_std_options', type='string', default='{}') - parser.add_option('--serialized_compiler_specific_options', type='string', default='{}') - parser.add_option('--serialized_version_specific_options', type='string', default='{}') - parser.add_option('--max_procs', type='int', default=0) - (opts, args) = parser.parse_args() - - std_options = eval(opts.serialized_std_options) - version_specific_options = eval(opts.serialized_version_specific_options) - compiler_specific_options = eval(opts.serialized_compiler_specific_options) - - def format_command(name, version, root): - base = "%s-%s" % (name, version) if version != "." else name - bin = "%s/test.%s.out" % (opts.stagedir, base.replace('.', '')) - compile_log = "%s/test.%s.compile.log" % (opts.stagedir, base.replace('.', '')) - execute_log = "%s/test.%s.execute.log" % (opts.stagedir, base.replace('.', '')) - compiler = "%s/%s/bin/%s++" % (root, base, name.rstrip('c')) if version != "." else "%s++" % name.rstrip('c') - return "%s -o %s" \ - " %s %s" \ - " %s %s" \ - " %s > %s 2>&1" \ - " && %s > %s 2>&1" \ - % (compiler, bin, - std_options.get(base, ''), opts.all_options, - compiler_specific_options.get(name, ''), version_specific_options.get(base, ''), - opts.test_cpp, compile_log, - bin, execute_log - ) - - pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) - return sum(result != 0 for result in pool.map( - build, - ([format_command('gcc', version, opts.gcc_root) - for version in opts.gcc_version.split(' ') - ] if opts.gcc_version != ' ' - else [] - ) - + - ([format_command('clang', version, opts.clang_root) - for version in opts.clang_version.split(' ') - ] if opts.clang_version != ' ' - else [] - ) - )) - -if __name__ == "__main__": - sys.exit(main()) +#!/usr/bin/env python +# ============================================================================= +# Copyright (c) 2011-2014 Bolero MURAKAMI +# https://github.com/bolero-MURAKAMI/Sprout +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# ============================================================================= +import sys +import optparse +import subprocess +import multiprocessing + +def build(command): + sys.stdout.write(".") + sys.stdout.flush() + return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + +def main(): + parser = optparse.OptionParser(description='test.py') + parser.add_option('--stagedir', type='string', default='testspr') + parser.add_option('--gcc_version', type='string', default='.') + parser.add_option('--clang_version', type='string', default='.') + parser.add_option('--gcc_root', type='string', default='/usr/local') + parser.add_option('--clang_root', type='string', default='/usr/local') + parser.add_option('--all_options', type='string', default='') + parser.add_option('--test_cpp', type='string') + parser.add_option('--serialized_std_options', type='string', default='{}') + parser.add_option('--serialized_compiler_specific_options', type='string', default='{}') + parser.add_option('--serialized_version_specific_options', type='string', default='{}') + parser.add_option('--max_procs', type='int', default=0) + (opts, args) = parser.parse_args() + + std_options = eval(opts.serialized_std_options) + version_specific_options = eval(opts.serialized_version_specific_options) + compiler_specific_options = eval(opts.serialized_compiler_specific_options) + + def format_command(name, version, root): + base = "%s-%s" % (name, version) if version != "." else name + bin = "%s/test.%s.out" % (opts.stagedir, base.replace('.', '')) + compile_log = "%s/test.%s.compile.log" % (opts.stagedir, base.replace('.', '')) + execute_log = "%s/test.%s.execute.log" % (opts.stagedir, base.replace('.', '')) + compiler = "%s/%s/bin/%s++" % (root, base, name.rstrip('c')) if version != "." else "%s++" % name.rstrip('c') + return "%s -o %s" \ + " %s %s" \ + " %s %s" \ + " %s > %s 2>&1" \ + " && %s > %s 2>&1" \ + % (compiler, bin, + std_options.get(base, ''), opts.all_options, + compiler_specific_options.get(name, ''), version_specific_options.get(base, ''), + opts.test_cpp, compile_log, + bin, execute_log + ) + + pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None) + return sum(result != 0 for result in pool.map( + build, + ([format_command('gcc', version, opts.gcc_root) + for version in opts.gcc_version.split(' ') + ] if opts.gcc_version != ' ' + else [] + ) + + + ([format_command('clang', version, opts.clang_root) + for version in opts.clang_version.split(' ') + ] if opts.clang_version != ' ' + else [] + ) + )) + +if __name__ == "__main__": + sys.exit(main())