diff --git a/libknet/tests/Makefile.am b/libknet/tests/Makefile.am index 8c5fab51..dc00351a 100644 --- a/libknet/tests/Makefile.am +++ b/libknet/tests/Makefile.am @@ -1,87 +1,69 @@ # # Copyright (C) 2016-2017 Red Hat, Inc. All rights reserved. # # Authors: Fabio M. Di Nitto # # 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 AM_CFLAGS = $(PTHREAD_CFLAGS) LIBS = $(top_builddir)/libknet/libknet.la \ $(PTHREAD_LIBS) $(dl_LIBS) 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 \ - ../common.c \ - ../crypto.c \ - ../logging.c \ - test-common.c - -int_crypto_test_CFLAGS = $(nss_CFLAGS) $(openssl_CFLAGS) - int_timediff_test_SOURCES = int_timediff.c -crypto_bench_test_SOURCES = crypto_bench.c \ - ../common.c \ - ../crypto.c \ - ../logging.c \ - test-common.c - -crypto_bench_test_CFLAGS = $(nss_CFLAGS) $(openssl_CFLAGS) - 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 deleted file mode 100644 index cf00403d..00000000 --- a/libknet/tests/crypto_bench.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (C) 2016-2017 Red Hat, Inc. All rights reserved. - * - * Authors: Fabio M. Di Nitto - * - * This software licensed under GPL-2.0+, LGPL-2.0+ - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "libknet.h" - -#include "common.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; - struct knet_handle_stats knet_stats; - 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 (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); - - knet_handle_get_stats(knet_h, &knet_stats, sizeof(knet_stats)); - - printf("Shutdown crypto\n"); - - 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[]) -{ - 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 deleted file mode 100644 index 164c40da..00000000 --- a/libknet/tests/int_crypto.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2016-2017 Red Hat, Inc. All rights reserved. - * - * Authors: Fabio M. Di Nitto - * - * This software licensed under GPL-2.0+, LGPL-2.0+ - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "libknet.h" - -#include "common.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 (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