From e6ba43e3c978a9212b21da25819934098ae75fca Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 3 Aug 2006 23:42:44 +0000 Subject: [PATCH] merged interim/pmt r2248:HEAD into trunk git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3128 221aa14e-8319-0410-a670-987f0aec2ac5 --- pmt/src/lib/Makefile.am | 14 ++++--- pmt/src/lib/generate_unv.py | 68 ++++++++++++++++++++++++++++---- pmt/src/lib/pmt.cc | 19 ++++++++- pmt/src/lib/pmt.h | 24 +++++------ pmt/src/lib/pmt_int.h | 1 + pmt/src/lib/qa_pmt.cc | 4 +- pmt/src/lib/unv_qa_template.cc.t | 35 ++++++++++++++++ 7 files changed, 137 insertions(+), 28 deletions(-) create mode 100644 pmt/src/lib/unv_qa_template.cc.t diff --git a/pmt/src/lib/Makefile.am b/pmt/src/lib/Makefile.am index 1c084dea..ac1ecda3 100644 --- a/pmt/src/lib/Makefile.am +++ b/pmt/src/lib/Makefile.am @@ -31,13 +31,16 @@ lib_LTLIBRARIES = libpmt.la libpmt-qa.la CODE_GENERATOR = \ generate_unv.py \ unv_template.h.t \ - unv_template.cc.t + unv_template.cc.t \ + unv_qa_template.cc.t GENERATED_H = \ - pmt_unv_int.h + pmt_unv_int.h \ + qa_pmt_unv.h GENERATED_CC = \ - pmt_unv.cc + pmt_unv.cc \ + qa_pmt_unv.cc $(GENERATED_H) $(GENERATED_I) $(GENERATED_CC): $(CODE_GENERATOR) @@ -54,7 +57,7 @@ EXTRA_DIST = \ # These are the source files that go into the pmt shared library libpmt_la_SOURCES = \ pmt.cc \ - $(GENERATED_CC) + pmt_unv.cc # magic flags libpmt_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version @@ -77,7 +80,8 @@ noinst_HEADERS = \ libpmt_qa_la_SOURCES = \ qa_pmt.cc \ - qa_pmt_prims.cc + qa_pmt_prims.cc \ + qa_pmt_unv.cc # magic flags libpmt_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version diff --git a/pmt/src/lib/generate_unv.py b/pmt/src/lib/generate_unv.py index 46a168a1..a9d63f03 100755 --- a/pmt/src/lib/generate_unv.py +++ b/pmt/src/lib/generate_unv.py @@ -66,11 +66,6 @@ header = """\ */ """ -guard_head = """ -#ifndef INCLUDED_PMT_UNV_INT_H -#define INCLUDED_PMT_UNV_INT_H -""" - guard_tail = """ #endif """ @@ -85,6 +80,14 @@ includes = """ """ +qa_includes = """ +#include +#include +#include +#include + +""" + # set srcdir to the directory that contains Makefile.am try: @@ -99,6 +102,17 @@ def open_src (name, mode): return open(os.path.join (srcdir, name), mode) +def guard_name(filename): + return 'INCLUDED_' + re.sub('\.', '_', filename.upper()) + +def guard_head(filename): + guard = guard_name(filename) + return """ +#ifndef %s +#define %s +""" % (guard, guard) + + def do_substitution (d, input, out_file): def repl (match_obj): key = match_obj.group (1) @@ -111,15 +125,15 @@ def do_substitution (d, input, out_file): def generate_h(): template = open_src('unv_template.h.t', 'r').read() - output = open('pmt_unv_int.h', 'w') + output_filename = 'pmt_unv_int.h' + output = open(output_filename, 'w') output.write(header) - output.write(guard_head) + output.write(guard_head(output_filename)) for tag, typ in unv_types: d = { 'TAG' : tag, 'TYPE' : typ } do_substitution(d, template, output) output.write(guard_tail) - def generate_cc(): template = open_src('unv_template.cc.t', 'r').read() output = open('pmt_unv.cc', 'w') @@ -130,9 +144,47 @@ def generate_cc(): do_substitution(d, template, output) +def generate_qa_h(): + output_filename = 'qa_pmt_unv.h' + output = open(output_filename, 'w') + output.write(header) + output.write(guard_head(output_filename)) + + output.write(''' +#include +#include + +class qa_pmt_unv : public CppUnit::TestCase { + + CPPUNIT_TEST_SUITE(qa_pmt_unv); +''') + for tag, typ in unv_types: + output.write(' CPPUNIT_TEST(test_%svector);\n' % (tag,)) + output.write('''\ + CPPUNIT_TEST_SUITE_END(); + + private: +''') + for tag, typ in unv_types: + output.write(' void test_%svector();\n' % (tag,)) + output.write('};\n') + output.write(guard_tail) + +def generate_qa_cc(): + template = open_src('unv_qa_template.cc.t', 'r').read() + output = open('qa_pmt_unv.cc', 'w') + output.write(header) + output.write(qa_includes) + for tag, typ in unv_types: + d = { 'TAG' : tag, 'TYPE' : typ } + do_substitution(d, template, output) + + def main(): generate_h() generate_cc() + generate_qa_h() + generate_qa_cc() if __name__ == '__main__': main() diff --git a/pmt/src/lib/pmt.cc b/pmt/src/lib/pmt.cc index 093f6fb2..12c69286 100644 --- a/pmt/src/lib/pmt.cc +++ b/pmt/src/lib/pmt.cc @@ -634,6 +634,21 @@ pmt_equal(pmt_t x, pmt_t y) return true; } + if (x->is_uniform_vector() && y->is_uniform_vector()){ + pmt_uniform_vector *xv = _uniform_vector(x); + pmt_uniform_vector *yv = _uniform_vector(y); + if (xv->length() != yv->length()) + return false; + + size_t len_x, len_y; + if (memcmp(xv->uniform_elements(len_x), + yv->uniform_elements(len_y), + len_x) == 0) + return true; + + return true; + } + // FIXME add other cases here... return false; @@ -645,8 +660,10 @@ pmt_length(pmt_t x) if (x->is_vector()) return _vector(x)->length(); + if (x->is_uniform_vector()) + return _uniform_vector(x)->length(); + // FIXME list length - // FIXME uniform vector length // FIXME dictionary length (number of entries) throw pmt_wrong_type("pmt_length", x); diff --git a/pmt/src/lib/pmt.h b/pmt/src/lib/pmt.h index 4fd6c290..d158d39c 100644 --- a/pmt/src/lib/pmt.h +++ b/pmt/src/lib/pmt.h @@ -363,18 +363,18 @@ const std::complex *pmt_c64vector_elements(pmt_t v, size_t &len); //< le void *pmt_uniform_vector_writeable_elements(pmt_t v, size_t &len); //< works with any; len is in bytes -uint8_t *pmt_u8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int8_t *pmt_s8vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint16_t *pmt_u16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int16_t *pmt_s16vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint32_t *pmt_u32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int32_t *pmt_s32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -uint64_t *pmt_u64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -int64_t *pmt_s64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -float *pmt_f32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -double *pmt_f64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c32vector_writable_elements(pmt_t v, size_t &len); //< len is in elements -std::complex *pmt_c64vector_writable_elements(pmt_t v, size_t &len); //< len is in elements +uint8_t *pmt_u8vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +int8_t *pmt_s8vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +uint16_t *pmt_u16vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +int16_t *pmt_s16vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +uint32_t *pmt_u32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +int32_t *pmt_s32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +uint64_t *pmt_u64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +int64_t *pmt_s64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +float *pmt_f32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +double *pmt_f64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c32vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements +std::complex *pmt_c64vector_writeable_elements(pmt_t v, size_t &len); //< len is in elements /* * ------------------------------------------------------------------------ diff --git a/pmt/src/lib/pmt_int.h b/pmt/src/lib/pmt_int.h index e6ee5ec9..738ca8a6 100644 --- a/pmt/src/lib/pmt_int.h +++ b/pmt/src/lib/pmt_int.h @@ -196,6 +196,7 @@ public: bool is_uniform_vector() const { return true; } virtual const void *uniform_elements(size_t &len) = 0; virtual void *uniform_writeable_elements(size_t &len) = 0; + virtual size_t length() const = 0; }; #include "pmt_unv_int.h" diff --git a/pmt/src/lib/qa_pmt.cc b/pmt/src/lib/qa_pmt.cc index 6ed681a6..c885f86a 100644 --- a/pmt/src/lib/qa_pmt.cc +++ b/pmt/src/lib/qa_pmt.cc @@ -26,6 +26,7 @@ #include #include +#include CppUnit::TestSuite * qa_pmt::suite () @@ -33,8 +34,7 @@ qa_pmt::suite () CppUnit::TestSuite *s = new CppUnit::TestSuite ("pmt"); s->addTest (qa_pmt_prims::suite ()); - //s->addTest (qa_gr_circular_file::suite ()); - //s->addTest (qa_gr_fxpt::suite ()); + s->addTest (qa_pmt_unv::suite ()); return s; } diff --git a/pmt/src/lib/unv_qa_template.cc.t b/pmt/src/lib/unv_qa_template.cc.t new file mode 100644 index 00000000..3db508bc --- /dev/null +++ b/pmt/src/lib/unv_qa_template.cc.t @@ -0,0 +1,35 @@ +void +qa_pmt_unv::test_@TAG@vector() +{ + static const size_t N = 3; + pmt_t v1 = pmt_make_@TAG@vector(N, 0); + CPPUNIT_ASSERT_EQUAL(N, pmt_length(v1)); + @TYPE@ s0 = @TYPE@(10); + @TYPE@ s1 = @TYPE@(20); + @TYPE@ s2 = @TYPE@(30); + + pmt_@TAG@vector_set(v1, 0, s0); + pmt_@TAG@vector_set(v1, 1, s1); + pmt_@TAG@vector_set(v1, 2, s2); + + CPPUNIT_ASSERT_EQUAL(s0, pmt_@TAG@vector_ref(v1, 0)); + CPPUNIT_ASSERT_EQUAL(s1, pmt_@TAG@vector_ref(v1, 1)); + CPPUNIT_ASSERT_EQUAL(s2, pmt_@TAG@vector_ref(v1, 2)); + + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_ref(v1, N), pmt_out_of_range); + CPPUNIT_ASSERT_THROW(pmt_@TAG@vector_set(v1, N, @TYPE@(0)), pmt_out_of_range); + + size_t len; + const @TYPE@ *rd = pmt_@TAG@vector_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + CPPUNIT_ASSERT_EQUAL(s0, rd[0]); + CPPUNIT_ASSERT_EQUAL(s1, rd[1]); + CPPUNIT_ASSERT_EQUAL(s2, rd[2]); + + @TYPE@ *wr = pmt_@TAG@vector_writeable_elements(v1, len); + CPPUNIT_ASSERT_EQUAL(len, N); + wr[0] = @TYPE@(0); + CPPUNIT_ASSERT_EQUAL(@TYPE@(0), wr[0]); + CPPUNIT_ASSERT_EQUAL(s1, wr[1]); + CPPUNIT_ASSERT_EQUAL(s2, wr[2]); +} -- 2.30.2