2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "../libsigrok.h"
26 /* Get a libsigrok driver by name. */
27 struct sr_dev_driver *srtest_driver_get(const char *drivername)
29 struct sr_dev_driver **drivers, *driver = NULL;
32 drivers = sr_driver_list();
33 fail_unless(drivers != NULL, "No drivers found.");
35 for (i = 0; drivers[i]; i++) {
36 if (strcmp(drivers[i]->name, drivername))
40 fail_unless(driver != NULL, "Driver '%s' not found.", drivername);
45 /* Initialize a libsigrok driver. */
46 void srtest_driver_init(struct sr_context *sr_ctx, struct sr_dev_driver *driver)
50 ret = sr_driver_init(sr_ctx, driver);
51 fail_unless(ret == SR_OK, "Failed to init '%s' driver: %d.",
55 /* Initialize all libsigrok drivers. */
56 void srtest_driver_init_all(struct sr_context *sr_ctx)
58 struct sr_dev_driver **drivers, *driver;
61 drivers = sr_driver_list();
62 fail_unless(drivers != NULL, "No drivers found.");
64 for (i = 0; drivers[i]; i++) {
66 ret = sr_driver_init(sr_ctx, driver);
67 fail_unless(ret == SR_OK, "Failed to init '%s' driver: %d.",
72 /* Set the samplerate for the respective driver to the specified value. */
73 void srtest_set_samplerate(struct sr_dev_driver *driver, uint64_t samplerate)
76 struct sr_dev_inst *sdi;
79 sdi = g_slist_nth_data(driver->priv, 0);
81 gvar = g_variant_new_uint64(samplerate);
82 ret = driver->config_set(SR_CONF_SAMPLERATE, gvar, sdi);
83 g_variant_unref(gvar);
85 fail_unless(ret == SR_OK, "%s: Failed to set SR_CONF_SAMPLERATE: %d.",
89 /* Get the respective driver's current samplerate. */
90 uint64_t srtest_get_samplerate(struct sr_dev_driver *driver)
94 struct sr_dev_inst *sdi;
97 sdi = g_slist_nth_data(driver->priv, 0);
99 ret = driver->config_get(SR_CONF_SAMPLERATE, &gvar, sdi);
100 samplerate = g_variant_get_uint64(gvar);
101 g_variant_unref(gvar);
103 fail_unless(ret == SR_OK, "%s: Failed to get SR_CONF_SAMPLERATE: %d.",
109 /* Check whether the respective driver can set/get the correct samplerate. */
110 void srtest_check_samplerate(struct sr_context *sr_ctx, const char *drivername,
113 struct sr_dev_driver *driver;
116 driver = srtest_driver_get(drivername);
117 srtest_driver_init(sr_ctx, driver);;
118 srtest_set_samplerate(driver, samplerate);
119 s = srtest_get_samplerate(driver);
120 fail_unless(s == samplerate, "%s: Incorrect samplerate: %" PRIu64 ".",