X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tests%2Flib.c;h=15beca27ae60096e070ff8bb41eb8be4716dc5e6;hb=1296bb5362292e4924a41e79c3d24bb5571517c6;hp=44777bb3cd86df272f5233250888dd36498ecfd9;hpb=79bb0e97d53526ef6deb491ea9c7698ed6e90631;p=libsigrok.git
diff --git a/tests/lib.c b/tests/lib.c
index 44777bb3..15beca27 100644
--- a/tests/lib.c
+++ b/tests/lib.c
@@ -14,14 +14,35 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
+#include
#include
#include
+#include
+#include
#include
-#include "../libsigrok.h"
+#include
+#include "lib.h"
+
+struct sr_context *srtest_ctx;
+
+void srtest_setup(void)
+{
+ int ret;
+
+ ret = sr_init(&srtest_ctx);
+ fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
+}
+
+void srtest_teardown(void)
+{
+ int ret;
+
+ ret = sr_exit(srtest_ctx);
+ fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
+}
/* Get a libsigrok driver by name. */
struct sr_dev_driver *srtest_driver_get(const char *drivername)
@@ -29,7 +50,7 @@ struct sr_dev_driver *srtest_driver_get(const char *drivername)
struct sr_dev_driver **drivers, *driver = NULL;
int i;
- drivers = sr_driver_list();
+ drivers = sr_driver_list(srtest_ctx);
fail_unless(drivers != NULL, "No drivers found.");
for (i = 0; drivers[i]; i++) {
@@ -58,7 +79,7 @@ void srtest_driver_init_all(struct sr_context *sr_ctx)
struct sr_dev_driver **drivers, *driver;
int i, ret;
- drivers = sr_driver_list();
+ drivers = sr_driver_list(srtest_ctx);
fail_unless(drivers != NULL, "No drivers found.");
for (i = 0; drivers[i]; i++) {
@@ -74,10 +95,14 @@ void srtest_set_samplerate(struct sr_dev_driver *driver, uint64_t samplerate)
{
int ret;
struct sr_dev_inst *sdi;
+ GVariant *gvar;
+
+ sdi = g_slist_nth_data(driver->context, 0);
- sdi = g_slist_nth_data(driver->priv, 0);
+ gvar = g_variant_new_uint64(samplerate);
+ ret = driver->config_set(SR_CONF_SAMPLERATE, gvar, sdi, NULL);
+ g_variant_unref(gvar);
- ret = driver->config_set(SR_CONF_SAMPLERATE, &samplerate, sdi);
fail_unless(ret == SR_OK, "%s: Failed to set SR_CONF_SAMPLERATE: %d.",
driver->name, ret);
}
@@ -86,18 +111,20 @@ void srtest_set_samplerate(struct sr_dev_driver *driver, uint64_t samplerate)
uint64_t srtest_get_samplerate(struct sr_dev_driver *driver)
{
int ret;
- uint64_t *samplerate;
+ uint64_t samplerate;
struct sr_dev_inst *sdi;
+ GVariant *gvar;
+
+ sdi = g_slist_nth_data(driver->context, 0);
- sdi = g_slist_nth_data(driver->priv, 0);
+ ret = driver->config_get(SR_CONF_SAMPLERATE, &gvar, sdi, NULL);
+ samplerate = g_variant_get_uint64(gvar);
+ g_variant_unref(gvar);
- ret = driver->config_get(SR_CONF_SAMPLERATE,
- (const void **)&samplerate, sdi);
fail_unless(ret == SR_OK, "%s: Failed to get SR_CONF_SAMPLERATE: %d.",
driver->name, ret);
- fail_unless(samplerate != NULL);
- return *samplerate;
+ return samplerate;
}
/* Check whether the respective driver can set/get the correct samplerate. */
@@ -114,3 +141,22 @@ void srtest_check_samplerate(struct sr_context *sr_ctx, const char *drivername,
fail_unless(s == samplerate, "%s: Incorrect samplerate: %" PRIu64 ".",
drivername, s);
}
+
+GArray *srtest_get_enabled_logic_channels(const struct sr_dev_inst *sdi)
+{
+ struct sr_channel *ch;
+ GArray *channels;
+ GSList *l;
+
+ channels = g_array_new(FALSE, FALSE, sizeof(int));
+ for (l = sr_dev_inst_channels_get(sdi); l; l = l->next) {
+ ch = l->data;
+ if (ch->type != SR_CHANNEL_LOGIC)
+ continue;
+ if (ch->enabled != TRUE)
+ continue;
+ g_array_append_val(channels, ch->index);
+ }
+
+ return channels;
+}