Skip to content

Commit

Permalink
[libnozzle] add nozzle_get_fd test
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Dec 15, 2018
1 parent 0e8dfca commit e667b03
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libnozzle/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ check_PROGRAMS = \
api_nozzle_set_mac_test \
api_nozzle_get_handle_by_name_test \
api_nozzle_get_name_by_handle_test \
api_nozzle_get_fd_test \
nozzle_test

noinst_PROGRAMS = $(check_PROGRAMS)
Expand Down Expand Up @@ -83,6 +84,9 @@ api_nozzle_get_handle_by_name_test_SOURCES = api_nozzle_get_handle_by_name.c \
api_nozzle_get_name_by_handle_test_SOURCES = api_nozzle_get_name_by_handle.c \
test-common.c

api_nozzle_get_fd_test_SOURCES = api_nozzle_get_fd.c \
test-common.c

nozzle_test_SOURCES = nozzle_test.c \
test-common.c \
../internals.c
Expand Down
77 changes: 77 additions & 0 deletions libnozzle/tests/api_nozzle_get_fd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
*
* Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
*
* This software licensed under GPL-2.0+, LGPL-2.0+
*/

#include "config.h"

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <limits.h>
#include <fcntl.h>

#include "test-common.h"

static int test(void)
{
char device_name[IFNAMSIZ];
size_t size = IFNAMSIZ;
int err=0;
nozzle_t nozzle;
int fd;

printf("Testing get fd\n");

memset(device_name, 0, size);
nozzle = nozzle_open(device_name, size, NULL);
if (!nozzle) {
printf("Unable to init %s\n", device_name);
return -1;
}

fd = nozzle_get_fd(nozzle);
if (fd < 0) {
printf("Unable to get fd\n");
err = -1;
goto out_clean;
}

if (fcntl(fd, F_GETFD) < 0) {
printf("Unable to get valid fd\n");
err = -1;
goto out_clean;
}

printf("Testing ERROR conditions\n");

printf("Passing empty struct to get_fd\n");
if (nozzle_get_fd(NULL) > 0) {
printf("Something is wrong in nozzle_get_fd sanity checks\n");
err = -1;
goto out_clean;
}

out_clean:
if (nozzle) {
nozzle_close(nozzle);
}

return err;
}

int main(void)
{
need_root();

if (test() < 0)
return FAIL;

return PASS;
}

0 comments on commit e667b03

Please sign in to comment.