Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/libknet/tests/api_knet_handle_free.c b/libknet/tests/api_knet_handle_free.c
index 0918662f..907dbb9a 100644
--- a/libknet/tests/api_knet_handle_free.c
+++ b/libknet/tests/api_knet_handle_free.c
@@ -1,96 +1,90 @@
/*
* Copyright (C) 2016 Red Hat, Inc. All rights reserved.
*
* Authors: Fabio M. Di Nitto <fabbione@kronosnet.org>
*
* This software licensed under GPL-2.0+, LGPL-2.0+
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "libknet.h"
#include "internals.h"
#include "test-common.h"
-static void test_noparam(void)
+static void test(void)
{
+ knet_handle_t knet_h;
+ int logfds[2];
+
+ setup_logpipes(logfds);
+
printf("Test knet_handle_free with invalid knet_h\n");
if ((!knet_handle_free(NULL)) || (errno != EINVAL)) {
printf("knet_handle_free failed to detect invalid parameter\n");
exit(FAIL);
}
-}
-
-static void test_param(void)
-{
- knet_handle_t knet_h;
- int logfds[2];
-
- setup_logpipes(logfds);
printf("Test knet_handle_free with one host configured\n");
knet_h = knet_handle_new(1, logfds[1], KNET_LOG_DEBUG);
if (!knet_h) {
printf("knet_handle_new failed: %s\n", strerror(errno));
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
if (knet_host_add(knet_h, 1) < 0) {
printf("Unable to add new knet_host: %s\n", strerror(errno));
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
if ((!knet_handle_free(knet_h)) || (errno != EBUSY)) {
printf("knet_handle_free didn't return error or correct errno with one host configured: %s\n", strerror(errno));
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
flush_logs(logfds[0], stdout);
if (knet_host_remove(knet_h, 1) < 0) {
printf("Unable to remove knet_host: %s\n", strerror(errno));
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
if (knet_handle_free(knet_h) < 0) {
printf("knet_handle_free failed: %s\n", strerror(errno));
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
flush_logs(logfds[0], stdout);
-
close_logpipes(logfds);
}
int main(int argc, char *argv[])
{
need_root();
- test_noparam();
-
- test_param();
+ test();
return PASS;
}
diff --git a/libknet/tests/api_knet_handle_new.c b/libknet/tests/api_knet_handle_new.c
index de1e8647..020f46da 100644
--- a/libknet/tests/api_knet_handle_new.c
+++ b/libknet/tests/api_knet_handle_new.c
@@ -1,157 +1,139 @@
/*
* Copyright (C) 2016 Red Hat, Inc. All rights reserved.
*
* Authors: Fabio M. Di Nitto <fabbione@kronosnet.org>
*
* This software licensed under GPL-2.0+, LGPL-2.0+
*/
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "libknet.h"
#include "internals.h"
#include "test-common.h"
-static void test_nologging(void)
+static void test(void)
{
knet_handle_t knet_h;
+ struct rlimit cur;
+ int logfds[2];
printf("Test knet_handle_new hostid 1, no logging\n");
knet_h = knet_handle_new(1, 0, 0);
if (!knet_h) {
printf("Unable to init knet_handle! err: %s\n", strerror(errno));
exit(FAIL);
}
if (knet_handle_free(knet_h) != 0) {
printf("Unable to free knet_handle\n");
exit(FAIL);
}
printf("Test knet_handle_new hostid -1, no logging\n");
knet_h = knet_handle_new(-1, 0, 0);
if (!knet_h) {
printf("Unable to init knet_handle! err: %s\n", strerror(errno));
exit(FAIL);
}
/*
* -1 == uint16_t 65535
*/
if (knet_h->host_id != 65535) {
printf("host_id size might have changed!\n");
+ knet_handle_free(knet_h);
exit(FAIL);
}
if (knet_handle_free(knet_h) != 0) {
printf("Unable to free knet_handle\n");
exit(FAIL);
}
-}
-
-static void test_logging(void)
-{
- knet_handle_t knet_h;
- struct rlimit cur;
- int logfds[2];
if (prlimit(0, RLIMIT_NOFILE, NULL, &cur) < 0) {
printf("Unable to get current fd limit: %s\n", strerror(errno));
exit(SKIP);
}
/*
* passing a bad fd and it should fail
*/
printf("Test knet_handle_new hostid 1, incorrect log_fd (-1)\n");
knet_h = knet_handle_new(1, -1, 0);
if ((!knet_h) && (errno != EINVAL)) {
printf("knet_handle_new returned incorrect errno on incorrect log_fd\n");
exit(FAIL);
}
if (knet_h) {
printf("knet_handle_new accepted an incorrect (-1) log_fd\n");
knet_handle_free(knet_h);
exit(FAIL);
}
/*
* passing a bad fd and it should fail
*/
printf("Test knet_handle_new hostid 1, incorrect log_fd (max_fd + 1)\n");
knet_h = knet_handle_new(1, (int) cur.rlim_max, 0);
- if ((!knet_h) && (errno != EINVAL)) {
- printf("knet_handle_new returned incorrect errno on incorrect log_fd: %s\n", strerror(errno));
- exit(FAIL);
- }
-
- if (knet_h) {
- printf("knet_handle_new accepted an incorrect (max_fd + 1) log_fd\n");
+ if ((knet_h) || (errno != EINVAL)) {
+ printf("knet_handle_new accepted an incorrect (max_fd + 1) log_fd or returned incorrect errno on incorrect log_fd: %s\n", strerror(errno));
knet_handle_free(knet_h);
exit(FAIL);
}
setup_logpipes(logfds);
printf("Test knet_handle_new hostid 1, proper log_fd, invalid log level (DEBUG + 1)\n");
knet_h = knet_handle_new(1, logfds[1], KNET_LOG_DEBUG + 1);
- if ((!knet_h) && (errno != EINVAL)) {
- printf("knet_handle_new returned incorrect errno on incorrect log level: %s\n", strerror(errno));
- flush_logs(logfds[0], stdout);
- close_logpipes(logfds);
- exit(FAIL);
- }
-
- if (knet_h) {
- printf("knet_handle_new accepted an incorrect log level\n");
+ if ((knet_h) || (errno != EINVAL)) {
+ printf("knet_handle_new accepted an incorrect log level or returned incorrect errno on incorrect log level: %s\n", strerror(errno));
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
printf("Test knet_handle_new hostid 1, proper log_fd, proper log level (DEBUG)\n");
knet_h = knet_handle_new(1, logfds[1], KNET_LOG_DEBUG);
if (!knet_h) {
printf("knet_handle_new failed: %s\n", strerror(errno));
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
}
int main(int argc, char *argv[])
{
need_root();
- test_nologging();
-
- test_logging();
+ test();
return PASS;
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 4:00 AM (8 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1018203
Default Alt Text
(6 KB)

Event Timeline