aboutsummaryrefslogtreecommitdiff
path: root/pw_log_tokenized/log_tokenized_test_c.c
blob: 1202ab1c7f96d2c27e662bf9faa07671ae4be439 (plain)
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
62
63
64
65
66
// Copyright 2021 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

#define PW_LOG_MODULE_NAME "log module name!"

// Configure the module so that the test runs against known values.
#undef PW_LOG_TOKENIZED_LEVEL_BITS
#undef PW_LOG_TOKENIZED_MODULE_BITS
#undef PW_LOG_TOKENIZED_FLAG_BITS
#undef PW_LOG_TOKENIZED_LINE_BITS

#define PW_LOG_TOKENIZED_LEVEL_BITS 3
#define PW_LOG_TOKENIZED_MODULE_BITS 16
#define PW_LOG_TOKENIZED_FLAG_BITS 2
#define PW_LOG_TOKENIZED_LINE_BITS 11

#include "pw_log_tokenized/log_tokenized.h"
#include "pw_log_tokenized_private/test_utils.h"

pw_log_tokenized_CapturedLog last_log;

void pw_log_tokenized_CaptureArgs(uintptr_t payload,
                                  size_t arg_count,
                                  const char* message,
                                  ...) {
  last_log.metadata = payload;
  last_log.format_string = message;
  last_log.arg_count = arg_count;
}

// These functions correspond to tests in log_tokenized_test.cc. The tests call
// these functions and check the results.
void pw_log_tokenized_Test_LogMetadata_LevelTooLarge_Clamps(void) {
#line 1000
  PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(8, PW_LOG_MODULE_NAME, 0, "");
}

void pw_log_tokenized_Test_LogMetadata_TooManyFlags_Truncates(void) {
  // clang-format off
#line 1100
  PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(1, PW_LOG_MODULE_NAME, 0xFFFFFFFF, "hello");
  // clang-format on
}

void pw_log_tokenized_Test_LogMetadata_LogMetadata_VariousValues(void) {
  // clang-format off
#line 1200
  PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(6, PW_LOG_MODULE_NAME, 3, "hello%s", "?");
  // clang-format on
}

void pw_log_tokenized_Test_LogMetadata_LogMetadata_Zero(void) {
#line 1300
  PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(0, PW_LOG_MODULE_NAME, 0, "");
}