Replace printf with DEBUG_ macros in 4 test files and partial in test_etcp_two_instances.c
This commit is contained in:
1 parent
3ddfb79338
commit
e1556eb8c4
10 files changed
+83
-49
No files matched your search
+3
-3
@@ -38,8 +38,8 @@ test_etcp_minimal_LDADD = $(top_builddir)/src/utun-etcp.o $(top_builddir)/src/ut
|
||||
|
||||
# Basic crypto test
|
||||
test_crypto_SOURCES = test_crypto.c
|
||||
test_crypto_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source
|
||||
test_crypto_LDADD = $(top_builddir)/tinycrypt/lib/source/utun-aes_encrypt.o $(top_builddir)/tinycrypt/lib/source/utun-aes_decrypt.o $(top_builddir)/tinycrypt/lib/source/utun-ccm_mode.o $(top_builddir)/tinycrypt/lib/source/utun-cmac_mode.o $(top_builddir)/tinycrypt/lib/source/utun-ctr_mode.o $(top_builddir)/tinycrypt/lib/source/utun-sha256.o $(top_builddir)/tinycrypt/lib/source/utun-utils.o -lpthread -lcrypto
|
||||
test_crypto_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -I$(top_srcdir)/lib
|
||||
test_crypto_LDADD = $(top_builddir)/tinycrypt/lib/source/utun-aes_encrypt.o $(top_builddir)/tinycrypt/lib/source/utun-aes_decrypt.o $(top_builddir)/tinycrypt/lib/source/utun-ccm_mode.o $(top_builddir)/tinycrypt/lib/source/utun-cmac_mode.o $(top_builddir)/tinycrypt/lib/source/utun-ctr_mode.o $(top_builddir)/tinycrypt/lib/source/utun-sha256.o $(top_builddir)/tinycrypt/lib/source/utun-utils.o $(top_builddir)/lib/libuasync.a -lpthread -lcrypto
|
||||
|
||||
# New comprehensive ll_queue test with current API
|
||||
test_ll_queue_SOURCES = test_ll_queue.c
|
||||
@@ -48,7 +48,7 @@ test_ll_queue_LDADD = $(top_builddir)/lib/libuasync.a -lpthread -lcrypto
|
||||
|
||||
# ECC encryption test
|
||||
test_ecc_encrypt_SOURCES = test_ecc_encrypt.c
|
||||
test_ecc_encrypt_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source
|
||||
test_ecc_encrypt_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -I$(top_srcdir)/lib
|
||||
test_ecc_encrypt_LDADD = $(top_builddir)/src/utun-secure_channel.o $(top_builddir)/src/utun-crc32.o $(top_builddir)/tinycrypt/lib/source/utun-aes_encrypt.o $(top_builddir)/tinycrypt/lib/source/utun-aes_decrypt.o $(top_builddir)/tinycrypt/lib/source/utun-ccm_mode.o $(top_builddir)/tinycrypt/lib/source/utun-cmac_mode.o $(top_builddir)/tinycrypt/lib/source/utun-ctr_mode.o $(top_builddir)/tinycrypt/lib/source/utun-ecc.o $(top_builddir)/tinycrypt/lib/source/utun-ecc_dh.o $(top_builddir)/tinycrypt/lib/source/utun-ecc_dsa.o $(top_builddir)/tinycrypt/lib/source/utun-sha256.o $(top_builddir)/tinycrypt/lib/source/utun-ecc_platform_specific.o $(top_builddir)/tinycrypt/lib/source/utun-utils.o $(top_builddir)/lib/libuasync.a -lpthread -lcrypto
|
||||
|
||||
# Intensive memory pool test
|
||||
|
||||
Binary file not shown.
+16
-11
@@ -3,34 +3,39 @@
|
||||
#include <tinycrypt/constants.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../lib/debug_config.h"
|
||||
|
||||
#define SC_TAG_SIZE 8
|
||||
#define SC_SESSION_KEY_SIZE 16
|
||||
|
||||
int main() {
|
||||
printf("=== Basic Crypto Test ===\n");
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL);
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "=== Basic Crypto Test ===");
|
||||
|
||||
struct tc_aes_key_sched_struct sched;
|
||||
uint8_t test_key[SC_SESSION_KEY_SIZE] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
|
||||
|
||||
if (tc_aes128_set_encrypt_key(&sched, test_key) != TC_CRYPTO_SUCCESS) {
|
||||
printf("❌ AES key setup failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "AES key setup failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ AES key setup successful\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "AES key setup successful");
|
||||
|
||||
struct tc_ccm_mode_struct ccm_state;
|
||||
TCCcmMode_t c = &ccm_state;
|
||||
uint8_t nonce[13] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD};
|
||||
|
||||
if (tc_ccm_config(c, &sched, nonce, 13, SC_TAG_SIZE) != TC_CRYPTO_SUCCESS) {
|
||||
printf("❌ CCM config failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "CCM config failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ CCM config successful\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "CCM config successful");
|
||||
|
||||
uint8_t plaintext[] = "Hello, World!";
|
||||
uint8_t ciphertext[64];
|
||||
@@ -38,25 +43,25 @@ int main() {
|
||||
size_t ciphertext_len = plaintext_len + SC_TAG_SIZE;
|
||||
|
||||
if (tc_ccm_generation_encryption(ciphertext, ciphertext_len, NULL, 0, plaintext, plaintext_len, c) != TC_CRYPTO_SUCCESS) {
|
||||
printf("❌ Encryption failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Encryption failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ Encryption successful\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Encryption successful");
|
||||
|
||||
uint8_t decrypted[64];
|
||||
if (tc_ccm_decryption_verification(decrypted, plaintext_len, NULL, 0, ciphertext, ciphertext_len, c) != TC_CRYPTO_SUCCESS) {
|
||||
printf("❌ Decryption failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Decryption failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ Decryption successful\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Decryption successful");
|
||||
|
||||
if (memcmp(plaintext, decrypted, plaintext_len) == 0) {
|
||||
printf("✅ Crypto test PASSED\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Crypto test PASSED");
|
||||
return 0;
|
||||
} else {
|
||||
printf("❌ Data mismatch\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Data mismatch");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -1,5 +1,6 @@
|
||||
#include "u_async.h"
|
||||
#include <stdio.h>
|
||||
#include "../lib/debug_config.h"
|
||||
|
||||
/* Test statistics */
|
||||
static struct {
|
||||
@@ -25,11 +26,15 @@ static struct {
|
||||
/* Timer callback for testing */
|
||||
static void test_timer_callback(void* arg) {
|
||||
test_stats.timer_callbacks++;
|
||||
printf("Timer callback fired. Total callbacks: %d\n", test_stats.timer_callbacks);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Timer callback fired. Total callbacks: %d", test_stats.timer_callbacks);
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Before any tests: immediate_timeouts = %d\n", test_stats.immediate_timeouts);
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL);
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Before any tests: immediate_timeouts = %d", test_stats.immediate_timeouts);
|
||||
|
||||
uasync_t* ua = uasync_create();
|
||||
|
||||
@@ -38,11 +43,11 @@ int main() {
|
||||
void* timer = uasync_set_timeout(ua, 0, NULL, test_timer_callback);
|
||||
}
|
||||
|
||||
printf("After setting 5 immediate timeouts, before poll: immediate_timeouts = %d\n", test_stats.immediate_timeouts);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After setting 5 immediate timeouts, before poll: immediate_timeouts = %d", test_stats.immediate_timeouts);
|
||||
|
||||
uasync_poll(ua, 1);
|
||||
|
||||
printf("After poll: immediate_timeouts = %d\n", test_stats.immediate_timeouts);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After poll: immediate_timeouts = %d", test_stats.immediate_timeouts);
|
||||
|
||||
uasync_destroy(ua, 0);
|
||||
return 0;
|
||||
|
||||
Binary file not shown.
+27
-13
@@ -41,24 +41,34 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../lib/debug_config.h"
|
||||
|
||||
#define TC_PASS 0
|
||||
#define TC_FAIL 1
|
||||
|
||||
#define TC_PRINT printf
|
||||
#define TC_ERROR(...) do { printf("ERROR: " __VA_ARGS__); } while(0)
|
||||
#define TC_START(name) printf("Starting test: %s\n", name)
|
||||
#define TC_END_RESULT(result) printf("Result: %s\n", (result) == TC_PASS ? "PASS" : "FAIL")
|
||||
#define TC_END_REPORT(result) printf("Test %s\n", (result) == TC_PASS ? "SUCCESSFUL" : "FAILED")
|
||||
#define TC_PRINT(...) DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, __VA_ARGS__)
|
||||
#define TC_ERROR(...) DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, __VA_ARGS__)
|
||||
#define TC_START(name) DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Starting test: %s", name)
|
||||
#define TC_END_RESULT(result) DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Result: %s", (result) == TC_PASS ? "PASS" : "FAIL")
|
||||
#define TC_END_REPORT(result) DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Test %s", (result) == TC_PASS ? "SUCCESSFUL" : "FAILED")
|
||||
|
||||
static void show_str(const char *label, const uint8_t *s, size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("%s = ", label);
|
||||
for (i = 0; i < (unsigned int) len; ++i) {
|
||||
printf("%02x", s[i]);
|
||||
char hex_buf[256];
|
||||
char *ptr = hex_buf;
|
||||
int remaining = sizeof(hex_buf);
|
||||
int written = snprintf(ptr, remaining, "%s = ", label);
|
||||
if (written < 0 || written >= remaining) return;
|
||||
ptr += written;
|
||||
remaining -= written;
|
||||
|
||||
for (unsigned int i = 0; i < len && remaining > 2; ++i) {
|
||||
written = snprintf(ptr, remaining, "%02x", s[i]);
|
||||
if (written < 0 || written >= remaining) break;
|
||||
ptr += written;
|
||||
remaining -= written;
|
||||
}
|
||||
printf("\n");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CRYPTO, "%s", hex_buf);
|
||||
}
|
||||
|
||||
static int test_key_exchange_and_encrypt(void)
|
||||
@@ -163,17 +173,21 @@ static int test_key_exchange_and_encrypt(void)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL);
|
||||
|
||||
unsigned int result = TC_PASS;
|
||||
|
||||
TC_START("Performing client-server key exchange and encryption test:");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Performing client-server key exchange and encryption test:");
|
||||
|
||||
/* Setup cryptographically secure PRNG */
|
||||
uECC_set_rng(&default_CSPRNG);
|
||||
|
||||
result = test_key_exchange_and_encrypt();
|
||||
|
||||
TC_END_RESULT(result);
|
||||
TC_END_REPORT(result);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Result: %s", result == TC_PASS ? "PASS" : "FAIL");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Test %s", result == TC_PASS ? "SUCCESSFUL" : "FAILED");
|
||||
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -4,12 +4,17 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "../lib/debug_config.h"
|
||||
|
||||
#define TEST_DATA "Hello, ETCP encrypted world!"
|
||||
#define TEST_DATA_LEN 28
|
||||
|
||||
int main() {
|
||||
printf("=== ETCP Crypto Test ===\n");
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL);
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "=== ETCP Crypto Test ===");
|
||||
|
||||
// Create test keys
|
||||
struct SC_MYKEYS server_keys, client_keys;
|
||||
@@ -27,7 +32,7 @@ int main() {
|
||||
// Initialize contexts
|
||||
sc_context_t server_ctx, client_ctx;
|
||||
if (sc_init_ctx(&server_ctx, &server_keys) != SC_OK || sc_init_ctx(&client_ctx, &client_keys) != SC_OK) {
|
||||
printf("❌ Failed to initialize crypto contexts\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Failed to initialize crypto contexts");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -46,7 +51,7 @@ int main() {
|
||||
memcpy(client_ctx.session_key, test_session_key, SC_SESSION_KEY_SIZE);
|
||||
memcpy(server_ctx.session_key, test_session_key, SC_SESSION_KEY_SIZE);
|
||||
|
||||
printf("✅ Crypto contexts initialized\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Crypto contexts initialized");
|
||||
|
||||
// Test encryption/decryption
|
||||
uint8_t plaintext[] = TEST_DATA;
|
||||
@@ -55,21 +60,21 @@ int main() {
|
||||
|
||||
// Client -> Server
|
||||
if (sc_encrypt(&client_ctx, plaintext, TEST_DATA_LEN, ciphertext, &ciphertext_len) != SC_OK) {
|
||||
printf("❌ Encryption failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Encryption failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sc_decrypt(&server_ctx, ciphertext, ciphertext_len, decrypted, &decrypted_len) != SC_OK) {
|
||||
printf("❌ Decryption failed\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Decryption failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (decrypted_len != TEST_DATA_LEN || memcmp(plaintext, decrypted, TEST_DATA_LEN) != 0) {
|
||||
printf("❌ Data mismatch\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CRYPTO, "Data mismatch");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("✅ Client->Server encryption/decryption: PASSED\n");
|
||||
printf("✅ ETCP crypto test PASSED\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "Client->Server encryption/decryption: PASSED");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CRYPTO, "ETCP crypto test PASSED");
|
||||
return 0;
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../src/tun_if.h"
|
||||
#include "../src/secure_channel.h"
|
||||
#include "../lib/u_async.h"
|
||||
#include "../lib/debug_config.h"
|
||||
|
||||
#define TEST_TIMEOUT_MS 3000 // Reduced to 3 seconds for faster testing
|
||||
|
||||
@@ -117,47 +118,51 @@ static void test_timeout(void* arg) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("=== ETCP Two-Instance Connection Test ===\n\n");
|
||||
debug_config_init();
|
||||
debug_set_level(DEBUG_LEVEL_TRACE);
|
||||
debug_set_categories(DEBUG_CATEGORY_ALL);
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "=== ETCP Two-Instance Connection Test ===");
|
||||
|
||||
// Explicitly disable TUN initialization for this test
|
||||
utun_instance_set_tun_init_enabled(0);
|
||||
|
||||
// Create server instance
|
||||
printf("Creating server instance...\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Creating server instance...");
|
||||
struct UASYNC* server_ua = uasync_create();
|
||||
server_instance = utun_instance_create(server_ua, "test_server.conf");
|
||||
if (!server_instance) {
|
||||
printf("Failed to create server instance\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to create server instance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if TUN is disabled and handle accordingly
|
||||
if (server_instance->tun.fd < 0) {
|
||||
printf("ℹ️ Server TUN disabled - skipping full initialization\n");
|
||||
printf("✅ Server instance created successfully (node_id=%llx)\n", (unsigned long long)server_instance->node_id);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_TUN, "Server TUN disabled - skipping full initialization");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Server instance created successfully (node_id=%llx)", (unsigned long long)server_instance->node_id);
|
||||
// Skip to client creation
|
||||
} else {
|
||||
// Normal initialization for TUN-enabled mode
|
||||
if (utun_instance_init(server_instance) < 0) {
|
||||
printf("Failed to initialize server instance\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize server instance");
|
||||
utun_instance_destroy(server_instance);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (utun_instance_register_sockets(server_instance) < 0) {
|
||||
printf("Failed to register server sockets\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to register server sockets");
|
||||
utun_instance_destroy(server_instance);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("Server instance ready (node_id=%llx)\n\n", (unsigned long long)server_instance->node_id);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Server instance ready (node_id=%llx)", (unsigned long long)server_instance->node_id);
|
||||
|
||||
// Create client instance
|
||||
printf("Creating client instance...\n");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "Creating client instance...");
|
||||
struct UASYNC* client_ua = uasync_create();
|
||||
client_instance = utun_instance_create(client_ua, "test_client.conf");
|
||||
if (!client_instance) {
|
||||
printf("Failed to create client instance\n");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to create client instance");
|
||||
utun_instance_destroy(server_instance);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user