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
17 #include "stack/btm/sco_pkt_status.h"
18
19 #include <gtest/gtest.h>
20
21 namespace {
22
23 using testing::Test;
24
25 class ScoPktStatusTest : public Test {
26 public:
27 protected:
SetUp()28 void SetUp() override {}
TearDown()29 void TearDown() override {}
30 };
31
TEST_F(ScoPktStatusTest,Update)32 TEST_F(ScoPktStatusTest, Update) {
33 tBTM_SCO_PKT_STATUS pkt_status;
34 pkt_status.init();
35 pkt_status.update(true);
36 ASSERT_NE(pkt_status.begin_ts_raw_us(), (uint64_t)0);
37 ASSERT_EQ(pkt_status.end_ts_raw_us(), pkt_status.begin_ts_raw_us() + 7500);
38 ASSERT_EQ(pkt_status.data_to_hex_string(), "01");
39 ASSERT_EQ(pkt_status.data_to_binary_string(), "1");
40 }
41
TEST_F(ScoPktStatusTest,data_to_string)42 TEST_F(ScoPktStatusTest, data_to_string) {
43 bool pl[9] = {1, 0, 1, 1, 0, 1, 1, 1, 1};
44 tBTM_SCO_PKT_STATUS pkt_status;
45 pkt_status.init();
46 for (bool b : pl) pkt_status.update(b);
47 ASSERT_EQ(pkt_status.data_to_binary_string(), "101101111");
48 ASSERT_EQ(pkt_status.data_to_hex_string(), "ed01");
49 }
50
TEST_F(ScoPktStatusTest,data_full)51 TEST_F(ScoPktStatusTest, data_full) {
52 bool pl[BTM_PKT_STATUS_LEN * 8] = {
53 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
54 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
55 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
56 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
57 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
58 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
59 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
60 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
61 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
62 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
63 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
64 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
65 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
66 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
67 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
68 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
69 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
70 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
71 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
72 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
73 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
74 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
75 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
76 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
77 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
78 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
79 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
80 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
81 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
82 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
83 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
84 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
85 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
86 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
87 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
88 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
89 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
90 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
91 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
92 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
93 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
94 0, 0, 0, 0, 0, 0, 0, 0, /* 00 */
95 0, 0, 0, 1, 1, 1, 1, 1, /* f8 */
96 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
97 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
98 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
99 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
100 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
101 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
102 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
103 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
104 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
105 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
106 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
107 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
108 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
109 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
110 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
111 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
112 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
113 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
114 1, 1, 1, 1, 1, 1, 1, 1, /* ff */
115 1, 1, 1, 1, 1, 1, 1, 0, /* 7f */
116 0, 0, 0, 0, 0, 0, 0, 0 /* 00 */
117 };
118 tBTM_SCO_PKT_STATUS pkt_status;
119 pkt_status.init();
120 for (bool b : pl) pkt_status.update(b);
121 ASSERT_EQ(pkt_status.data_to_binary_string(),
122 "111111110000000000000000000000000000000000000000000000000000000000"
123 "000000000000000000000000000000000000000000000000000000000000000000"
124 "000000000000000000000000000000000000000000000000000000000000000000"
125 "000000000000000000000000000000000000000000000000000000000000000000"
126 "000000000000000000000000000000000000000000000000000000000000000000"
127 "000000000111111111111111111111111111111111111111111111111111111111"
128 "111111111111111111111111111111111111111111111111111111111111111111"
129 "11111111111111111111111111111111111111111000000000");
130 uint64_t begin_ts_raw_us = pkt_status.begin_ts_raw_us();
131 ASSERT_EQ(pkt_status.data_to_hex_string(),
132 "ff0000000000000000000000000000000000000000000000000000000000000000"
133 "000000000000000000f8ffffffffffffffffffffffffffffffffffffff7f00");
134 pkt_status.update(true);
135 ASSERT_NE(begin_ts_raw_us, pkt_status.begin_ts_raw_us());
136 ASSERT_EQ(pkt_status.end_ts_raw_us(),
137 pkt_status.begin_ts_raw_us() +
138 BTM_PKT_STATUS_WBS_FRAME_US * BTM_PKT_STATUS_LEN * 8);
139 ASSERT_EQ(pkt_status.data_to_binary_string(),
140 "11111110000000000000000000000000000000000000000000000000000000000"
141 "000000000000000000000000000000000000000000000000000000000000000000"
142 "000000000000000000000000000000000000000000000000000000000000000000"
143 "000000000000000000000000000000000000000000000000000000000000000000"
144 "000000000000000000000000000000000000000000000000000000000000000000"
145 "000000000111111111111111111111111111111111111111111111111111111111"
146 "111111111111111111111111111111111111111111111111111111111111111111"
147 "111111111111111111111111111111111111111110000000001");
148 ASSERT_EQ(pkt_status.data_to_hex_string(),
149 "fe0000000000000000000000000000000000000000000000000000000000000000"
150 "000000000000000000f9ffffffffffffffffffffffffffffffffffffff7e01");
151 }
152
153 } // namespace
154