Replace all printfs with tf_printf, which redirects to android logging. Change into the files directory so that sqlite can do its thing. Getting closer.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4203 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-03-07 17:50:17 +00:00
parent 1c10768aa4
commit 61ff466908
16 changed files with 240 additions and 186 deletions

View File

@ -1,5 +1,6 @@
#include "ssb.h"
#include "log.h"
#include "mem.h"
#include "ssb.db.h"
#include "ssb.js.h"
@ -17,7 +18,7 @@
void tf_ssb_test_id_conversion(const tf_test_options_t* options)
{
printf("Testing id conversion.\n");
tf_printf("Testing id conversion.\n");
uint8_t bin[k_id_bin_len] = { 0 };
char str[k_id_base64_len] = { 0 };
const char* k_id = "@bzRTe6hgOII2yZ1keGGoNoQgostjQc830trHc453crY=.ed25519";
@ -59,20 +60,20 @@ static void _ssb_test_connections_changed(tf_ssb_t* ssb, tf_ssb_change_t change,
if (ssb == test->ssb0)
{
printf("callback0 change=%d connection=%p\n", change, connection);
tf_printf("callback0 change=%d connection=%p\n", change, connection);
test->connection_count0 = count;
}
else if (ssb == test->ssb1)
{
printf("callback1 change=%d connection=%p\n", change, connection);
tf_printf("callback1 change=%d connection=%p\n", change, connection);
test->connection_count1 = count;
}
else if (ssb == test->ssb2)
{
printf("callback2 change=%d connection=%p\n", change, connection);
tf_printf("callback2 change=%d connection=%p\n", change, connection);
test->connection_count2 = count;
}
printf("conns = %d %d %d\n", test->connection_count0, test->connection_count1, test->connection_count2);
tf_printf("conns = %d %d %d\n", test->connection_count0, test->connection_count1, test->connection_count2);
}
typedef struct _count_messages_t
@ -126,7 +127,7 @@ static void _ssb_test_idle(uv_idle_t* idle)
void tf_ssb_test_ssb(const tf_test_options_t* options)
{
printf("Testing SSB.\n");
tf_printf("Testing SSB.\n");
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
@ -162,7 +163,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
assert(b);
b = tf_ssb_whoami(ssb1, id1, sizeof(id1));
assert(b);
printf("ID %s and %s\n", id0, id1);
tf_printf("ID %s and %s\n", id0, id1);
char blob_id[k_id_base64_len] = { 0 };
const char* k_blob = "Hello, blob!";
@ -199,7 +200,7 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
tf_ssb_id_str_to_bin(id0bin, id0);
tf_ssb_connect(ssb1, "127.0.0.1", 12347, id0bin);
printf("Waiting for connection.\n");
tf_printf("Waiting for connection.\n");
while (test.connection_count0 != 1 ||
test.connection_count1 != 1)
{
@ -207,13 +208,13 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
}
tf_ssb_server_close(ssb0);
printf("Waiting for messages.\n");
tf_printf("Waiting for messages.\n");
while (_ssb_test_count_messages(ssb1) < 3)
{
uv_run(&loop, UV_RUN_ONCE);
}
printf("Waiting for blob.\n");
tf_printf("Waiting for blob.\n");
while (!tf_ssb_db_blob_get(ssb1, blob_id, NULL, NULL))
{
uv_run(&loop, UV_RUN_ONCE);
@ -223,12 +224,12 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
size_t s1 = 0;
b = tf_ssb_db_blob_get(ssb1, blob_id, &b1, &s1);
assert(b);
printf("s1 = %zd sl = %zd\n", s1, strlen(k_blob));
tf_printf("s1 = %zd sl = %zd\n", s1, strlen(k_blob));
assert(s1 == strlen(k_blob));
assert(memcmp(b1, k_blob, strlen(k_blob)) == 0);
tf_free(b1);
printf("Waiting for message to self.\n");
tf_printf("Waiting for message to self.\n");
int count0 = 0;
int count1 = 0;
tf_ssb_add_message_added_callback(ssb0, _message_added, NULL, &count0);
@ -240,13 +241,13 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
}
tf_ssb_remove_message_added_callback(ssb0, _message_added, &count0);
printf("Waiting for message from other.\n");
tf_printf("Waiting for message from other.\n");
while (count1 == 0)
{
uv_run(&loop, UV_RUN_ONCE);
}
tf_ssb_remove_message_added_callback(ssb1, _message_added, &count1);
printf("done\n");
tf_printf("done\n");
tf_ssb_send_close(ssb1);
@ -285,12 +286,12 @@ static void _broadcasts_changed(tf_ssb_t* ssb, void* user_data)
}
*count = 0;
tf_ssb_visit_broadcasts(ssb, _broadcasts_visit, count);
printf("BROADCASTS %d %d %d\n", test->broadcast_count0, test->broadcast_count1, test->broadcast_count2);
tf_printf("BROADCASTS %d %d %d\n", test->broadcast_count0, test->broadcast_count1, test->broadcast_count2);
}
void tf_ssb_test_rooms(const tf_test_options_t* options)
{
printf("Testing Rooms.\n");
tf_printf("Testing Rooms.\n");
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
@ -343,7 +344,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
assert(b);
b = tf_ssb_whoami(ssb2, id2, sizeof(id2));
assert(b);
printf("ID %s, %s, %s\n", id0, id1, id2);
tf_printf("ID %s, %s, %s\n", id0, id1, id2);
tf_ssb_server_open(ssb0, 12347);
@ -352,7 +353,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
tf_ssb_connect(ssb1, "127.0.0.1", 12347, id0bin);
tf_ssb_connect(ssb2, "127.0.0.1", 12347, id0bin);
printf("Waiting for connection.\n");
tf_printf("Waiting for connection.\n");
while (test.connection_count0 != 2 ||
test.connection_count1 != 1 ||
test.connection_count2 != 1)
@ -361,7 +362,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
}
tf_ssb_server_close(ssb0);
printf("Waiting for broadcasts.\n");
tf_printf("Waiting for broadcasts.\n");
while (test.broadcast_count1 != 1 ||
test.broadcast_count2 != 1)
{
@ -400,9 +401,9 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
JS_FreeValue(context, message);
tf_ssb_connection_t* tun0 = tf_ssb_connection_tunnel_create(ssb1, id0, tunnel_request_number, id2);
printf("tun0 = %p\n", tun0);
tf_printf("tun0 = %p\n", tun0);
printf("Done.\n");
tf_printf("Done.\n");
while (test.connection_count0 != 2 ||
test.connection_count1 != 2 ||
@ -411,7 +412,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
uv_run(&loop, UV_RUN_ONCE);
}
printf("Done.\n");
tf_printf("Done.\n");
uv_run(&loop, UV_RUN_NOWAIT);
@ -444,7 +445,7 @@ void tf_ssb_test_rooms(const tf_test_options_t* options)
void tf_ssb_test_following(const tf_test_options_t* options)
{
printf("Testing following.\n");
tf_printf("Testing following.\n");
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
@ -485,14 +486,14 @@ void tf_ssb_test_following(const tf_test_options_t* options)
#define DUMP(id, depth) \
do \
{ \
printf("following %d:\n", depth); \
tf_printf("following %d:\n", depth); \
const char** tf_ssb_get_following_deep(tf_ssb_t* ssb_param, const char** ids, int depth_param); \
const char** f = tf_ssb_get_following_deep(ssb0, (const char*[]) { id, NULL }, depth); \
for (const char** p = f; p && *p; p++) \
{ \
printf("* %s\n", *p); \
tf_printf("* %s\n", *p); \
} \
printf("\n"); \
tf_printf("\n"); \
tf_free(f); \
} \
while (0)
@ -527,7 +528,7 @@ void tf_ssb_test_following(const tf_test_options_t* options)
void tf_ssb_test_bench(const tf_test_options_t* options)
{
printf("Testing following.\n");
tf_printf("Testing following.\n");
uv_loop_t loop = { 0 };
uv_loop_init(&loop);
@ -547,7 +548,7 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
tf_ssb_append_post(ssb0, "Hello, world!");
}
clock_gettime(CLOCK_REALTIME, &end_time);
printf("insert = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f);
tf_printf("insert = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f);
tf_ssb_t* ssb1 = tf_ssb_create(&loop, NULL, ":memory:");
tf_ssb_generate_keys(ssb1);
@ -568,15 +569,15 @@ void tf_ssb_test_bench(const tf_test_options_t* options)
tf_ssb_server_open(ssb0, 12347);
tf_ssb_connect(ssb1, "127.0.0.1", 12347, id0bin);
printf("Waiting for messages.\n");
tf_printf("Waiting for messages.\n");
clock_gettime(CLOCK_REALTIME, &start_time);
while (_ssb_test_count_messages(ssb1) < k_messages)
{
uv_run(&loop, UV_RUN_ONCE);
}
clock_gettime(CLOCK_REALTIME, &end_time);
printf("Done.\n");
printf("replicate = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f);
tf_printf("Done.\n");
tf_printf("replicate = %f seconds\n", (float)(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1e9f);
tf_ssb_send_close(ssb1);
tf_ssb_server_close(ssb0);