summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rondeau2012-12-14 12:05:00 -0500
committerTom Rondeau2012-12-14 12:05:00 -0500
commit75b01cc4f55c38dfe5bb329c23df591e43cf4c66 (patch)
tree9982146780daf76a6904fb51ba964f36fb803181
parenta58a03f628016efb7597acb1e69ebb16424c6348 (diff)
downloadgnuradio-75b01cc4f55c38dfe5bb329c23df591e43cf4c66.tar.gz
gnuradio-75b01cc4f55c38dfe5bb329c23df591e43cf4c66.tar.bz2
gnuradio-75b01cc4f55c38dfe5bb329c23df591e43cf4c66.zip
core: Added detached header test to file metadata QA.
Also adds a flush when updating the headers.
-rw-r--r--gnuradio-core/src/lib/io/gr_file_meta_sink.cc2
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/qa_file_metadata.py84
2 files changed, 83 insertions, 3 deletions
diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc
index 9cec5bc28..b016dd1d3 100644
--- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc
@@ -261,6 +261,8 @@ gr_file_meta_sink::write_header(FILE *fp, pmt_t header, pmt_t extra)
throw std::runtime_error("file_meta_sink: error writing extra to file.\n");
}
}
+
+ fflush(fp);
}
void
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_file_metadata.py b/gnuradio-core/src/python/gnuradio/gr/qa_file_metadata.py
index 8ce1f3d5a..849f32299 100644
--- a/gnuradio-core/src/python/gnuradio/gr/qa_file_metadata.py
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_file_metadata.py
@@ -23,7 +23,7 @@
from gnuradio import gr, gr_unittest
from gnuradio import parse_file_metadata
import pmt
-import os
+import os, time
class test_file_metadata(gr_unittest.TestCase):
@@ -50,6 +50,7 @@ class test_file_metadata(gr_unittest.TestCase):
samp_rate, 1,
gr.GR_FILE_FLOAT, True,
1000000, extras_str, detached)
+ fsnk.set_unbuffered(True)
self.tb.connect(src, head, fsnk)
self.tb.run()
@@ -110,9 +111,86 @@ class test_file_metadata(gr_unittest.TestCase):
os.remove(outfile)
- def est_002(self):
- fsrc = gr.file_meta_source("/tmp/metadat_file.out", False, True, "/tmp/metadat_file.out.hdr")
+ def test_002(self):
+ outfile = "test_out.dat"
+ outfile_hdr = "test_out.dat.hdr"
+
+ detached = True
+ samp_rate = 200000
+ key = pmt.pmt_intern("samp_rate")
+ val = pmt.pmt_from_double(samp_rate)
+ extras = pmt.pmt_make_dict()
+ extras = pmt.pmt_dict_add(extras, key, val)
+ extras_str = pmt.pmt_serialize_str(extras)
+
+ src = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0)
+ head = gr.head(gr.sizeof_gr_complex, 1000)
+ fsnk = gr.file_meta_sink(gr.sizeof_gr_complex, outfile,
+ samp_rate, 1,
+ gr.GR_FILE_FLOAT, True,
+ 1000000, extras_str, detached)
+ fsnk.set_unbuffered(True)
+
+ self.tb.connect(src, head, fsnk)
+ self.tb.run()
+ fsnk.close()
+
+ # Open detached header for reading
+ handle = open(outfile_hdr, "rb")
+ header_str = handle.read(parse_file_metadata.HEADER_LENGTH)
+ if(len(header_str) == 0):
+ self.assertFalse()
+
+ try:
+ header = pmt.pmt_deserialize_str(header_str)
+ except RuntimeError:
+ self.assertFalse()
+
+ info = parse_file_metadata.parse_header(header, False)
+ extra_str = handle.read(info["extra_len"])
+ self.assertGreater(len(extra_str), 0)
+ handle.close()
+
+ try:
+ extra = pmt.pmt_deserialize_str(extra_str)
+ except RuntimeError:
+ self.assertFalse()
+
+ extra_info = parse_file_metadata.parse_extra_dict(extra, info, False)
+
+ self.assertEqual(info['rx_rate'], samp_rate)
+ self.assertEqual(pmt.pmt_to_double(extra_info['samp_rate']), samp_rate)
+
+
+ # Test file metadata source
+ # Create a new sig source to start from the beginning
+ src2 = gr.sig_source_c(samp_rate, gr.GR_COS_WAVE, 1000, 1, 0)
+ fsrc = gr.file_meta_source(outfile, False, detached, outfile_hdr)
+ vsnk = gr.vector_sink_c()
+ tsnk = gr.tag_debug(gr.sizeof_gr_complex, "QA")
+ ssnk = gr.vector_sink_c()
+ head.reset()
+ self.tb.disconnect(src, head, fsnk)
+ self.tb.connect(fsrc, vsnk)
+ self.tb.connect(fsrc, tsnk)
+ self.tb.connect(src2, head, ssnk)
+ self.tb.run()
+
+ # Test to make sure tags with 'samp_rate' and 'rx_rate' keys
+ # were generated and received correctly.
+ tags = tsnk.current_tags()
+ for t in tags:
+ if(pmt.pmt_eq(t.key, pmt.pmt_intern("samp_rate"))):
+ self.assertEqual(pmt.pmt_to_double(t.value), samp_rate)
+ elif(pmt.pmt_eq(t.key, pmt.pmt_intern("rx_rate"))):
+ self.assertEqual(pmt.pmt_to_double(t.value), samp_rate)
+
+ # Test that the data portion was extracted and received correctly.
+ self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5)
+
+ os.remove(outfile)
+ os.remove(outfile_hdr)
if __name__ == '__main__':
gr_unittest.run(test_file_metadata, "test_file_metadata.xml")