mirror of
https://fuchsia.googlesource.com/third_party/pigweed.googlesource.com/pigweed/pigweed
synced 2024-09-20 05:41:06 +00:00
ebbce4c898
- Add an optional line number to the 32-bit log tokenized payload. - Update default payload field widths. Log level: 3 bits Line number: 11 bits (up to 2047, 0 if larger) Flags: 2 bits (implementation defined) Module token: 16 bits - Use the maximum log level to indicate that a log is an assert. This preserves an additional bit which can be used for the flags or line number. - Store data as key-value pairs in the format string. - Reorganize pw_log_tokenized tests and add C tests. Change-Id: I1daa2e6ce40038f96857caeb38976cf48f620dc3 Requires: pigweed-internal:12920 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/47861 Reviewed-by: Keir Mierle <keir@google.com> Commit-Queue: Wyatt Hepler <hepler@google.com>
59 lines
2.1 KiB
C
59 lines
2.1 KiB
C
// 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) {
|
|
PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(8, 0, "hello");
|
|
}
|
|
|
|
void pw_log_tokenized_Test_LogMetadata_TooManyFlags_Truncates(void) {
|
|
PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(1, 0xFFFFFFFF, "hello");
|
|
}
|
|
|
|
void pw_log_tokenized_Test_LogMetadata_LogMetadata_VariousValues(void) {
|
|
PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(6, 3, "hello%s", "?");
|
|
}
|
|
|
|
void pw_log_tokenized_Test_LogMetadata_LogMetadata_Zero(void) {
|
|
PW_LOG_TOKENIZED_TO_GLOBAL_HANDLER_WITH_PAYLOAD(0, 0, "hello");
|
|
}
|