Implement basic formatting check
This commit is contained in:
parent
a0df5545fa
commit
fbe87c1385
268
test/correct_style.cpp
Normal file
268
test/correct_style.cpp
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#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<class Field, class SuperCoder>
|
||||||
|
using finite_field_layers =
|
||||||
|
finite_field_math<typename fifi::default_field<Field>::type,
|
||||||
|
finite_field<Field, SuperCoder>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<class Features, class SuperCoder>
|
||||||
|
using on_the_fly_generator =
|
||||||
|
kodo_core::check_partial_generator<
|
||||||
|
kodo_core::uniform_generator_layers::type<Features,
|
||||||
|
kodo_core::pivot_aware_generator<
|
||||||
|
SuperCoder> > >;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<Features,
|
||||||
|
kodo_core::pivot_aware_generator<
|
||||||
|
// Encoder API
|
||||||
|
kodo_core::write_symbol_tracker<
|
||||||
|
kodo_core::zero_symbol_encoder<
|
||||||
|
kodo_core::trace_write_symbol<kodo_core::find_enable_trace<Features>,
|
||||||
|
kodo_core::trace_symbol<kodo_core::find_enable_trace<Features>,
|
||||||
|
kodo_core::linear_block_encoder<
|
||||||
|
// Coefficient Storage API
|
||||||
|
kodo_core::coefficient_value_access<
|
||||||
|
// Proxy
|
||||||
|
kodo_core::proxy_layer<MainStack,
|
||||||
|
kodo_core::final_layer
|
||||||
|
> > > > > > > > > > > > >
|
||||||
|
{ };
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace fifi
|
||||||
|
{
|
||||||
|
template
|
||||||
|
<
|
||||||
|
class T,
|
||||||
|
typename std::enable_if<has_region_multiply_constant<T>::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<field_type>(coefficient);
|
||||||
|
|
||||||
|
m_field->region_multiply_add(symbol_dest, symbol_src, coefficient,
|
||||||
|
symbol_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace magic
|
||||||
|
{
|
||||||
|
class my_class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
stub::function<uint32_t, const storage::const_storage> 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<endpoint_type> ep =
|
||||||
|
std::make_shared<endpoint_type>();
|
||||||
|
|
||||||
|
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<T>::value, uint8_t>::type = 0
|
||||||
|
>
|
||||||
|
resource_pool() :
|
||||||
|
m_pool(std::make_shared<impl>(
|
||||||
|
allocate_function(std::make_shared<value_type>)))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
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<class T>
|
||||||
|
struct is_regular :
|
||||||
|
std::integral_constant<bool,
|
||||||
|
std::is_default_constructible<T>::value &&
|
||||||
|
std::is_copy_constructible<T>::value &&
|
||||||
|
std::is_move_constructible<T>::value &&
|
||||||
|
std::is_copy_assignable<T>::value &&
|
||||||
|
std::is_move_assignable<T>::value>
|
||||||
|
{ };
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[])
|
||||||
|
{
|
||||||
|
uint16_t num = 42;
|
||||||
|
|
||||||
|
auto recycle = [&recycled](std::shared_ptr<dummy_two> o)
|
||||||
|
{
|
||||||
|
EXPECT_TRUE((bool) o);
|
||||||
|
++recycled;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<uint8_t> 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<int> v = {0, 1, 2, 3, 4, 5};
|
||||||
|
|
||||||
|
for (int& i : v)
|
||||||
|
std::cout << i << ' ';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
70
wscript
70
wscript
@ -1,11 +1,19 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# encoding: utf-8
|
# 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'
|
APPNAME = 'astyle'
|
||||||
VERSION = '0.1.0'
|
VERSION = '0.1.0'
|
||||||
|
|
||||||
import waflib.extras.wurf_options
|
|
||||||
|
|
||||||
|
|
||||||
def options(opt):
|
def options(opt):
|
||||||
|
|
||||||
@ -44,8 +52,64 @@ def build(bld):
|
|||||||
static_libs = ['Shell32']
|
static_libs = ['Shell32']
|
||||||
|
|
||||||
bld.program(
|
bld.program(
|
||||||
features='cxx',
|
features='cxx test_astyle',
|
||||||
source=bld.path.ant_glob('src/*.cpp'),
|
source=bld.path.ant_glob('src/*.cpp'),
|
||||||
lib=static_libs,
|
lib=static_libs,
|
||||||
target='astyle')
|
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))
|
Loading…
x
Reference in New Issue
Block a user