Skip to content

Commit

Permalink
fix(travis): add check to verify existence of udev (#1619)
Browse files Browse the repository at this point in the history
Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
sai chaithanya authored Feb 25, 2020
1 parent dd61520 commit 3ce311e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ addons:
apt:
update: true

before_install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install --yes -qq gcc
- sudo apt-get install --yes -qq libudev-dev
install:
- make bootstrap
- make format
Expand Down
10 changes: 8 additions & 2 deletions ci/travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi

curl https://raw.githubusercontent.com/openebs/openebs/master/k8s/ci/test-script.sh > test-script.sh

# append mayactl tests to this script
## Compile udev c code and build binary in /var/openebs/sparse
echo "Creating /var/openebs/sparse/udev_checks directory"
sudo mkdir -p /var/openebs/sparse/udev_checks
echo "Compiling and building the binary"
sudo gcc ci/udev_check.c -ludev -o /var/openebs/sparse/udev_checks/udev_check

# append mayactl tests to this script
cat ./ci/mayactl.sh >> ./test-script.sh

# append local pv tests to this script
# append local pv tests to this script
#cat ./ci/local_pv.sh >> ./test-script.sh

chmod +x test-script.sh && ./test-script.sh
Expand Down
42 changes: 42 additions & 0 deletions ci/udev_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <libudev.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char **argv)
{
char *device;
struct udev *udev;
struct udev_device *dev = NULL;
int initialized = -1;
int rc = -1;

if ((udev = udev_new()) == NULL) {
fprintf(stderr, "failed to get udev device\n");
return (-1);
}

if (argc > 1) {
device = argv[1];
} else {
fprintf(stderr, "device is not provided\n");
return (-1);
}

dev = udev_device_new_from_subsystem_sysname(udev, "block", device);

/* https://github.com/jcnelson/vdev/blob/ceb7a6c4f44dec542dc1c3c3d5abd27dec7f3e0e/libudev-compat/libudev-device.c#L1772
* From above code comments udev_device_get_is_initialized
* Returns: 1 if the device is set up. 0 otherwise.
*/
if ((dev != NULL) && (rc = udev_device_get_is_initialized(dev)) == 1) {
printf("device = %s is initialized by udev\n", device);
initialized = 0;
} else {
printf("device = %s is not initialized by udev errno: %d\n", device, errno);
}

udev_device_unref(dev);
udev_unref(udev);
return initialized;
}

0 comments on commit 3ce311e

Please sign in to comment.