Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/libknet/tests/Makefile.am b/libknet/tests/Makefile.am
index df02077d..a748fd45 100644
--- a/libknet/tests/Makefile.am
+++ b/libknet/tests/Makefile.am
@@ -1,91 +1,87 @@
#
# 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+
#
MAINTAINERCLEANFILES = Makefile.in
include $(top_srcdir)/build-aux/check.mk
include $(top_srcdir)/libknet/tests/api-check.mk
EXTRA_DIST = \
api-test-coverage \
api-check.mk
AM_CPPFLAGS = -I$(top_srcdir)/libknet
# override global LIBS that pulls in lots of craft we don't need here
LIBS = $(top_builddir)/libknet/libknet.la
noinst_HEADERS = \
test-common.h
# the order of those tests is NOT random.
# some functions can only be tested properly after some dependents
# API have been validated upfront.
check_PROGRAMS = \
$(api_checks) \
$(int_checks) \
$(fun_checks)
int_checks = \
int_crypto_test \
int_timediff_test
fun_checks =
benchmarks = \
crypto_bench_test \
knet_bench_test
noinst_PROGRAMS = \
api_knet_handle_new_limit_test \
pckt_test \
$(benchmarks) \
$(check_PROGRAMS)
noinst_SCRIPTS = \
api-test-coverage
TESTS = $(check_PROGRAMS)
check-local: check-api-test-coverage
check-api-test-coverage:
chmod u+x $(top_srcdir)/libknet/tests/api-test-coverage
$(top_srcdir)/libknet/tests/api-test-coverage $(top_srcdir) $(top_builddir)
pckt_test_SOURCES = pckt_test.c
int_crypto_test_SOURCES = int_crypto.c \
../crypto.c \
../crypto_nss.c \
../logging.c \
test-common.c
int_crypto_test_CFLAGS = $(nss_CFLAGS)
-int_crypto_test_LDFLAGS = $(nss_LIBS)
-
int_timediff_test_SOURCES = int_timediff.c
crypto_bench_test_SOURCES = crypto_bench.c \
../crypto.c \
../crypto_nss.c \
../logging.c \
test-common.c
crypto_bench_test_CFLAGS = $(nss_CFLAGS)
-crypto_bench_test_LDFLAGS = $(nss_LIBS)
-
knet_bench_test_SOURCES = knet_bench.c \
test-common.c \
../common.c \
../logging.c \
../compat.c \
../transport_common.c
diff --git a/libknet/tests/crypto_bench.c b/libknet/tests/crypto_bench.c
index f54e09be..5d1d83c6 100644
--- a/libknet/tests/crypto_bench.c
+++ b/libknet/tests/crypto_bench.c
@@ -1,279 +1,269 @@
/*
* 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 <time.h>
#include <pthread.h>
#include "libknet.h"
#include "internals.h"
#include "crypto.h"
#include "threads_common.h"
#include "test-common.h"
pthread_rwlock_t shlib_rwlock;
static void test(void)
{
knet_handle_t knet_h;
int logfd;
struct knet_handle_crypto_cfg knet_handle_crypto_cfg;
char *buf1, *buf2, *buf3;
const char *input = "Encrypt me!\x0";
ssize_t input_len = strlen(input) + 1;
ssize_t outbuf_len;
int loops;
struct timespec clock_start, clock_end;
unsigned long long time_diff;
struct iovec iov_in;
struct iovec iov_multi[4];
int err = 0;
err = pthread_rwlock_init(&shlib_rwlock, NULL);
if (err) {
printf("unable to init lock: %s\n", strerror(err));
exit(FAIL);
}
memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
logfd = start_logging(stdout);
knet_h = knet_handle_new(1, logfd, KNET_LOG_DEBUG);
if (!knet_h) {
printf("knet_handle_new failed: %s\n", strerror(errno));
exit(FAIL);
}
printf("Test knet_handle_crypto with nss/aes128/sha1 and normal key\n");
memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
strncpy(knet_handle_crypto_cfg.crypto_model, "nss", sizeof(knet_handle_crypto_cfg.crypto_model) - 1);
strncpy(knet_handle_crypto_cfg.crypto_cipher_type, "aes128", sizeof(knet_handle_crypto_cfg.crypto_cipher_type) - 1);
strncpy(knet_handle_crypto_cfg.crypto_hash_type, "sha1", sizeof(knet_handle_crypto_cfg.crypto_hash_type) - 1);
knet_handle_crypto_cfg.private_key_len = 2000;
- if (knet_handle_crypto(knet_h, &knet_handle_crypto_cfg)) {
+ if (crypto_init(knet_h, &knet_handle_crypto_cfg) < 0) {
printf("knet_handle_crypto failed with correct config: %s\n", strerror(errno));
knet_handle_free(knet_h);
exit(FAIL);
}
buf1=malloc(input_len);
buf2=malloc(input_len + knet_h->sec_header_size);
buf3=malloc(input_len + knet_h->sec_header_size);
memset(buf1, 0, input_len);
memset(buf2, 0, input_len + knet_h->sec_header_size);
memset(buf3, 0, input_len + knet_h->sec_header_size);
/*
* setup source buffer
*/
if (clock_gettime(CLOCK_MONOTONIC, &clock_start) != 0) {
printf("Unable to get start time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
for (loops=0; loops<1000000; loops++) {
memset(buf1, 0, input_len);
memset(buf2, 0, input_len + knet_h->sec_header_size);
memset(buf3, 0, input_len + knet_h->sec_header_size);
strncpy(buf1, input, input_len);
if (crypto_encrypt_and_sign(knet_h, (unsigned char *)buf1, strlen(buf1)+1, (unsigned char *)buf2, &outbuf_len) < 0) {
printf("Unable to crypt and sign!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (crypto_authenticate_and_decrypt(knet_h, (unsigned char *)buf2, outbuf_len, (unsigned char *)buf3, &outbuf_len) < 0) {
printf("Unable to auth and decrypt!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (memcmp(buf1, buf3, outbuf_len)) {
printf("Crypt / Descrypt produced two different data set!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
}
if (clock_gettime(CLOCK_MONOTONIC, &clock_end) != 0) {
printf("Unable to get end time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
timespec_diff(clock_start, clock_end, &time_diff);
printf("Execution of 1000000 loops (buf_in api): %llu/ns\n", time_diff);
if (clock_gettime(CLOCK_MONOTONIC, &clock_start) != 0) {
printf("Unable to get start time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
memset(buf1, 0, input_len);
strncpy(buf1, input, input_len);
for (loops=0; loops<1000000; loops++) {
memset(buf2, 0, input_len + knet_h->sec_header_size);
memset(buf3, 0, input_len + knet_h->sec_header_size);
memset(&iov_in, 0, sizeof(iov_in));
iov_in.iov_base = (unsigned char *)buf1;
iov_in.iov_len = strlen(buf1)+1;
if (crypto_encrypt_and_signv(knet_h, &iov_in, 1, (unsigned char *)buf2, &outbuf_len) < 0) {
printf("Unable to crypt and sign!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (crypto_authenticate_and_decrypt(knet_h, (unsigned char *)buf2, outbuf_len, (unsigned char *)buf3, &outbuf_len) < 0) {
printf("Unable to auth and decrypt!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (memcmp(buf1, buf3, outbuf_len)) {
printf("Crypt / Descrypt produced two different data set!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
}
if (clock_gettime(CLOCK_MONOTONIC, &clock_end) != 0) {
printf("Unable to get end time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
timespec_diff(clock_start, clock_end, &time_diff);
printf("Execution of 1000000 loops (iov_in api): %llu/ns\n", time_diff);
if (clock_gettime(CLOCK_MONOTONIC, &clock_start) != 0) {
printf("Unable to get start time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
memset(buf1, 0, input_len);
strncpy(buf1, input, input_len);
for (loops=0; loops<1000000; loops++) {
memset(buf2, 0, input_len + knet_h->sec_header_size);
memset(buf3, 0, input_len + knet_h->sec_header_size);
memset(&iov_multi, 0, sizeof(iov_multi));
/*
* "Encrypt me!\n" = 12 bytes
*/
iov_multi[0].iov_base = (unsigned char *)buf1;
iov_multi[0].iov_len = 3;
iov_multi[1].iov_base = (unsigned char *)buf1 + 3;
iov_multi[1].iov_len = 3;
iov_multi[2].iov_base = (unsigned char *)buf1 + 6;
iov_multi[2].iov_len = 3;
iov_multi[3].iov_base = (unsigned char *)buf1 + 9;
iov_multi[3].iov_len = 3;
if (crypto_encrypt_and_signv(knet_h, iov_multi, 4, (unsigned char *)buf2, &outbuf_len) < 0) {
printf("Unable to crypt and sign!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (crypto_authenticate_and_decrypt(knet_h, (unsigned char *)buf2, outbuf_len, (unsigned char *)buf3, &outbuf_len) < 0) {
printf("Unable to auth and decrypt!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
if (memcmp(buf1, buf3, outbuf_len)) {
printf("Crypt / Descrypt produced two different data set!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
}
if (clock_gettime(CLOCK_MONOTONIC, &clock_end) != 0) {
printf("Unable to get end time!\n");
knet_handle_free(knet_h);
exit(FAIL);
}
timespec_diff(clock_start, clock_end, &time_diff);
printf("Execution of 1000000 loops (iov_in multi api): %llu/ns\n", time_diff);
printf("Shutdown crypto\n");
- memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
- strncpy(knet_handle_crypto_cfg.crypto_model, "none", sizeof(knet_handle_crypto_cfg.crypto_model) - 1);
- strncpy(knet_handle_crypto_cfg.crypto_cipher_type, "none", sizeof(knet_handle_crypto_cfg.crypto_cipher_type) - 1);
- strncpy(knet_handle_crypto_cfg.crypto_hash_type, "none", sizeof(knet_handle_crypto_cfg.crypto_hash_type) - 1);
- knet_handle_crypto_cfg.private_key_len = 2000;
-
- if (knet_handle_crypto(knet_h, &knet_handle_crypto_cfg) < 0) {
- printf("Unable to shutdown crypto: %s\n", strerror(errno));
- knet_handle_free(knet_h);
- exit(FAIL);
- }
+ crypto_fini(knet_h);
knet_handle_free(knet_h);
free(buf1);
free(buf2);
free(buf3);
pthread_rwlock_destroy(&shlib_rwlock);
}
int main(int argc, char *argv[])
{
need_root();
printf("Testing with default scheduler\n");
set_scheduler(SCHED_OTHER);
test();
printf("Testing with SCHED_RR scheduler\n");
set_scheduler(SCHED_RR);
test();
printf("Testing with SCHED_FIFO scheduler\n");
set_scheduler(SCHED_FIFO);
test();
return PASS;
}
diff --git a/libknet/tests/int_crypto.c b/libknet/tests/int_crypto.c
index eb715440..77f39de9 100644
--- a/libknet/tests/int_crypto.c
+++ b/libknet/tests/int_crypto.c
@@ -1,159 +1,145 @@
/*
* 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 <pthread.h>
#include "libknet.h"
#include "internals.h"
#include "crypto.h"
#include "test-common.h"
pthread_rwlock_t shlib_rwlock;
static void test(void)
{
knet_handle_t knet_h;
int logfds[2];
struct knet_handle_crypto_cfg knet_handle_crypto_cfg;
char *buf1, *buf2, *buf3;
const char *input = "Encrypt me!\x0";
ssize_t input_len = strlen(input) + 1;
ssize_t outbuf_len;
int i;
int err = 0;
err = pthread_rwlock_init(&shlib_rwlock, NULL);
if (err) {
printf("unable to init lock: %s\n", strerror(err));
exit(FAIL);
}
memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
setup_logpipes(logfds);
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);
}
flush_logs(logfds[0], stdout);
printf("Test knet_handle_crypto with nss/aes128/sha1 and normal key\n");
memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
strncpy(knet_handle_crypto_cfg.crypto_model, "nss", sizeof(knet_handle_crypto_cfg.crypto_model) - 1);
strncpy(knet_handle_crypto_cfg.crypto_cipher_type, "aes128", sizeof(knet_handle_crypto_cfg.crypto_cipher_type) - 1);
strncpy(knet_handle_crypto_cfg.crypto_hash_type, "sha1", sizeof(knet_handle_crypto_cfg.crypto_hash_type) - 1);
knet_handle_crypto_cfg.private_key_len = 2000;
- if (knet_handle_crypto(knet_h, &knet_handle_crypto_cfg)) {
- printf("knet_handle_crypto failed with correct config: %s\n", strerror(errno));
+ if (crypto_init(knet_h, &knet_handle_crypto_cfg) < 0) {
+ printf("crypto_init failed: %s\n", strerror(errno));
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
flush_logs(logfds[0], stdout);
buf1=malloc(input_len);
buf2=malloc(input_len + knet_h->sec_header_size);
buf3=malloc(input_len + knet_h->sec_header_size);
memset(buf1, 0, input_len);
memset(buf2, 0, input_len + knet_h->sec_header_size);
memset(buf3, 0, input_len + knet_h->sec_header_size);
/*
* setup source buffer
*/
strncpy(buf1, input, input_len);
printf("Source Data: %s\n", buf1);
if (crypto_encrypt_and_sign(knet_h, (unsigned char *)buf1, strlen(buf1)+1, (unsigned char *)buf2, &outbuf_len) < 0) {
printf("Unable to crypt and sign!\n");
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
printf("Encrypted Data: ");
for (i=0; i<outbuf_len; i++) {
printf("%02x ", (unsigned char)buf2[i]);
}
printf("\n");
if (crypto_authenticate_and_decrypt(knet_h, (unsigned char *)buf2, outbuf_len, (unsigned char *)buf3, &outbuf_len) < 0) {
printf("Unable to auth and decrypt!\n");
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
printf("Decrypted Data: %s\n", buf3);
if (memcmp(buf1, buf3, outbuf_len)) {
printf("Crypt / Descrypt produced two different data set!\n");
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}
printf("Shutdown crypto\n");
-
- memset(&knet_handle_crypto_cfg, 0, sizeof(struct knet_handle_crypto_cfg));
- strncpy(knet_handle_crypto_cfg.crypto_model, "none", sizeof(knet_handle_crypto_cfg.crypto_model) - 1);
- strncpy(knet_handle_crypto_cfg.crypto_cipher_type, "none", sizeof(knet_handle_crypto_cfg.crypto_cipher_type) - 1);
- strncpy(knet_handle_crypto_cfg.crypto_hash_type, "none", sizeof(knet_handle_crypto_cfg.crypto_hash_type) - 1);
- knet_handle_crypto_cfg.private_key_len = 2000;
-
- if (knet_handle_crypto(knet_h, &knet_handle_crypto_cfg) < 0) {
- printf("Unable to shutdown crypto: %s\n", strerror(errno));
- knet_handle_free(knet_h);
- flush_logs(logfds[0], stdout);
- close_logpipes(logfds);
- exit(FAIL);
- }
-
+ crypto_fini(knet_h);
flush_logs(logfds[0], stdout);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
free(buf1);
free(buf2);
free(buf3);
pthread_rwlock_destroy(&shlib_rwlock);
}
int main(int argc, char *argv[])
{
need_root();
test();
return PASS;
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Feb 27, 1:48 AM (1 d, 3 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1466012
Default Alt Text
(14 KB)

Event Timeline