1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add std:: for <cstdint> types

This commit is contained in:
bolero-MURAKAMI 2014-03-26 11:57:33 +09:00
parent 5baa0580d8
commit 11a96da4bb
9 changed files with 442 additions and 438 deletions

View file

@ -1 +1 @@
subdirs( test )
subdirs( test )

View file

@ -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 )

View file

@ -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 <sprout/net/endian.hpp>
#include <testspr/tools.hpp>
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 <testspr/include_main.hpp>
#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 <cstdint>
#include <sprout/net/endian.hpp>
#include <testspr/tools.hpp>
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 <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP

View file

@ -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 <sprout/config.hpp>
#include <sprout/net/endian.hpp>
#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 <sprout/config.hpp>
#include <sprout/net/endian.hpp>
#endif // #ifndef SPROUT_NET_HPP

View file

@ -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 <cstdint>
#include <sprout/config.hpp>
#include <boost/detail/endian.hpp>
namespace sprout {
namespace net {
namespace detail {
/*
* lshift_by
* Left shift 'val' by 'n' bytes
*/
template<typename T>
SPROUT_CONSTEXPR T lshift_by(T val, uint_fast8_t n) {
return val << (n * 8);
}
/*
* rshift_by
* Right shift 'val' by 'n' bytes
*/
template<typename T>
SPROUT_CONSTEXPR T rshift_by(T val, uint_fast8_t n) {
return val >> (n * 8);
}
/*
* mask_t
* Mask 'n'th byte
*/
template<typename T>
SPROUT_CONSTEXPR T mask_at(uint_fast8_t n) {
return lshift_by(T(0xFF), n);
}
/*
* byte_at
* Get 'n'th byte from 'val'
*/
template<typename T>
SPROUT_CONSTEXPR T byte_at(T val, uint_fast8_t n) {
return rshift_by((val & mask_at<T>(n)), n);
}
/*
* replace_at
* Replace, in 'val', 'n'th byte with 'byte_val'
*/
template<typename T>
SPROUT_CONSTEXPR T replace_at(T val, uint8_t byte_val, uint_fast8_t n) {
return (val & ~mask_at<T>(n)) | lshift_by(T(byte_val), n);
}
/*
* copy
* Copy, in 'val', byte at index 'from' to byte at index 'to'
*/
template<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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 <cstdint>
#include <sprout/config.hpp>
#include <boost/detail/endian.hpp>
namespace sprout {
namespace net {
namespace detail {
/*
* lshift_by
* Left shift 'val' by 'n' bytes
*/
template<typename T>
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<typename T>
SPROUT_CONSTEXPR T rshift_by(T val, std::uint_fast8_t n) {
return val >> (n * 8);
}
/*
* mask_t
* Mask 'n'th byte
*/
template<typename T>
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<typename T>
SPROUT_CONSTEXPR T byte_at(T val, std::uint_fast8_t n) {
return rshift_by((val & mask_at<T>(n)), n);
}
/*
* replace_at
* Replace, in 'val', 'n'th byte with 'byte_val'
*/
template<typename T>
SPROUT_CONSTEXPR T replace_at(T val, std::uint8_t byte_val, std::uint_fast8_t n) {
return (val & ~mask_at<T>(n)) | lshift_by(T(byte_val), n);
}
/*
* copy
* Copy, in 'val', byte at index 'from' to byte at index 'to'
*/
template<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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<typename T>
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

View file

@ -46,6 +46,7 @@
#include <sprout/limits.hpp>
#include <sprout/logic.hpp>
#include <sprout/math.hpp>
#include <sprout/net.hpp>
#include <sprout/none.hpp>
#include <sprout/numeric.hpp>
#include <sprout/numeric/dft.hpp>

View file

@ -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

View file

@ -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())

View file

@ -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())