diff --git a/libnozzle/tests/api_nozzle_get_name_by_handle.c b/libnozzle/tests/api_nozzle_get_name_by_handle.c index 0fe9eb4f..c05e4486 100644 --- a/libnozzle/tests/api_nozzle_get_name_by_handle.c +++ b/libnozzle/tests/api_nozzle_get_name_by_handle.c @@ -1,74 +1,78 @@ /* * Copyright (C) 2018-2019 Red Hat, Inc. All rights reserved. * * Author: Fabio M. Di Nitto * * This software licensed under GPL-2.0+ */ #include "config.h" #include #include #include #include #include "test-common.h" static int test(void) { char device_name[2*IFNAMSIZ]; const char *device_name_tmp; size_t size = IFNAMSIZ; nozzle_t nozzle; int err = 0; printf("Testing get name by handle\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; } device_name_tmp = nozzle_get_name_by_handle(nozzle); - if ((!device_name_tmp) && (errno != ENOENT)) { - printf("Unable to get name by handle\n"); + if (!device_name_tmp) { + if (errno != ENOENT) { + printf("Unable to get name by handle\n"); + } else { + printf("received incorrect errno!\n"); + } err = -1; goto out_clean; } if (strcmp(device_name, device_name_tmp)) { printf("get name by handle returned different names for the same handle\n"); err = -1; goto out_clean; } printf("Testing error conditions\n"); device_name_tmp = nozzle_get_name_by_handle(NULL); if ((device_name_tmp) || (errno != ENOENT)) { printf("get name by handle returned wrong error\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; } diff --git a/libnozzle/tests/api_nozzle_set_mac.c b/libnozzle/tests/api_nozzle_set_mac.c index 244e866f..abb96364 100644 --- a/libnozzle/tests/api_nozzle_set_mac.c +++ b/libnozzle/tests/api_nozzle_set_mac.c @@ -1,162 +1,158 @@ /* * Copyright (C) 2018-2019 Red Hat, Inc. All rights reserved. * * Author: Fabio M. Di Nitto * * This software licensed under GPL-2.0+ */ #include "config.h" #include #include #include #include #include #include #include #include #include #ifdef KNET_LINUX #include #include #endif #ifdef KNET_BSD #include #endif #include "test-common.h" static int test(void) { char device_name[IFNAMSIZ]; size_t size = IFNAMSIZ; int err=0; nozzle_t nozzle; - char *original_mac = NULL, *current_mac = NULL, *temp_mac = NULL, *err_mac = NULL; + char *original_mac = NULL, *current_mac = NULL, *temp_mac = NULL; struct ether_addr *orig_mac, *cur_mac, *tmp_mac; printf("Testing set MAC\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; } printf("Get current MAC\n"); if (nozzle_get_mac(nozzle, &original_mac) < 0) { printf("Unable to get current MAC address.\n"); err = -1; goto out_clean; } orig_mac = ether_aton(original_mac); if (nozzle_get_mac(nozzle, ¤t_mac) < 0) { printf("Unable to get current MAC address.\n"); err = -1; goto out_clean; } printf("Current MAC: %s\n", current_mac); printf("Setting MAC: 00:01:01:01:01:01\n"); if (nozzle_set_mac(nozzle, "00:01:01:01:01:01") < 0) { printf("Unable to set current MAC address.\n"); err = -1; goto out_clean; } if (nozzle_get_mac(nozzle, &temp_mac) < 0) { printf("Unable to get current MAC address.\n"); err = -1; goto out_clean; } printf("Current MAC: %s\n", temp_mac); cur_mac = ether_aton(current_mac); tmp_mac = ether_aton(temp_mac); printf("Comparing MAC addresses\n"); if (memcmp(cur_mac, tmp_mac, sizeof(struct ether_addr))) { printf("Mac addresses are not the same?!\n"); err = -1; goto out_clean; } printf("Testing reset_mac\n"); if (nozzle_reset_mac(nozzle) < 0) { printf("Unable to reset mac address\n"); err = -1; goto out_clean; } - if (current_mac) + if (current_mac) { free(current_mac); + current_mac = NULL; + } if (nozzle_get_mac(nozzle, ¤t_mac) < 0) { printf("Unable to get current MAC address.\n"); err = -1; goto out_clean; } cur_mac = ether_aton(current_mac); if (memcmp(cur_mac, orig_mac, sizeof(struct ether_addr))) { printf("Mac addresses are not the same?!\n"); err = -1; goto out_clean; } printf("Testing ERROR conditions\n"); printf("Pass NULL to set_mac (pass1)\n"); errno = 0; if ((nozzle_set_mac(nozzle, NULL) >= 0) || (errno != EINVAL)) { printf("Something is wrong in nozzle_set_mac sanity checks\n"); err = -1; goto out_clean; } printf("Pass NULL to set_mac (pass2)\n"); errno = 0; - if ((nozzle_set_mac(NULL, err_mac) >= 0) || (errno != EINVAL)) { + if ((nozzle_set_mac(NULL, current_mac) >= 0) || (errno != EINVAL)) { printf("Something is wrong in nozzle_set_mac sanity checks\n"); err = -1; goto out_clean; } out_clean: - if (err_mac) { - printf("Something managed to set err_mac!\n"); - err = -1; - free(err_mac); - } - if (current_mac) free(current_mac); if (temp_mac) free(temp_mac); if (original_mac) free(original_mac); if (nozzle) { nozzle_close(nozzle); } return err; } int main(void) { need_root(); if (test() < 0) return FAIL; return PASS; }