]> git.proxmox.com Git - mirror_kronosnet.git/blame - libnozzle/tests/api_nozzle_get_name_by_handle.c
[nozzle] fix a few coverity errors in the test suite
[mirror_kronosnet.git] / libnozzle / tests / api_nozzle_get_name_by_handle.c
CommitLineData
3f56e1b2 1/*
ec84794b 2 * Copyright (C) 2018-2019 Red Hat, Inc. All rights reserved.
3f56e1b2
FDN
3 *
4 * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
5 *
312ef273 6 * This software licensed under GPL-2.0+
3f56e1b2
FDN
7 */
8
9#include "config.h"
10
11#include <stdio.h>
12#include <string.h>
13#include <errno.h>
14#include <limits.h>
15
16#include "test-common.h"
17
18static int test(void)
19{
20 char device_name[2*IFNAMSIZ];
21 const char *device_name_tmp;
22 size_t size = IFNAMSIZ;
23 nozzle_t nozzle;
24 int err = 0;
25
26 printf("Testing get name by handle\n");
27
28 memset(device_name, 0, size);
29 nozzle = nozzle_open(device_name, size, NULL);
30 if (!nozzle) {
31 printf("Unable to init %s\n", device_name);
32 return -1;
33 }
34
35 device_name_tmp = nozzle_get_name_by_handle(nozzle);
bca3b8a6
FDN
36 if (!device_name_tmp) {
37 if (errno != ENOENT) {
38 printf("Unable to get name by handle\n");
39 } else {
40 printf("received incorrect errno!\n");
41 }
3f56e1b2
FDN
42 err = -1;
43 goto out_clean;
44 }
45
46 if (strcmp(device_name, device_name_tmp)) {
47 printf("get name by handle returned different names for the same handle\n");
48 err = -1;
49 goto out_clean;
50 }
51
52 printf("Testing error conditions\n");
53
54 device_name_tmp = nozzle_get_name_by_handle(NULL);
55 if ((device_name_tmp) || (errno != ENOENT)) {
56 printf("get name by handle returned wrong error\n");
57 err = -1;
58 goto out_clean;
59 }
60
61out_clean:
62
63 if (nozzle) {
64 nozzle_close(nozzle);
65 }
66
67 return err;
68}
69
70int main(void)
71{
72 need_root();
73
74 if (test() < 0)
75 return FAIL;
76
77 return PASS;
78}