GENERATE_TESTS_TO_VERIFY_DATA_WO_TRIGGER (DATA, 64, 2);
/**
+ * @brief Run pipeline for a few frames with data verification
+ */
+static gboolean test_tensor_src_iio_data_verify_util (iio_dev_dir_struct *dev0,
+ gint data_value, guint data_bits, gint samp_freq)
+{
+ static const gint MAX_NUM_TRY = 100;
+ gint num_try;
+ gint fd;
+ size_t bytes_to_read, bytes_read;
+ gchar *data_buffer;
+ guint64 expect_val_mask;
+ gfloat expect_val, actual_val;
+ gchar *expect_val_char, *actual_val_char;
+ gint ret;
+ struct stat stat_buf;
+
+ for (int idx = 0; idx < NUM_FRAMES; idx++) {
+ ret = 0;
+ memset (&stat_buf, 0, sizeof (stat_buf));
+ num_try = 0;
+
+ /** wait for filter to process the frame and multifilesink to write it */
+ while ((fd = open (dev0->log_file, O_RDONLY)) < 0) {
+ if (num_try >= MAX_NUM_TRY) {
+ return FALSE;
+ }
+ g_usleep (MAX (10, 1000000 / samp_freq));
+ num_try++;
+ }
+
+ /** wait for filter to process the frame and multifilesink to write it */
+ for (num_try = 0; num_try < MAX_NUM_TRY; ++num_try) {
+ ret = stat (dev0->log_file, &stat_buf);
+ if (ret == 0 && stat_buf.st_size != 0) {
+ break;
+ }
+ g_usleep (MAX (1, 1000000 / samp_freq));
+ }
+
+ /** verify correctness of data */
+ bytes_to_read = sizeof (float) * BUF_LENGTH * dev0->num_scan_elements;
+ data_buffer = (gchar *) malloc (bytes_to_read);
+ if (data_buffer == NULL) {
+ close (fd);
+ return FALSE;
+ }
+ ret = read (fd, data_buffer, bytes_to_read);
+ if (ret < 0) {
+ close (fd);
+ free (data_buffer);
+ return FALSE;
+ }
+ bytes_read = static_cast<size_t>(ret); \
+ EXPECT_EQ (bytes_read, bytes_to_read);
+ expect_val_mask = G_MAXUINT64 >> (64 - data_bits);
+ expect_val = ((data_value & expect_val_mask) + OFFSET) * SCALE;
+ expect_val_char = g_strdup_printf ("%.2f", expect_val);
+ for (size_t idx = 0; idx < bytes_to_read; idx += sizeof (float)) {
+ actual_val = *((gfloat *) data_buffer);
+ actual_val_char = g_strdup_printf ("%.2f", actual_val);
+ EXPECT_STREQ (expect_val_char, actual_val_char);
+ g_free (actual_val_char);
+ }
+ g_free (expect_val_char);
+ close (fd);
+ free (data_buffer);
+ if (safe_remove (dev0->log_file) != 0)
+ return FALSE;
+ /** update data value to check data updates */
+ data_value += 1;
+ ret = build_dev_dir_scan_elements (dev0, data_bits, data_value, data_value);
+ if (ret != 0)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* @brief tests tensor source IIO data with trigger
* @note verifies that no frames have been lost as well
* @note verifies caps for the src pad as well
*/
TEST (test_tensor_src_iio, data_verify_trigger)
{
- static const int MAX_NUM_TRY = 100;
- int num_try;
iio_dev_dir_struct *dev0;
GstElement *src_iio_pipeline;
GstElement *src_iio;
gint samp_freq;
gint data_value;
guint data_bits;
- gint fd, ret;
- size_t bytes_to_read, bytes_read;
- gchar *data_buffer;
- gfloat expect_val, actual_val;
- guint64 expect_val_mask;
- gchar *expect_val_char, *actual_val_char;
- struct stat stat_buf;
data_value = DATA;
data_bits = 16;
GstCaps *caps;
gst_object_unref (src_pad);
gst_caps_unref (caps);
- /** let a few frames transfer */
- for (int idx = 0; idx < NUM_FRAMES; idx++) {
- num_try = 0;
- /** wait for filter to process the frame and multifilesink to write it */
- while ((fd = open (dev0->log_file, O_RDONLY)) < 0) {
- if (num_try >= MAX_NUM_TRY) {
- FAIL() << "Failed to open " << dev0->log_file;
- }
- g_usleep (MAX (10, 1000000 / samp_freq));
- num_try++;
- }
-
- /** wait for filter to process the frame and multifilesink to write it */
- for (num_try = 0; num_try < MAX_NUM_TRY; ++num_try) {
- ret = stat (dev0->log_file, &stat_buf);
- if (ret == 0 && stat_buf.st_size != 0) {
- break;
- }
- g_usleep (MAX (1, 1000000 / samp_freq));
- }
-
- /** verify correctness of data */
- bytes_to_read = sizeof (float) * BUF_LENGTH * dev0->num_scan_elements;
- data_buffer = (gchar *) malloc (bytes_to_read);
- if (data_buffer == NULL) {
- close (fd);
- FAIL() << "Failed to malloc for data_buffer";
- }
- ret = read (fd, data_buffer, bytes_to_read);
- if (ret < 0) {
- close (fd);
- free (data_buffer);
- FAIL() << "Failed to read file descriptor, " << fd;
- }
- bytes_read = static_cast<size_t>(ret); \
- EXPECT_EQ (bytes_read, bytes_to_read);
- expect_val_mask = G_MAXUINT64 >> (64 - data_bits);
- expect_val = ((data_value & expect_val_mask) + OFFSET) * SCALE;
- expect_val_char = g_strdup_printf ("%.2f", expect_val);
- for (size_t idx = 0; idx < bytes_to_read; idx += sizeof (float)) {
- actual_val = *((gfloat *) data_buffer);
- actual_val_char = g_strdup_printf ("%.2f", actual_val);
- EXPECT_STREQ (expect_val_char, actual_val_char);
- g_free (actual_val_char);
- }
- g_free (expect_val_char);
- close (fd);
- free (data_buffer);
- ASSERT_EQ (safe_remove (dev0->log_file), 0);
- /** update data value to check data updates */
- data_value += 1;
- ASSERT_EQ (build_dev_dir_scan_elements (dev0, data_bits, data_value,
- data_value), 0);
- }
+ EXPECT_EQ (test_tensor_src_iio_data_verify_util (dev0, data_value, data_bits,
+ samp_freq), TRUE);
/** verify playing state has been maintained */
status =
gint samp_freq;
gint data_value;
guint data_bits;
- gint fd, bytes_to_read, bytes_read;
- gchar *data_buffer;
- gfloat expect_val, actual_val;
- guint64 expect_val_mask;
- gchar *expect_val_char, *actual_val_char;
- struct stat stat_buf;
- gint stat_ret;
GstCaps *caps;
GstPad *src_pad;
GstStructure *structure;
gst_object_unref (src_pad);
gst_caps_unref (caps);
- /** let a few frames transfer */
- for (int idx = 0; idx < NUM_FRAMES; idx++) {
- /** wait for filter to process the frame and multifilesink to write it */
- while (TRUE) {
- if (g_file_test (dev0->log_file, G_FILE_TEST_IS_REGULAR)) {
- stat_ret = stat (dev0->log_file, &stat_buf);
- if (stat_ret == 0 && stat_buf.st_size != 0) {
- break;
- }
- }
- g_usleep (MAX (1, 1000000 / samp_freq));
- }
-
- /** verify correctness of data */
- fd = open (dev0->log_file, O_RDONLY);
- ASSERT_GE (fd, 0);
- bytes_to_read = sizeof (float) * BUF_LENGTH * dev0->num_scan_elements;
- data_buffer = (gchar *) malloc (bytes_to_read);
- ASSERT_TRUE (data_buffer != NULL);
- bytes_read = read (fd, data_buffer, bytes_to_read);
- EXPECT_EQ (bytes_read, bytes_to_read);
- expect_val_mask = G_MAXUINT64 >> (64 - data_bits);
- expect_val = ((data_value & expect_val_mask) + OFFSET) * SCALE;
- expect_val_char = g_strdup_printf ("%.2f", expect_val);
- for (int idx = 0; idx < bytes_to_read; idx += sizeof (float)) {
- actual_val = *((gfloat *) data_buffer);
- actual_val_char = g_strdup_printf ("%.2f", actual_val);
- EXPECT_STREQ (expect_val_char, actual_val_char);
- g_free (actual_val_char);
- }
- g_free (expect_val_char);
- close (fd);
- free (data_buffer);
- ASSERT_EQ (safe_remove (dev0->log_file), 0);
- /** update data value to check data updates */
- data_value += 1;
- ASSERT_EQ (build_dev_dir_scan_elements (dev0, data_bits, data_value,
- data_value), 0);
- }
+ EXPECT_EQ (test_tensor_src_iio_data_verify_util (dev0, data_value, data_bits,
+ samp_freq), TRUE);
/** verify playing state has been maintained */
status =