From fbe87c1385b06b3b963b0703b190faedadce8306 Mon Sep 17 00:00:00 2001 From: Peter Vingelmann Date: Tue, 27 Sep 2016 20:37:42 +0200 Subject: [PATCH] Implement basic formatting check --- test/correct_style.cpp | 268 +++++++++++++++++++++++++++++++++++++++++ wscript | 70 ++++++++++- 2 files changed, 335 insertions(+), 3 deletions(-) create mode 100644 test/correct_style.cpp diff --git a/test/correct_style.cpp b/test/correct_style.cpp new file mode 100644 index 0000000..a374f0b --- /dev/null +++ b/test/correct_style.cpp @@ -0,0 +1,268 @@ +#include +#include +#include +#include + +#if defined(PLATFORM_WINDOWS_PHONE) + #if defined(PLATFORM_MSVC_ARM) + // NEON introduced in VS2012 + #if (_MSC_VER >= 1700) + #define PLATFORM_NEON 1 + #endif + #endif +#elif defined(PLATFORM_MSVC_X86) + // SSSE3, SSE4.1, SSE4.2, PCLMUL introduced in VS2008 + #if (_MSC_VER >= 1500) + #define PLATFORM_SSSE3 1 + #define PLATFORM_SSE41 1 + #define PLATFORM_SSE42 1 + #define PLATFORM_PCLMUL 1 + #endif + // AVX and AVX2 introduced in VS2012 + #if (_MSC_VER >= 1700) + #define PLATFORM_AVX 1 + #define PLATFORM_AVX2 1 + #endif +#endif + +namespace kodo_core +{ +/// @ingroup finite_field_layers +/// +/// @brief Template alias for the common set of finite field +/// layers used in most stacks +template +using finite_field_layers = + finite_field_math::type, + finite_field>; +} + +namespace kodo_rlnc +{ +/// @ingroup coefficient_generator_layers +/// +/// @brief Generates an uniform random coefficient (from the +/// chosen Finite Field) for every symbol. In addition +/// using the pivot_aware_generate means that we will only +/// generate non-zero coefficients for symbols which are +/// available locally. +template +using on_the_fly_generator = + kodo_core::check_partial_generator< + kodo_core::uniform_generator_layers::type > >; +} + +namespace kodo_rlnc +{ +template +< + class MainStack, + class Features +> +class full_vector_recoding_stack : public + // Payload API + kodo_core::payload_info< + // Codec Header API + kodo_core::default_off_systematic_encoder< + kodo_core::symbol_id_encoder< + // Symbol ID API + recoder_symbol_id< + // Coefficient Generator API + kodo_core::uniform_generator_layers::type, + kodo_core::trace_symbol, + kodo_core::linear_block_encoder< + // Coefficient Storage API + kodo_core::coefficient_value_access< + // Proxy + kodo_core::proxy_layer > > > > > > > > > > > > +{ }; +} + +namespace fifi +{ +template +< + class T, + typename std::enable_if::value, + uint8_t>::type = 0 +> +inline void region_multiply_constant(T& t, uint8_t* dest, + typename T::value_type constant, + uint32_t size) +{ + t.region_multiply_constant(dest, constant, size); +} + +/// @copydoc layer::multipy_add(uint8_t*, const uint8_t*, +/// value_type, uint32_t) +void multiply_add(uint8_t* symbol_dest, + const uint8_t* symbol_src, + value_type coefficient, uint32_t symbol_size) +{ + assert(m_field); + assert(symbol_dest != 0); + assert(symbol_src != 0); + assert(symbol_size > 0); + + coefficient = fifi::pack_constant(coefficient); + + m_field->region_multiply_add(symbol_dest, symbol_src, coefficient, + symbol_size); +} +} + +namespace magic +{ +class my_class +{ +public: + + stub::function copy_into_symbol; + + stub::function< + void(uint8_t**, const uint8_t**, uint8_t**, + uint32_t, uint32_t, uint32_t) + > m_vector_dot_product; + + stub::function< + void (uint8_t*, const uint8_t*, value_type, uint32_t) + > multiply_add; + + my_class() : + m_value(0U), + m_second(1U) + { } + + uint32_t value() const + { + return m_value; + } + + void set_value(uint32_t value) + { + m_value = value; + + m_pep = m_pep * std::pow(base, losses + 1.0) + + (1.0 - std::pow(base, losses)); + + if (coffee_pot == full && + second_condition::value && + third_condition::value) + { + continue; + } + + try + { + my_function(); + } + catch (const std::exception& e) + { + // handles std::exception + } + catch (...) + { + // handles int or std::string or any other unrelated type + } + + m_redundancy_estimator.sample( + (1.0 + m_redundancy_estimator.estimate()) * + m_generation_size() / m_worst.get() - 1.0); + + m_worst = + (m_worst) ? std::max(*m_worst, s.m_rank) : s.m_rank; + } + + /// Queues an async receive call on the socket + void queue_async_receive() + { + assert(m_socket && "Invalid socket in queue_async_receive"); + + assert(cancelled == 0 && + "Rate limiter send called multiple times without " + "waiting for callback!"); + + namespace ph = std::placeholders; + + m_receive_buffer.resize(receive_buffer_size, 0u); + + std::shared_ptr ep = + std::make_shared(); + + m_timer->async_wait(std::bind(&rate_limiter::timeout_handler, + this, std::placeholders::_1, callback)); + + m_socket->async_receive_from( + boost::asio::buffer(m_receive_buffer), *ep, std::bind( + &sockets::handle_async_receive_from, this, + ph::_1, ph::_2, ep)); + } + + + template + < + class T = Value, + typename std::enable_if< + std::is_default_constructible::value, uint8_t>::type = 0 + > + resource_pool() : + m_pool(std::make_shared( + allocate_function(std::make_shared))) + { } + +private: + + uint32_t m_value; +}; +} + +/// Test that our resource pool is a regular type. We are not +/// implementing equality or less than here, but maybe we could. +namespace +{ +template +struct is_regular : + std::integral_constant::value && + std::is_copy_constructible::value && + std::is_move_constructible::value && + std::is_copy_assignable::value && + std::is_move_assignable::value> +{ }; +} + +int main(int argc, const char* argv[]) +{ + uint16_t num = 42; + + auto recycle = [&recycled](std::shared_ptr o) + { + EXPECT_TRUE((bool) o); + ++recycled; + }; + + std::vector data = + { + 0x67, 0x42, 0x00, 0x0A, 0xF8, 0x41, 0xA2 + }; + + // insert code here... + std::cout << "This is a very loooooooooong line for this Hello World! " + << num << std::endl; + + std::vector v = {0, 1, 2, 3, 4, 5}; + + for (int& i : v) + std::cout << i << ' '; + + return 0; +} diff --git a/wscript b/wscript index a05cb82..eadef83 100644 --- a/wscript +++ b/wscript @@ -1,11 +1,19 @@ #! /usr/bin/env python # encoding: utf-8 +import os +import filecmp +import difflib +import sys +import subprocess +import shutil +from waflib.TaskGen import feature, after_method +from waflib import Errors +import waflib.extras.wurf_options + APPNAME = 'astyle' VERSION = '0.1.0' -import waflib.extras.wurf_options - def options(opt): @@ -44,8 +52,64 @@ def build(bld): static_libs = ['Shell32'] bld.program( - features='cxx', + features='cxx test_astyle', source=bld.path.ant_glob('src/*.cpp'), lib=static_libs, target='astyle') + +@feature('test_astyle') +@after_method('apply_link') +def test_astyle(self): + # Only execute the tests within the current project + if self.path.is_child_of(self.bld.srcnode): + if self.bld.has_tool_option('run_tests'): + self.bld.add_post_fun(run_astyle_tests) + + +def run_command(args): + print("Running: {}".format(args)) + sys.stdout.flush() + subprocess.check_call(args) + + +def run_astyle_tests(bld): + astyle = bld.get_tgen_by_name('astyle').link_task.outputs[0].abspath() + options = "--options={}".format(bld.path.find_node('.astylerc').abspath()) + + if os.path.isdir('test'): + test_folder = os.path.join(os.getcwd(), 'test') + correct_style = os.path.join(test_folder, 'correct_style.cpp') + correct_lines = open(correct_style, 'r').readlines() + + temp_folder = os.path.join(test_folder, 'temp') + # Make sure that the temp folder is deleted before copytree + if os.path.isdir(temp_folder): + shutil.rmtree(temp_folder) + shutil.copytree(test_folder, temp_folder) + + incorrect_files = 0 + + # Run astyle to format each test file + for file in sorted(os.listdir(temp_folder)): + test_file = os.path.join(temp_folder, file) + if (os.path.isfile(test_file)): + print('Test file: '+test_file) + run_command([astyle, options, test_file]) + + # Compare the formatted file with the correct style + if not filecmp.cmp(correct_style, test_file): + incorrect_files += 1 + print('\nIncorrect formatting: {}'.format(test_file)) + + test_lines = open(test_file, 'r').readlines() + + diff = difflib.unified_diff(correct_lines, test_lines) + print(''.join(diff)) + + # Clean up the temp directory + shutil.rmtree(temp_folder) + + if incorrect_files > 0: + raise Errors.WafError('Number of incorrectly formatted ' + 'files: {}'.format(incorrect_files)) \ No newline at end of file