File: logging_test_utilities.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (61 lines) | stat: -rw-r--r-- 3,348 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* NOLINTNEXTLINE(llvm-header-guard) */
#ifndef AWS_COMMON_LOGGING_TEST_UTILITIES_H
#define AWS_COMMON_LOGGING_TEST_UTILITIES_H

/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/logging.h>

#include <aws/testing/aws_test_harness.h>

/**
 * A staging function for basic logging tests.  It
 *   (1) Initializes and globally attaches a test logger
 *   (2) Invokes the supplied callback, which should perform the logging operations under test
 *   (3) Detaches and cleans up the test logger
 *   (4) Checks if what was recorded by the test logger matches what the test expected.
 */
int do_log_test(
    struct aws_allocator *allocator,
    enum aws_log_level level,
    const char *expected_result,
    void (*callback)(enum aws_log_level));

/**
 * A macro capable of defining simple logging tests that follow the do_log_test function pattern
 */
#define TEST_LEVEL_FILTER(log_level, expected, action_fn)                                                              \
    static int s_logging_filter_at_##log_level##_##action_fn(struct aws_allocator *allocator, void *ctx) {             \
        (void)ctx;                                                                                                     \
        return do_log_test(allocator, log_level, expected, action_fn);                                                 \
    }                                                                                                                  \
    AWS_TEST_CASE(test_logging_filter_at_##log_level##_##action_fn, s_logging_filter_at_##log_level##_##action_fn);

/**
 * A macro that defines a function that invokes all 6 LOGF_<level> variants
 *
 * Needs to be a macro and not just a function because the compile-time filtering tests require a private implementation
 * that is compiled with AWS_STATIC_LOG_LEVEL at the level to be tested.  There's no way to shared a single definition
 * that does so.
 */
#define DECLARE_LOGF_ALL_LEVELS_FUNCTION(fn_name)                                                                      \
    static void fn_name(enum aws_log_level level) {                                                                    \
        (void)level;                                                                                                   \
        AWS_LOGF_FATAL(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_FATAL);                                                \
        AWS_LOGF_ERROR(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_ERROR);                                                \
        AWS_LOGF_WARN(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_WARN);                                                  \
        AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_INFO);                                                  \
        AWS_LOGF_DEBUG(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_DEBUG);                                                \
        AWS_LOGF_TRACE(AWS_LS_COMMON_GENERAL, "%d", (int)AWS_LL_TRACE);                                                \
    }

/**
 * Return new string with format "./aws_log_writer_test_{UUID}.log"
 * This function cannot fail.
 */
struct aws_string *aws_string_new_log_writer_test_filename(struct aws_allocator *allocator);

#endif /* AWS_COMMON_LOGGING_TEST_UTILITIES_H */