1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #define PW_LOG_MODULE_NAME "log module name!"
16
17 // Configure the module so that the test runs against known values.
18 #undef PW_LOG_TOKENIZED_LEVEL_BITS
19 #undef PW_LOG_TOKENIZED_MODULE_BITS
20 #undef PW_LOG_TOKENIZED_FLAG_BITS
21 #undef PW_LOG_TOKENIZED_LINE_BITS
22
23 #define PW_LOG_TOKENIZED_LEVEL_BITS 3
24 #define PW_LOG_TOKENIZED_MODULE_BITS 16
25 #define PW_LOG_TOKENIZED_FLAG_BITS 2
26 #define PW_LOG_TOKENIZED_LINE_BITS 11
27
28 #include "pw_log_tokenized/log_tokenized.h"
29 #include "pw_log_tokenized_private/test_utils.h"
30
31 pw_log_tokenized_CapturedLog last_log;
32
pw_log_tokenized_CaptureArgs(uintptr_t payload,size_t arg_count,const char * message,...)33 void pw_log_tokenized_CaptureArgs(uintptr_t payload,
34 size_t arg_count,
35 const char* message,
36 ...) {
37 last_log.metadata = payload;
38 last_log.format_string = message;
39 last_log.arg_count = arg_count;
40 }
41
42 // These functions correspond to tests in log_tokenized_test.cc. The tests call
43 // these functions and check the results.
pw_log_tokenized_Test_LogMetadata_LevelTooLarge_Clamps(void)44 void pw_log_tokenized_Test_LogMetadata_LevelTooLarge_Clamps(void) {
45 #line 1000
46 PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(8, PW_LOG_MODULE_NAME, 0, "");
47 }
48
pw_log_tokenized_Test_LogMetadata_TooManyFlags_Truncates(void)49 void pw_log_tokenized_Test_LogMetadata_TooManyFlags_Truncates(void) {
50 // clang-format off
51 #line 1100
52 PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(1, PW_LOG_MODULE_NAME, 0xFFFFFFFF, "hello");
53 // clang-format on
54 }
55
pw_log_tokenized_Test_LogMetadata_LogMetadata_VariousValues(void)56 void pw_log_tokenized_Test_LogMetadata_LogMetadata_VariousValues(void) {
57 // clang-format off
58 #line 1200
59 PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(6, PW_LOG_MODULE_NAME, 3, "hello%s", "?");
60 // clang-format on
61 }
62
pw_log_tokenized_Test_LogMetadata_LogMetadata_Zero(void)63 void pw_log_tokenized_Test_LogMetadata_LogMetadata_Zero(void) {
64 #line 1300
65 PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(0, PW_LOG_MODULE_NAME, 0, "");
66 }
67