1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {assertDefined} from 'common/assert_utils';
18import {TimestampConverterUtils} from 'test/unit/timestamp_converter_utils';
19import {UnitTestUtils} from 'test/unit/utils';
20import {CoarseVersion} from 'trace/coarse_version';
21import {Parser} from 'trace/parser';
22import {TraceType} from 'trace/trace_type';
23import {PropertyTreeNode} from 'trace/tree_node/property_tree_node';
24
25describe('ShellFileParserTransitions', () => {
26  let parser: Parser<PropertyTreeNode>;
27
28  beforeAll(async () => {
29    jasmine.addCustomEqualityTester(UnitTestUtils.timestampEqualityTester);
30    parser = (await UnitTestUtils.getParser(
31      'traces/elapsed_and_real_timestamp/shell_transition_trace.pb',
32    )) as Parser<PropertyTreeNode>;
33  });
34
35  it('has expected trace type', () => {
36    expect(parser.getTraceType()).toEqual(TraceType.SHELL_TRANSITION);
37  });
38
39  it('has expected coarse version', () => {
40    expect(parser.getCoarseVersion()).toEqual(CoarseVersion.LEGACY);
41  });
42
43  it('provides timestamps', () => {
44    const timestamps = assertDefined(parser.getTimestamps());
45    const expected = [
46      TimestampConverterUtils.makeRealTimestamp(1683188477607285317n),
47      TimestampConverterUtils.makeRealTimestamp(1683130827957362976n),
48      TimestampConverterUtils.makeRealTimestamp(1683130827957362976n),
49      TimestampConverterUtils.makeRealTimestamp(1683188479256449868n),
50      TimestampConverterUtils.makeRealTimestamp(1683130827957362976n),
51      TimestampConverterUtils.makeRealTimestamp(1683130827957362976n),
52    ];
53    expect(timestamps).toEqual(expected);
54  });
55});
56