Start of db_dump tests.

This commit is contained in:
Roger A. Light
2022-11-10 23:27:47 +00:00
parent a111668629
commit 6b1b0bf7bc
24 changed files with 267 additions and 164 deletions
+16 -57
View File
@@ -6,26 +6,24 @@ CFLAGS_FINAL=${CFLAGS} ${APP_CFLAGS} -I${R}/include -I${R}/ -I${R}/lib -I${R}/sr
OBJS = \
db_dump.o \
print.o \
\
memory_mosq.o \
memory_public.o \
packet_datatypes.o \
packet_mosq.o \
persist_read.o \
persist_read_v234.o \
persist_read_v5.o \
property_mosq.o \
send_disconnect.o \
stubs.o \
time_mosq.o \
topic_tok.o \
utf8_mosq.o
stubs.o
BROKER_OBJS = \
${R}/src/memory_mosq.o \
${R}/src/memory_public.o \
${R}/src/packet_datatypes.o \
${R}/src/persist_read.o \
${R}/src/persist_read_v234.o \
${R}/src/persist_read_v5.o \
${R}/src/property_mosq.o \
${R}/src/topic_tok.o \
${R}/src/utf8_mosq.o
.PHONY: all clean reallyclean
all : mosquitto_db_dump
mosquitto_db_dump : ${OBJS}
mosquitto_db_dump : ${OBJS} ${BROKER_OBJS}
${CROSS_COMPILE}${CC} $^ -o $@ ${LDFLAGS} ${LIBS} ${APP_LDFLAGS}
db_dump.o : db_dump.c db_dump.h ${R}/src/persist.h
@@ -34,55 +32,16 @@ db_dump.o : db_dump.c db_dump.h ${R}/src/persist.h
print.o : print.c db_dump.h ${R}/src/persist.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
memory_mosq.o : ${R}/lib/memory_mosq.c ${R}/lib/memory_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
memory_public.o : ${R}/src/memory_public.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
net_mosq.o : ${R}/lib/net_mosq.c ${R}/lib/net_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
packet_datatypes.o : ${R}/lib/packet_datatypes.c ${R}/lib/packet_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
packet_mosq.o : ${R}/lib/packet_mosq.c ${R}/lib/packet_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
persist_read.o : ${R}/src/persist_read.c ${R}/src/persist.h ${R}/src/mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
persist_read_v234.o : ${R}/src/persist_read_v234.c ${R}/src/persist.h ${R}/src/mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
persist_read_v5.o : ${R}/src/persist_read_v5.c ${R}/src/persist.h ${R}/src/mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
property_mosq.o : ${R}/lib/property_mosq.c ${R}/lib/property_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
read_handle.o : ${R}/src/read_handle.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
${BROKER_OBJS} :
make -C ${R}/src
stubs.o : stubs.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
send_disconnect.o : ${R}/lib/send_disconnect.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
time_mosq.o : ${R}/common/time_mosq.c ${R}/common/time_mosq.h
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
topic_tok.o : ${R}/src/topic_tok.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
utf8_mosq.o : ${R}/lib/utf8_mosq.c
${CROSS_COMPILE}${CC} $(CFLAGS_FINAL) -c $< -o $@
reallyclean: clean
clean :
-rm -f *.o mosquitto_db_dump
-rm -f *.o mosquitto_db_dump *.gcda *.gcno
install:
+8 -102
View File
@@ -22,11 +22,7 @@ void context__add_to_by_id(struct mosquitto *context)
int db__message_store(const struct mosquitto *source, struct mosquitto_base_msg *base_msg, uint32_t message_expiry_interval, dbid_t store_id, enum mosquitto_msg_origin origin)
{
UNUSED(source);
UNUSED(base_msg);
UNUSED(message_expiry_interval);
UNUSED(store_id);
UNUSED(origin);
UNUSED(source); UNUSED(base_msg); UNUSED(message_expiry_interval); UNUSED(store_id); UNUSED(origin);
return 0;
}
@@ -35,132 +31,42 @@ void db__msg_store_ref_inc(struct mosquitto_base_msg *base_msg)
UNUSED(base_msg);
}
int handle__packet(struct mosquitto *context)
{
UNUSED(context);
return 0;
}
int log__printf(struct mosquitto *mosq, unsigned int level, const char *fmt, ...)
{
UNUSED(mosq);
UNUSED(level);
UNUSED(fmt);
UNUSED(mosq); UNUSED(level); UNUSED(fmt);
return 0;
}
FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read)
{
UNUSED(path);
UNUSED(mode);
UNUSED(restrict_read);
UNUSED(path); UNUSED(mode); UNUSED(restrict_read);
return NULL;
}
enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq)
{
UNUSED(mosq);
return mosq_cs_new;
}
int mux__add_out(struct mosquitto *mosq)
{
UNUSED(mosq);
return 0;
}
int mux__remove_out(struct mosquitto *mosq)
{
UNUSED(mosq);
return 0;
}
bool net__is_connected(struct mosquitto *mosq)
{
UNUSED(mosq);
return false;
}
ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count)
{
UNUSED(mosq);
UNUSED(buf);
UNUSED(count);
return 0;
}
ssize_t net__read_ws(struct mosquitto *mosq, void *buf, size_t count)
{
UNUSED(mosq);
UNUSED(buf);
UNUSED(count);
return 0;
}
ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count)
{
UNUSED(mosq);
UNUSED(buf);
UNUSED(count);
return 0;
}
int retain__store(const char *topic, struct mosquitto_base_msg *base_msg, char **split_topics, bool persist)
{
UNUSED(topic);
UNUSED(base_msg);
UNUSED(split_topics);
UNUSED(persist);
UNUSED(topic); UNUSED(base_msg); UNUSED(split_topics); UNUSED(persist);
return 0;
}
int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options)
{
UNUSED(context);
UNUSED(sub);
UNUSED(qos);
UNUSED(identifier);
UNUSED(options);
return 0;
}
int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, int retain, struct mosquitto_base_msg **base_msg)
{
UNUSED(source_id);
UNUSED(topic);
UNUSED(qos);
UNUSED(retain);
UNUSED(base_msg);
return 0;
}
int keepalive__update(struct mosquitto *context)
{
UNUSED(context);
UNUSED(context); UNUSED(sub); UNUSED(qos); UNUSED(identifier); UNUSED(options); UNUSED(root);
return 0;
}
void db__msg_add_to_inflight_stats(struct mosquitto_msg_data *msg_data, struct mosquitto_client_msg *msg)
{
UNUSED(msg_data);
UNUSED(msg);
UNUSED(msg_data); UNUSED(msg);
}
void db__msg_add_to_queued_stats(struct mosquitto_msg_data *msg_data, struct mosquitto_client_msg *msg)
{
UNUSED(msg_data);
UNUSED(msg);
UNUSED(msg_data); UNUSED(msg);
}
int session_expiry__add_from_persistence(struct mosquitto *context, time_t expiry_time)
{
UNUSED(context);
UNUSED(expiry_time);
UNUSED(context); UNUSED(expiry_time);
return 0;
}
void mosquitto_log_printf(int level, const char *fmt, ...)
{
UNUSED(level);
UNUSED(fmt);
}
+5 -5
View File
@@ -524,11 +524,11 @@ int persist__restore(void)
fclose(fptr);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld base messages", base_msg_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld retained messages", retained_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld clients", client_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld subscriptions", subscription_count);
mosquitto_log_printf(MOSQ_LOG_INFO, "Restored %ld client messages", client_msg_count);
log__printf(NULL, MOSQ_LOG_INFO, "Restored %ld base messages", base_msg_count);
log__printf(NULL, MOSQ_LOG_INFO, "Restored %ld retained messages", retained_count);
log__printf(NULL, MOSQ_LOG_INFO, "Restored %ld clients", client_count);
log__printf(NULL, MOSQ_LOG_INFO, "Restored %ld subscriptions", subscription_count);
log__printf(NULL, MOSQ_LOG_INFO, "Restored %ld client messages", client_msg_count);
return rc;
error:
+2
View File
@@ -14,11 +14,13 @@ test-compile:
check : test
test : utest
$(MAKE) -C apps test
$(MAKE) -C broker test
$(MAKE) -C lib test
$(MAKE) -C client test
ptest : utest
$(MAKE) -C apps ptest
$(MAKE) -C broker ptest
$(MAKE) -C lib ptest
$(MAKE) -C client ptest
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
from mosq_test_helper import *
def do_test(file, counts):
stdout = f"SC: {counts[0]} " + \
f"SS: {counts[1]} " + \
f"MC: {counts[2]} " + \
f"MS: {counts[3]} " + \
f" {counts[4]}\n"
cmd = ['../../apps/db_dump/mosquitto_db_dump',
'--client-stats',
f'db_dump/{file}'
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8')
if res.stdout != stdout:
print(res.stdout)
print(stdout)
raise mosq_test.TestError
do_test('v6-single-all.test-db', [1,27,1,111,'single-all'])
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
from mosq_test_helper import *
def do_test(file, stdout):
cmd = ['../../apps/db_dump/mosquitto_db_dump',
f'db_dump/{file}'
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8')
if res.stdout != stdout:
raise mosq_test.TestError
v3_empty = """Mosquitto DB dump
CRC: 0
DB version: 3
DB_CHUNK_CFG:
Length: 10
Shutdown: 1
DB ID size: 8
Last DB ID: 51
"""
do_test('v3-empty.test-db', v3_empty)
v4_empty = """Mosquitto DB dump
CRC: 0
DB version: 4
DB_CHUNK_CFG:
Length: 10
Shutdown: 1
DB ID size: 8
Last DB ID: 102
"""
do_test('v4-empty.test-db', v4_empty)
v5_empty = """Mosquitto DB dump
CRC: 0
DB version: 5
DB_CHUNK_CFG:
Length: 16
Shutdown: 1
DB ID size: 8
Last DB ID: 52
"""
do_test('v5-empty.test-db', v5_empty)
v6_empty = """Mosquitto DB dump
CRC: 0
DB version: 6
DB_CHUNK_CFG:
Length: 16
Shutdown: 1
DB ID size: 8
Last DB ID: 208485212291791
"""
do_test('v6-empty.test-db', v6_empty)
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from mosq_test_helper import *
def do_test(file, stdout):
cmd = ['../../apps/db_dump/mosquitto_db_dump',
f'db_dump/{file}'
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8')
if res.stdout != stdout:
raise mosq_test.TestError
stdout = """Mosquitto DB dump
CRC: 0
DB version: 6
DB_CHUNK_CFG:
Length: 16
Shutdown: 1
DB ID size: 8
Last DB ID: 208508774941868
DB_CHUNK_BASE_MSG:
Length: 85
Store ID: 208508774941868
Source Port: 1883
Source MID: 1
Topic: (null)
QoS: 1
Retain: 1
Payload Length: 7
Expiry Time: 0
Payload: message
DB_CHUNK_CLIENT:
Length: 34
Client ID: single-all
Last MID: 1
Session expiry time: 0
Session expiry interval: 4294967295
DB_CHUNK_CLIENT_MSG:
Length: 26
Client ID: single-all
Store ID: 208508774941868
MID: 1
QoS: 1
Retain: 0
Direction: 1
State: 11
Dup: 0
DB_CHUNK_SUB:
Length: 27
Client ID: single-all
Topic: topic
QoS: 1
Subscription ID: 0
Options: 0x00
DB_CHUNK_RETAIN:
Length: 8
Store ID: 208508774941868
"""
do_test('v6-single-all.test-db', stdout)
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
from mosq_test_helper import *
def do_test(file, counts):
stdout = f"DB_CHUNK_CFG: {counts[0]}\n" + \
f"DB_CHUNK_BASE_MSG: {counts[1]}\n" + \
f"DB_CHUNK_CLIENT_MSG: {counts[2]}\n" + \
f"DB_CHUNK_RETAIN: {counts[3]}\n" + \
f"DB_CHUNK_SUB: {counts[4]}\n" + \
f"DB_CHUNK_CLIENT: {counts[5]}\n"
cmd = ['../../apps/db_dump/mosquitto_db_dump',
'--stats',
f'db_dump/{file}'
]
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=1, encoding='utf-8')
if res.stdout != stdout:
print(res.stdout)
raise mosq_test.TestError
do_test('v3-empty.test-db', [1,0,0,0,0,0])
do_test('v4-empty.test-db', [1,0,0,0,0,0])
do_test('v5-empty.test-db', [1,0,0,0,0,0])
do_test('v6-empty.test-db', [1,0,0,0,0,0])
do_test('v4-single-client.test-db', [1,0,0,0,0,1])
do_test('v6-single-client.test-db', [1,0,0,0,0,1])
do_test('v4-single-retain.test-db', [1,1,0,1,0,0])
do_test('v6-single-retain.test-db', [1,1,0,1,0,0])
do_test('v4-single-sub.test-db', [1,0,0,0,1,1])
do_test('v6-single-sub.test-db', [1,0,0,0,1,1])
do_test('v4-single-cmsg.test-db', [1,1,1,0,1,1])
do_test('v6-single-cmsg.test-db', [1,1,1,0,1,1])
do_test('v6-single-all.test-db', [1,1,1,1,1,1])
+19
View File
@@ -0,0 +1,19 @@
file(GLOB PY_TEST_FILES [0-9][0-9]-*.py)
set(EXCLUDE_LIST
# none
)
foreach(PY_TEST_FILE ${PY_TEST_FILES})
get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE)
if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST)
continue()
endif()
add_test(NAME apps-${PY_TEST_NAME}
COMMAND ${PY_TEST_FILE}
)
set_tests_properties(apps-${PY_TEST_NAME}
PROPERTIES
ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}"
)
endforeach()
+18
View File
@@ -0,0 +1,18 @@
R=../..
include ${R}/config.mk
.PHONY: all check test ptest clean
all :
check : test
ptest : test
test : 01
01 :
./01-db-dump-client-stats.py
./01-db-dump-print-empty.py
./01-db-dump-print-v6-all.py
./01-db-dump-stats.py
clean:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
import mqtt5_opts
import mqtt5_props
import mqtt5_rc
import socket
import ssl
import struct
import subprocess
import time
import errno