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;
78 sdi = g_slist_nth_data(driver->priv, 0);
80 ret = driver->config_set(SR_CONF_SAMPLERATE, &samplerate, sdi);
81 fail_unless(ret == SR_OK, "%s: Failed to set SR_CONF_SAMPLERATE: %d.",
85 /* Get the respective driver's current samplerate. */
86 uint64_t srtest_get_samplerate(struct sr_dev_driver *driver)
90 struct sr_dev_inst *sdi;
92 sdi = g_slist_nth_data(driver->priv, 0);
94 ret = driver->config_get(SR_CONF_SAMPLERATE,
95 (const void **)&samplerate, sdi);
96 fail_unless(ret == SR_OK, "%s: Failed to get SR_CONF_SAMPLERATE: %d.",
98 fail_unless(samplerate != NULL);
103 /* Check whether the respective driver can set/get the correct samplerate. */
104 void srtest_check_samplerate(struct sr_context *sr_ctx, const char *drivername,
107 struct sr_dev_driver *driver;
110 driver = srtest_driver_get(drivername);
111 srtest_driver_init(sr_ctx, driver);;
112 srtest_set_samplerate(driver, samplerate);
113 s = srtest_get_samplerate(driver);
114 fail_unless(s == samplerate, "%s: Incorrect samplerate: %" PRIu64 ".",