Index

lognestmonster / dev

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
20222 Jul 2020 20:27616a224Bring repository up to dateJosh Stockin162G

Blob @ lognestmonster / tests / header_unit.c

text/plain3541 bytesdownload raw
1/* lognestmonster Copyright (c) 2020 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://github.com/JoshuaS3/lognestmonster>
4 *
5 * This software is licensed and distributed under the terms of the MIT License.
6 * See the MIT License in the LICENSE file of this project's root folder.
7 *
8 * This comment block and its contents, including this disclaimer, MUST be
9 * preserved in all copies or distributions of this software's source.
10 */
11
12// main.c
13// C file for testing the lognestmonster library header
14
15#include <stdio.h>
16
17#define LNM_INIT
18#define LNM_DEBUG
19#include "lognestmonster.h"
20
21void verify_queue_integrity(lnmQueue queue, char * queueName);
22
23int main(void) {
24 long t1 = lnm_getus();
25
26 printf("data testing\n");
27 printf("============\n");
28
29 printf("word size/ptr length: %zu\n", sizeof(lnmItem));
30 printf("\n\n");
31
32 printf("queue persistence testing\n");
33 printf("=========================\n");
34
35 printf("creating \"master\" queue with path \"/var/log/lognestmonster\"\n");
36 lnmQueue queue = lnmQueueInit("master", "/var/log/lognestmonster");
37 printf("queue \"master\" created at 0x%llx\n", (long long)queue);
38 printf("\n");
39
40 printf("checking queue integrity in registry...\n");
41 printf("tests/header_unit.c: queue == lnmQueueByName(\"master\"): ");
42 if (queue == lnmQueueByName("master")) {
43 printf("true\n");
44 } else {
45 printf("false. exiting...\n");
46 return 1;
47 }
48 printf("checking queue integrity across translation units...\n");
49 verify_queue_integrity(queue, "master");
50 printf("\n\n");
51
52 printf("log tree persistence testing\n");
53 printf("============================\n");
54
55 printf("creating log tree\n");
56 lnmItem event = lnmEvent("EVENT_TAG");
57 lnmEventPushS(event, lnmInfo, "Each log statement has a verbosity level attached and holds general information you want to write in a log file.");
58 lnmEventPushS(event, lnmVerbose, "There are 6 verbosity levels: lnmInfo, lnmDebug, lnmVerbose, lnmVeryVerbose, lnmWarning, and lnmError.");
59 lnmEventPushS(event, lnmInfo, "An event is a container for log statements or other events. Events can later be deserialized and queried.");
60 lnmEventPushS(event, lnmVeryVerbose, "Events can hold other events, like this: ");
61 lnmItem nested_event = lnmEvent("NESTED_EVENT");
62 lnmEventPush(event, nested_event);
63 lnmEventPushS(nested_event, lnmDebug, "Each event is assigned a tag to make querying easy.");
64 lnmItem deep_event = lnmEventS("DEEP_EVENT", lnmInfo, "Events can be as deep as you want, as long as you don't run out of memory.");
65 lnmEventPush(nested_event, deep_event);
66 lnmEventPushS(nested_event, lnmWarning, "Events have a capacity of 2^31 (2147483648) items.");
67 lnmEventPushS(nested_event, lnmError, "Messages have a maximum message length of 2^16 (65536) characters.");
68 printf("created log tree\n");
69 printf("\n\n");
70
71 printf("debug registry logtree (1 top level items expected)\n");
72 lnm_debug_parse_registry();
73 printf("\n\n");
74
75 printf("push event to queue\n");
76 lnmQueuePush(queue, event);
77 printf("\n");
78
79 printf("debug registry logtree (0 top level items expected)\n");
80 lnm_debug_parse_registry();
81 printf("\n");
82
83 printf("debug queue (master)\n");
84 lnm_debug_parse_queue(queue);
85 printf("\n\n");
86
87 printf("freeing queue\n");
88 lnm_free_queue(queue);
89 printf("\n");
90
91 printf("debug queue (master, 0 items expected)\n");
92 lnm_debug_parse_queue(queue);
93 printf("\n\n");
94
95 printf("tests finished\n");
96 printf("----------------------------\n");
97 unsigned long long elapsed = lnm_getus() - t1;
98 printf("time elapsed (us): %llu\n", elapsed);
99
100 return 0;
101}
102