1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "fixture.h" 6 7#include <fbl/algorithm.h> 8#include <fbl/string_printf.h> 9#include <trace/event.h> 10#include <trace-engine/instrumentation.h> 11#include <zircon/syscalls.h> 12 13namespace { 14 15static bool blob_test(void) { 16 BEGIN_TRACE_TEST; 17 18 fixture_start_tracing(); 19 20 const char name[] = "name"; 21 trace_string_ref_t name_ref = trace_make_inline_c_string_ref(name); 22 const char blob[] = "abc"; 23 24 { 25 auto context = trace::TraceContext::Acquire(); 26 27 trace_context_write_blob_record(context.get(), 28 TRACE_BLOB_TYPE_DATA, 29 &name_ref, 30 blob, sizeof(blob)); 31 } 32 33 auto expected = fbl::StringPrintf("Blob(name: %s, size: %zu)\n", 34 name, sizeof(blob)); 35 EXPECT_TRUE(fixture_compare_records(expected.c_str()), "record mismatch"); 36 37 END_TRACE_TEST; 38} 39 40static bool blob_macro_test(void) { 41 BEGIN_TRACE_TEST; 42 43 fixture_start_tracing(); 44 45 const char name[] = "all-byte-values"; 46 char blob[256]; 47 for (unsigned i = 0; i < sizeof(blob); ++i) { 48 blob[i] = static_cast<char>(i); 49 } 50 51 TRACE_BLOB(TRACE_BLOB_TYPE_DATA, name, blob, sizeof(blob)); 52 auto expected = fbl::StringPrintf("String(index: 1, \"%s\")\n" 53 "Blob(name: %s, size: %zu)\n", 54 name, name, sizeof(blob)); 55 EXPECT_TRUE(fixture_compare_records(expected.c_str()), "record mismatch"); 56 57 END_TRACE_TEST; 58} 59 60} // namespace 61 62BEGIN_TEST_CASE(records) 63RUN_TEST(blob_test) 64RUN_TEST(blob_macro_test) 65END_TEST_CASE(records) 66