libhilogCtest.cpp 33.3 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * 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
 *
 *     http://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.
 */
#include <cstdarg>
#include <ctime>
#include <ostream>
#include <streambuf>
#include <queue>
#include <securec.h>
#include <pthread.h>
#include <sys/time.h>
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include <gtest/gtest.h>
#include "file_utils.h"

#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003E00
#define LOG_TAG "testtag0testtag0testtag0testta"
using namespace std;
using namespace testing::ext;

class LibhilogCtest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
private:
};
void LibhilogCtest::SetUp()
{
    CleanCmd();
}
void LibhilogCtest::TearDown()
{
}
void LibhilogCtest::SetUpTestCase()
{
}
void LibhilogCtest::TearDownTestCase()
{
    std::cout << "TearDownTestCase" << std::endl;
}

/**
 * @tc.name Provides user-mode interfaces(C)INFO
 * @tc.number DFX_DFT_HilogC_0180
 * @tc.desc Provides user-mode interfaces(C)INFO
 */
HWTEST_F(LibhilogCtest, HILOG_INFO, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    int i = 1;
    HILOG_INFO(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
70 71
    std::string expected{"I 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
72
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
73 74 75
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

/**
 * @tc.desc Provides user-mode interfaces(C)debug
 * @tc.number DFX_DFT_HilogC_0170
 * @tc.desc Provides user-mode interfaces(C)debug
 */
HWTEST_F(LibhilogCtest, HILOG_DEBUG, Function|MediumTest|Level1)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    int i = 1;
    HILOG_DEBUG(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
    "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
90 91
    std::string expected{"D 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
92 93 94
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
95
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109
}

/**
 * @tc.name Provides user-mode interfaces(C)warning
 * @tc.number DFX_DFT_HilogC_0210
 * @tc.desc Provides user-mode interfaces(C)warning
 */
HWTEST_F(LibhilogCtest, HILOG_WARNING, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    int i = 1;
    HILOG_WARN(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
110 111
    std::string expected{"W 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
112 113 114
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
115
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129
}

/**
 * @tc.desc Provides user-mode interfaces(C)error
 * @tc.number DFX_DFT_HilogC_0190
 * @tc.desc Provides user-mode interfaces(C)error
 */
HWTEST_F(LibhilogCtest, HILOG_ERROR, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    int i = 1;
    HILOG_ERROR(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
    "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
130 131
    std::string expected{"E 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
132 133 134
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
135
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149
}

/**
 * @tc.name Provides user-mode interfaces(C)fatal
 * @tc.number DFX_DFT_HilogC_0200
 * @tc.desc Provides user-mode interfaces(C)fatal
 */
HWTEST_F(LibhilogCtest, HILOG_FATAL, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    int i = 1;
    HILOG_FATAL(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
    "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
150 151
    std::string expected{"F 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
152 153 154
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
155
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168
}

/**
 * @tc.name libhilog-log integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0360
 * @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER:%{private}d,%{public}d,%d;", 1, 1, 1);
    std::string expected{"INTEGER:<private>,1,<private>;"};
169 170 171
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
172
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185
}

/**
 * @tc.name libhilog-log long integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0370
 * @tc.desc libhilog-log long integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L);
    std::string expected{"INTEGER_long:<private>,2147483647,<private>;"};
186 187 188
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
189
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202
}

/**
 * @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0380
 * @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_4, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000);
    std::string expected{"INTEGER_4:<private>,2000,<private>;"};
203 204 205
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
206
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219
}

/**
 * @tc.name libhilog-log short integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0390
 * @tc.desc libhilog-log short integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024);
    std::string expected{"INTEGER_short:<private>,1024,<private>;"};
220 221 222
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
223
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236
}

/**
 * @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0400
 * @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_UN, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u);
    std::string expected{"INTEGER_un:<private>,2147483647,<private>;"};
237 238 239
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
240
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253
}

/**
 * @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0410
 * @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG_UN, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647lu, 2147483647lu, 2147483647lu);
    std::string expected{"INTEGER_long_un:<private>,2147483647,<private>;"};
254 255 256
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
257
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270
}

/**
 * @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0420
 * @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_4_UN, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000u, 4000u, 4000u);
    std::string expected{"INTEGER_4_un:<private>,4000,<private>;"};
271 272 273
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
274
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288
}

/**
 * @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0430
 * @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT_UN, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;",
    (unsigned short)65535, (unsigned short)65535, (unsigned short)65535);
    std::string expected{"INTEGER_short_un:<private>,65535,<private>;"};
289 290 291
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
292
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305
}

/**
 * @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0440
 * @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_FLOAT, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01);
    std::string expected{"FLOAT:<private>,1.010000,<private>;"};
306 307 308
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
309
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
310 311 312 313 314 315 316 317 318 319 320 321 322
}

/**
 * @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0450
 * @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_FLOAT_LONG, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647);
    std::string expected{"FLOAT_long:<private>,2.147484,<private>;"};
323 324 325
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
326
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
}

/**
 * @tc.name libhilog-Formatting of fixed-width floating-point identifiers in
 *          the decimal part of the log ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0460
 * @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in
 *          the decimal part of the log ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_FLOAT_POINT2, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647);
    std::string expected{"FLOAT_.2:<private>,2.15,<private>;"};
342 343 344
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
345
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
}

/**
 * @tc.name libhilog-Formatting of floating-point identifiers for
 *          the decimal part and integer part of the log ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0470
 * @tc.desc libhilog-Formatting of floating-point identifiers for
 *          the decimal part and integer part of the log ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_FLOAT_3POINT2, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647);
    std::string expected{"FLOAT_3.2:<private>,321.1,<private>;"};
361 362 363
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
364
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377
}

/**
 * @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0480
 * @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_CHAR, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c');
    std::string expected{"CHAR:<private>,b,<private>;"};
378 379 380
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
381
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394
}

/**
 * @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0520
 * @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_OCTAL, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17);
    std::string expected{"OCTAL:<private>,20,<private>;"};
395 396 397
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
398
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411
}

/**
 * @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0530
 * @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_OCTAL_LONG, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 022l, 023l, 024l);
    std::string expected{"OCTAL_long:<private>,23,<private>;"};
412 413 414
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
415
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
416 417 418 419 420 421 422 423 424 425 426 427 428
}

/**
 * @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0540
 * @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX:%{private}x,%{public}x,%x;", 0x0F, 0x10, 0x11);
    std::string expected{"HEX:<private>,10,<private>;"};
429 430 431
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
432
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445
}

/**
 * @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0550
 * @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX_#:%{private}#x,%{public}#x,%#x;", 0x12, 0x13, 0x14);
    std::string expected{"HEX_#:<private>,0x13,<private>;"};
446 447 448
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
449
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
}

/**
 * @tc.name libhilog-Logs are formatted with long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0560
 * @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX_LONG, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX_long:%{private}lx,%{public}lx,%lx;", 0x15l, 0x16l, 0x17l);
    std::string expected{"HEX_long:<private>,16,<private>;"};
465 466 467
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
468
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0570
 * @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX_X, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX_X:%{private}X,%{public}X,%X;", 0x18, 0x19, 0x1A);
    std::string expected{"HEX_X:<private>,19,<private>;"};
484 485 486
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
487
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0580
 * @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER_X, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX_#X:%{private}#X,%{public}#X,%#X;", 0x1B, 0x1C, 0x1C);
    std::string expected{"HEX_#X:<private>,0X1C,<private>;"};
503 504 505
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
506
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0590
 * @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_HEX_LONG_UPPER_X, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 0x1El, 0x1Fl, 0x20l);
    std::string expected{"HEX_long_X:<private>,1F,<private>;"};
522 523 524
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
525
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
526 527 528 529 530 531 532 533 534 535 536 537 538
}

/**
 * @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0490
 * @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_STR, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3");
    std::string expected{"STRING:<private>,STRING2,<private>;"};
539 540 541
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
542
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
543 544 545 546 547 548 549 550 551 552 553 554 555
}

/**
 * @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0510
 * @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_STR_EMPTY, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "STRING_empty:%{private}s,%{public}s,%s;", "", "", "");
    std::string expected{"STRING_empty:<private>,,<private>;"};
556 557 558
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
559
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
560 561 562 563 564 565 566 567 568 569 570 571 572 573
}

/**
 * @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0500
 * @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
 */

HWTEST_F(LibhilogCtest, HILOG_STR_CHINESE, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文");
    std::string expected{"STRING_Chinese:<private>,中文,<private>;"};
574 575 576
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
577
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0600
 * @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_E_DOUBLE, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13);
    std::string expected{"DOUBLE_e:<private>,2.231000e+10,<private>;"};
591 592 593
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
594
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0610
 * @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_E_UPPER_DOUBLE, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13);
    std::string expected{"DOUBLE_E:<private>,5.676767E-02,<private>;"};
610 611 612
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
613
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0620
 * @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_E_AUTO, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13);
    std::string expected{"AUTO:<private>,2.231e+10,<private>;"};
629 630 631
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
632
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
}

/**
 * @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
 *          identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogC_0630
 * @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
 *          identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCtest, HILOG_E_UPPER_AUTO, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13);
    std::string expected{"AUTO_E:<private>,0.0567677,<private>;"};
648 649 650
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
651
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
652 653 654 655 656 657 658 659 660 661 662 663 664 665
}

/**
 * @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden
 * @tc.number DFX_DFT_HilogC_3100
 * @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden
 */
HWTEST_F(LibhilogCtest, HILOG_PRIVATE, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "private:%{private}d,%{private}lf,%{private}.2f,"
    "%{private}s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"private:<private>,<private>,<private>,<private>,<private>"};
666 667 668
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
669
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
670 671 672 673 674 675 676 677 678 679 680 681 682 683
}

/**
 * @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed
 * @tc.number DFX_DFT_HilogC_3200
 * @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed
 */
HWTEST_F(LibhilogCtest, HILOG_PUBLIC, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c",
    1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"public:1,1.000010,2.33,sse,a"};
684 685 686
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
687
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
688 689 690 691 692 693 694 695 696 697 698 699 700
}

/**
 * @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
 * @tc.number DFX_DFT_HilogC_3300
 * @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
 */
HWTEST_F(LibhilogCtest, HILOG_NO_SIGN, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"no_sign:<private>,<private>,<private>,<private>,<private>"};
701 702 703
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
704
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
}

/**
 * @tc.name libhilog-Log privacy flags are used together, and parameters are
 *          correctly displayed or hidden
 * @tc.number DFX_DFT_HilogC_3400
 * @tc.desc libhilog-Log privacy flags are used together, and parameters are
 *          correctly displayed or hidden
 */
HWTEST_F(LibhilogCtest, HILOG_MIX, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"MIX:1,<private>,2.33,<private>,<private>"};
720 721 722
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
723
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
724 725 726 727 728 729 730 731 732 733 734 735 736
}

/**
 * @tc.name libhilog-log are not truncated with normal length tag
 * @tc.number DFX_DFT_HilogC_0280
 * @tc.desc libhilog-log are not truncated with normal length tag
 */
HWTEST_F(LibhilogCtest, TAG_CHECK, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03e00/testtag0testtag0testtag0testta:"};
737 738 739
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
740
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
741 742 743 744
}

/**
 * @tc.name libhilog-log are not truncated with normal length tag
745
 * @tc.number DFX_DFT_HilogC_0300
M
mamingshuai 已提交
746 747 748 749 750 751 752 753
 * @tc.desc libhilog-log are not truncated with normal length tag
 */
HWTEST_F(LibhilogCtest, TYPE_APP_CHECK, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_APP;
    HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03e00/testtag0testtag0testtag0testta:"};
754 755 756
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
    std::cout<<cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
757
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
}

/**
 * @tc.name libhilog-log are truncated with too long tag
 * @tc.number DFX_DFT_HilogC_0290
 * @tc.desc libhilog-log are truncated with too long tag
 */
HWTEST_F(LibhilogCtest, TAG_OVER_CHECK, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
#undef LOG_TAG
#define LOG_TAG "testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0"
    HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03e00/testtag0testtag0testtag0testtag:"};
773
    sleep(1);
774 775
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testtag", cmdRunResult);
    std::cout<<"expected = " + expected<<std::endl;
776
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
}

/**
 * @tc.name libhilog-log domain
 * @tc.number DFX_DFT_HilogC_0270
 * @tc.desc libhilog-log domain
 */
HWTEST_F(LibhilogCtest, DOMAIN_CHECK, Function|MediumTest|Level1)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD001111
    HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"01111/testtag0testtag0testtag0testtag:"};
792
    sleep(1);
793 794
    CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testtag", cmdRunResult);
    std::cout<<"expected = " + expected<<std::endl;
795
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
796
}