1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.event
;
12 import static org
.junit
.Assert
.assertArrayEquals
;
13 import static org
.junit
.Assert
.assertEquals
;
15 import java
.util
.stream
.Collectors
;
16 import java
.util
.stream
.LongStream
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.tracecompass
.internal
.tmf
.ctf
.core
.trace
.iterator
.CtfIterator
;
20 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
25 import org
.junit
.After
;
26 import org
.junit
.Before
;
27 import org
.junit
.Test
;
30 * Tests making sure sign extension sign extension of field values works
33 * See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=491382
35 * @author Alexandre Montplaisir
37 public class CtfTmfEventFieldSignExtensionTest
{
39 private static final @NonNull CtfTestTrace DEBUG_INFO_TRACE
= CtfTestTrace
.DEBUG_INFO3
;
41 private CtfTmfTrace trace
;
48 trace
= CtfTmfTestTraceUtils
.getTrace(DEBUG_INFO_TRACE
);
55 public void teardown() {
62 * Test that signed 8-byte integers are printed correctly.
65 public void testUnsignedByte() {
67 * Third event of the trace is printed like this by Babeltrace:
69 * [16:25:03.003427176] (+0.000001578) sonoshee lttng_ust_statedump:build_id:
70 * { cpu_id = 0 }, { ip = 0x7F3BBEDDDE1E, vpid = 3520 },
71 * { baddr = 0x400000, _build_id_length = 20, build_id = [ [0] = 0x1, [1] = 0xC6, [2] = 0x5, [3] = 0xBC, [4] = 0xF3, [5] = 0x8D, [6] = 0x6, [7] = 0x8D, [8] = 0x77, [9] = 0xA6, [10] = 0xE0, [11] = 0xA0, [12] = 0x2C, [13] = 0xED, [14] = 0xE6, [15] = 0xA5, [16] = 0xC, [17] = 0x57, [18] = 0x50, [19] = 0xB5 ] }
73 long[] expectedValues
= new long[] {
96 String expectedToString
= LongStream
.of(expectedValues
)
97 .mapToObj(i
-> "0x" + Long
.toHexString(i
))
98 .collect(Collectors
.joining(", ", "build_id=[", "]"));
100 try (CtfIterator iter
= (CtfIterator
) trace
.createIterator();) {
101 /* Go to third event */
105 /* Retrieve the event's field called "build_id" */
106 CtfTmfEvent event
= iter
.getCurrentEvent();
107 ITmfEventField field
= event
.getContent().getField("build_id");
108 long[] values
= (long[]) field
.getValue();
110 assertArrayEquals(expectedValues
, values
);
111 assertEquals(expectedToString
, field
.toString());