main: Add helper for mocking device node

This commit is contained in:
Bastien Nocera
2021-01-20 18:25:57 +01:00
parent 4f990284ce
commit e8d22fe304
3 changed files with 25 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ sources = [
'accel-mount-matrix.c',
'accel-scale.c',
'accel-attributes.c',
'utils.c',
resources,
]

21
src/utils.c Normal file
View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021 Bastien Nocera <hadess@hadess.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
*/
#include "utils.h"
char *
get_device_file (GUdevDevice *device)
{
if (!IS_TEST)
return g_udev_device_get_device_file (device);
return g_build_filename (g_getenv ("UMOCKDEV_DIR"),
"iio-dev-data.bin",
NULL);
}

View File

@@ -10,5 +10,8 @@
#pragma once
#include <glib.h>
#include <gudev/gudev.h>
#define IS_TEST (g_getenv ("UMOCKDEV_DIR") != NULL)
char *get_device_file (GUdevDevice *device);