ActsTimeApiTest.cpp 19.8 KB
Newer Older
W
wenjun 已提交
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
/*
 * Copyright (c) 2020 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <time.h>
#include <unistd.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/utsname.h>

#include "gtest/gtest.h"
#include "XtsActsUtil.h"
#include "XtsActsTimeApiExpect.h"

using namespace testing::ext;

class ActsTimeApiTest : public testing::Test {
protected:
    // SetUpTestCase: Testsuit setup, run before 1st testcase
    static void SetUpTestCase(void)
    {
    }
    // TearDownTestCase: Testsuit teardown, run after last testcase
    static void TearDownTestCase(void)
    {
    }
    // Testcase setup
    virtual void SetUp()
    {
        errno = 0;
    }
    // Testcase teardown
    virtual void TearDown()
    {
    }
};

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0100
* @tc.name       test clock_getres api para CLOCK_REALTIME
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetRes0100, TestSize.Level1) {
    struct timespec res;
    int returnVal;
    
    returnVal = clock_getres(CLOCK_REALTIME, &res);
    LogPrint("    clock_getres clock_id:='CLOCK_REALTIME=%d' &res:='&res',   --> returnVal:='%d', "
        "{res.tv_sec:='%lld' res.tv_nsec:='%ld'}\n", CLOCK_REALTIME, returnVal, res.tv_sec, res.tv_nsec);

    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', {res.tv_sec:='"
        << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0200
* @tc.name       test clock_getres api para CLOCK_MONOTONIC
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetRes0200, TestSize.Level1) {
    struct timespec res;
    int returnVal;

    returnVal = clock_getres(CLOCK_MONOTONIC, &res);
    LogPrint("    clock_getres clock_id:='CLOCK_MONOTONIC=%d' &res:='&res',   --> returnVal:='%d', "
        "{res.tv_sec:='%lld' res.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC, returnVal, res.tv_sec, res.tv_nsec);

    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', {res.tv_sec:='"
        << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0400
* @tc.name       test clock_getres api para CLOCK_REALTIME_COARSE
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetRes0400, TestSize.Level1) {
    struct timespec res;
    int returnVal;

    returnVal = clock_getres(CLOCK_REALTIME_COARSE, &res);
    LogPrint("    clock_getres clock_id:='CLOCK_REALTIME_COARSE=%d' &res:='&res',   --> returnVal:='%d', "
        "{res.tv_sec:='%lld', res.tv_nsec:='%ld'}\n", CLOCK_REALTIME_COARSE, returnVal, res.tv_sec, res.tv_nsec);

    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='CLOCK_REALTIME_COARSE=" << CLOCK_REALTIME_COARSE
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', {res.tv_sec:='"
        << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0500
* @tc.name       test clock_getres api para CLOCK_MONOTONIC_COARSE
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetRes0500, TestSize.Level1) {
    struct timespec res;
    int returnVal;

    returnVal = clock_getres(CLOCK_MONOTONIC_COARSE, &res);
    LogPrint("    clock_getres clock_id:='CLOCK_MONOTONIC_COARSE=%d' &res:='&res',   --> returnVal:='%d', "
        "{res.tv_sec:='%lld', res.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC_COARSE, returnVal, res.tv_sec, res.tv_nsec);

    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='CLOCK_MONOTONIC_COARSE=" << CLOCK_MONOTONIC_COARSE
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', {res.tv_sec:='"
        << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_1000
* @tc.name       test clock_getres api para CLOCK_PROCESS_CPUTIME_ID not support
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetRes1000, TestSize.Level1) {
    struct timespec res;
    int returnVal, thisErrno;

    returnVal = clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res);
    thisErrno = errno;
    LogPrint("    clock_getres clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' &res:='&res',   --> returnVal:='%d', "
        "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, returnVal, thisErrno);

    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EOPNOTSUPP)
        << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";

    returnVal = clock_getres(CLOCK_PROCESS_CPUTIME_ID + 30, &res);
    thisErrno = errno;
    LogPrint("    clock_getres clock_id:='%d' &res:='&res',   --> returnVal:='%d', "
        "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID + 30, returnVal, thisErrno);

    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EINVAL)
        << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30
        << "', &res:='&res',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0100
* @tc.name       test clock_gettime api para CLOCK_REALTIME
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetTime0100, TestSize.Level1) {
    struct timespec tp;
    int returnVal;
    tp.tv_sec = 0;
    tp.tv_nsec = 0;
    
    returnVal = clock_gettime(CLOCK_REALTIME, &tp);
    LogPrint("    clock_gettime clock_id:='CLOCK_REALTIME=%d' &tp:='&tp',   --> returnVal:='%d', "
        "{tp.tv_sec:='%lld' tp.tv_nsec:='%ld'}\n", CLOCK_REALTIME, returnVal, tp.tv_sec, tp.tv_nsec);
    LogPrint("    time is: %lld.%d\n", tp.tv_sec, tp.tv_nsec);
    LogPrint("    sec  : %lld,   size:%d\n", tp.tv_sec, sizeof(tp.tv_sec));
    LogPrint("    nsec : %ld,   size:%d\n", tp.tv_nsec, sizeof(tp.tv_nsec));
    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', {tp.tv_sec:='"
        << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0200
* @tc.name       test clock_gettime api para CLOCK_MONOTONIC
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetTime0200, TestSize.Level1) {
    struct timespec tp;
    int returnVal;

    returnVal = clock_gettime(CLOCK_MONOTONIC, &tp);
    LogPrint("    clock_gettime clock_id:='CLOCK_MONOTONIC=%d' &tp:='&tp',   --> returnVal:='%d', "
        "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC, returnVal, tp.tv_sec, tp.tv_nsec);
    LogPrint("    time is: %lld.%d\n", tp.tv_sec, tp.tv_nsec);
    LogPrint("    sec  : %lld,   size:%d\n", tp.tv_sec, sizeof(tp.tv_sec));
    LogPrint("    nsec : %ld,   size:%d\n", tp.tv_nsec, sizeof(tp.tv_nsec));
    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', {tp.tv_sec:='"
        << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0400
* @tc.name       test clock_gettime api para CLOCK_REALTIME_COARSE
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetTime0400, TestSize.Level1) {
    struct timespec tp;
    int returnVal;

    returnVal = clock_gettime(CLOCK_REALTIME_COARSE, &tp);
    LogPrint("    clock_gettime clock_id:='CLOCK_REALTIME_COARSE=%d' &tp:='&tp',   --> returnVal:='%d', "
        "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_REALTIME_COARSE, returnVal, tp.tv_sec, tp.tv_nsec);
    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_REALTIME_COARSE=" << CLOCK_REALTIME_COARSE
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', {tp.tv_sec:='"
        << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0500
* @tc.name       test clock_gettime api para CLOCK_MONOTONIC_COARSE
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetTime0500, TestSize.Level1) {
    struct timespec tp;
    int returnVal;

    returnVal = clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
    LogPrint("    clock_gettime clock_id:='CLOCK_MONOTONIC_COARSE=%d' &tp:='&tp',   --> returnVal:='%d', "
        "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC_COARSE, returnVal, tp.tv_sec, tp.tv_nsec);
    EXPECT_EQ(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_MONOTONIC_COARSE=" << CLOCK_MONOTONIC_COARSE
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', {tp.tv_sec:='"
        << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}";	
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_1000
* @tc.name       test clock_gettime api para CLOCK_PROCESS_CPUTIME_ID not support
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockGetTime1000, TestSize.Level1) {
    struct timespec tp;
    int returnVal, thisErrno;

    returnVal = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
    thisErrno = errno;
    LogPrint("    clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' &tp:='&tp',   --> returnVal:='%d', "
        "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, returnVal, thisErrno);
    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EOPNOTSUPP)
        << "ErrInfo: clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";

    returnVal = clock_gettime(CLOCK_PROCESS_CPUTIME_ID + 30, &tp);
    thisErrno = errno;
    LogPrint("    clock_gettime clock_id:='%d' &tp:='&tp',   --> returnVal:='%d', "
        "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID + 30, returnVal, thisErrno);
    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_gettime clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EINVAL)
        << "ErrInfo: clock_gettime clock_id:='" << CLOCK_PROCESS_CPUTIME_ID +30
        << "', &tp:='&tp',   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1000
* @tc.name       test clock_settime api para CLOCK_MONOTONIC not support
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockSetTime1000, TestSize.Level1) {
    struct timespec tp;
    int returnVal, thisErrno;
	
    tp.tv_sec = 1565308800;
    tp.tv_nsec = 0;

    returnVal = clock_settime(CLOCK_MONOTONIC, &tp);
    thisErrno = errno;
    LogPrint("    clock_settime clock_id:='CLOCK_MONOTONIC=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'}   "
        "--> returnVal:='%d', errno:='%d'\n", CLOCK_MONOTONIC, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno);
    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_settime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EINVAL)
        << "ErrInfo: clock_settime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1100
* @tc.name       test clock_settime api para CLOCK_PROCESS_CPUTIME_ID not support
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockSetTime1100, TestSize.Level1) {
    struct timespec tp;
    int returnVal, thisErrno;
	
    tp.tv_sec = 1565308800;
    tp.tv_nsec = 0;

    returnVal = clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tp);
    thisErrno = errno;
    LogPrint("    clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'}   "
        "--> returnVal:='%d', errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno);
    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EOPNOTSUPP)
        << "ErrInfo: clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1200
* @tc.name       test clock_settime api para CLOCK_REALTIME nsec less than zero
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testClockSetTime1200, TestSize.Level1) {
    struct timespec tp;
    int returnVal, thisErrno;
	
    tp.tv_sec = 1565308800;
    tp.tv_nsec = -1000;

    returnVal = clock_settime(CLOCK_REALTIME, &tp);
    thisErrno = errno;
    LogPrint("    clock_settime clock_id:='CLOCK_REALTIME=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'}   "
        "--> returnVal:='%d', errno:='%d'\n", CLOCK_REALTIME, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno);
    EXPECT_NE(returnVal, 0)
        << "ErrInfo: clock_settime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
    EXPECT_EQ(thisErrno, EINVAL)
        << "ErrInfo: clock_settime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME
        << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec
        << "'}   --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_ASCTIME_0100
* @tc.name       test asctime api
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testAscTime0100, TestSize.Level1) {
    struct tm timeptr;
    char *returnStr;
    int thisErrno;
	
    timeptr.tm_sec = 0;
    timeptr.tm_min = 10;
    timeptr.tm_hour = 10;
    timeptr.tm_mday = 9;
    timeptr.tm_mon = 7;
    timeptr.tm_year = 119;
    timeptr.tm_wday = 5;
    
    returnStr = asctime(&timeptr);
    thisErrno = errno;
    LogPrint("    asctime &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}'   "
        "--> returnStr:='%s'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, returnStr);
    EXPECT_STREQ("Fri Aug  9 10:10:00 2019\n", returnStr)
        << "ErrInfo: asctime &timeptr:='{timeptr.tm_year=" << timeptr.tm_year
        << " timeptr.tm_mon=" << timeptr.tm_mon << "' timeptr.tm_mday=" << timeptr.tm_mday
        << "}'   --> returnStr:='" << returnStr << "'";
    EXPECT_EQ(thisErrno, 0)
        << "ErrInfo: asctime &timeptr:='{timeptr.tm_year=" << timeptr.tm_year
        << " timeptr.tm_mon=" << timeptr.tm_mon << "' timeptr.tm_mday=" << timeptr.tm_mday
        << "}'   --> returnStr:='" << returnStr << "', errno:='" << thisErrno << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_CTIME_0100
* @tc.name       test ctime api
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testCtime0100, TestSize.Level1) {
    time_t curClock;
    char *returnStr;
	
    time(&curClock);
    returnStr = ctime(&curClock);
    LogPrint("    ctime &clock:='&clock'   --> returnStr:='%s'\n", returnStr);
    EXPECT_STRNE(NULL, returnStr)
        << "ErrInfo: ctime &clock:='&clock'   --> returnStr:='" << returnStr << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_DIFFTIME_0100
* @tc.name       test difftime api
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testDiffTime0100, TestSize.Level1) {
    time_t timeStart, timeEnd;
    double returnVal;
    
    time(&timeStart);
    sleep(1);
    time(&timeEnd);
	
    returnVal = difftime(timeEnd, timeStart);
    LogPrint("    difftime timeEnd:='%lld' timeStart:='%lld'   "
        "--> returnVal:='%f'\n", timeEnd, timeStart, returnVal);
    LogPrint("    sizeof timeEnd:='%d'   sizeof timeStart:='%d'\n", sizeof(timeEnd), sizeof(timeStart));
    EXPECT_GE(returnVal, 0)
        << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='"
        << timeStart << "'   --> returnVal:='" << returnVal << "'";
    EXPECT_LE(returnVal, 2)
        << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='"
        << timeStart << "'   --> returnVal:='" << returnVal << "'";
}

/**
* @tc.number     SUB_KERNEL_NDKAPI_TIME_TIMEGM_0100
* @tc.name       test timegm api
* @tc.desc       [C- SOFTWARE -0200]
* @tc.size       SMALL
* @tc.type       FUNC
*/
HWTEST_F(ActsTimeApiTest, testTimegm_0100, TestSize.Level1) {
    struct tm timeptr;
    time_t timeThis;
	
    timeptr.tm_sec = 0;
    timeptr.tm_min = 10;
    timeptr.tm_hour = 10;
    timeptr.tm_mday = 9;
    timeptr.tm_mon = 7;
    timeptr.tm_year = 119;
    timeptr.tm_wday = 5;
    
    timeThis = timegm(&timeptr);
    LogPrint("    timegm &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}'   "
        "--> return timeThis:='%lld'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, timeThis);

    EXPECT_GE(timeThis, 1)
        << "ErrInfo: timegm &timeptr:='{timeptr.tm_year=" << timeptr.tm_year
        << " timeptr.tm_mon=" << timeptr.tm_mon << " timeptr.tm_mday="
        << timeptr.tm_mday << "}'   --> return timeThis:='" << timeThis << "'";
}